Skip to content

Commit 6d5e641

Browse files
authored
merge: tweak DIRECTORY.md generation (TheAlgorithms#999)
* tests: change extention of helper file * chore: revert previous change * chore: ignore dirs with name "test" * docs: update directory styling Removed headings from `DIRECTORY.md` generation. * refactor: make code more idiomatic * docs: format directories to be bold * chore: change char conting method * fix: add 1 to ident count
1 parent 2e18fbb commit 6d5e641

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

‎.github/workflows/UpdateDirectory.mjs‎

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@ import path from 'path'
22
importfsfrom'fs'
33
import{globby}from'globby'
44

5-
constURL_BASE='https://github.com/TheAlgorithms/Javascript/blob/master'
6-
75
functionpathPrefix(i){
8-
if(i){
9-
constres=' '.repeat(i)
10-
returnres+'*'
11-
}else{
12-
return'\n##'
13-
}
6+
constres=' '.repeat(i)
7+
returnres+'*'
148
}
159

1610
functionprintPath(oldPath,newPath,output){
1711
constoldParts=oldPath.split(path.sep)
1812
constnewParts=newPath.split(path.sep)
13+
1914
for(leti=0;i<newParts.length;++i){
2015
constnewPart=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
returnnewPath
2824
}
2925

@@ -36,38 +32,23 @@ function pathsToMarkdown (filePaths){
3632
if(a.toLowerCase()>b.toLowerCase())return1
3733
return0
3834
})
35+
3936
for(letfilepathoffilePaths){
40-
constfile=filepath.split(path.sep)
41-
letfilename=''
42-
if(file.length===1){
43-
filepath=''
44-
filename=file[0]
45-
}else{
46-
consttotal=file.length
47-
filename=file[total-1]
48-
filepath=file.splice(0,total-1).join(path.sep)
49-
}
37+
letfilename=path.basename(filepath)
38+
filepath=path.dirname(path.sep)
39+
5040
if(filepath!==oldPath){
5141
oldPath=printPath(oldPath,filepath,output)
5242
}
53-
letindent=0
54-
for(leti=0;i<filepath.length;++i){
55-
if(filepath[i]===path.sep){
56-
++indent
57-
}
58-
}
59-
if(filepath){
60-
++indent
61-
}
43+
44+
letindent=filepath.split(path.sep).length
6245

6346
// prepare the markdown-esque prefix to the file's line
6447
constprefix=pathPrefix(indent)
6548

6649
// remove extension from filename
67-
constname=filename.split('.')[0]
68-
69-
// create URL to the actual file on github
70-
consturl=encodeURI([URL_BASE,filepath,filename].join('/'))
50+
constname=path.basename(filename,".js")
51+
consturl=path.join(filepath,filename)
7152

7253
output.push(`${prefix} [${name}](${url})`)
7354
}
@@ -79,6 +60,7 @@ function pathsToMarkdown (filePaths){
7960
globby([
8061
'**/*.js',
8162
'!(node_modules|.github)/**/*',
63+
"!**/test/**/*",
8264
'!**/*.test.js',
8365
'!**/*.manual-test.js',
8466
'!babel.config.js'

0 commit comments

Comments
(0)