UNPKG

695 BJavaScriptView Raw
1#!/usr/bin/env node
2import f, { writeFileSync as w } from 'fs'
3import i from './index.js'
4
5let a = process.argv[2]
6
7if (a == 'init') {
8 let p = 'package.json'
9 let d = JSON.parse(f.readFileSync(p))
10 ; (d.scripts ||= {}).prepare = 'husky'
11 w('package.json', JSON.stringify(d, null, /\t/.test() ? '\t' : 2) + '\n')
12 process.stdout.write(i())
13 try { f.mkdirSync('.husky') } catch { }
14 w('.husky/pre-commit', process.env.npm_config_user_agent.split('/')[0] + ' test\n')
15 process.exit()
16}
17
18let d = c => console.error(`${c} command is deprecated`)
19if (['add', 'set', 'uninstall'].includes(a)) { d(a); process.exit(1) }
20if (a == 'install') d(a)
21
22process.stdout.write(i(a == 'install' ? undefined : a))
\No newline at end of file