浏览代码

updated all cheerpx files, post-process.cjs now appends cxCoreInit() at the end of cxcore.js

oscar 2 月之前
父节点
当前提交
30fef95135
共有 6 个文件被更改,包括 685 次插入673 次删除
  1. 227 222
      assets/cx_esm.js
  2. 227 222
      cx.js
  3. 164 164
      cxcore.js
  4. 二进制
      cxcore.wasm
  5. 67 35
      post_process.cjs
  6. 0 30
      src/lib/WebVM.svelte

文件差异内容过多而无法显示
+ 227 - 222
assets/cx_esm.js


文件差异内容过多而无法显示
+ 227 - 222
cx.js


文件差异内容过多而无法显示
+ 164 - 164
cxcore.js


二进制
cxcore.wasm


+ 67 - 35
post_process.cjs

@@ -1,5 +1,6 @@
 const fs = require('fs');
 const path = require('path');
+const { exec }= require("child_process");
 
 const directoryPath = path.resolve(__dirname, 'build');
 
@@ -9,50 +10,86 @@ function postProcess() {
       console.error("Error reading directory: ", err);
       return;
     }
+    processHtmlFiles(files);
 
-    console.log();
-    console.log(`---Starting post-processing---`);
-    console.log();
-    const htmlFiles = files.filter(file => file.endsWith('html'));
-    htmlFiles.forEach(htmlFile => {
-      console.log(htmlFile);
-      const filePath = path.join(directoryPath, htmlFile);
-      const fileContent = fs.readFileSync(filePath, 'utf-8');
-
-      const scriptContent = extractScript(fileContent);
-      if (scriptContent === '') {
-        if (htmlFile === 'login.html')  {
-          console.log(`Caught login.html: No expected script for ${filePath}, skipping`);
-          return;
-        }
-        console.warn(`Warning: no script content for ${filePath}`);
-        return;
-      }
-      const scriptName = createJsFile(htmlFile, scriptContent);
-      if (scriptName === '') {
-        console.warn(`Warning: no scriptName for ${filePath}`);
+    // 
+    // wanted to take it out of the readdir callback but it messes up print orders
+    // 
+    appendToCxcore();
+
+    console.log("---Finished post-processing---");
+  });
+}
+
+function processHtmlFiles(files) {
+  console.log();
+  console.log(`---Starting post-processing---`);
+  console.log();
+  const htmlFiles = files.filter(file => file.endsWith('html'));
+  htmlFiles.forEach(htmlFile => {
+    console.log( '-' + htmlFile);
+    const filePath = path.join(directoryPath, htmlFile);
+    const fileContent = fs.readFileSync(filePath, 'utf-8');
+
+    const scriptContent = extractScript(fileContent);
+    if (scriptContent === '') {
+      if (htmlFile === 'login.html')  {
+        console.log(`\tAll good! No expected script for ${filePath}, skipped`);
         return;
       }
-      replaceScript(fileContent, filePath, scriptName);
-      console.log(`Successfully extracted scripts from [${htmlFile}] into separate [${scriptName}].`);
-      console.log('')
-    });
+      console.warn(`\tWarning: no script content for ${filePath}`);
+      return;
+    }
+    const scriptName = createJsFile(htmlFile, scriptContent);
+    if (scriptName === '') {
+      console.warn(`\tWarning: no scriptName for ${filePath}`);
+      return;
+    }
+    replaceScript(fileContent, filePath, scriptName);
+    console.log(`\tSuccessfully extracted scripts from [${htmlFile}] into separate [${scriptName}].`);
+  });
 
