Skip to content

Instantly share code, notes, and snippets.

@Fraasi
Created May 12, 2019 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fraasi/eb9ac67063abbdbbcab6d463fa7faff5 to your computer and use it in GitHub Desktop.
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.
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