@@ -3,33 +3,61 @@ import path from "node:path";
33
44import { glob } from "./lib/glob" ;
55
6+ /**
7+ * Build script for processing and copying documentation to the website
8+ *
9+ * This script:
10+ * 1. Collects rule documentation from ESLint plugins
11+ * 2. Copies them to the website with proper naming
12+ * 3. Processes the changelog
13+ * 4. Sets up dependencies for the website build
14+ */
15+
16+ // Find all rule documentation markdown files from the various plugins
617const docs = glob ( [ "packages/plugins/eslint-plugin-react-*/src/rules/*.md" ] ) ;
718
819// TODO: Generate the meta.json file as well
20+ // Process each documentation file:
21+ // - Extract plugin name and rule name
22+ // - Format destination path and rule title
23+ // - Build arrays of file paths and rule metadata
924const [
1025 files ,
11- // rules,
26+ // rules, // Currently commented out but would contain rule metadata
1227] = Array . from ( docs ) . reduce < readonly [ [ string , string ] [ ] , [ string , string ] [ ] ] > (
1328 ( [ files , rules ] , doc ) => {
1429 const catename = / ^ p a c k a g e s \/ p l u g i n s \/ e s l i n t - p l u g i n - r e a c t - ( [ ^ / ] + ) / u. exec ( doc ) ?. [ 1 ] ?? "" ;
1530 const basename = path . parse ( path . basename ( doc ) ) . name ;
31+
32+ // Special handling for "react-x" plugin (the core plugin)
1633 const isPluginX = catename === "x" ;
34+
35+ // Format the rule name differently based on which plugin it belongs to
1736 const name = isPluginX
18- ? basename
19- : `${ catename } -${ basename } ` ;
37+ ? basename // For react-x plugin: just use the rule name
38+ : `${ catename } -${ basename } ` ; // For other plugins: prefix with category
39+
40+ // Format the rule title for display purposes
2041 const title = isPluginX
21- ? basename
22- : `${ catename } /${ basename } ` ;
42+ ? basename // For react-x plugin: just use the rule name
43+ : `${ catename } /${ basename } ` ; // For other plugins: use category/rule format
44+
45+ // Define destination path in the website content directory
2346 const dest = path . join ( "apps" , "website" , "content" , "docs" , "rules" , `${ name } .mdx` ) ;
47+
48+ // Add to our accumulator arrays
2449 return [ [ ...files , [ doc , dest ] ] , [ ...rules , [ name , title ] ] ] as const ;
2550 } ,
2651 [ [ ] , [ ] ] ,
2752) ;
2853
54+ // Copy all documentation files to their respective destinations in parallel
2955await Promise . all ( files . map ( ( [ src , dest ] ) => fs . copyFile ( src , dest ) ) ) ;
3056
57+ // Write rule metadata to a JSON file for the website
3158// fs.writeFileSync(path.join("apps", "website", "content", "docs", "rules", "data.json"), JSON.stringify(rules, null, 2));
3259
60+ // Process the changelog file by adding frontmatter for the documentation system
3361const changelog = await fs . readFile ( "CHANGELOG.md" , "utf-8" ) ;
3462
3563const changelogWithFrontmatter = [
@@ -40,9 +68,13 @@ const changelogWithFrontmatter = [
4068 changelog ,
4169] . join ( "\n" ) ;
4270
71+ // Write the processed changelog to the website content directory
4372await fs . writeFile ( path . join ( "apps" , "website" , "content" , "docs" , "changelog.md" ) , changelogWithFrontmatter ) ;
4473
45- // workaround for @tailwindcss /postcss plugin not working with symlinked node_modules
74+ // Workaround for @tailwindcss /postcss plugin not working with symlinked node_modules:
75+ // 1. Find the actual (real) path of the symlinked fumadocs-ui
76+ // 2. Copy the entire directory to a non-symlinked location in the website deps
77+ // 3. This ensures Tailwind can properly process the CSS in these files
4678const linkPath = path . join ( "apps" , "website" , "node_modules" , "fumadocs-ui" , "dist" ) ;
4779const realPath = await fs . realpath ( linkPath ) ;
4880const distPath = path . join ( "apps" , "website" , "deps" , "fumadocs-ui" ) ;
@@ -51,10 +83,11 @@ await fs.rm(distPath, { force: true, recursive: true });
5183await fs . cp (
5284 realPath ,
5385 distPath ,
54- { dereference : true , recursive : true } ,
86+ { dereference : true , recursive : true } , // dereference ensures we copy actual files, not symlinks
5587) ;
5688
57- // generate tailwindcss sources
89+ // Commented out: Generate tailwindcss source mapping configuration
90+ // This would tell Tailwind which directories to scan for CSS classes
5891// const sourcePath = path.join("apps", "website", "app", "sources.css");
5992// const sourceCode = [
6093// `@source "../deps/fumadocs-ui/**/*.js";`,
0 commit comments