Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added package.json formatting check #1493

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ docs/.vitepress/dist
docs/.env
docs/sponsorkit/.cache.json
docs/sponsorkit/sponsors.json
docs/sponsorkit/sponsors.png
docs/sponsorkit/sponsors.png
.vscode/
1 change: 1 addition & 0 deletions .husky/V7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./test.sh
npm test
11 changes: 8 additions & 3 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ a = p.argv[2]

if (a == 'init') {
n = 'package.json'
s = f.readFileSync(n)
s = f.readFileSync(n, 'utf8')
o = JSON.parse(s)

const indentMatch = s.match(/^[\t ]+/m)
const indent = indentMatch ? indentMatch[0].length : 2

;(o.scripts ||= {}).prepare = 'husky'
w(n, JSON.stringify(o, 0, /\t/.test(s) ? '\t' : 2) + '\n')
w(n, JSON.stringify(o, null, indent) + '\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')
Expand All @@ -23,4 +28,4 @@ d = c => console.error(`${c} command is DEPRECATED`)
if (['add', 'set', 'uninstall'].includes(a)) { d(a); p.exit(1) }
if (a == 'install') d(a)

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