Skip to content

Commit

Permalink
Replace lint-staged precommit script
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Nov 21, 2023
1 parent dfe3119 commit 7addeb3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 107 deletions.
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@
"*.json": "prettier --write",
"*.md": "prettier --write"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged --quiet --relative"
}
},
"eslintConfig": {
"root": true,
"extends": [
Expand All @@ -85,7 +80,6 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-tsdoc": "^0.2.17",
"graphql": "^16.6.0",
"husky-v4": "^4.3.8",
"lint-staged": "^13.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
Expand Down
88 changes: 0 additions & 88 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 7 additions & 13 deletions scripts/prepare.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
const path = require('path');
const fs = require('fs');

const hookSource = path.resolve(__dirname, '../node_modules/husky-v4/sh/husky.sh');
const hook = path.resolve(__dirname, '../.git/hooks/husky.sh');
const localHook = path.resolve(__dirname, '../.git/hooks/husky.local.sh');
const gitConfig = path.resolve(__dirname, '../.git/config');
const precommit = path.resolve(__dirname, '../.git/hooks/pre-commit');

let script = fs.readFileSync(hookSource, { encoding: 'utf-8' });
script = script.replace(`$(basename "$0")`, `$(basename "$0" .sh)`);
const hook = `
#!/bin/sh
pnpm exec lint-staged --quiet --relative
`.trim();

let config = fs.readFileSync(gitConfig, { encoding: 'utf-8' });
config = config.replace(/\s*hooksPath\s*=\s*\.husky\n?/g, '\n');

fs.writeFileSync(hook, script);
fs.writeFileSync(gitConfig, config);

fs.writeFileSync(localHook, 'packageManager=yarn\n' + 'cd "."\n');
fs.writeFileSync(precommit, hook);
fs.chmodSync(precommit, '755');

0 comments on commit 7addeb3

Please sign in to comment.