Skip to content

Commit

Permalink
refactor: reduce file size (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode authored Feb 1, 2024
1 parent d091328 commit a5a45fc
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
import f, { writeFileSync as w } from 'fs'
import i from './index.js'

let a = process.argv[2]
let p, a, n, s, o, d

p = process
a = p.argv[2]

if (a == 'init') {
let p = 'package.json'
let s = f.readFileSync(p);
let d = JSON.parse(s)
; (d.scripts ||= {}).prepare = 'husky'
w('package.json', JSON.stringify(d, null, /\t/.test(s) ? '\t' : 2) + '\n')
process.stdout.write(i())
try { f.mkdirSync('.husky') } catch { }
w('.husky/pre-commit', process.env.npm_config_user_agent.split('/')[0] + ' test\n')
process.exit()
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] + ' test\n')
p.exit()
}

let d = c => console.error(`${c} command is deprecated`)
if (['add', 'set', 'uninstall'].includes(a)) { d(a); process.exit(1) }
d = c => console.error(`${c} command is deprecated`)
if (['add', 'set', 'uninstall'].includes(a)) { d(a); p.exit(1) }
if (a == 'install') d(a)

process.stdout.write(i(a == 'install' ? undefined : a))
p.stdout.write(i(a == 'install' ? undefined : a))

0 comments on commit a5a45fc

Please sign in to comment.