Files
husky/scripts/replace-script-path.js
T
typicodeandGitHub 29feb2d188 v1.0.0-rc.14 (#301)
Merging dev branch back to master 🎉
2018-09-22 01:20:22 +02:00

23 lines
676 B
JavaScript

const fs = require('fs')
const path = require('path')
module.exports = function replaceScriptPath(newPath) {
const regExp = /scriptPath="(.*)"/
fs.readdirSync('.git/hooks')
.filter(filename => path.extname(filename) !== '.sample')
.map(filename => {
console.log('devinstall: update', filename)
const absoluteFilename = path.join('.git/hooks', filename)
const data = fs.readFileSync(absoluteFilename, 'utf-8')
if (!regExp.test(data)) {
throw new Error("Can't find scriptPath")
}
const updatedData = data.replace(regExp, `scriptPath="${newPath}"`)
fs.writeFileSync(absoluteFilename, updatedData)
})
}