@ls-age/update-section
v0.5.0
Published
Update a section of a file
Downloads
112
Readme
@ls-age/update-section
Update a section of a file
Installation
Run npm install --save-dev @ls-age/update-section
as usual.
Usage
@ls-age/update-section
provides an easy way to update files that are party generated.
Example:
<!-- README.md -->
# My monorepo
## Packages
<!-- BEGIN packages -->
<!-- END packages -->
/* scripts/update-readme.js */
const Template = require('@ls-age/update-section');
// Update the packages list
const packages = [
{ name: 'First', description: 'My first package' },
{ name: 'Second', description: 'Another package' },
];
async function updateReadme() {
// Generate a list of packages
const packageList = packages.map((p) => `- **${p.name}** - ${p.description}`).join('\n');
// ...and write it to the readme file
await Template.updateSection('./README.md', 'packages', packageList);
}
updateReadme().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Running node scripts/update-readme.js
results in:
<!-- README.md -->
# My monorepo
## Packages
<!-- BEGIN packages -->
<!-- This section is generated, do not edit it! -->
- **First** - My first package
- **Second** - Another package
<!-- END packages -->
For a more advanced usage example, check out this script.
BTW: This readme was also created with @ls-age/update-section, check it out on GitHub.