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

Commit

Permalink
Merge pull request #106 from mamoruuu/feat/husky
Browse files Browse the repository at this point in the history
feat: git hooks integration
  • Loading branch information
streamich committed Jan 16, 2020
2 parents b56800a + 2519d1c commit 1512b64
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 15 deletions.
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

17 changes: 16 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const {spawn} = require('child_process');
const fs = require('fs');
const {join} = require('path');
const shellescape = require('any-shell-escape');
const minimist = require('minimist');
const signale = require('signale');
const createState = require('./createState');
const runInteractiveQuestions = require('./runInteractiveQuestions');
const formatCommitMessage = require('./formatCommitMessage');
const getGitRootDir = require('./util/getGitRootDir');

// eslint-disable-next-line no-process-env
const executeCommand = (command, args = [], env = process.env) => {
Expand All @@ -31,7 +34,7 @@ const main = async () => {
params[arg] = true;
}

const {'dry-run': isDryRun, ...passThroughParams} = params;
const {'dry-run': isDryRun, hook: isHook, ...passThroughParams} = params;

if (isDryRun) {
// eslint-disable-next-line no-console
Expand All @@ -42,6 +45,18 @@ const main = async () => {

const message = formatCommitMessage(state);

/**
* @author https://github.com/oxyii
* @see https://github.com/streamich/git-cz/issues/79
*/
if (isHook) {
const commitMsgFile = join(getGitRootDir(), '.git', 'COMMIT_EDITMSG');

fs.writeFileSync(commitMsgFile, message);
// eslint-disable-next-line no-process-exit
process.exit(0);
}

const appendedArgs = [];

// eslint-disable-next-line guard-for-in
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"build:readme": "mmarkdown",
"build:binaries": "mkdirp binaries && pkg lib/cli.js --out-path binaries",
"test": "mocha",
"precommit": "yarn lint",
"semantic-release": "semantic-release",
"eslint": "eslint lib/*.js"
},
Expand All @@ -39,7 +38,7 @@
"commitizen": "2.10.1",
"eslint": "4.19.1",
"eslint-config-mailonline": "9.0.0",
"husky": "0.14.3",
"husky": "^4.0.10",
"inquirer": "6.5.2",
"inquirer-list-search-prompt": "^1.0.2",
"minimist": "1.2.0",
Expand All @@ -50,6 +49,12 @@
"signale": "1.4.0",
"word-wrap": "1.2.3"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint",
"prepare-commit-msg": "exec < /dev/tty && node ./lib/cli.js --hook || true"
}
},
"config": {
"commitizen": {
"path": "./dist/cz.js"
Expand Down
54 changes: 43 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2726,7 +2726,7 @@ find-up@^2.0.0, find-up@^2.1.0:
dependencies:
locate-path "^2.0.0"

find-up@^4.1.0:
find-up@^4.0.0, find-up@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19"
dependencies:
Expand Down Expand Up @@ -3377,13 +3377,19 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"

husky@0.14.3:
version "0.14.3"
resolved "https://registry.yarnpkg.com/husky/-/husky-0.14.3.tgz#c69ed74e2d2779769a17ba8399b54ce0b63c12c3"
husky@^4.0.10:
version "4.0.10"
resolved "https://registry.yarnpkg.com/husky/-/husky-4.0.10.tgz#659b52c404d3163b943a73f6c1d454708c0226d8"
integrity sha512-Ptm4k2DqOwxeK/kzu5RaJmNRoGvESrgDXObFcZ8aJZcyXyMBHhM2FqZj6zYKdetadmP3wCwxEHCBuB9xGlRp8A==
dependencies:
is-ci "^1.0.10"
normalize-path "^1.0.0"
strip-indent "^2.0.0"
chalk "^3.0.0"
ci-info "^2.0.0"
cosmiconfig "^6.0.0"
opencollective-postinstall "^2.0.2"
pkg-dir "^4.2.0"
please-upgrade-node "^3.2.0"
slash "^3.0.0"
which-pm-runs "^1.0.0"

iconv-lite@^0.4.17, iconv-lite@~0.4.13:
version "0.4.23"
Expand Down Expand Up @@ -5156,10 +5162,6 @@ normalize-package-data@~2.4.0:
semver "2 || 3 || 4 || 5"
validate-npm-package-license "^3.0.1"

normalize-path@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-1.0.0.tgz#32d0e472f91ff345701c15a8311018d3b0a90379"

normalize-path@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9"
Expand Down Expand Up @@ -5687,6 +5689,11 @@ onetime@^5.1.0:
dependencies:
mimic-fn "^2.1.0"

opencollective-postinstall@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz#5657f1bede69b6e33a45939b061eb53d3c6c3a89"
integrity sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw==

opencollective@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/opencollective/-/opencollective-1.0.3.tgz#aee6372bc28144583690c3ca8daecfc120dd0ef1"
Expand Down Expand Up @@ -6168,9 +6175,17 @@ pkg-dir@^1.0.0:
dependencies:
find-up "^1.0.0"

pkg-dir@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
integrity sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==
dependencies:
find-up "^4.0.0"

pkg-fetch@^2.6.4:
version "2.6.4"
resolved "https://registry.yarnpkg.com/pkg-fetch/-/pkg-fetch-2.6.4.tgz#0faac4c4ae9668e1daf9819180606966a5e33f96"
integrity sha512-4j4jiuo6RRIuD9e9xUE6OQYnIkQCArZjkHXNYsSJjxhJeiHE16MA+rENMblvGLbeWsTY3BPfcYVCGFXzpfJetA==
dependencies:
"@babel/runtime" "^7.7.5"
byline "^5.0.0"
Expand Down Expand Up @@ -6202,6 +6217,13 @@ pkg@4.4.2:
resolve "^1.13.1"
stream-meter "^1.0.4"

please-upgrade-node@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942"
integrity sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==
dependencies:
semver-compare "^1.0.0"

pluralize@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
Expand Down Expand Up @@ -6929,6 +6951,11 @@ semantic-release@15.13.31:
signale "^1.2.1"
yargs "^15.0.1"

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
integrity sha1-De4hahyUGrN+nvsXiPavxf9VN/w=

semver-diff@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/semver-diff/-/semver-diff-2.1.0.tgz#4bbb8437c8d37e4b0cf1a68fd726ec6d645d6d36"
Expand Down Expand Up @@ -7957,6 +7984,11 @@ which-module@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"

which-pm-runs@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/which-pm-runs/-/which-pm-runs-1.0.0.tgz#670b3afbc552e0b55df6b7780ca74615f23ad1cb"
integrity sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs=

which@1, which@1.3.1, which@^1.2.12, which@^1.2.9, which@^1.3.0, which@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
Expand Down

0 comments on commit 1512b64

Please sign in to comment.