Skip to content

Commit

Permalink
Merge pull request finos#196 from vaibssingh/fix/188-add-prepare-hook
Browse files Browse the repository at this point in the history
fix: add prepare hook for husky install
  • Loading branch information
JamieSlome committed Jul 10, 2023
2 parents 95d27fc + 0a1b1f7 commit d3f4ea0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"server-test": "mocha --exit",
"test": "mocha --exit",
"eject": "react-scripts eject",
"preinstall": "npx husky install"
"prepare": "node ./scripts/prepare.js"
},
"author": "Paul Groves",
"license": "Apache-2.0",
Expand Down
41 changes: 41 additions & 0 deletions scripts/prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// =======
// Import.
// =======

const { execSync } = require('child_process');
const { existsSync } = require('fs');

// ===========
// File paths.
// ===========

const FILE_COMMIT = './.husky/commit-msg';
const FILE_HUSKY = './.husky/_/husky.sh';

// =========
// Commands.
// =========

const COMMIT_MSG_STRING = `'npx --no -- commitlint --edit $'{1}''`
const CLI_COMMIT = `npx husky add .husky/commit-msg ${COMMIT_MSG_STRING}`;
const CLI_HUSKY = 'npx husky install';

// ==============
// Husky install.
// ==============

// this will create .husky/_/husky.sh if it does not yet exist.
if (!existsSync(FILE_HUSKY)) {
global.console.log(CLI_HUSKY);
execSync(CLI_HUSKY);
}

// ====================
// Add pre-commit hook.
// ====================

// this will create .husky/commit-msg if it does not yet exist.
if (!existsSync(FILE_COMMIT)) {
global.console.log(CLI_COMMIT);
execSync(CLI_COMMIT);
}

0 comments on commit d3f4ea0

Please sign in to comment.