chore: move git hooks to js

This commit is contained in:
AJ ONeal
2023-10-12 04:40:25 +00:00
parent db5113e025
commit 73af48eb9d
4 changed files with 49 additions and 3 deletions

View File

@@ -27,7 +27,7 @@ async function copyScripts() {
var gitHooksDir = Path.join(gitDir, 'hooks');
var src = Path.join(scriptsDir, 'git-hooks-pre-commit');
var src = Path.join(scriptsDir, 'git-hooks-pre-commit.js');
var dst = Path.join(gitHooksDir, 'pre-commit');
console.info(`[git-hooks] Checking for pre-commit hooks...`);

View File

@@ -0,0 +1,12 @@
#!/usr/bin/env node
'use strict';
var Process = require('child_process');
var procOpts = { stdio: 'inherit' };
var commands = ['npm run fmt', 'npm run lint', 'npm run test'];
for (let cmd of commands) {
console.info(`[pre-commit] exec: ${cmd}`);
Process.execSync(cmd, procOpts);
}

32
_scripts/tooling-init.js Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env node
'use strict';
var Cmd = require('node:child_process');
var Os = require('node:os');
var procOpts = { stdio: 'inherit' };
var commands = ['shfmt --version', 'shellcheck --version'];
for (let cmd of commands) {
console.info(`[tooling-init] checking for '${cmd}':`);
try {
Cmd.execSync(cmd, procOpts);
} catch (e) {
// ignore e
printInstallHelp(cmd);
process.exit(1);
}
}
function printInstallHelp(cmd) {
console.error('');
console.error('ERROR');
console.error(` could not run '${cmd}'`);
console.error('POSSIBLE FIX');
if (/^win/i.test(Os.platform())) {
console.error(` curl.exe https://webi.ms/${cmd} | powershell`);
} else {
console.error(` curl -fsS https://webi.sh/${cmd} | sh`);
}
console.error('');
}

View File

@@ -7,13 +7,15 @@
"scripts": {
"fmt": "npm run prettier && npm run shfmt",
"lint": "npm run shellcheck && npm run jshint",
"prepare": "node _scripts/git-hooks-init.js",
"prepare": "npm run tooling-init && npm run git-hooks-init",
"test": "node _webi/test.js ./node/",
"----": "------------------------------------",
"git-hooks-init": "node ./_scripts/git-hooks-init.js",
"jshint": "npx -p jshint@2.x -- jshint -c ./.jshintrc --exclude 'node_modules/**/*' */*.js */*/*.js",
"prettier": "npx -p prettier@3.x -- prettier -w '**/*.{js,md,html}'",
"shellcheck": "shellcheck -s sh -S style --exclude=SC2154,SC2034 */*.sh",
"shfmt": "shfmt -w -i 4 -sr -ci -s ./"
"shfmt": "shfmt -w -i 4 -sr -ci -s ./",
"tooling-init": "node ./_scripts/tooling-init.js"
},
"repository": {
"type": "git",