3
0

indexize.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const testFolder = './modules';
  2. const fs = require('fs');
  3. let Modules = fs.readdirSync(testFolder).filter(file =>
  4. fs.lstatSync(testFolder + '/' + file).isDirectory());
  5. writeToFile(testFolder + "/index.js", makeFile(Modules));
  6. Modules.forEach((mod) => {
  7. try {
  8. let styles = fs.readdirSync(testFolder + "/" + mod + "/styles")
  9. .filter(file => file !== 'index.js' && file.includes('.js'))
  10. .map(file => file.replace('.js', ''));
  11. writeToFile(testFolder + "/" + mod + "/styles/index.js", makeFile(styles));
  12. } catch(e) {
  13. console.log("[-] Module: " + mod + " has no styles");
  14. }
  15. })
  16. function writeToFile(filename, content){
  17. fs.writeFile(filename, content, function(err) {
  18. if(err) {
  19. return console.log(err);
  20. }
  21. console.log("File: " + filename + " written sucessfully");
  22. });
  23. }
  24. function makeFile(arr) {
  25. let indexFile = "";
  26. // imports first
  27. arr.forEach((mod) => {
  28. indexFile += "import " + mod + " from './" + mod + "';\r\n";
  29. });
  30. // exports
  31. indexFile += "\r\nexport default {\r\n";
  32. indexFile += arr.join(',\r\n');
  33. indexFile += "\r\n}\r\n";
  34. return indexFile;
  35. }