From a5a45fc3ce4d9375396966ebeeea14ba87f47396 Mon Sep 17 00:00:00 2001 From: typicode Date: Thu, 1 Feb 2024 15:01:08 +0100 Subject: [PATCH] refactor: reduce file size (#1377) --- bin.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/bin.js b/bin.js index 275f026f2..2f1c3be39 100755 --- a/bin.js +++ b/bin.js @@ -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)) \ No newline at end of file