Skip to content

Latest commit

 

History

History
44 lines (37 loc) · 1.38 KB

readme.md

File metadata and controls

44 lines (37 loc) · 1.38 KB

Readme Tool

Table of Contents

Purpose of the readme Tool

The readme package is meant to facilitate automated creation and updates for readme files. It's a useful tool to call via a yarn script, for example.

Example Programmatic Usage

Modifying an Existing Readme

import { Readme } from './src/readme/readme';
const content = `
# Test Readme
This is a demonstration readme for the ts-tools readme tool.
## Contributing
Please submit a pull request.
`;
// read in and parse the readme into content blocks
const readme = new Readme(content);
const prLink = '';
// Add a contributing block if it doesn't exist
if (!readme.getSection(/^ *#* Contributing/)) {
  readme.setSection(
    '## Contributing',
    'Please submit a pull request <a href="https://github.com/luddites-me/ts-tools/pulls">here</a>.',
  );
}
// Add a License block if it doesn't exist
if (!readme.getSection(/^# License/)) {
  readme.appendBlock(Readme.getLicenseBlock());
}
// Generate a Table of Contents from the existing readme and insert it the title.
if (!readme.getSection(/^ *#* Table of Contents/)) {
  readme.insertAfter(/# Test Readme/, readme.getTocBlock());
}