Created
May 12, 2019 18:37
-
-
Save Fraasi/eb9ac67063abbdbbcab6d463fa7faff5 to your computer and use it in GitHub Desktop.
Little node script to check what coding train challenges have been ported to P5/Processing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const fs = require('fs') | |
let folderCount = 0 | |
let stdoutWidth = process.stdout.columns - 9 | |
let startTime | |
const results = {} | |
function checkChallenges(startDir) { | |
startTime = new Date() | |
const folders = fs.readdirSync(startDir) | |
for (dir of folders) { | |
if (folderCount === 0) { | |
console.log(`\n Start\n`) | |
} | |
++folderCount | |
process.stdout.clearLine(); | |
process.stdout.cursorTo(0); | |
process.stdout.write(` ${folderCount}...${startDir}`.slice(0, stdoutWidth) + '...') | |
let isDir | |
try { | |
isDir = fs.lstatSync(path.join(startDir, dir)).isDirectory() | |
} catch (e) { | |
/* | |
* Error: EPERM: operation not permitted, lstat | |
* Error: EBUSY: File is busy | |
* Silently just jump over & continue | |
*/ | |
} | |
if (isDir) { | |
const subDirs = fs.readdirSync(path.join(startDir, dir)) | |
const result = {} | |
subDirs.forEach((el) => { | |
result[el] = true | |
}) | |
results[dir] = result | |
} | |
} | |
const stopTime = new Date() | |
const time = ((stopTime - startTime) / 1000).toFixed(2) | |
process.stdout.clearLine(); | |
process.stdout.cursorTo(0); | |
console.log(` Traversed ${folderCount} folders in ${time}s\n Done!`) | |
fs.writeFileSync(__dirname + '/results.json', JSON.stringify(results, null, 2)) | |
} | |
// path to your local clone of the website\CodingChallenges | |
const startDir = 'G:\\Code\\GitClones\\website\\CodingChallenges' | |
checkChallenges(startDir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment