fix build in command line

This commit is contained in:
codetypes committed 2025-05-22 11:30:41 +08:00
1 parent 10c417808b
commit 825c4fdb63
2 files changed
+26 -4

No files matched your search

+16 -2
View File
@@ -1,4 +1,5 @@
import { app, BrowserWindow, ipcMain, shell } from "electron"; import { app, BrowserWindow, ipcMain, shell } from "electron";
import * as fs from "fs";
import { createRequire } from "node:module"; import { createRequire } from "node:module";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
@@ -29,6 +30,9 @@ for (let i = 0; i < argv.length; i++) {
} }
} }
// buildProject = "D:/Users/bite/Desktop/work/bit-common/btree/btree.b3-workspace";
// buildOutput = "C:/Users/bite/Codetypes/bit-client/assets/resources/data/btree";
const printHelp = () => { const printHelp = () => {
console.log(`Usage: Behavior3 Editor ${VERSION} [options]`); console.log(`Usage: Behavior3 Editor ${VERSION} [options]`);
console.log("Options:"); console.log("Options:");
@@ -49,8 +53,8 @@ if (buildOutput || buildProject || buildHelp) {
process.exit(1); process.exit(1);
} }
try { try {
const project = Path.posixPath(buildProject!); const project = Path.posixPath(Path.resolve(buildProject!));
const buildDir = Path.posixPath(buildOutput!); const buildDir = Path.posixPath(Path.resolve(buildOutput!));
console.log("start build project:", project); console.log("start build project:", project);
if (!project.endsWith(".b3-workspace")) { if (!project.endsWith(".b3-workspace")) {
throw new Error(`'${project}' is not a workspace`); throw new Error(`'${project}' is not a workspace`);
@@ -59,6 +63,16 @@ if (buildOutput || buildProject || buildHelp) {
b3util.initWorkdir(workdir, (msg) => { b3util.initWorkdir(workdir, (msg) => {
console.error(`${msg}`); console.error(`${msg}`);
}); });
console.debug = () => {};
const files = Path.ls(workdir, true);
for (const file of files) {
if (file.endsWith(".json")) {
const path = Path.relative(workdir, file).replaceAll(Path.sep, "/");
b3util.files[path] = fs.statSync(file).mtimeMs;
}
}
const hasError = await b3util.buildProject(project, buildDir); const hasError = await b3util.buildProject(project, buildDir);
if (hasError) { if (hasError) {
console.error("build failed***"); console.error("build failed***");
+10 -2
View File
@@ -857,7 +857,15 @@ export const loadModule = async (path: string) => {
if (typeof require !== "undefined" && require.cache) { if (typeof require !== "undefined" && require.cache) {
delete require.cache[require.resolve(path)]; delete require.cache[require.resolve(path)];
} }
return await import(/* @vite-ignore */ `${path}?t=${Date.now()}`); if (process.type === "renderer") {
return await import(/* @vite-ignore */ `${path}?t=${Date.now()}`);
} else {
const mjs = path.endsWith(".mjs") ? path : path.replace(".js", ".mjs");
fs.copyFileSync(path, mjs);
const ret = await import(/* @vite-ignore */ `file:///${mjs}?t=${Date.now()}`);
fs.unlinkSync(mjs);
return ret;
}
} catch (e) { } catch (e) {
console.error(`failed to load module: ${path}`, e); console.error(`failed to load module: ${path}`, e);
return null; return null;
@@ -919,7 +927,7 @@ export const isTreeFile = (path: string) => {
const loadVarDecl = (list: ImportDecl[], arr: Array<VarDecl>) => { const loadVarDecl = (list: ImportDecl[], arr: Array<VarDecl>) => {
for (const entry of list) { for (const entry of list) {
if (!files[entry.path]) { if (!files[entry.path]) {
console.warn(`file not found:${workdir}/${entry.path}`); console.warn(`file not found: ${workdir}/${entry.path}`);
continue; continue;
} }