123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- const testFolder = './modules';
- const fs = require('fs');
- let Modules = fs.readdirSync(testFolder).filter(file =>
- fs.lstatSync(testFolder + '/' + file).isDirectory());
- writeToFile(testFolder + "/index.js", makeFile(Modules));
- Modules.forEach((mod) => {
- try {
- let styles = fs.readdirSync(testFolder + "/" + mod + "/styles")
- .filter(file => file !== 'index.js' && file.includes('.js'))
- .map(file => file.replace('.js', ''));
- writeToFile(testFolder + "/" + mod + "/styles/index.js", makeFile(styles));
- } catch(e) {
- console.log("[-] Module: " + mod + " has no styles");
- }
- })
- function writeToFile(filename, content){
- fs.writeFile(filename, content, function(err) {
- if(err) {
- return console.log(err);
- }
- console.log("File: " + filename + " written sucessfully");
- });
- }
- function makeFile(arr) {
- let indexFile = "";
- // imports first
- arr.forEach((mod) => {
- indexFile += "import " + mod + " from './" + mod + "';\r\n";
- });
- // exports
- indexFile += "\r\nexport default {\r\n";
- indexFile += arr.join(',\r\n');
- indexFile += "\r\n}\r\n";
- return indexFile;
- }
|