@@ -2,28 +2,24 @@ import path from 'path'
22import fs from 'fs'
33import { globby } from 'globby'
44
5- const URL_BASE = 'https://github.com/TheAlgorithms/Javascript/blob/master'
6-
75function pathPrefix ( i ) {
8- if ( i ) {
9- const res = ' ' . repeat ( i )
10- return res + '*'
11- } else {
12- return '\n##'
13- }
6+ const res = ' ' . repeat ( i )
7+ return res + '*'
148}
159
1610function printPath ( oldPath , newPath , output ) {
1711 const oldParts = oldPath . split ( path . sep )
1812 const newParts = newPath . split ( path . sep )
13+
1914 for ( let i = 0 ; i < newParts . length ; ++ i ) {
2015 const newPart = newParts [ i ]
2116 if ( i + 1 > oldParts . length || oldParts [ i ] !== newPart ) {
2217 if ( newPart ) {
23- output . push ( `${ pathPrefix ( i ) } ${ newPart . replace ( '_' , ' ' ) } ` )
18+ output . push ( `${ pathPrefix ( i ) } ** ${ newPart . replace ( '_' , ' ' ) } ** ` )
2419 }
2520 }
2621 }
22+
2723 return newPath
2824}
2925
@@ -36,38 +32,23 @@ function pathsToMarkdown (filePaths) {
3632 if ( a . toLowerCase ( ) > b . toLowerCase ( ) ) return 1
3733 return 0
3834 } )
35+
3936 for ( let filepath of filePaths ) {
40- const file = filepath . split ( path . sep )
41- let filename = ''
42- if ( file . length === 1 ) {
43- filepath = ''
44- filename = file [ 0 ]
45- } else {
46- const total = file . length
47- filename = file [ total - 1 ]
48- filepath = file . splice ( 0 , total - 1 ) . join ( path . sep )
49- }
37+ let filename = path . basename ( filepath )
38+ filepath = path . dirname ( path . sep )
39+
5040 if ( filepath !== oldPath ) {
5141 oldPath = printPath ( oldPath , filepath , output )
5242 }
53- let indent = 0
54- for ( let i = 0 ; i < filepath . length ; ++ i ) {
55- if ( filepath [ i ] === path . sep ) {
56- ++ indent
57- }
58- }
59- if ( filepath ) {
60- ++ indent
61- }
43+
44+ let indent = filepath . split ( path . sep ) . length
6245
6346 // prepare the markdown-esque prefix to the file's line
6447 const prefix = pathPrefix ( indent )
6548
6649 // remove extension from filename
67- const name = filename . split ( '.' ) [ 0 ]
68-
69- // create URL to the actual file on github
70- const url = encodeURI ( [ URL_BASE , filepath , filename ] . join ( '/' ) )
50+ const name = path . basename ( filename , ".js" )
51+ const url = path . join ( filepath , filename )
7152
7253 output . push ( `${ prefix } [${ name } ](${ url } )` )
7354 }
@@ -79,6 +60,7 @@ function pathsToMarkdown (filePaths) {
7960globby ( [
8061 '**/*.js' ,
8162 '!(node_modules|.github)/**/*' ,
63+ "!**/test/**/*" ,
8264 '!**/*.test.js' ,
8365 '!**/*.manual-test.js' ,
8466 '!babel.config.js'
0 commit comments