index.js 858 B

1234567891011121314151617181920212223242526272829303132333435
  1. import fs from "node:fs/promises";
  2. import path from "path";
  3. const main = (options)=> {
  4. fs.mkdir(path.join(import.meta.dirname, ".build"), {recursive: true});
  5. readFiles(path.join(import.meta.dirname, "src"));
  6. }
  7. const readFiles = async (dir)=>{
  8. const files = await fs.readdir(dir, {withFileTypes: true});
  9. for(let i = 0; i < files.length; i++){
  10. let curDir = path.join(dir, files[i].name);
  11. if(files[i].isDirectory()) {
  12. readFiles(curDir);
  13. }
  14. }
  15. parse(dir);
  16. }
  17. const parse = async (dir)=>{
  18. const htmlFile = path.join(dir, "index.html");
  19. const cssFile = path.join(dir, "index.css");
  20. const jsFile = path.join(dir, "index.js");
  21. const [html, css, js] = await Promise.allSettled([
  22. fs.readFile(htmlFile),
  23. fs.readFile(cssFile),
  24. fs.readFile(jsFile)
  25. ]);
  26. }
  27. main();