feat(normalize-packages): generate README.md from USAGE.md
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
"exec-promise": "^0.7.0",
|
||||
"flow-bin": "^0.114.0",
|
||||
"globby": "^10.0.0",
|
||||
"handlebars": "^4.7.6",
|
||||
"husky": "^3.0.0",
|
||||
"jest": "^24.1.0",
|
||||
"lint-staged": "^9.5.0",
|
||||
|
||||
36
scripts/README.md.tpl
Normal file
36
scripts/README.md.tpl
Normal file
@@ -0,0 +1,36 @@
|
||||
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||
|
||||
# {{pkg.name}} [](https://travis-ci.org/vatesfr/xen-orchestra)
|
||||
|
||||
{{#if pkg.description}}
|
||||
> {{pkg.description}}
|
||||
{{/if}}
|
||||
|
||||
{{#unless pkg.private}}
|
||||
## Install
|
||||
|
||||
Installation of the [npm package](https://npmjs.org/package/{{pkg.name}}):
|
||||
|
||||
```
|
||||
> npm install --save {{pkg.name}}
|
||||
```
|
||||
{{/unless}}
|
||||
|
||||
## Usage
|
||||
|
||||
{{{usage}}}
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are _very_ welcomed, either on the documentation or on
|
||||
the code.
|
||||
|
||||
You may:
|
||||
|
||||
- report any [issue]({{pkg.bugs}})
|
||||
you've encountered;
|
||||
- fork and create a pull request.
|
||||
|
||||
## License
|
||||
|
||||
{{pkg.license}} © [{{pkg.author.name}}]({{pkg.author.url}})
|
||||
@@ -18,6 +18,10 @@ const deleteProperties = (object, property, properties) => {
|
||||
}
|
||||
}
|
||||
|
||||
const generateReadme = require('handlebars').compile(
|
||||
require('fs').readFileSync(`${__dirname}/README.md.tpl`, 'utf8')
|
||||
)
|
||||
|
||||
require('exec-promise')(() =>
|
||||
getPackages(true).map(({ dir, name, package: pkg, relativeDir }) => {
|
||||
// consider packages as private by default to avoid publishing them by mistake
|
||||
@@ -92,27 +96,26 @@ 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(
|
||||
readFile(`${dir}/USAGE.md`, 'utf8')
|
||||
.then(content =>
|
||||
writeFile(
|
||||
`${dir}/README.md`,
|
||||
content.replace(
|
||||
/\$\{([^}]+)\}/g,
|
||||
(_, path) => get(data, path, _) || _
|
||||
)
|
||||
generateReadme({
|
||||
pkg: {
|
||||
...pkg,
|
||||
author: {
|
||||
name: 'Vates SAS',
|
||||
url: 'https://vates.fr',
|
||||
},
|
||||
},
|
||||
usage: content.trim(),
|
||||
})
|
||||
)
|
||||
})
|
||||
)
|
||||
.catch(error => {
|
||||
console.error('Error while handling README', error)
|
||||
if (error.code !== 'ENOENT') {
|
||||
console.error('Error while handling README', error)
|
||||
}
|
||||
}),
|
||||
writeFile(`${dir}/package.json`, JSON.stringify(pkg, null, 2) + '\n'),
|
||||
unlink(`${dir}/.editorconfig`),
|
||||
|
||||
@@ -8244,7 +8244,7 @@ handle-thing@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e"
|
||||
integrity sha512-9Qn4yBxelxoh2Ow62nP+Ka/kMnOXRi8BXnRaUwezLNhqelnN49xKz4F/dPP8OYLxLxq6JDtZb2i9XznUQbNPTg==
|
||||
|
||||
handlebars@^4.0.6:
|
||||
handlebars@^4.0.6, handlebars@^4.7.6:
|
||||
version "4.7.6"
|
||||
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.6.tgz#d4c05c1baf90e9945f77aa68a7a219aa4a7df74e"
|
||||
integrity sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA==
|
||||
|
||||
Reference in New Issue
Block a user