From 825c4fdb634b3d9c74f3161805122f939813c841 Mon Sep 17 00:00:00 2001 From: codetypes Date: Thu, 22 May 2025 11:30:41 +0800 Subject: [PATCH] fix build in command line --- electron/main/index.ts | 18 ++++++++++++++++-- src/misc/b3util.ts | 12 ++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 4d1f51b..9b72d1a 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -1,4 +1,5 @@ import { app, BrowserWindow, ipcMain, shell } from "electron"; +import * as fs from "fs"; import { createRequire } from "node:module"; import os from "node:os"; 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 = () => { console.log(`Usage: Behavior3 Editor ${VERSION} [options]`); console.log("Options:"); @@ -49,8 +53,8 @@ if (buildOutput || buildProject || buildHelp) { process.exit(1); } try { - const project = Path.posixPath(buildProject!); - const buildDir = Path.posixPath(buildOutput!); + const project = Path.posixPath(Path.resolve(buildProject!)); + const buildDir = Path.posixPath(Path.resolve(buildOutput!)); console.log("start build project:", project); if (!project.endsWith(".b3-workspace")) { throw new Error(`'${project}' is not a workspace`); @@ -59,6 +63,16 @@ if (buildOutput || buildProject || buildHelp) { b3util.initWorkdir(workdir, (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); if (hasError) { console.error("build failed***"); diff --git a/src/misc/b3util.ts b/src/misc/b3util.ts index bf65e7b..f5b48ea 100644 --- a/src/misc/b3util.ts +++ b/src/misc/b3util.ts @@ -857,7 +857,15 @@ export const loadModule = async (path: string) => { if (typeof require !== "undefined" && require.cache) { 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) { console.error(`failed to load module: ${path}`, e); return null; @@ -919,7 +927,7 @@ export const isTreeFile = (path: string) => { const loadVarDecl = (list: ImportDecl[], arr: Array) => { for (const entry of list) { if (!files[entry.path]) { - console.warn(`file not found:${workdir}/${entry.path}`); + console.warn(`file not found: ${workdir}/${entry.path}`); continue; }