@ls-age/update-section
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

@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.

Package Sidebar

Install

npm i @ls-age/update-section

Weekly Downloads

64

Version

0.5.0

License

MIT

Unpacked Size

24.6 kB

Total Files

17

Last publish

Collaborators

  • lukashechenberger
  • lhechenberger