diff --git a/.github/workflows/build-readme.yml b/.github/workflows/build-readme.yml index 048078c27..a18b5e22f 100644 --- a/.github/workflows/build-readme.yml +++ b/.github/workflows/build-readme.yml @@ -1,4 +1,4 @@ -name: Build README +name: Build readme file on: #push: @@ -25,13 +25,8 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: Use zsh (dependency) - run: | - sudo apt install zsh -y - - name: Completion Table - run: | - zsh -c 'table=$(node ./.github/workflows/updateCompletionTable.js); echo $table; awk -v r=$table "{gsub(//,r)}1" .github/README_template.md > README.md' + run: node ./.github/workflows/updateCompletionTable.js; - name: Check for modified files id: git-check diff --git a/.github/workflows/updateCompletionTable.js b/.github/workflows/updateCompletionTable.js index 9f58078fd..ae13ec90f 100644 --- a/.github/workflows/updateCompletionTable.js +++ b/.github/workflows/updateCompletionTable.js @@ -1,9 +1,8 @@ const { readdirSync } = require('fs'); -const fs = require("fs") -const path = require("path") +const fs = require('fs'); +const path = require('path'); const IGNORE_DIRS = ['.github', '.git']; -const PREPEND_PATH = process.argv[2] || './'; const FOLDER_TO_LANG = { javascript: 'JS', typescript: 'TS', @@ -17,8 +16,11 @@ const FOLDER_TO_LANG = { scala: 'Scala', swift: 'Swift', cpp: 'C++', - kotlin: 'Kotlin' + kotlin: 'Kotlin', }; +const PREPEND_PATH = process.argv[2] || './'; +const TEMPLATE_PATH = process.argv[3] || './.github/README_template.md'; +const WRITE_PATH = process.argv[3] || './README.md'; const PROBLEM_LISTS = { 'NeetCode 150': [ @@ -486,29 +488,28 @@ const URLS = { }; delete URLS['Blind 75']; - const getDirectories = (source) => readdirSync(source, { withFileTypes: true }) .filter((dirent) => dirent.isDirectory()) .map((dirent) => dirent.name); -function *walkSync(dir) { - const files = fs.readdirSync(dir, { withFileTypes: true }); - for (const file of files) { - if (file.isDirectory()) { - yield* walkSync(path.join(dir, file.name)); - } else { - yield path.join(dir, file.name); +function* walkSync(dir) { + const files = fs.readdirSync(dir, { withFileTypes: true }); + for (const file of files) { + if (file.isDirectory()) { + yield* walkSync(path.join(dir, file.name)); + } else { + yield path.join(dir, file.name); + } } - } } function nestedFiles(dir) { - files = [] + files = []; for (const filePath of walkSync(dir)) { - files.push(filePath) + files.push(filePath); } - return files + return files; } const buildTableColumn = ( @@ -518,7 +519,7 @@ const buildTableColumn = ( directory = False ) => { directory = directory || language; - let files = nestedFiles(directory) + let files = nestedFiles(directory); let checkbox = problems.reduce((acc, [, number]) => { acc[number] = false; return acc; @@ -546,8 +547,11 @@ const makeMarkdown = (table, urls) => { ...table.slice(1).map((row, rowIndex) => row .map((cell, index) => { - if (index == 0) return `[${cell}](${urls[rowIndex]})`; - return `
${cell ? "✔️" : "❌"}
` + if (index == 0) + return `[${cell}](${urls[rowIndex]})`; + return `
${ + cell ? '✔️' : '❌' + }
`; }) .join(' | ') ), @@ -562,6 +566,7 @@ Object.entries(PROBLEM_LISTS).forEach(([name, list]) => { }); }); +let outputMarkdownTable = ''; for (const key in tables) { getDirectories(PREPEND_PATH) .filter((dir) => !IGNORE_DIRS.includes(dir)) @@ -576,5 +581,13 @@ for (const key in tables) { tables[key] = makeMarkdown(tables[key], URLS[key]); // console.log(`##### ${key}`); - console.log(`\n${tables[key]}`); + outputMarkdownTable += `\n${tables[key]}`; } + +const template = fs.readFileSync(TEMPLATE_PATH, { encoding: 'utf8' }) + +const full = template.replaceAll('', outputMarkdownTable); + +fs.writeFileSync(WRITE_PATH, full, { + encoding: 'utf8', +}); diff --git a/README.md b/README.md index 51980afcf..f3efb4246 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ If you would like to have collaborator permissions on the repo to merge your own [15 - 3Sum](https://leetcode.com/problems/3sum/) |
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
|
✔️
|
✔️
[11 - Container with Most Water](https://leetcode.com/problems/container-with-most-water/) |
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
|
✔️
|
✔️
[42 - Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/) |
✔️
|
✔️
|
✔️
|
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
|
|
✔️
|
✔️
-[121 - Best Time to Buy Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) |
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
|
✔️
|
✔️
+[121 - Best Time to Buy & Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) |
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
|
✔️
|
✔️
[3 - Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) |
|
✔️
|
✔️
|
|
✔️
|
✔️
|
✔️
|
✔️
|
✔️
|
|
✔️
|
✔️
|
✔️
[424 - Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/) |
|
✔️
|
✔️
|
|
✔️
|
✔️
|
|
✔️
|
✔️
|
|
|
|
✔️
[567 - Permutation in String](https://leetcode.com/problems/permutation-in-string/) |
|
✔️
|
✔️
|
|
✔️
|
✔️
|
✔️
|
✔️
|
|
|
|
|
✔️