mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-02-14 17:49:53 +00:00
chore: move git hooks to js
This commit is contained in:
@@ -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...`);
|
||||
|
||||
12
_scripts/git-hooks-pre-commit.js
Executable file
12
_scripts/git-hooks-pre-commit.js
Executable 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
32
_scripts/tooling-init.js
Executable 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('');
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user