Last active
June 10, 2016 19:10
-
-
Save daniellizik/d32bb0d64b7064c82a1a87bbfa4cb33b to your computer and use it in GitHub Desktop.
exposed public directory
This file contains hidden or 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
'use strict'; | |
const fs = require('fs'); | |
const path = require('path'); | |
const walkSync = (dir, filelist) => { | |
const files = fs.readdirSync(dir); | |
filelist = filelist || []; | |
files.forEach(function(file) { | |
if (fs.statSync(dir + '/' + file).isDirectory()) { | |
filelist = walkSync(dir + '/' + file, filelist); | |
} | |
else { | |
let norm = path.normalize(dir); | |
let split = norm.split(path.sep) | |
filelist.push(split.join('/')); | |
} | |
}); | |
return filelist; | |
}; | |
const dirs = walkSync(__dirname + '/../public'); | |
const reduced = dirs.reduce((bucket, dir) => { | |
bucket.acc.push({ publicPath: dir.replace(bucket.first, '') + '/', path: dir }); | |
return bucket; | |
}, { first: dirs[0], acc: []}).acc; | |
console.log(reduced) | |
module.exports = reduced; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment