Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
♻️ grep package.json old-fashioned way
Browse files Browse the repository at this point in the history
This allows us to have a folder to folder ratio with dist <=> src
  • Loading branch information
JeromeFitz committed May 4, 2021
1 parent d7b0ecd commit 0911dc9
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ else
:
yarn pretty-quick --staged
exec < /dev/tty
node ./dist/src/cli.js --hook || true
node ./dist/cli.js --hook || true
fi

2 changes: 1 addition & 1 deletion bin/git-cz.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/* eslint-disable filenames/match-regex */
/* eslint-disable import/no-unassigned-import */

require('../dist/src/cli')
require('../dist/cli')
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@jeromefitz/git-cz",
"version": "8.0.0-canary.1",
"description": "Semantic emojified git commit, git-cz w/ gitflow branching.",
"main": "dist/src/cz.js",
"description": "git(moji)-cz => conventional commits, gitflow branching",
"main": "dist/cz.js",
"bin": {
"git-cz": "./bin/git-cz.js",
"gitcz": "./bin/git-cz.js"
Expand Down Expand Up @@ -38,10 +38,10 @@
],
"scripts": {
"branch": "git-cz --branch --allow-empty",
"build:binaries": "mkdirp binaries && pkg ./dist/src/cli.js --out-path binaries --targets node12-linux-x64,node12-macos-x64,node12-win-x64",
"build:binaries": "mkdirp binaries && pkg ./dist/cli.js --out-path binaries --targets node12-linux-x64,node12-macos-x64,node12-win-x64",
"build": "tsc",
"clean": "rimraf dist",
"dry:run": "yarn clean && tsc && node ./dist/src/cli",
"dry:run": "yarn clean && tsc && node ./dist/cli",
"gitmoji": "./scripts/gitmoji/gitmojiInit.sh && yarn lint-fix",
"lint-eslint": "eslint . --ext js,jsx,ts,tsx --max-warnings=0",
"lint-fix": "yarn prettier-fix && eslint . --ext js,jsx,ts,tsx --fix --max-warnings=0",
Expand Down Expand Up @@ -107,7 +107,7 @@
},
"config": {
"commitizen": {
"path": "./dist/src/cz.js"
"path": "./dist/cz.js"
}
}
}
47 changes: 47 additions & 0 deletions src/utils/getConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable global-require, import/no-dynamic-require, operator-linebreak */
import path from 'path'
import fs from 'fs'

const configFiles = ['package.json']

const findOverrides = (root) => {
const dir = root || process.cwd()

for (const file of configFiles) {
const filename = path.resolve(dir, file)

if (fs.existsSync(filename) && fs.statSync(filename).isFile()) {
return require(filename)
}
}

const parent = path.resolve(dir, '..')

if (parent !== dir) {
return findOverrides(parent)
}

const pkgFilename = path.join(dir, 'package.json')

if (fs.existsSync(pkgFilename)) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const changelog = require(pkgFilename).config.commitizen.changelog

if (changelog) {
return changelog
}
// eslint-disable-next-line no-empty
} catch (error) {}
}

return {}
}

const getConfig = (root) => {
const overrides = findOverrides(root)

return { ...overrides }
}

export default getConfig
16 changes: 14 additions & 2 deletions src/utils/parseArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
/* eslint-disable no-console */
/* eslint-disable id-length */
import minimist from 'minimist'
import pkg from '../../package.json'
import getConfig from './getConfig'
import getGitRootDir from './getGitRootDir'

let root
try {
root = getGitRootDir()
} catch (error) {
throw new Error('Could not find Git root folder')
}

const pkg = getConfig(root)

const helpScreen = `
${pkg.description}
> ${pkg.name}
> ${pkg.version}
> ${pkg.description}
Usage: git-cz [options]
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"outDir": "./dist",
"paths": {},
"noUnusedParameters": false, // @todo(lint)
"rootDir": ".",
"rootDir": "./src",
"strict": false,
"target": "ES6"
},
"extends": "@jeromefitz/codestyle/tsconfig.react.json",
"include": ["src/**/*.js", "src/**/*.ts", "package.json"],
"include": ["src/**/*.js", "src/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit 0911dc9

Please sign in to comment.