-
Notifications
You must be signed in to change notification settings - Fork 17
Fetch readme and generate Markdown for CLI flags at build time #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch readme and generate Markdown for CLI flags at build time #113
Conversation
|
The rich text headings + monospace blocks is actually quite good. It makes the docs scannable while preserving the exact CLI output format. I'd keep this. About the em dash issue, a few alternatives come to mind:
Have you tried to use Astro's integration system instead? Create a proper Astro integration that runs during the build: // astro.config.mjs
import { generateCliDocs } from './src/integrations/cli-docs.ts';
export default defineConfig({
integrations: [
generateCliDocs(),
]
});// src/integrations/cli-docs.ts
import type { AstroIntegration } from 'astro';
import { generateCliOptionsMarkdown } from '../fetchReadme';
import { writeFileSync, readFileSync, rmSync } from 'node:fs';
export function generateCliDocs(): AstroIntegration {
return {
name: 'generate-cli-docs',
hooks: {
'astro:config:setup': async () => {
const docTemplateFile = "src/content/docs/guides/_cli.md";
const docOutputFile = docTemplateFile.replace('_', '');
rmSync(docOutputFile, { force: true });
const usageText = await generateCliOptionsMarkdown();
const docTemplateText = readFileSync(docTemplateFile, "utf-8");
const docOutput = docTemplateText.replace(
'README-OPTIONS-PLACEHOLDER',
usageText
);
writeFileSync(docOutputFile, docOutput);
}
}
};
}The main benefit would be that the dev server would regenerate the docs on restart, and you wouldn't need to manually run a script to update the docs. |
|
@mre good point. I hadn't considered using Astro's integration API to add this functionality. Because you mentioned that, I started going through community made integrations and came across this https://github.com/natemoo-re/astro-remote#README which enables "render remote HTML or Markdown content in Astro with full control over the output." what do you think? |
|
I've made changes following @mre's suggestions. We disable smart dashes across the entire site and we use a custom integration to generate the file. The integration code is basically the same as mre's suggestion, but we have to add addWatchFile to reload when the md file is changed. |
|
@katrinafyi Cool, I really like that. Rebasing on top of master should fix the link check errors. |
|
I've added some colourful boxes. However, it's pretty naive and they're not quite valid examples - they still use placeholder variables and, in the case where a flag requires another, it does not show the flags being used together. The more I work with this, the more I think that it would be nice if the docs site shows the CLI help as markdown formatted text. Initially, I was reluctant because it means the CLI help text would have to be written with a particular formatting which is only useful to the website. But maybe it's not so bad because it's already most of the way there and the hard wrapping of lines is already a requirement with the code block approach. I'll investigate. The CI pipeline that builds astro is failing at the astro build step. Idk why because the package should exist as a transitive dependency, and it works on my machine with an |
This reverts commit 0936b31.
that this is generally nicer to read. However, this means that the website text is rendered from the same text as the CLI --help. The website understands Markdown, but the CLI does not (obviously) so we have to be careful. I would suggest that when writing help, the focus should be on readability within the *console*. This means that while Markdown can be used, it should be limited to syntax which is unobtrusive in raw text. Raw text is still the main format which the help text will be rendered in. Personally, these would be okay: - single `*` or `_` for emphasis (with preference for `*`) - single backticks for inline code - four space indentation for code blocks - bullet and numbered lists Imo, these would *not* be okay, because they appear too jarring in plain text: - code blocks with triple backtick fences. this includes any astro-specific asides and the like. - link syntax with `[link](https://url)` - bold when used for subheadings like `**Note**:` I think this is a good compromise which lets the same text be usable for both CLI --help and the website's rich text HTML.
|
Update to my last comment, I've gone ahead and made it markdown text rather than code blocks. See commit for commentary de6c2a8
This generally works fine and looks nice, aside from --files-from: If this is something we want, I'll PR to tweak the files-from help text. |
|
Check if |
|
It exists in my node modules after I use npm ci. Should I be using npm or pnpm? Is there a difference? Idk pnpm, so it would be good to have some commands in the readme. |
|
Use PNPM. I've added back the commands in the readme. |
|
I really like the new formatting! |
Co-authored-by: Matthias Endler <matthias@endler.dev>
|
Greatly appreciated PR, this really helps to keep our documentation up to date! |





It looks like this:
This implementation works but there are fun details to think about:
Todo: