Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add prepare hook for husky install #196

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}