From 3590019c6e5efddbd10fced1ad3d6c2e3b6f1426 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Apr 2022 14:24:51 +0530 Subject: [PATCH 1/8] tests: change extention of helper file --- Cache/test/{cacheTest.js => cacheTest.test.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Cache/test/{cacheTest.js => cacheTest.test.js} (100%) diff --git a/Cache/test/cacheTest.js b/Cache/test/cacheTest.test.js similarity index 100% rename from Cache/test/cacheTest.js rename to Cache/test/cacheTest.test.js From 848b1d1e39f09b71bc498f8efd1fe3d02a424b86 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Apr 2022 14:31:30 +0530 Subject: [PATCH 2/8] chore: revert previous change --- Cache/test/{cacheTest.test.js => cacheTest.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Cache/test/{cacheTest.test.js => cacheTest.js} (100%) diff --git a/Cache/test/cacheTest.test.js b/Cache/test/cacheTest.js similarity index 100% rename from Cache/test/cacheTest.test.js rename to Cache/test/cacheTest.js From 676000e3235d329b70542629f1ba5fb29340f911 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Apr 2022 14:33:51 +0530 Subject: [PATCH 3/8] chore: ignore dirs with name "test" --- .github/workflows/UpdateDirectory.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/UpdateDirectory.mjs b/.github/workflows/UpdateDirectory.mjs index d79e5a4b69..340de31b30 100644 --- a/.github/workflows/UpdateDirectory.mjs +++ b/.github/workflows/UpdateDirectory.mjs @@ -79,6 +79,7 @@ function pathsToMarkdown (filePaths) { globby([ '**/*.js', '!(node_modules|.github)/**/*', + "!**/test/**/*", '!**/*.test.js', '!**/*.manual-test.js', '!babel.config.js' From 85e81a883e8ec256b719199edcfd4a98e8207021 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Apr 2022 14:38:39 +0530 Subject: [PATCH 4/8] docs: update directory styling Removed headings from `DIRECTORY.md` generation. --- .github/workflows/UpdateDirectory.mjs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/UpdateDirectory.mjs b/.github/workflows/UpdateDirectory.mjs index 340de31b30..6e54997c20 100644 --- a/.github/workflows/UpdateDirectory.mjs +++ b/.github/workflows/UpdateDirectory.mjs @@ -5,12 +5,8 @@ import { globby } from 'globby' const URL_BASE = 'https://github.com/TheAlgorithms/Javascript/blob/master' function pathPrefix (i) { - if (i) { - const res = ' '.repeat(i) - return res + '*' - } else { - return '\n##' - } + const res = ' '.repeat(i) + return res + '*' } function printPath (oldPath, newPath, output) { From e0a6a9c8cee98894d9db58ac544060bd4e0ccdb3 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Apr 2022 15:00:58 +0530 Subject: [PATCH 5/8] refactor: make code more idiomatic --- .github/workflows/UpdateDirectory.mjs | 35 ++++++++------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/.github/workflows/UpdateDirectory.mjs b/.github/workflows/UpdateDirectory.mjs index 6e54997c20..017713ea6b 100644 --- a/.github/workflows/UpdateDirectory.mjs +++ b/.github/workflows/UpdateDirectory.mjs @@ -2,8 +2,6 @@ import path from 'path' import fs from 'fs' import { globby } from 'globby' -const URL_BASE = 'https://github.com/TheAlgorithms/Javascript/blob/master' - function pathPrefix (i) { const res = ' '.repeat(i) return res + '*' @@ -12,6 +10,7 @@ function pathPrefix (i) { function printPath (oldPath, newPath, output) { const oldParts = oldPath.split(path.sep) const newParts = newPath.split(path.sep) + for (let i = 0; i < newParts.length; ++i) { const newPart = newParts[i] if (i + 1 > oldParts.length || oldParts[i] !== newPart) { @@ -20,6 +19,7 @@ function printPath (oldPath, newPath, output) { } } } + return newPath } @@ -32,38 +32,23 @@ function pathsToMarkdown (filePaths) { if (a.toLowerCase() > b.toLowerCase()) return 1 return 0 }) + for (let filepath of filePaths) { - const file = filepath.split(path.sep) - let filename = '' - if (file.length === 1) { - filepath = '' - filename = file[0] - } else { - const total = file.length - filename = file[total - 1] - filepath = file.splice(0, total - 1).join(path.sep) - } + let filename = path.basename(filepath) + filepath = path.dirname(path.sep) + if (filepath !== oldPath) { oldPath = printPath(oldPath, filepath, output) } - let indent = 0 - for (let i = 0; i < filepath.length; ++i) { - if (filepath[i] === path.sep) { - ++indent - } - } - if (filepath) { - ++indent - } + + let indent = filepath.replace(new RegExp(`/[^${path.sep}]/`)).length + 1 // prepare the markdown-esque prefix to the file's line const prefix = pathPrefix(indent) // remove extension from filename - const name = filename.split('.')[0] - - // create URL to the actual file on github - const url = encodeURI([URL_BASE, filepath, filename].join('/')) + const name = path.basename(filename, ".js") + const url = path.join(filepath, filename) output.push(`${prefix} [${name}](${url})`) } From c668a30e1269846325fab8587ec78bb46c7f1a41 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Apr 2022 15:04:18 +0530 Subject: [PATCH 6/8] docs: format directories to be bold --- .github/workflows/UpdateDirectory.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/UpdateDirectory.mjs b/.github/workflows/UpdateDirectory.mjs index 017713ea6b..df468e2c7f 100644 --- a/.github/workflows/UpdateDirectory.mjs +++ b/.github/workflows/UpdateDirectory.mjs @@ -15,7 +15,7 @@ function printPath (oldPath, newPath, output) { const newPart = newParts[i] if (i + 1 > oldParts.length || oldParts[i] !== newPart) { if (newPart) { - output.push(`${pathPrefix(i)} ${newPart.replace('_', ' ')}`) + output.push(`${pathPrefix(i)} **${newPart.replace('_', ' ')}**`) } } } From 2537c520527d1a3692813e6d2ac8a92ddd4aa6b5 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Apr 2022 15:12:36 +0530 Subject: [PATCH 7/8] chore: change char conting method --- .github/workflows/UpdateDirectory.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/UpdateDirectory.mjs b/.github/workflows/UpdateDirectory.mjs index df468e2c7f..8dc418f302 100644 --- a/.github/workflows/UpdateDirectory.mjs +++ b/.github/workflows/UpdateDirectory.mjs @@ -41,7 +41,7 @@ function pathsToMarkdown (filePaths) { oldPath = printPath(oldPath, filepath, output) } - let indent = filepath.replace(new RegExp(`/[^${path.sep}]/`)).length + 1 + let indent = filepath.split(path.sep).length - 1 // prepare the markdown-esque prefix to the file's line const prefix = pathPrefix(indent) From 457e63747be5e377807495e40d806c9ad86b78aa Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Apr 2022 15:15:39 +0530 Subject: [PATCH 8/8] fix: add 1 to ident count --- .github/workflows/UpdateDirectory.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/UpdateDirectory.mjs b/.github/workflows/UpdateDirectory.mjs index 8dc418f302..9a528bf20d 100644 --- a/.github/workflows/UpdateDirectory.mjs +++ b/.github/workflows/UpdateDirectory.mjs @@ -41,7 +41,7 @@ function pathsToMarkdown (filePaths) { oldPath = printPath(oldPath, filepath, output) } - let indent = filepath.split(path.sep).length - 1 + let indent = filepath.split(path.sep).length // prepare the markdown-esque prefix to the file's line const prefix = pathPrefix(indent)