Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 60 additions & 62 deletions README.md

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions npm/load-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Writes the table of options in the README from the config of the CLI, so the README and the help say the same.
// Run by `yarn prerelease`.
import fs from 'fs';
import path from 'path';
import {argInfo} from '../../argmate/src/argMate.ts';
import {argConfig} from '../src/options.ts';

const re = {
// From the first row under the headline Usage to the next headline, as a row can break over lines
optionsTable: /(\n## Usage\n[^]*?\n)\|[^]*?\n(?=\n## )/,
};

const file = path.join(import.meta.dir, '..', 'README.md');
const help = argInfo({config: argConfig, format: 'markdown', showIntro: false, showOutro: false});

// Only the table, as the README has its own headline for it
const table = help.slice(help.indexOf('|')).trim() + '\n';

const readme = fs.readFileSync(file, 'utf8');
if (!re.optionsTable.test(readme)) {
throw new Error('No table of options under the headline Usage in README.md');
}

// A function, as the table has `$1` and `$&` that a replacement string would read
fs.writeFileSync(
file,
readme.replace(re.optionsTable, (all, before) => before + table)
);
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
"test-cli-bun": "AGENT=1 bash test/runtime/bun.sh",
"test-cli-only": "AGENT=1 bash test/cli/run.sh && bash test/cli/run.ai.sh ",
"test-ci": "yarn test-format && yarn build && yarn test-cli && yarn test-js && yarn test-minify",
"test-speed": "bash test/speed/run.sh",
"rebase": "yarn is-git-clean && git fetch && git rebase origin/main",
"load-options": "# rr -h | rr 'Options:(.+)Examples:' _ -ms | rr '\\n {26,}|\\n\\n *' ' ' | rr \"'\" '`' | rr '^ (-.+?), (--[^ ]+) *' '`€1` | **`€2`** ' | rr '(^---- . ----).+?(## Good to know)' '€1 + nl + pipe + nl + nl + €2' readme.md -jspT",
"load-options": "bun npm/load-options.ts",
"test-format": "biome format || (echo 'Please correct file formatting using `yarn format` and try again.' && exit 1)",
"format": "biome format --write",
"is-git-clean": "(git diff --quiet --exit-code --cached && git diff --quiet --exit-code) || (echo Please commit or stash changes && exit 1)",
Expand Down
Loading
Loading