Created
May 3, 2017 10:17
-
-
Save FezVrasta/a29f3d8f6a715993a05ba1d24a241d3b to your computer and use it in GitHub Desktop.
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 fs = require('fs'); | |
const path = require('path'); | |
const MODULES_FOLDER = 'mymodules/'; | |
const OUTPUT_DIR = './dist'; | |
function getDirectories(srcpath) { | |
return fs.readdirSync(srcpath) | |
.filter(file => | |
fs.statSync(path.join(srcpath, file)).isDirectory() | |
); | |
} | |
const modulesPath = path.resolve(__dirname, '../../${MODULES_FOLDER}'); | |
const components = getDirectories(modulesPath).map(module => { | |
return `import ${module} from '../${MODULES_FOLDER}/${module}'; export { ${module} };`; | |
}); | |
let indexJs = '// Autogenerated!\n\n'; | |
indexJs += components.join('\n'); | |
if (!fs.existsSync(OUTPUT_DIR)){ | |
fs.mkdirSync(OUTPUT_DIR); | |
} | |
fs.writeFile(`${OUTPUT_DIR}/index.js`, indexJs, function(err) { | |
if (err) { | |
return console.error(err); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment