husky/bin.js

27 lines
687 B
JavaScript
Raw Permalink Normal View History

2024-01-25 09:49:33 +08:00
#!/usr/bin/env node
import f, { writeFileSync as w } from 'fs'
2024-07-17 23:41:58 +08:00
import i from './index.js'
2024-01-25 09:49:33 +08:00
2024-02-01 22:01:08 +08:00
let p, a, n, s, o, d
p = process
a = p.argv[2]
2024-01-25 09:49:33 +08:00
if (a == 'init') {
2024-02-01 22:01:08 +08:00
n = 'package.json'
s = f.readFileSync(n)
o = JSON.parse(s)
;(o.scripts ||= {}).prepare = 'husky'
w(n, JSON.stringify(o, 0, /\t/.test(s) ? '\t' : 2) + '\n')
p.stdout.write(i())
try { f.mkdirSync('.husky') } catch {}
w('.husky/pre-commit', (p.env.npm_config_user_agent?.split('/')[0] ?? 'npm') + ' test\n')
2024-02-01 22:01:08 +08:00
p.exit()
2024-01-25 09:49:33 +08:00
}
d = c => console.error(`husky - ${c} command is DEPRECATED`)
2024-02-01 22:01:08 +08:00
if (['add', 'set', 'uninstall'].includes(a)) { d(a); p.exit(1) }
2024-01-25 09:49:33 +08:00
if (a == 'install') d(a)
p.stdout.write(i(a == 'install' ? undefined : a))