Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate updating the README's usage section
- Loading branch information
1 parent
7ef2e07
commit 6d0b5e2
Showing
3 changed files
with
62 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { options } = require('../lib/options') | ||
|
||
const generateMarkdown = (options) => { | ||
const tableRows = options.map((option) => { | ||
const env = option[1] ? `\`${option[1] || ''}\`` : '' | ||
return `|\`${option[0]}\`|${env}|${option[2] || ''}|` | ||
}) | ||
return [ | ||
`|Options|Environment variable|Description|`, | ||
`|---|---|---|` | ||
].concat(tableRows).join('\n') | ||
} | ||
|
||
const readmeFilename = path.join(__dirname, '../README.md') | ||
const README = fs.readFileSync(readmeFilename).toString() | ||
|
||
const updatedText = ` | ||
\`\`\` | ||
Usage: maildev [options] | ||
\`\`\` | ||
${generateMarkdown(options)} | ||
` | ||
|
||
const updatedREADME = README.replace(/(## Usage)(.|\n)+(\n## API)/, `$1${updatedText}$3`) | ||
|
||
fs.writeFileSync(readmeFilename, updatedREADME) | ||
|
||
console.log(`Successfully updated ${readmeFilename}`) |