feat(normalize-packages): replace vars in READMEs

This commit is contained in:
Julien Fontanet
2019-11-15 11:25:51 +01:00
parent 5568be91d2
commit a8122f9add
6 changed files with 42 additions and 18 deletions

View File

@@ -1,8 +1,9 @@
#!/usr/bin/env node
const get = require('lodash/get')
const isEmpty = require('lodash/isEmpty')
const sortedObject = require('sorted-object')
const { getPackages, writeFile, unlink } = require('./utils')
const { getPackages, readFile, writeFile, unlink } = require('./utils')
const deleteProperties = (object, property, properties) => {
const nestedObject = object[property]
@@ -86,6 +87,28 @@ require('exec-promise')(() =>
}
return Promise.all([
readFile(`${dir}/README.md`, 'utf8')
.then(content => {
const data = {
pkg: {
...pkg,
author: {
name: 'Vates SAS',
url: 'https://vates.fr',
},
},
}
return writeFile(
`${dir}/README.md`,
content.replace(
/\$\{([^}]+)\}/g,
(_, path) => get(data, path, _) || _
)
)
})
.catch(error => {
console.error('Error while handling README', error)
}),
writeFile(`${dir}/package.json`, JSON.stringify(pkg, null, 2) + '\n'),
unlink(`${dir}/.editorconfig`),
unlink(`${dir}/.eslintrc.js`),