99 * Usage: node scripts/generate-root-readme.js
1010 */
1111
12- const fs = require ( 'fs' ) ;
13- const path = require ( 'path' ) ;
14-
15- const GITHUB_BASE = 'https://github.com/nullvariant/nullvariant-vscode-extensions/blob/main' ;
16- const EXTENSION_PATH = 'extensions/git-id-switcher' ;
17-
18- const SOURCE_PATH = path . join ( __dirname , '..' , 'docs' , 'i18n' , 'en' , 'README.md' ) ;
19- const OUTPUT_PATH = path . join ( __dirname , '..' , 'README.md' ) ;
12+ const fs = require ( "node:fs" ) ;
13+ const path = require ( "node:path" ) ;
14+
15+ const GITHUB_BASE =
16+ "https://github.com/nullvariant/nullvariant-vscode-extensions/blob/main" ;
17+ const EXTENSION_PATH = "extensions/git-id-switcher" ;
18+
19+ const SOURCE_PATH = path . join (
20+ __dirname ,
21+ ".." ,
22+ "docs" ,
23+ "i18n" ,
24+ "en" ,
25+ "README.md" ,
26+ ) ;
27+ const OUTPUT_PATH = path . join ( __dirname , ".." , "README.md" ) ;
2028
2129const AUTO_GENERATED_HEADER = `<!-- 🚨 AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY 🚨
2230 Source: docs/i18n/en/README.md
@@ -25,100 +33,70 @@ const AUTO_GENERATED_HEADER = `<!-- 🚨 AUTO-GENERATED FILE - DO NOT EDIT DIREC
2533` ;
2634
2735/**
28- * Transform relative language links to absolute GitHub URLs
29- * ../ja/README.md -> https://github.com/.../docs/i18n/ja/README.md
30- */
31- function transformLanguageLinks ( content ) {
32- // Match href="../XX/README.md" or href="../XX-YY/README.md"
33- return content . replace (
34- / h r e f = " \. \. \/ ( [ a - z A - Z - ] + ) \/ R E A D M E \. m d " / g,
35- `href="${ GITHUB_BASE } /${ EXTENSION_PATH } /docs/i18n/$1/README.md"`
36- ) ;
37- }
38-
39- /**
40- * Transform LANGUAGES.md link to absolute GitHub URL
41- * ../../LANGUAGES.md -> https://github.com/.../docs/LANGUAGES.md
42- */
43- function transformLanguagesLink ( content ) {
44- return content . replace (
45- / h r e f = " \. \. \/ \. \. \/ L A N G U A G E S \. m d " / g,
46- `href="${ GITHUB_BASE } /${ EXTENSION_PATH } /docs/LANGUAGES.md"`
47- ) ;
48- }
49-
50- /**
51- * Remove -en suffix from image filenames
52- * demo-en.png -> demo.png
53- * quickpick-en.png -> quickpick.png
54- */
55- function removeEnSuffixFromImages ( content ) {
56- return content . replace ( / - e n \. p n g / g, '.png' ) ;
57- }
58-
59- /**
60- * Transform CONTRIBUTING.md link to absolute GitHub URL
61- * ../../CONTRIBUTING.md -> https://github.com/.../CONTRIBUTING.md
36+ * All link transformations to apply.
37+ * Each transformation has a pattern (regex) and replacement (string or function).
6238 */
63- function transformContributingLink ( content ) {
64- return content . replace (
65- / \[ C O N T R I B U T I N G \. m d \] \( [ ^ ) ] + \) / g,
66- `[CONTRIBUTING.md](${ GITHUB_BASE } /CONTRIBUTING.md)`
67- ) ;
68- }
39+ const TRANSFORMATIONS = [
40+ // Transform relative language links: ../ja/README.md -> absolute GitHub URL
41+ {
42+ pattern : / h r e f = " \. \. \/ ( [ a - z A - Z - ] + ) \/ R E A D M E \. m d " / g,
43+ replacement : `href="${ GITHUB_BASE } /${ EXTENSION_PATH } /docs/i18n/$1/README.md"` ,
44+ } ,
45+ // Transform LANGUAGES.md link: ../../LANGUAGES.md -> absolute GitHub URL
46+ {
47+ pattern : / h r e f = " \. \. \/ \. \. \/ L A N G U A G E S \. m d " / g,
48+ replacement : `href="${ GITHUB_BASE } /${ EXTENSION_PATH } /docs/LANGUAGES.md"` ,
49+ } ,
50+ // Remove -en suffix from image filenames: demo-en.png -> demo.png
51+ {
52+ pattern : / - e n \. p n g / g,
53+ replacement : ".png" ,
54+ } ,
55+ // Transform CONTRIBUTING.md markdown link to absolute GitHub URL
56+ {
57+ pattern : / \[ C O N T R I B U T I N G \. m d \] \( [ ^ ) ] + \) / g,
58+ replacement : `[CONTRIBUTING.md](${ GITHUB_BASE } /CONTRIBUTING.md)` ,
59+ } ,
60+ // Transform LICENSE markdown link to absolute GitHub URL
61+ {
62+ pattern : / \[ L I C E N S E \] \( [ ^ ) ] + \) / g,
63+ replacement : `[LICENSE](${ GITHUB_BASE } /LICENSE)` ,
64+ } ,
65+ // Transform DESIGN_PHILOSOPHY.md markdown-style link to absolute GitHub URL
66+ {
67+ pattern : / \( \. \. \/ \. \. \/ D E S I G N _ P H I L O S O P H Y \. m d \) / g,
68+ replacement : `(${ GITHUB_BASE } /${ EXTENSION_PATH } /docs/DESIGN_PHILOSOPHY.md)` ,
69+ } ,
70+ // Transform DESIGN_PHILOSOPHY.md HTML href to absolute GitHub URL
71+ {
72+ pattern : / h r e f = " \. \. \/ \. \. \/ D E S I G N _ P H I L O S O P H Y \. m d " / g,
73+ replacement : `href="${ GITHUB_BASE } /${ EXTENSION_PATH } /docs/DESIGN_PHILOSOPHY.md"` ,
74+ } ,
75+ ] ;
6976
7077/**
71- * Transform LICENSE link to absolute GitHub URL
72- * ../../../../../LICENSE -> https://github.com/.../LICENSE
78+ * Apply all transformations to content
79+ * @param {string } content - The content to transform
80+ * @returns {string } - The transformed content
7381 */
74- function transformLicenseLink ( content ) {
75- return content . replace (
76- / \[ L I C E N S E \] \( [ ^ ) ] + \) / g ,
77- `[LICENSE]( ${ GITHUB_BASE } /LICENSE)`
82+ function applyTransformations ( content ) {
83+ return TRANSFORMATIONS . reduce (
84+ ( text , { pattern , replacement } ) => text . replaceAll ( pattern , replacement ) ,
85+ content ,
7886 ) ;
7987}
8088
81- /**
82- * Transform DESIGN_PHILOSOPHY.md link to absolute GitHub URL
83- * ../../DESIGN_PHILOSOPHY.md -> https://github.com/.../docs/DESIGN_PHILOSOPHY.md
84- * Handles both markdown links (...) and HTML href="..."
85- */
86- function transformDesignPhilosophyLink ( content ) {
87- // Transform markdown-style links to absolute GitHub URL
88- content = content . replace (
89- / \( \. \. \/ \. \. \/ D E S I G N _ P H I L O S O P H Y \. m d \) / g,
90- `(${ GITHUB_BASE } /${ EXTENSION_PATH } /docs/DESIGN_PHILOSOPHY.md)`
91- ) ;
92- // Transform HTML href attributes to absolute GitHub URL
93- content = content . replace (
94- / h r e f = " \. \. \/ \. \. \/ D E S I G N _ P H I L O S O P H Y \. m d " / g,
95- `href="${ GITHUB_BASE } /${ EXTENSION_PATH } /docs/DESIGN_PHILOSOPHY.md"`
96- ) ;
97- return content ;
98- }
99-
10089function main ( ) {
101- // Read source file
10290 if ( ! fs . existsSync ( SOURCE_PATH ) ) {
10391 console . error ( `Error: Source file not found: ${ SOURCE_PATH } ` ) ;
10492 process . exit ( 1 ) ;
10593 }
10694
107- let content = fs . readFileSync ( SOURCE_PATH , 'utf-8' ) ;
108-
109- // Apply transformations
110- content = transformLanguageLinks ( content ) ;
111- content = transformLanguagesLink ( content ) ;
112- content = removeEnSuffixFromImages ( content ) ;
113- content = transformContributingLink ( content ) ;
114- content = transformLicenseLink ( content ) ;
115- content = transformDesignPhilosophyLink ( content ) ;
116-
117- // Add auto-generated header
95+ let content = fs . readFileSync ( SOURCE_PATH , "utf-8" ) ;
96+ content = applyTransformations ( content ) ;
11897 content = AUTO_GENERATED_HEADER + content ;
11998
120- // Write output file
121- fs . writeFileSync ( OUTPUT_PATH , content , 'utf-8' ) ;
99+ fs . writeFileSync ( OUTPUT_PATH , content , "utf-8" ) ;
122100
123101 console . log ( `✅ Generated ${ OUTPUT_PATH } ` ) ;
124102 console . log ( ` Source: ${ SOURCE_PATH } ` ) ;
0 commit comments