Skip to content

Commit

Permalink
husky-upgrade: don't create husky config if no hooks exist (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s authored and typicode committed Sep 27, 2018
1 parent ee39cf9 commit 1aac5c3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/upgrader/index.ts
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

0 comments on commit 1aac5c3

Please sign in to comment.