Permalink
Browse files

fix(install): be a bit smarter about adding to attributes files

  • Loading branch information...
zkat committed Dec 5, 2017
1 parent 46e0442 commit a046cbce21c0037ce25db26322259450990cdea3
Showing with 17 additions and 6 deletions.
  1. +17 −6 index.js
@@ -105,12 +105,23 @@ function install (argv) {
: ''}"`
)
mkdirp.sync(path.dirname(attrFile))
fs.appendFileSync(
attrFile,
'\n' +
argv.files.map(f => `${f} merge=${argv.driverName}`).join('\n') +
'\n'
)
let attrContents = ''
try {
const RE = new RegExp(`.* merge\\s*=\\s*${argv.driverName}$`)
attrContents = fs
.readFileSync(attrFile, 'utf8')
.split(/\r?\n/)
.filter(line => !line.match(RE))
.join('\n')
} catch (e) {}
if (attrContents && !attrContents.match(/[\n\r]$/g)) {
attrContents = '\n'
}
attrContents += argv.files
.map(f => `${f} merge=${argv.driverName}`)
.join('\n')
attrContents += '\n'
fs.writeFileSync(attrFile, attrContents)
console.error(
'npm-merge-driver:',
argv.driverName,

0 comments on commit a046cbc

Please sign in to comment.