Skip to content

Instantly share code, notes, and snippets.

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 FezVrasta/a29f3d8f6a715993a05ba1d24a241d3b to your computer and use it in GitHub Desktop.
Save FezVrasta/a29f3d8f6a715993a05ba1d24a241d3b to your computer and use it in GitHub Desktop.
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