Ver Fonte

Bug fix: css/js was rendering strange if missing in neovan file.

Lee Morgan há 5 dias atrás
pai
commit
033275ab98
2 ficheiros alterados com 14 adições e 4 exclusões
  1. 2 1
      index.js
  2. 12 3
      parseComponent.js

+ 2 - 1
index.js

@@ -30,7 +30,8 @@ const readFiles = async (dir, root, app)=>{
 
     let indexFile = await findIndexFile(dir);
     if(!indexFile) return;
-    writeBundleFile(dir, await parseComponent(indexFile));
+    await writeBundleFile(dir, await parseComponent(indexFile));
+    fs.rm(path.join(dir, "tmp/"), {recursive: true, force: true});
 }
 
 const findIndexFile = async (dir)=>{

+ 12 - 3
parseComponent.js

@@ -12,7 +12,6 @@ const parseComponent = async (file)=>{
     }else{
         data = await parseHtml(file);
     }
-    fs.rm(path.join(dir, "tmp/"), {recursive: true, force: true});
     return await createBundle(data);
 }
 
@@ -21,8 +20,16 @@ const getNeovanData = async (index)=>{
     const parentPath = path.dirname(index);
     
     const html = neovan.slice(neovan.indexOf("<contents>") + 10, neovan.indexOf("</contents>"));
-    const css = neovan.slice(neovan.indexOf("<style>") + 7, neovan.indexOf("</style>"));
-    const js = neovan.slice(neovan.indexOf("<script>") + 8, neovan.indexOf("</script>"));
+    let css = "";
+    let js = "";
+    const cssIndex = neovan.indexOf("<style>");
+    if(cssIndex >= 0){
+        css = neovan.slice(cssIndex + 7, neovan.indexOf("</style>"));
+    }
+    const jsIndex = neovan.indexOf("<script>")
+    if(jsIndex >= 0){
+        js = neovan.slice(jsIndex + 8, neovan.indexOf("</script>"));
+    }
 
     const cssFile = path.join(parentPath, `tmp/${path.basename(index, ".neovan")}.css`);
     const jsFile = path.join(parentPath, `tmp/${path.basename(index, ".neovan")}.js`);
@@ -103,6 +110,8 @@ const createBundle = async (data)=>{
 }
 
 const mergeFiles = (comps)=>{
+    console.log(comps);
+    console.log();
     let cssIndex = comps.html.indexOf("</head>");
     cssIndex = cssIndex < 0 ? 0 : cssIndex;
     comps.css = comps.css ? `<style>${comps.css}</style>` : "";