Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Oct 30, 2023
1 parent 5a88c05 commit 958dadc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 966 deletions.
13 changes: 12 additions & 1 deletion bin.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#!/usr/bin/env node
import f, { writeFileSync as w } from 'fs'
import i from './index.js'

let d = c => console.error(`${c} command is deprecated`)
let a = process.argv[2]
if (a == 'init') {
let p = process.env.npm_package_json
let d = JSON.parse(f.readFileSync(p))
d.scripts.prepare = 'husky'
w('package.json', JSON.stringify(d, null, /\t/.test() ? '\t' : 2))
process.stdout.write(i())
w('.husky/pre-commit', process.env.npm_config_user_agent.split('/')[0] + ' test')
process.exit()
}
if (['add', 'set', 'uninstall'].includes(a)) { d(a); process.exit(1) }
if (a == 'install') d(a)
process.stdout.write(i(a == 'install' ? undefined : a))
process.stdout.write(i(a == 'install' ? undefined : a))
17 changes: 8 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ export default (d = '.husky') => {
if (d.includes('..')) throw '.. not allowed'
if (!f.existsSync('.git')) return `.git can't be found`

let _ = p.join(d, '_')
let { status: s, stderr: e } = c.spawnSync('git', ['config', 'core.hooksPath', _])
let _ = (x = '') => p.join(d, '_', x)
let { status: s, stderr: e } = c.spawnSync('git', ['config', 'core.hooksPath', _()])
if (s == null) return 'git command not found'
if (s) return '' + e

f.mkdirSync(_, { recursive: true })
process.chdir(_)
f.writeFileSync('.gitignore', '*')
f.copyFileSync(new URL('husky.sh', import.meta.url), 'h')
l.forEach(h => f.writeFileSync(h, `#!/usr/bin/env sh\n. "\${0%/*}/h"`, { mode: 0o755 }))
f.writeFileSync('husky.sh', '')
f.mkdirSync(_(), { recursive: true })
f.writeFileSync(_('.gitignore'), '*')
f.copyFileSync(new URL('husky.sh', import.meta.url), _('h'))
l.forEach(h => f.writeFileSync(_(h), `#!/usr/bin/env sh\n. "\${0%/*}/h"`, { mode: 0o755 }))
f.writeFileSync(_('husky.sh'), '')
return ''
}
}
Loading

0 comments on commit 958dadc

Please sign in to comment.