Skip to content

Instantly share code, notes, and snippets.

@daniellizik
Last active June 10, 2016 19:10
Show Gist options
  • Save daniellizik/d32bb0d64b7064c82a1a87bbfa4cb33b to your computer and use it in GitHub Desktop.
Save daniellizik/d32bb0d64b7064c82a1a87bbfa4cb33b to your computer and use it in GitHub Desktop.
exposed public directory
'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