1- import fs from ' fs/promises' ;
2- import path from ' path' ;
3- import { fileURLToPath } from ' url' ;
1+ import fs from " fs/promises" ;
2+ import path from " path" ;
3+ import { fileURLToPath } from " url" ;
44
55const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
6- const REPO_ROOT = path . join ( __dirname , '..' ) ;
6+ const REPO_ROOT = path . join ( __dirname , ".." ) ;
77
88interface EntryStatus {
9- entry : string ;
10- migrated : boolean ;
11- cpprefUrl : string ;
12- cppdocUrl : string ;
13- issueUrl : string ;
9+ entry : string ;
10+ migrated : boolean ;
11+ cpprefUrl : string ;
12+ cppdocUrl : string ;
13+ issueUrl : string ;
1414}
1515
1616async function fileExists ( filePath : string ) : Promise < boolean > {
17- try {
18- await fs . access ( filePath ) ;
19- return true ;
20- } catch {
21- return false ;
22- }
17+ try {
18+ await fs . access ( filePath ) ;
19+ return true ;
20+ } catch {
21+ return false ;
22+ }
2323}
2424
2525async function isMigrated ( entry : string ) : Promise < boolean > {
26- // Possible paths
27- const mdxPath = path . join ( REPO_ROOT , 'src/content/docs' , `${ entry } .mdx` ) ;
28- const indexPath = path . join ( REPO_ROOT , 'src/content/docs' , entry , 'index.mdx' ) ;
26+ // Possible paths
27+ const mdxPath = path . join ( REPO_ROOT , "src/content/docs" , `${ entry } .mdx` ) ;
28+ const indexPath = path . join (
29+ REPO_ROOT ,
30+ "src/content/docs" ,
31+ entry ,
32+ "index.mdx"
33+ ) ;
2934
30- return ( await fileExists ( mdxPath ) ) || ( await fileExists ( indexPath ) ) ;
35+ return ( await fileExists ( mdxPath ) ) || ( await fileExists ( indexPath ) ) ;
3136}
3237
33- function generateUrls ( entry : string ) : Omit < EntryStatus , ' entry' | ' migrated' > {
34- const cpprefUrl = `http://en.cppreference.com/w/${ entry } .html` ;
35- const cppdocUrl = `http://cppdoc.cc/${ entry } ` ;
36- const issueUrl = `https://github.com/cppdoc-cc/cppdoc/issues/new?title=${ encodeURIComponent ( cpprefUrl ) } &labels=migrate-cppref-page` ;
37- return { cpprefUrl, cppdocUrl, issueUrl } ;
38+ function generateUrls ( entry : string ) : Omit < EntryStatus , " entry" | " migrated" > {
39+ const cpprefUrl = `http://en.cppreference.com/w/${ entry } .html` ;
40+ const cppdocUrl = `http://cppdoc.cc/${ entry } ` ;
41+ const issueUrl = `https://github.com/cppdoc-cc/cppdoc/issues/new?title=${ encodeURIComponent ( cpprefUrl ) } &labels=migrate-cppref-page` ;
42+ return { cpprefUrl, cppdocUrl, issueUrl } ;
3843}
3944
4045function generateMarkdown ( status : EntryStatus ) : string {
41- const { entry, migrated, cpprefUrl, cppdocUrl, issueUrl } = status ;
42- if ( migrated ) {
43- return `| ✅ | [cppref](${ cpprefUrl } ) | [cppdoc](${ cppdocUrl } ) | \`${ entry } \` | ` ;
44- } else {
45- return `| ❌ | [cppref](${ cpprefUrl } ) | [create](${ issueUrl } ) | \`${ entry } \` |` ;
46- }
46+ const { entry, migrated, cpprefUrl, cppdocUrl, issueUrl } = status ;
47+ if ( migrated ) {
48+ return `| ✅ | [cppref](${ cpprefUrl } ) | [cppdoc](${ cppdocUrl } ) | \`${ entry } \` | ` ;
49+ } else {
50+ return `| ❌ | [cppref](${ cpprefUrl } ) | [create](${ issueUrl } ) | \`${ entry } \` |` ;
51+ }
4752}
4853
4954async function loadEntries ( ) : Promise < string [ ] > {
50- const indexPath = path . join ( __dirname , 'cppref_index.json' ) ;
51- const content = await fs . readFile ( indexPath , 'utf-8' ) ;
52- const entries = JSON . parse ( content ) as string [ ] ;
53- // Ensure entries are strings and filter out any empty
54- return entries . filter ( ( e ) : e is string => typeof e === 'string' && e . length > 0 ) ;
55+ const indexPath = path . join ( __dirname , "cppref_index.json" ) ;
56+ const content = await fs . readFile ( indexPath , "utf-8" ) ;
57+ const entries = JSON . parse ( content ) as string [ ] ;
58+ // Ensure entries are strings and filter out any empty
59+ return entries . filter (
60+ ( e ) : e is string => typeof e === "string" && e . length > 0
61+ ) ;
5562}
5663
5764async function main ( ) {
58- console . log ( ' Loading entries from cppref_index.json...' ) ;
59- const entries = await loadEntries ( ) ;
60- console . log ( `Total entries: ${ entries . length } ` ) ;
65+ console . log ( " Loading entries from cppref_index.json..." ) ;
66+ const entries = await loadEntries ( ) ;
67+ console . log ( `Total entries: ${ entries . length } ` ) ;
6168
62- const statuses : EntryStatus [ ] = [ ] ;
63- for ( const entry of entries ) {
64- const migrated = await isMigrated ( entry ) ;
65- const urls = generateUrls ( entry ) ;
66- statuses . push ( { entry, migrated, ...urls } ) ;
67- if ( statuses . length % 100 === 0 ) {
68- console . log ( `Processed ${ statuses . length } entries...` ) ;
69- }
69+ const statuses : EntryStatus [ ] = [ ] ;
70+ for ( const entry of entries ) {
71+ const migrated = await isMigrated ( entry ) ;
72+ const urls = generateUrls ( entry ) ;
73+ statuses . push ( { entry, migrated, ...urls } ) ;
74+ if ( statuses . length % 100 === 0 ) {
75+ console . log ( `Processed ${ statuses . length } entries...` ) ;
7076 }
77+ }
7178
72- const migratedCount = statuses . filter ( s => s . migrated ) . length ;
73- const markdownLines = statuses . map ( generateMarkdown ) ;
74- const output =
75- `### cppreference.com Migration Progress
79+ const migratedCount = statuses . filter ( ( s ) => s . migrated ) . length ;
80+ const markdownLines = statuses . map ( generateMarkdown ) ;
81+ const output = `### cppreference.com Migration Progress
7682#### Overall Progress: ${ migratedCount } / ${ statuses . length } migrated (${ ( ( migratedCount / statuses . length ) * 100 ) . toFixed ( 2 ) } %)
7783Updated at ${ new Date ( ) . toISOString ( ) }
7884
7985| Status | Cppref Link | Cppdoc Link | Entry |
8086|--------|-------------|-------------|-------|
81- ${ markdownLines . join ( '\n' ) } `;
87+ ${ markdownLines . join ( "\n" ) } `;
8288
83- const outputPath = path . join ( REPO_ROOT , ' CPPREF_MIGRATE_PROGRESS.md' ) ;
84- await fs . writeFile ( outputPath , output , ' utf-8' ) ;
85- console . log ( `Written to ${ outputPath } ` ) ;
89+ const outputPath = path . join ( REPO_ROOT , " CPPREF_MIGRATE_PROGRESS.md" ) ;
90+ await fs . writeFile ( outputPath , output , " utf-8" ) ;
91+ console . log ( `Written to ${ outputPath } ` ) ;
8692}
8793
8894main ( ) . catch ( ( err ) => {
89- console . error ( err ) ;
90- process . exit ( 1 ) ;
91- } ) ;
95+ console . error ( err ) ;
96+ process . exit ( 1 ) ;
97+ } ) ;
0 commit comments