@@ -2,28 +2,24 @@ import path from 'path'
2
2
import fs from 'fs'
3
3
import { globby } from 'globby'
4
4
5
- const URL_BASE = 'https://github.com/TheAlgorithms/Javascript/blob/master'
6
-
7
5
function 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 + '*'
14
8
}
15
9
16
10
function printPath ( oldPath , newPath , output ) {
17
11
const oldParts = oldPath . split ( path . sep )
18
12
const newParts = newPath . split ( path . sep )
13
+
19
14
for ( let i = 0 ; i < newParts . length ; ++ i ) {
20
15
const newPart = newParts [ i ]
21
16
if ( i + 1 > oldParts . length || oldParts [ i ] !== newPart ) {
22
17
if ( newPart ) {
23
- output . push ( `${ pathPrefix ( i ) } ${ newPart . replace ( '_' , ' ' ) } ` )
18
+ output . push ( `${ pathPrefix ( i ) } ** ${ newPart . replace ( '_' , ' ' ) } ** ` )
24
19
}
25
20
}
26
21
}
22
+
27
23
return newPath
28
24
}
29
25
@@ -36,38 +32,23 @@ function pathsToMarkdown (filePaths) {
36
32
if ( a . toLowerCase ( ) > b . toLowerCase ( ) ) return 1
37
33
return 0
38
34
} )
35
+
39
36
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
+
50
40
if ( filepath !== oldPath ) {
51
41
oldPath = printPath ( oldPath , filepath , output )
52
42
}
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
62
45
63
46
// prepare the markdown-esque prefix to the file's line
64
47
const prefix = pathPrefix ( indent )
65
48
66
49
// 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 )
71
52
72
53
output . push ( `${ prefix } [${ name } ](${ url } )` )
73
54
}
@@ -79,6 +60,7 @@ function pathsToMarkdown (filePaths) {
79
60
globby ( [
80
61
'**/*.js' ,
81
62
'!(node_modules|.github)/**/*' ,
63
+ "!**/test/**/*" ,
82
64
'!**/*.test.js' ,
83
65
'!**/*.manual-test.js' ,
84
66
'!babel.config.js'
0 commit comments