1
1
const { readdirSync} = require ( 'fs' ) ;
2
- const fs = require ( "fs" )
3
- const path = require ( " path" )
2
+ const fs = require ( 'fs' ) ;
3
+ const path = require ( ' path' ) ;
4
4
5
5
const IGNORE_DIRS = [ '.github' , '.git' ] ;
6
- const PREPEND_PATH = process . argv [ 2 ] || './' ;
7
6
const FOLDER_TO_LANG = {
8
7
javascript :'JS' ,
9
8
typescript :'TS' ,
@@ -17,8 +16,11 @@ const FOLDER_TO_LANG = {
17
16
scala :'Scala' ,
18
17
swift :'Swift' ,
19
18
cpp :'C++' ,
20
- kotlin :'Kotlin'
19
+ kotlin :'Kotlin' ,
21
20
} ;
21
+ const PREPEND_PATH = process . argv [ 2 ] || './' ;
22
+ const TEMPLATE_PATH = process . argv [ 3 ] || './.github/README_template.md' ;
23
+ const WRITE_PATH = process . argv [ 3 ] || './README.md' ;
22
24
23
25
const PROBLEM_LISTS = {
24
26
'NeetCode 150' :[
@@ -486,29 +488,28 @@ const URLS = {
486
488
} ;
487
489
delete URLS [ 'Blind 75' ] ;
488
490
489
-
490
491
const getDirectories = ( source ) =>
491
492
readdirSync ( source , { withFileTypes :true } )
492
493
. filter ( ( dirent ) => dirent . isDirectory ( ) )
493
494
. map ( ( dirent ) => dirent . name ) ;
494
495
495
- function * walkSync ( dir ) {
496
- const files = fs . readdirSync ( dir , { withFileTypes :true } ) ;
497
- for ( const file of files ) {
498
- if ( file . isDirectory ( ) ) {
499
- yield * walkSync ( path . join ( dir , file . name ) ) ;
500
- } else {
501
- yield path . join ( dir , file . name ) ;
496
+ function * walkSync ( dir ) {
497
+ const files = fs . readdirSync ( dir , { withFileTypes :true } ) ;
498
+ for ( const file of files ) {
499
+ if ( file . isDirectory ( ) ) {
500
+ yield * walkSync ( path . join ( dir , file . name ) ) ;
501
+ } else {
502
+ yield path . join ( dir , file . name ) ;
503
+ }
502
504
}
503
- }
504
505
}
505
506
506
507
function nestedFiles ( dir ) {
507
- files = [ ]
508
+ files = [ ] ;
508
509
for ( const filePath of walkSync ( dir ) ) {
509
- files . push ( filePath )
510
+ files . push ( filePath ) ;
510
511
}
511
- return files
512
+ return files ;
512
513
}
513
514
514
515
const buildTableColumn = (
@@ -518,7 +519,7 @@ const buildTableColumn = (
518
519
directory = False
519
520
) => {
520
521
directory = directory || language ;
521
- let files = nestedFiles ( directory )
522
+ let files = nestedFiles ( directory ) ;
522
523
let checkbox = problems . reduce ( ( acc , [ , number ] ) => {
523
524
acc [ number ] = false ;
524
525
return acc ;
@@ -546,8 +547,11 @@ const makeMarkdown = (table, urls) => {
546
547
...table . slice ( 1 ) . map ( ( row , rowIndex ) =>
547
548
row
548
549
. map ( ( cell , index ) => {
549
- if ( index == 0 ) return `<sub>[${ cell } ](${ urls [ rowIndex ] } )</sub>` ;
550
- return `<sub><div align='center'>${ cell ?"✔️" :"❌" } </div></sub>`
550
+ if ( index == 0 )
551
+ return `<sub>[${ cell } ](${ urls [ rowIndex ] } )</sub>` ;
552
+ return `<sub><div align='center'>${
553
+ cell ?'✔️' :'❌'
554
+ } </div></sub>`;
551
555
} )
552
556
. join ( ' | ' )
553
557
) ,
@@ -562,6 +566,7 @@ Object.entries(PROBLEM_LISTS).forEach(([name, list]) => {
562
566
} ) ;
563
567
} ) ;
564
568
569
+ let outputMarkdownTable = '' ;
565
570
for ( const key in tables ) {
566
571
getDirectories ( PREPEND_PATH )
567
572
. filter ( ( dir ) => ! IGNORE_DIRS . includes ( dir ) )
@@ -576,5 +581,13 @@ for (const key in tables) {
576
581
tables [ key ] = makeMarkdown ( tables [ key ] , URLS [ key ] ) ;
577
582
578
583
// console.log(`##### ${key}`);
579
- console . log ( `\n${ tables [ key ] } ` ) ;
584
+ outputMarkdownTable += `\n${ tables [ key ] } ` ;
580
585
}
586
+
587
+ const template = fs . readFileSync ( TEMPLATE_PATH , { encoding :'utf8' } )
588
+
589
+ const full = template . replaceAll ( '<completion-table />' , outputMarkdownTable ) ;
590
+
591
+ fs . writeFileSync ( WRITE_PATH , full , {
592
+ encoding :'utf8' ,
593
+ } ) ;