diff --git a/_scripts/git-hooks-init.js b/_scripts/git-hooks-init.js index 49705f1..418b708 100755 --- a/_scripts/git-hooks-init.js +++ b/_scripts/git-hooks-init.js @@ -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...`); diff --git a/_scripts/git-hooks-pre-commit.js b/_scripts/git-hooks-pre-commit.js new file mode 100755 index 0000000..ed3fa50 --- /dev/null +++ b/_scripts/git-hooks-pre-commit.js @@ -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); +} diff --git a/_scripts/tooling-init.js b/_scripts/tooling-init.js new file mode 100755 index 0000000..75477fd --- /dev/null +++ b/_scripts/tooling-init.js @@ -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(''); +} diff --git a/package.json b/package.json index 5f8d509..a0350f7 100644 --- a/package.json +++ b/package.json @@ -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",