Skip to content

Commit

Permalink
feat: upgrade husky hooks setup
Browse files Browse the repository at this point in the history
BREAKING CHANGE: husky hooks have now a new place where they live
  • Loading branch information
AVVS committed Oct 4, 2018
1 parent e02bee2 commit 3fd5dab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"scripts": {
"test": "./bin/cli.js test run",
"postinstall": "node ./scripts/setup-semantic-release.js",
"semantic-release": "semantic-release",
"commitmsg": "commitlint -e $GIT_PARAMS"
"semantic-release": "semantic-release"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -48,6 +47,8 @@
"glob": "^7.1.3",
"husky": "^1.1.0",
"is": "^3.2.1",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"ms-conf": "^3.3.0",
"npm-path": "^2.0.4",
"pino": "^5.6.3",
Expand All @@ -73,5 +74,10 @@
],
"jest": {
"testURL": "http://tester.local"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS"
}
}
}
16 changes: 9 additions & 7 deletions scripts/setup-semantic-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

const debug = require('debug')('makeomatic:deploy');
const path = require('path');
const get = require('lodash.get');
const set = require('lodash.set');
const fs = require('fs');

const isForced = process.argv.some(a => a === '--force');
Expand Down Expand Up @@ -49,7 +51,10 @@ function copyConfiguration(filename) {
function alreadyInstalled(scriptName, script, holder) {
const filename = clientPackageJsonFilename();
const pkg = JSON.parse(fs.readFileSync(filename));
if (!pkg[holder] || !pkg[holder][scriptName] || pkg[holder][scriptName] !== script) {
if (!get(pkg, holder)
|| !get(pkg, holder)[scriptName]
|| !get(pkg, holder)[scriptName] !== script
) {
return false;
}

Expand All @@ -60,19 +65,16 @@ function addPlugin(scriptName, script, holder) {
const filename = clientPackageJsonFilename();
const pkg = JSON.parse(fs.readFileSync(filename));

// default this to {}
if (!pkg[holder]) pkg[holder] = {};

pkg[holder][scriptName] = script;
set(pkg, `${holder}.${scriptName}`, script);
const text = `${JSON.stringify(pkg, null, 2)}\n`;
fs.writeFileSync(filename, text, 'utf8');
console.log(`✅ set ${holder}.${scriptName} to "${script}" in`, filename);
}

[
['semantic-release', 'semantic-release', 'scripts'],
['commitmsg', 'commitlint -e $GIT_PARAMS', 'scripts'],
['preparecommitmsg', './node_modules/@makeomatic/deploy/git-hooks/prepare-commit-msg $GIT_PARAMS', 'scripts'],
['commit-msg', 'commitlint -e $HUSKY_GIT_PARAMS', 'husky.hooks'],
['prepare-commit-msg', './node_modules/@makeomatic/deploy/git-hooks/prepare-commit-msg $HUSKY_GIT_PARAMS', 'husky.hooks'],
].forEach((input) => {
const [scriptName, name, holder] = input;
if (!alreadyInstalled(scriptName, name, holder)) {
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4630,6 +4630,11 @@ lodash.escaperegexp@^4.1.2:
resolved "https://registry.yarnpkg.com/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz#64762c48618082518ac3df4ccf5d5886dae20347"
integrity sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=

lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=

lodash.isplainobject@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"
Expand Down Expand Up @@ -4670,6 +4675,11 @@ lodash.reduce@^4.6.0:
resolved "https://registry.yarnpkg.com/lodash.reduce/-/lodash.reduce-4.6.0.tgz#f1ab6b839299ad48f784abbf476596f03b914d3b"
integrity sha1-8atrg5KZrUj3hKu/R2WW8DuRTTs=

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
integrity sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=

[email protected]:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d"
Expand Down

0 comments on commit 3fd5dab

Please sign in to comment.