@@ -9,34 +9,32 @@ console.log("TSConfig Ref: MD for CLI Opts");
99
1010import { writeFileSync , readdirSync , existsSync , readFileSync } from "fs" ;
1111import { join } from "path" ;
12- import { read as readMarkdownFile } from "gray-matter" ;
13- import * as prettier from "prettier" ;
12+ import { fileURLToPath } from "url" ;
13+ import matter from "gray-matter" ;
14+ import prettier from "prettier" ;
1415import { CompilerOptionJSON } from "./generateJSON.js" ;
15- import { parseMarkdown } from "../tsconfigRules" ;
16+ import { parseMarkdown } from "../tsconfigRules.js " ;
1617
17- const options = require ( join ( __dirname , "../../data/cliOpts.json" ) ) as {
18- options : CompilerOptionJSON [ ] ;
19- build : CompilerOptionJSON [ ] ;
20- watch : CompilerOptionJSON [ ] ;
21- cli : CompilerOptionJSON [ ] ;
22- } ;
18+ // @ts -ignore
19+ import cliOpts from "../../data/cliOpts.json" ;
2320
2421const knownTypes : Record < string , string > = { } ;
2522
26- const languages = readdirSync ( join ( __dirname , ".." , ".. ", "copy" ) ) . filter (
23+ const languages = readdirSync ( new URL ( "../../copy " , import . meta . url ) ) . filter (
2724 ( f ) => ! f . startsWith ( "." )
2825) ;
2926
3027languages . forEach ( ( lang ) => {
31- const locale = join ( __dirname , ".." , ".." , " copy" , lang ) ;
32- const fallbackLocale = join ( __dirname , ".." , ".." , " copy", "en" ) ;
28+ const locale = new URL ( `../../ copy/ ${ lang } /` , import . meta . url ) ;
29+ const fallbackLocale = new URL ( "../../ copy/en/ " , import . meta . url ) ;
3330
3431 const markdownChunks : string [ ] = [ ] ;
3532
3633 const getPathInLocale = ( path : string , optionalExampleContent ?: string ) => {
37- if ( existsSync ( join ( locale , path ) ) ) return join ( locale , path ) ;
38- if ( existsSync ( join ( fallbackLocale , path ) ) ) return join ( fallbackLocale , path ) ;
39- const en = join ( fallbackLocale , path ) ;
34+ if ( existsSync ( new URL ( path , locale ) ) ) return new URL ( path , locale ) ;
35+ if ( existsSync ( new URL ( path , fallbackLocale ) ) )
36+ return new URL ( path , fallbackLocale ) ;
37+ const en = new URL ( path , fallbackLocale ) ;
4038
4139 const localeDesc = lang === "en" ? lang : `either ${ lang } or English` ;
4240 // prettier-ignore
@@ -45,7 +43,11 @@ languages.forEach((lang) => {
4543 ) ;
4644 } ;
4745
48- function renderTable ( title : string , options : CompilerOptionJSON [ ] , opts ?: { noDefaults : true } ) {
46+ function renderTable (
47+ title : string ,
48+ options : typeof cliOpts [ keyof typeof cliOpts ] ,
49+ opts ?: { noDefaults : true }
50+ ) {
4951 markdownChunks . push ( `<h3>${ title } </h3>` ) ;
5052
5153 // Trim leading whitespaces so that it is not rendered as a markdown code block
@@ -68,13 +70,17 @@ languages.forEach((lang) => {
6870 // CLI description
6971 let description = option . description ?. message ;
7072 try {
71- const sectionsPath = getPathInLocale ( join ( "options" , option . name + ".md" ) ) ;
72- const optionFile = readMarkdownFile ( sectionsPath ) ;
73+ const sectionsPath = getPathInLocale (
74+ join ( "options" , option . name + ".md" )
75+ ) ;
76+ const optionFile = matter . read ( fileURLToPath ( sectionsPath ) ) ;
7377 description = optionFile . data . oneline ;
7478 } catch ( error ) {
7579 try {
76- const sectionsPath = getPathInLocale ( join ( "cli" , option . name + ".md" ) ) ;
77- const optionFile = readMarkdownFile ( sectionsPath ) ;
80+ const sectionsPath = getPathInLocale (
81+ join ( "cli" , option . name + ".md" )
82+ ) ;
83+ const optionFile = matter . read ( fileURLToPath ( sectionsPath ) ) ;
7884 description = optionFile . data . oneline ;
7985 } catch ( error ) { }
8086 }
@@ -122,21 +128,23 @@ languages.forEach((lang) => {
122128 markdownChunks . push ( `</tbody></table>\n` ) ;
123129 }
124130
125- renderTable ( "CLI Commands" , options . cli , { noDefaults : true } ) ;
126- renderTable ( "Build Options" , options . build , { noDefaults : true } ) ;
127- renderTable ( "Watch Options" , options . watch , { noDefaults : true } ) ;
128- renderTable ( "Compiler Flags" , options . options ) ;
131+ renderTable ( "CLI Commands" , cliOpts . cli , { noDefaults : true } ) ;
132+ renderTable ( "Build Options" , cliOpts . build , { noDefaults : true } ) ;
133+ renderTable ( "Watch Options" , cliOpts . watch , { noDefaults : true } ) ;
134+ renderTable ( "Compiler Flags" , cliOpts . options ) ;
129135
130136 // Write the Markdown and JSON
131- const markdown = prettier . format ( markdownChunks . join ( "\n" ) , { filepath : "index.md" } ) ;
132- const mdPath = join ( __dirname , ".." , ".." , "output" , lang + "-cli.md" ) ;
137+ const markdown = prettier . format ( markdownChunks . join ( "\n" ) , {
138+ filepath : "index.md" ,
139+ } ) ;
140+ const mdPath = new URL ( `../../output/${ lang } -cli.md` , import . meta. url ) ;
133141 writeFileSync ( mdPath , markdown ) ;
134142} ) ;
135143
136144languages . forEach ( ( lang ) => {
137- const mdCLI = join ( __dirname , ".." , ".." , " output" , lang + " -cli.md" ) ;
145+ const mdCLI = new URL ( `../../ output/ ${ lang } -cli.md` , import . meta . url ) ;
138146 // prettier-ignore
139- const compOptsPath = join ( __dirname , ".." , ".." , ".." , ` documentation/copy/${ lang } /project-config/Compiler Options.md`) ;
147+ const compOptsPath = new URL ( `../../../ documentation/copy/${ lang } /project-config/Compiler Options.md`, import . meta . url ) ;
140148
141149 if ( existsSync ( compOptsPath ) ) {
142150 const md = readFileSync ( compOptsPath , "utf8" ) ;
0 commit comments