-    console.log();
-    console.log("---Finished post-processing---");
+
+  console.log();
+  console.log("---Finished post-processing HTML files---");
+  
+}
+
+function appendToCxcore() {
+  console.log();
+  console.log("adding init call to cxcore");
+  console.log();
+  const cxcoreFile = path.resolve(__dirname, 'cxcore.js');
+  exec("tail -n 1 cxcore.js", (err, stdout) => {
+    if (err) {
+      console.error("Failed to exec tail command: ", err);
+      return;
+    }
+    const lastLine = stdout.trim();
+    const content = 'cxCoreInit.promise.then(function(){cxCoreInit();}).catch(function(e){postMessage({type:", m, ",value:e.toString()});})';
+
+    if (lastLine == content) {
+      console.log("All good! cxcore.js already contains correct last line, skipped");
+    } else {
+      try {
+        fs.appendFileSync(cxcoreFile, content);
+      } catch (err) {
+        console.error("Failed to append: ", err);
+      }
+    }
   });
 }
 
 function extractScript(fileContent) {
   const scriptStart = fileContent.indexOf('__sveltekit_');
   if (scriptStart === -1)  {
-    console.log("Could not find __sveltekit_ script start");
+    console.log('\tCould not find __sveltekit_ script start');
     return '';
   }
   var scriptEnd = fileContent.lastIndexOf('</script>');
   scriptEnd -= 6; // getting rid of extra } closing bracket. Will find a better solution than this.
   if (scriptEnd === -1) {
-    console.log("Could not match the closing <script> tag");
+    console.log('\tCould not match the closing <script> tag');
     return '';
   }
   const scriptContent = fileContent.substring(scriptStart, scriptEnd);
@@ -60,7 +97,7 @@ function extractScript(fileContent) {
   if (containsPromiseAll !== -1) {
     return scriptContent;
   } else {
-    console.log("Could not find Promise.all call in generated __sveltekit_ script");
+    console.log('\tCould not find Promise.all call in generated __sveltekit_ script');
     return '';
   }
 }
@@ -80,11 +117,6 @@ function createJsFile(ogFileName, fileContent) {
 
 function replaceScript(fileContent, filePath, scriptName) {
   const updatedContent = fileContent.replace(/<script>[\s\S]*?<\/script>/, `<script src="${scriptName}" defer></script>`);
-  //
-  // debug
-  //
-  // console.log(`Updated content: \n ${updatedContent}`);
-
   fs.writeFileSync(filePath, updatedContent, 'utf-8', (err) =>{
     if (err) {
       console.log("Failed to write replacedContent instead of inlined script: ", err);

+ 0 - 30
src/lib/WebVM.svelte

@@ -308,36 +308,6 @@
 		];
 		try
 		{
-		//
-		// what seems to happen is:
-		// 	- loadCheerpOS() called in IDBDevice::create() from WebVM and runs successfully
-		// 	- WebVM calls Linux.create()
-		// 	- Linux.create() successfully runs? (returns as intended, its lambda also seems to return successfully)
-		// 	- go in CheerpXBase::init();
-		// 	- skip loading CheerpOS because CheerpOSState is already = 2
-		// 	- load tailscale
-		// 		- *loadTailscale calls handleCheerpOSLoadEvent() in a lambda that runs on client(I think)
-		// 	- CheerpOSState doesn't get set to ready* so createCoreWorker() isn't called in init.
-		// 	- instead createCoreWorker() is called client side in handleCheerpOSLoadEvent(), which gets called from loading tailscale
-		// 	- coreWorker() successfully builds and returns, last log I get, pretty sure this is where it's supposed to end and return if there's more execution after this I missed it
-		// 	- WebVM still awaits Linux.create() ?
-		//
-		//
-		// tried:
-		// 	- force setting CheerpOSState to ready after loading tailscale but doesn't seem to change the resulting behaviour, other than iwaStart (from getCheerpXURL) is much higher than usual
-		// 	- tweaking the mountPoints but nothing worked.
-		// 	- networkInterface is optional on cheerpx side so it's not the issue (still tested removing it and behaviour is the same)
-		// 	- commenting out Linux.create() lets WebVM execution go up to registering callbacks where registerCallback() is null and fails, which makes sense
-		//
-		// note:
-		// 	- Jules mentioned it could be from how cheerpX gets cheerpOS, I did run into an issue of getting cheerpOS before but I had fixed it by serving from the WebVM itself, so it should be okay?
-		// 	- Don't remember the exact change I made to make cheerpOS work
-		//
-		// thoughts:
-		// 	- network tab says we're pending on debian_large for a long time (4.5mins) and returns 101 switching protocol?
-		// 	- there has to be more execution I'm missing? but linux.create() is called from WebVM and seems to finish running so nothing else should be called until it returns?
-		// 	- or we keep awaiting for no reason?
-		// 
 			console.debug("calling Linux.create()");
 			cx = await CheerpX.Linux.create({mounts: mountPoints});
 			console.debug("Linux.create() finished");

部分文件因为文件数量过多而无法显示