11import assert from "node:assert" ;
2- import { readFileSync , realpathSync , rmSync , writeFileSync } from "node:fs" ;
3- import { basename , dirname , join } from "node:path" ;
4- import type { AstroIntegration } from "astro" ;
5- import { LYCHEE_VERSION } from "./lychee-version" ;
6-
7- // https://raw.githubusercontent.com/lycheeverse/lychee/master/README.md
8- const url = `https://raw.githubusercontent.com/lycheeverse/lychee/refs/tags/${ LYCHEE_VERSION } /README.md` ;
9-
10- const TEMPLATE = "README-OPTIONS-PLACEHOLDER" ;
2+ import { versionNote as versionGenerationNote } from "./generate" ;
113
124function extractHelpFromReadme ( readme : string ) {
135 const [ , section ] = readme . split ( / # # # C o m m a n d l i n e P a r a m e t e r s / , 2 ) ;
@@ -50,12 +42,7 @@ function* generateMarkdown(lines: string[]) {
5042 yield "```bash" ;
5143 yield line . replace ( / ^ U s a g e : / , "" ) ;
5244 yield "```" ;
53- yield `
54- :::note
55- This page is up-to-date as of
56- [${ LYCHEE_VERSION } ](https://github.com/lycheeverse/lychee/releases/tag/${ LYCHEE_VERSION } ).
57- :::
58- ` ;
45+ yield versionGenerationNote ( ) ;
5946 } else if ( ( match = line . match ( headingRegex ) ) ) {
6047 yield `## ${ match [ 1 ] } ` ;
6148 } else if ( ( match = line . match ( optionRegex ) ) ) {
@@ -82,12 +69,9 @@ This page is up-to-date as of
8269}
8370// biome-ignore-end lint/suspicious/noAssignInExpressions: using assignment expressions for regex match is conventional
8471
85- export async function generateCliOptionsMarkdown ( ) {
86- const readme = await fetch ( url ) ;
87- assert ( readme . ok , `${ readme . status } when fetching ${ url } ` ) ;
88-
89- const rawUsageText = extractHelpFromReadme ( await readme . text ( ) ) ;
90- const usageText = [ ...generateMarkdown ( splitLines ( rawUsageText ) ) ] . join ( "\n" ) ;
72+ export async function generate ( readmeContents : string ) {
73+ const rawHelpText = extractHelpFromReadme ( readmeContents ) ;
74+ const usageText = [ ...generateMarkdown ( splitLines ( rawHelpText ) ) ] . join ( "\n" ) ;
9175
9276 assert (
9377 usageText . match ( "\n## Options\n" ) ,
@@ -108,37 +92,3 @@ export async function generateCliOptionsMarkdown() {
10892
10993 return usageText ;
11094}
111-
112- export function generateCliOptionsIntegration (
113- templatePath : string ,
114- ) : AstroIntegration {
115- const [ dir , file ] = [ dirname ( templatePath ) , basename ( templatePath ) ] ;
116-
117- const outputPath = join ( dir , file . replace ( "_" , "" ) ) ;
118-
119- return {
120- name : "lycheeverse:generate-cli-page" ,
121- hooks : {
122- "astro:config:setup" : async ( { logger, addWatchFile } ) => {
123- logger . info ( `Using template file ${ templatePath } ` ) ;
124-
125- addWatchFile ( realpathSync ( templatePath ) ) ;
126- addWatchFile ( import . meta. filename ) ;
127-
128- logger . info ( `Fetching from git tag ${ LYCHEE_VERSION } ` ) ;
129- rmSync ( outputPath , { force : true } ) ;
130- const usageText = generateCliOptionsMarkdown ( ) ;
131-
132- const docTemplateText = readFileSync ( templatePath , "utf-8" ) ;
133- const docOutput = docTemplateText . replace ( TEMPLATE , await usageText ) ;
134-
135- assert (
136- docOutput !== docTemplateText ,
137- `Placeholder ${ TEMPLATE } not found in template file` ,
138- ) ;
139- logger . info ( `Writing output file ${ outputPath } ` ) ;
140- writeFileSync ( outputPath , docOutput ) ;
141- } ,
142- } ,
143- } ;
144- }
0 commit comments