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

perf(husky-upgrade): don't create husky config if no hooks exist #359

Merged
merged 2 commits into from
Sep 27, 2018
Merged
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
11 changes: 8 additions & 3 deletions src/upgrader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,28 @@ export default function upgrade(cwd: string) {
)
}

// Create empty husky.hooks field
pkg.husky = { hooks: {} }
const hooks: IHookMap = {}

// Loop trhough hooks and move them to husky.hooks
Object.keys(hookList).forEach(name => {
const script = pkg.scripts[name]
if (script) {
delete pkg.scripts[name]
const newName = hookList[name]
pkg.husky.hooks[newName] = script.replace(
hooks[newName] = script.replace(
/\bGIT_PARAMS\b/g,
'HUSKY_GIT_PARAMS'
)
console.log(`moved scripts.${name} to husky.hooks.${newName}`)
}
})

if (Object.keys(hooks).length) {
pkg.husky = { hooks }
} else {
console.log('no hooks found')
}

// Update package.json
fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`, 'utf-8')
console.log(`husky > done`)
Expand Down