From 2ee2c162dabbc51d7c955be6201e63921750c83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BA=B7?= Date: Mon, 9 Nov 2026 18:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + README.md | 36 ++++--- package.json | 1 + scripts/build-cad.mjs | 94 ++++++++++++++++++ scripts/build.mjs | 47 ++++----- scripts/cad-engine.mjs | 4 +- scripts/lib/version-site-assets.mjs | 23 ++++- scripts/server.mjs | 1 + tests/build-isolation.test.js | 148 ++++++++++++++++++++++++++++ tests/build-versions.test.js | 34 +++++++ 10 files changed, 349 insertions(+), 41 deletions(-) create mode 100644 scripts/build-cad.mjs create mode 100644 tests/build-isolation.test.js diff --git a/.gitignore b/.gitignore index 11c14ed..2609746 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ node_modules/ /dist-dev/ dist.zip dist-dev.zip +/dist-cad/ +/dist-cad.zip vibemake-dist/ .DS_Store sandbox/node_modules/ diff --git a/README.md b/README.md index 26958fb..407951d 100644 --- a/README.md +++ b/README.md @@ -14,26 +14,38 @@ npm --prefix sandbox ci npm run build:walking ``` -开发环境部署执行 `npm run build:dev`,生成 `dist-dev/` 和固定连接 dev 接口的 `dist-dev.zip`;线上部署执行 `npm run build`,生成 `dist/` 和按访问域名选择接口的 `dist.zip`。两个目录互不覆盖。压缩包中的 `DEPLOY.md` 标明目标域名和构建版本;发布后通过网站 `/build-info.json` 核对版本。`dist/`、`dist-dev/`、`play/` 和 `deliverables/` 为本地产物,不提交 Git;生成仿真运行器所需的源码、素材和锁文件保存在 `sandbox/`。 +开发环境部署执行 `npm run build:dev`,生成 `dist-dev/` 和固定连接 dev 接口的 `dist-dev.zip`;线上部署执行 `npm run build`,生成 `dist/` 和按访问域名选择接口的 `dist.zip`。两个目录互不覆盖。主站包排除 `cad/`、`pcb/`、`js/cad/` 和 `css/cad.css`,无需 PCB / CAD 仓库或引擎文件。发布时合并覆盖主站文件,保留线上独立模块;不要清空网站根目录。压缩包中的 `DEPLOY.md` 标明目标域名和构建版本;发布后通过网站 `/build-info.json` 核对版本。`dist/`、`dist-dev/`、`dist-cad/`、`play/` 和 `deliverables/` 为本地产物,不提交 Git;生成仿真运行器所需的源码、素材和锁文件保存在 `sandbox/`。 生成 `/play/robots/index.html`(Robot Package 通用运行器)和 `/play/microduck/index.html`(旧版 Microduck 包)。两者由本站提供,按详情接口选择;关闭弹窗会释放仿真。修改沙盒后再次执行 `npm run build:walking`;`npm run build` 会自动构建并收录。默认暂停,点击开始后按住键盘 / 触摸方向键运动,松开停止。来源记录见 `sandbox/NOTICE`。 ### CAD Web engine -Build the engine with `./build.sh` in the SolidCraft repository. Then run these commands from the VibeMake project root: +For a complete independent CAD release, run `./build.sh` in the SolidCraft repository. It builds the current engine and produces `dist/vibemake-cad.zip`. The ZIP root contains `index.html`, `editor/index.html`, the matching engine, CAD and shared dependency modules under `js/`, `css/fonts.css`, `css/style.css`, `css/cad.css`, required `vendor/` and brand/environment assets, icons, and robot indexes under `data/` and `robots/`. It has no enclosing `cad/` directory. + +Extract the complete ZIP directly into the website's `cad/` directory, so it creates `cad/index.html` and `cad/editor/index.html`: + +```bash +unzip -o /path/to/solidcraft-main/dist/vibemake-cad.zip -d /path/to/vibemake/cad +``` + +Extract the archive itself; merely uploading the ZIP does not publish its HTML. Do not extract the complete package into the website root or add an extra directory. CAD has its own JS, CSS, fonts, navigation/authentication dependencies and vendor files inside `cad/`, so publishing the main site cannot replace those copies. The build script reads CAD page sources from the adjacent `../vibemake` checkout; run `npm ci` here once to install its packaging dependency. Set `VIBEMAKE_SITE_ROOT` when that checkout lives elsewhere. + +SolidCraft also produces `dist/vibemake-cad-engine.zip`, which contains only engine resources and **no HTML pages**. Use it only to update an already deployed CAD application, or install it for local development with these commands from the VibeMake project root: ```bash unzip -o ../solidcraft-main/dist/vibemake-cad-engine.zip -d . npm run dev ``` -The archive already contains a `cad/` directory. Merge it into the project root so that `cad/engine.json`, `cad/sw.js` and `cad/_assets//` sit beside the existing `cad/editor/`. Do not extract it into `cad/cad/` or replace the whole existing `cad/` directory. No CAD engine path environment variable is needed. Restart the development server after installing a new engine. +The engine-only archive already contains a top-level `cad/` directory. Unlike the complete package, extract it into the website or project root so that `cad/engine.json`, `cad/sw.js` and `cad/_assets//` sit beside the existing pages. Do not extract it into `cad/cad/` or replace the whole existing `cad/` directory. No CAD engine path environment variable is needed. Restart the development server after installing a new engine. -`npm run build` and `npm run build:dev` validate the engine installed in `cad/` and include its current assets in the site ZIP. If no engine is installed, the build reports that the engine must be deployed separately. Engine binaries are generated files and are not committed to this repository. +CAD is published independently. `npm run build` and `npm run build:dev` never read or include the CAD engine, pages, private JS or CAD stylesheet. They work without any engine installed. Engine binaries are generated files and are not committed to this repository. + +The optional compatibility command `npm run build:cad` generates `dist-cad/` and `dist-cad.zip` from the engine already installed locally, together with the CAD pages and all frontend dependencies. Extract this complete package directly into the website's `cad/` directory too. It is not required after SolidCraft's `./build.sh`, which directly generates `vibemake-cad.zip` using the newly built engine. Preserve main-site and PCB files, and keep older `cad/_assets//` directories for open editors. Do not clear the website or CAD directory before extraction. The site registers `/cad/worker.js`, which imports the engine package's `/cad/sw.js` and supplies the update activation protocol, including for older engine packages. The refresh action first runs the unsaved-changes guard, activates the waiting worker, and then reloads. Update notices compare the published engine build with the running build, rather than treating every waiting worker as a new editor version. Login state, IndexedDB drafts, and other applications' caches are retained. -Deploy the site changes (including `cad/worker.js` and `js/cad/`) once with this fix; replacing only the engine ZIP cannot repair the old site's refresh handler. Serve `/cad/engine.json`, `/cad/sw.js`, `/cad/worker.js`, the editor HTML, and `js/cad/` with `Cache-Control: no-cache` (or `no-store`). Only `/cad/_assets//` should use long-lived immutable caching. The development server already applies these cache policies. Update regressions: `node --test tests/cad/engine-updates.browser.mjs`. +Publish the complete CAD package (`vibemake-cad.zip`, or the compatibility `dist-cad.zip`) when changing `cad/worker.js`, `js/cad/` source files or the CAD pages; replacing only the engine ZIP cannot update those files. Serve `/cad/engine.json`, `/cad/sw.js`, `/cad/worker.js`, the editor HTML, and `/cad/js/` with `Cache-Control: no-cache` (or `no-store`). Only `/cad/_assets//` should use long-lived immutable caching. Update regressions: `node --test tests/cad/engine-updates.browser.mjs`. ### 项目装配与行走资源 @@ -186,17 +198,19 @@ robots/demo-*/ 早期用基础几何体生成的演示 URDF(已不在 ```bash npm install # 第一次打包前装一次(只是打包工具:模型压缩) -pnpm -C ../ziro-designer-main/designer build # 独立构建 PCB 应用 -npm run build # 构建仿真并收录 PCB 应用,生成 dist/ 和 dist.zip -npm run build:dev # 同样收录 PCB 应用,生成固定 dev 接口的 dist-dev/ 和 dist-dev.zip -PCB_DIST=/path/to/designer/dist node scripts/build.mjs # PCB 仓库不在默认相邻目录时指定构建产物 +npm run build # 只构建主站与仿真,生成 dist/ 和 dist.zip +npm run build:dev # 只构建 dev 主站,生成 dist-dev/ 和 dist-dev.zip +npm run build:cad # 可选兼容命令:用本地已安装引擎生成 dist-cad.zip +# PCB:在 ziro-designer-main 中执行 ./build.sh,生成 dist/vibemake-pcb.zip +# CAD 完整发布:在 solidcraft-main 中执行 ./build.sh,生成 dist/vibemake-cad.zip +# CAD 引擎单独更新:同一次构建还会生成 dist/vibemake-cad-engine.zip(没有 HTML) SITE_ROOT=dist PORT=8093 node scripts/server.mjs # 本地预览线上包 SITE_ROOT=dist-dev PORT=8094 node scripts/server.mjs # 本地预览 dev 包 ``` -主站打包时将独立构建的 PCB 静态产物复制到输出目录的 `pcb/`。线上服务器需将无扩展名 PCB 工程地址回退到 `/pcb/index.html`,静态资源按原路径返回。 +主站、PCB、CAD 各自发布,主站包中没有 `cad/`、`pcb/`、`js/cad/` 或 `css/cad.css`,不会用本地旧模块覆盖线上版本。主站 ZIP 解压到网站根目录。PCB 的 `dist/vibemake-pcb/` 与 `dist/vibemake-pcb.zip` 根目录直接包含 `index.html`、`assets/` 等文件,不带额外一层 `pcb/`,完整 PCB ZIP 必须解压到网站的 `pcb/` 目录。完整 CAD 包 `vibemake-cad.zip` 的根目录直接是 `index.html`、`editor/`、`js/`、`css/` 和引擎资源,必须解压到网站的 `cad/` 目录。CAD 所需脚本、样式、字体和公共依赖均在自己的 `cad/` 内,不再依赖网站根目录的同名资源。不要只把 ZIP 放进去而不解压,也不要额外套一层目录。`vibemake-cad-engine.zip` 仅用于引擎更新,没有 HTML,自带顶层 `cad/`,反而应解压到网站根目录;不能作为首次 CAD 部署包。保留旧的 CAD build-id 和 PCB 哈希资源目录。后端服务和 API 反向代理继续独立维护。线上服务器需将无扩展名 PCB 工程地址回退到 `/pcb/index.html`,但 `/pcb/pcb-api/` 必须先由后端代理处理。 -两种输出目录都附带 `DEPLOY.md` 和 `build-info.json`,记录目标域名、环境、构建版本和时间。手动上传时核对服务器、网站和根目录,先解压到新版本目录,确认完整后再切换网站目录,保留上一版本以便回退。发布后核对网站 `/build-info.json` 的 `buildId` 和 `deploymentTarget` 与上传包一致。 +两种主站输出目录都附带 `DEPLOY.md` 和 `build-info.json`,记录目标域名、环境、构建版本和时间。手动上传时核对服务器、网站和根目录,合并覆盖包内文件,保留独立模块和上一版本以便回退;不要使用不带排除规则的 `rsync --delete`。如需切换整个网站目录,新目录必须先保留当前线上 `cad/`、`pcb/`、`js/cad/` 和 `css/cad.css`,或使用独立模块的固定软链接。发布后核对网站 `/build-info.json` 的 `buildId` 和 `deploymentTarget` 与上传包一致。 CAD 平台助手的容量、截图、超时和请求频率读取 `/api/cad/ai/capabilities` 的实际 `limits`,缺失或为 0 的字段不增加前端业务上限。每次续调都会向模型补充当前限额、已用容量和剩余图片数;图片自动缩小并重新编码,过大的工具文字结果返回明确错误,要求缩小查询,禁止将残缺 JSON 当成结果或重做已执行修改。旧历史只按完整用户轮次裁剪。按照复杂建模需求,当前前端继续取消单轮 12 次模型调用和 24 条修改的限制;这些整轮限额若要恢复,需要前后端先统一产品配置。 diff --git a/package.json b/package.json index e907a33..58476b3 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "test:experiences": "node --test scripts/experience-packages.test.mjs scripts/model-assets.test.mjs scripts/project-resources.test.mjs scripts/assembly-motion.test.mjs scripts/assembly-explode.test.mjs", "build": "npm run build:walking && node scripts/build.mjs", "build:dev": "npm run build:walking && node scripts/build.mjs --env=dev", + "build:cad": "node scripts/build-cad.mjs", "test:cad": "node --test tests/cad/*.test.js scripts/cad-engine.test.mjs", "test:cad:browser": "node tests/cad/browser-e2e.mjs", "test:cad:assistant": "node tests/cad/assistant-browser.mjs", diff --git a/scripts/build-cad.mjs b/scripts/build-cad.mjs new file mode 100644 index 0000000..7d671bf --- /dev/null +++ b/scripts/build-cad.mjs @@ -0,0 +1,94 @@ +// Publish a self-contained directory mounted at /cad/, separate from the main site. +import { build } from 'esbuild'; +import { cpSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'; +import { basename, dirname, join, resolve, sep } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { execFileSync } from 'node:child_process'; +import { readCadEngine, copyCadEngine } from './cad-engine.mjs'; +import { versionSiteAssets } from './lib/version-site-assets.mjs'; + +const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url))); +const DIST = resolve(process.env.VIBEMAKE_CAD_PACKAGE_DIR || join(ROOT, 'dist-cad')); +const ARCHIVE = resolve(process.env.VIBEMAKE_CAD_PACKAGE_ZIP || join(ROOT, 'dist-cad.zip')); +// A CAD build supplies its fresh engine directly instead of using an older local install. +const engine = readCadEngine(process.env.VIBEMAKE_CAD_ENGINE_DIST || join(ROOT, 'cad')); +const contains = (directory, path) => path === directory || path.startsWith(directory + sep); +if (contains(DIST, ROOT) || contains(DIST, engine.root) + || ['cad', 'js', 'css', 'scripts'].some(path => contains(join(ROOT, path), DIST))) { + throw new Error('CAD package output must not replace the site sources or engine input.'); +} +const archiveName = basename(ARCHIVE); +const buildId = Date.now().toString(36); +const pages = [ + { source: 'cad.html', target: 'index.html' }, + { source: 'cad/editor/index.html', target: 'editor/index.html' }, +].map(page => ({ ...page, html: readFileSync(join(ROOT, page.source), 'utf8') })); +if (pages.some(page => !/<\/head>/i.test(page.html))) throw new Error('CAD HTML must contain a document head for its import map.'); +const importMapSource = readFileSync(join(ROOT, 'index.html'), 'utf8').match(/]*type=["']importmap["'][^>]*>([\s\S]*?)<\/script>/i); +if (!importMapSource) throw new Error('The site import map is required for the CAD dependencies.'); +const importMap = JSON.parse(importMapSource[1]); +// Copy the actual module closure, including lazy imports, without publishing unrelated site pages. +const entryPoints = [...new Set(pages.flatMap(page => [...page.html.matchAll(/]*src=["']\/(js\/[^"'?#]+\.js)(?:[^"']*)["']/gi)].map(match => match[1])))]; +if (!entryPoints.includes('js/cad/app.js')) throw new Error('The CAD application entry is missing from its HTML.'); +const graph = await build({ + absWorkingDir: ROOT, entryPoints, outdir: join(DIST, 'js'), + bundle: true, format: 'esm', platform: 'browser', packages: 'external', + external: ['/vendor/*'], write: false, metafile: true, logLevel: 'silent', +}); +const modules = Object.keys(graph.metafile.inputs); +if (modules.some(path => !path.startsWith('js/') || !path.endsWith('.js') || path.split('/').includes('..'))) { + throw new Error('A CAD application dependency is outside the site JavaScript directory.'); +} +// Change static assets only; navigation, API endpoints and existing /cad/ engine URLs stay intact. +const localize = text => text + .replace(/(?${JSON.stringify(importMap, null, 2)}`; +rmSync(DIST, { recursive: true, force: true }); +mkdirSync(DIST, { recursive: true }); +const put = (path, text) => { + mkdirSync(dirname(join(DIST, path)), { recursive: true }); + writeFileSync(join(DIST, path), text); +}; +const copy = path => { + mkdirSync(dirname(join(DIST, path)), { recursive: true }); + cpSync(join(ROOT, path), join(DIST, path), { recursive: true, filter: source => !/(^|\/)\.DS_Store$/.test(source) }); +}; +for (const page of pages) put(page.target, localize(page.html).replace(/<\/head>/i, `${importMapTag}\n`)); +for (const file of ['manifest.webmanifest', 'worker.js']) put(file, localize(readFileSync(join(ROOT, 'cad', file), 'utf8'))); +for (const file of modules) put(file, localize(readFileSync(join(ROOT, file), 'utf8'))); +for (const file of ['css/fonts.css', 'css/style.css', 'css/cad.css']) put(file, localize(readFileSync(join(ROOT, file), 'utf8'))); +for (const path of ['vendor', 'assets/brand', 'assets/environments', 'data', 'robots/robots.json', 'favicon.svg', 'favicon.ico', 'apple-touch-icon.png', 'icon-192.png', 'icon-512.png']) copy(path); +copyCadEngine(engine, DIST, { directory: '' }); +await versionSiteAssets(DIST, buildId, pages.map(page => page.target), { publicPath: '/cad/' }); +writeFileSync(join(DIST, 'build-info.json'), JSON.stringify({ + scope: 'cad', buildId, engineBuildId: engine.manifest.buildId, + builtAt: new Date().toISOString(), archive: archiveName, mountPath: '/cad/', +}, null, 2) + '\n'); +writeFileSync(join(DIST, 'DEPLOY.md'), `# CAD independent deployment + +Extract the contents of ${archiveName} directly into /cad/: + + mkdir -p /path/to/vibemake/cad + unzip -o /path/to/${archiveName} -d /path/to/vibemake/cad + +The ZIP root contains index.html, editor/, js/, css/, vendor/, assets/, icons and the verified engine. It has no enclosing cad/ directory. Do not extract this complete package into the website root. +The result must be /cad/index.html and /cad/editor/index.html, never cad/cad/. Both directory URLs must serve index.html (configure the static server's directory index). Use HTTP(S), not file://. +All CAD scripts, common styles, fonts and vendor dependencies are included inside cad/. No main-site build or deployment is required. Navigation still links to the main site; authentication and project storage use the existing backend and vm.auth login. +Keep existing cad/_assets// directories for open editors. Do not delete the website or unrelated modules before extraction. +Check /cad/build-info.json after deployment: buildId=${buildId}, engineBuildId=${engine.manifest.buildId}. +Serve CAD HTML, engine.json, sw.js, worker.js, js/, css/ and vendor/ with Cache-Control: no-cache. Only cad/_assets// uses immutable caching. Serve WASM as application/wasm. +To update only the engine of an already deployed CAD frontend, merge SolidCraft's dist/vibemake-cad-engine.zip into the website root instead. That engine-only archive has an enclosing cad/ directory, no HTML and cannot provide an initial CAD deployment. Use the complete package when publishing CAD. +`); +mkdirSync(dirname(ARCHIVE), { recursive: true }); +const temporaryArchive = join(dirname(ARCHIVE), `.${archiveName}.${buildId}.tmp.zip`); +try { + execFileSync('zip', ['-qr', temporaryArchive, '.'], { cwd: DIST }); + execFileSync('unzip', ['-tq', temporaryArchive], { stdio: 'pipe' }); + renameSync(temporaryArchive, ARCHIVE); +} finally { + rmSync(temporaryArchive, { force: true }); +} +console.log(`CAD package: ${ARCHIVE} (pages ${buildId}, engine ${engine.manifest.buildId})`); diff --git a/scripts/build.mjs b/scripts/build.mjs index ddd16f1..eea7391 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -6,7 +6,6 @@ import { join, resolve } from 'node:path'; import { execFileSync } from 'node:child_process'; import { fileURLToPath } from 'node:url'; import { compressRobot } from './meshes.mjs'; -import { readCadEngine, copyCadEngine } from './cad-engine.mjs'; import { versionSiteAssets } from './lib/version-site-assets.mjs'; const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url))); @@ -20,14 +19,14 @@ const ARCHIVE_NAME = `${OUTPUT_NAME}.zip`; const TARGET_NAME = IS_DEV ? 'DEV 开发环境' : '线上正式环境'; const FRONTEND = IS_DEV ? 'https://dev-vibemake.robotquan.com' : 'https://vibemake.robotquan.com'; const API_BASE = IS_DEV ? 'https://dev-vibemake-api.robotquan.com/api' : 'https://vibemake-api.robotquan.com/api'; -const CAD_ENGINE = existsSync(join(ROOT, 'cad/engine.json')) ? readCadEngine(join(ROOT, 'cad')) : null; -const PCB_DIST = resolve(process.env.PCB_DIST || join(ROOT, '../ziro-designer-main/designer/dist')); -if (!existsSync(join(PCB_DIST, 'index.html'))) - throw new Error(`PCB build not found at ${PCB_DIST}. Build ziro-designer-main/designer first, or set PCB_DIST.`); const SKIP = /(^|\/)(\.DS_Store|Thumbs\.db)$/; -const copy = (rel) => cpSync(join(ROOT, rel), join(DIST, rel), { recursive: true, filter: (src) => !SKIP.test(src) }); +const INDEPENDENT_PATHS = ['cad', 'pcb', 'js/cad', 'css/cad.css']; +const copy = (rel) => cpSync(join(ROOT, rel), join(DIST, rel), { + recursive: true, + filter: (src) => !SKIP.test(src) && !INDEPENDENT_PATHS.some((path) => src === join(ROOT, path)), +}); -// Rebuild the site package and include the CAD engine installed in the project. +// CAD and PCB are independently published and never belong to the site package. mkdirSync(DIST, { recursive: true }); for (const name of readdirSync(DIST)) rmSync(join(DIST, name), { recursive: true, force: true }); @@ -38,18 +37,11 @@ if (!apiSource.includes("export const BUILD_ENV = 'auto';")) throw new Error(' writeFileSync(apiFile, apiSource.replace("export const BUILD_ENV = 'auto';", `export const BUILD_ENV = '${BUILD_ENV}';`)); // 浏览器标签、收藏夹和添加到手机桌面使用独立的简化机器人图标。 for (const f of ['favicon.svg', 'favicon.ico', 'apple-touch-icon.png', 'site.webmanifest', 'icon-16.png', 'icon-32.png', 'icon-48.png', 'icon-64.png', 'icon-192.png', 'icon-512.png']) copy(f); -// 静态网站:每个页面放进同名目录的 index.html,地址是 /explore/、/studio/、/cad/、/pcb/、/project/?id=…、/workspace/?code=… -for (const page of ['explore', 'project', 'studio', 'cad', 'workspace']) { +// 静态网站:CAD / PCB 页面由各自的独立发布包提供。 +for (const page of ['explore', 'project', 'studio', 'workspace']) { mkdirSync(join(DIST, page), { recursive: true }); cpSync(join(ROOT, `${page}.html`), join(DIST, page, 'index.html')); } -cpSync(PCB_DIST, join(DIST, 'pcb'), { recursive: true }); - -cpSync(join(ROOT, 'cad/editor'), join(DIST, 'cad/editor'), { recursive: true }); -cpSync(join(ROOT, 'cad/manifest.webmanifest'), join(DIST, 'cad/manifest.webmanifest')); -cpSync(join(ROOT, 'cad/worker.js'), join(DIST, 'cad/worker.js')); -if (CAD_ENGINE) copyCadEngine(CAD_ENGINE, DIST); - // 只带 robots.json 里用到的模型目录(demo-* 是早期示例,不上线) mkdirSync(join(DIST, 'robots')); copy('robots/robots.json'); @@ -73,6 +65,8 @@ writeFileSync(join(DIST, 'build-info.json'), JSON.stringify({ frontend: FRONTEND, apiBase: API_BASE, archive: ARCHIVE_NAME, + scope: 'site', + excludedPaths: INDEPENDENT_PATHS, }, null, 2) + '\n'); writeFileSync(join(DIST, 'DEPLOY.md'), `# ${TARGET_NAME}部署 @@ -82,7 +76,9 @@ writeFileSync(join(DIST, 'DEPLOY.md'), `# ${TARGET_NAME}部署 - 构建版本:${BUILD_ID} - 本地目录:${OUTPUT_NAME}/(两种环境分别输出,互不覆盖) -手动发布时先核对面板中的服务器、网站域名和网站根目录。建议先解压到本网站的新版本目录,确认完整后再切换网站目录,避免访问到解压过程中新旧混合的文件;保留上一版本以便回退,不覆盖服务器配置。 +本包只更新主站,不包含 cad/、pcb/、js/cad/ 和 css/cad.css,也不需要 CAD / PCB 源码或构建产物。 +手动发布时先核对面板中的服务器、网站域名和网站根目录,再将包内文件合并覆盖到现有网站根目录。保留线上 cad/、pcb/、js/cad/ 和 css/cad.css;不要先清空网站,不要使用不带排除规则的 rsync --delete。 +如需先解压到新版本目录再切换网站目录,必须先将上述独立模块从当前线上目录完整保留到新目录,或使用指向独立模块目录的固定软链接;主站 ZIP 本身不能替代整个网站目录。保留上一版本和服务器配置以便回退。 发布后打开 ${FRONTEND}/build-info.json?check=${BUILD_ID},核对 buildId 为 ${BUILD_ID},deploymentTarget 为 ${IS_DEV ? 'dev' : 'production'}。若不同,检查解压位置、网站根目录及缓存配置。 ${BUILD_ENV === 'dev' ? `本包仅用于 dev 环境,接口固定为 https://dev-vibemake-api.robotquan.com/api,始终读取接口数据。 @@ -96,9 +92,9 @@ ${BUILD_ENV === 'dev' ? `本包仅用于 dev 环境,接口固定为 https://de ` : ''}静态网站,1Panel 新建「静态网站」,把本目录所有文件放到网站根目录即可,不需要运行 npm 或 Node 服务。 - 页面地址:\`/\`、\`/explore/\`、\`/studio/\`、\`/cad/\`、\`/pcb/\`、\`/project/?id=<编号>\`、\`/workspace/\`、\`/workspace/?code=<编号>\` -- PCB:与主站同源部署在 /pcb/,由独立 PCB 仓库构建;项目列表和工程深链接由 PCB 单页应用处理。站点包将 PCB_DIST 指定的独立构建复制到 dist/pcb,无需合并两份源码。 -- CAD:/cad/ 为同源项目列表,/cad/editor/?project= 直接加载 Rust/WASM;CAD / PCB 仅电脑端开放。 -- CAD engine: ${CAD_ENGINE ? `included from cad/ (build ${CAD_ENGINE.manifest.buildId}).` : 'not installed in this build; extract the SolidCraft Web package into the website root before using the CAD editor.'} +- PCB:在 PCB 仓库执行 ./build.sh,生成 dist/vibemake-pcb.zip 和 dist/vibemake-pcb/。目录与压缩包根目录直接包含 index.html、assets/ 等文件,不带额外一层 pcb/;将包内文件直接解压到网站根目录下的 pcb/ 目录,不随主站发布。 +- CAD:在 SolidCraft 仓库执行 ./build.sh,将完整发布包 dist/vibemake-cad.zip 解压到网站根目录下的 cad/ 目录;包内直接是 index.html、editor/、js/、css/、vendor/ 和当次构建的引擎,不再套一层 cad/。dist/vibemake-cad-engine.zip 只有引擎,没有 HTML,仅用于已部署 CAD 页面的引擎更新,该引擎包自带 cad/,需合并解压到网站根目录。主站 build / build:dev 不发布这些文件。 +- CAD / PCB 仅电脑端开放;更新主站后继续使用线上已发布的模块版本。 - Nginx 等静态服务器需让 PCB 无扩展名深链接回退到 /pcb/index.html,例如:location ^~ /pcb/ { try_files $uri $uri/ /pcb/index.html; }。 - 接口:${BUILD_ENV === 'dev' ? '固定连接 https://dev-vibemake-api.robotquan.com/api。' : '浏览器按访问的域名直接请求后端(js/api.js 的 API_HOSTS):dev-vibemake.robotquan.com → https://dev-vibemake-api.robotquan.com/api;vibemake.robotquan.com → https://vibemake-api.robotquan.com/api。'} - **后端需要允许前端域名跨域**(CORS:允许来源 ${BUILD_ENV === 'dev' ? 'https://dev-vibemake.robotquan.com' : 'https://dev-vibemake.robotquan.com、https://vibemake.robotquan.com'}; @@ -109,7 +105,13 @@ ${BUILD_ENV === 'dev' ? `本包仅用于 dev 环境,接口固定为 https://de - HTML 建议设置 Cache-Control: no-cache,确保浏览器能获取新入口。首次修复旧缓存后强制刷新一次;若启用了 CDN 缓存 HTML,发布后同步刷新页面缓存。 `); -await versionSiteAssets(DIST, BUILD_ID, ['index.html', 'explore/index.html', 'project/index.html', 'studio/index.html', 'cad/index.html', 'cad/editor/index.html', 'pcb/index.html', 'workspace/index.html']); +await versionSiteAssets(DIST, BUILD_ID, ['index.html', 'explore/index.html', 'project/index.html', 'studio/index.html', 'workspace/index.html'], { + externalDirectories: ['js/cad'], externalUrls: { 'js/cad': '/cad/js/cad' }, +}); + +for (const path of INDEPENDENT_PATHS) { + if (existsSync(join(DIST, path))) throw new Error(`主站包不得包含独立模块:${path}`); +} // 检查:不能有 .mjs(静态服务器常把它当成二进制文件返回,模块脚本加载失败) const walk = (d) => readdirSync(d, { withFileTypes: true }).flatMap((e) => (e.isDirectory() ? walk(join(d, e.name)) : [join(d, e.name)])); @@ -128,7 +130,6 @@ try { } console.log(`部署目标:${TARGET_NAME} · ${FRONTEND} · 版本 ${BUILD_ID}`); console.log(`dist:${DIST}`); -console.log(`PCB:${join(DIST, 'pcb')} ← ${PCB_DIST}`); -console.log(CAD_ENGINE ? `CAD: ${join(DIST, 'cad')} (build ${CAD_ENGINE.manifest.buildId})` : 'CAD: no local engine installed; deploy the SolidCraft Web package separately.'); +console.log('CAD / PCB:独立发布,主站包不包含模块页面、引擎和专用 JS/CSS。'); console.log(`模型:${dirs.join('、')}`); if (!existsSync(join(DIST, 'robots/so101/so101.urdf'))) throw new Error('模型文件没有复制成功'); diff --git a/scripts/cad-engine.mjs b/scripts/cad-engine.mjs index 2377d4d..29a0448 100644 --- a/scripts/cad-engine.mjs +++ b/scripts/cad-engine.mjs @@ -17,8 +17,8 @@ export function readCadEngine(source) { for (const key of ['js', 'wasm', 'chineseFont']) if (!names.has(manifest[key])) throw new Error(`CAD engine ${key} missing from manifest`); return { root, manifest }; } -export function copyCadEngine(engine, destination) { - const target = join(destination, 'cad'); mkdirSync(join(target, '_assets'), { recursive: true }); +export function copyCadEngine(engine, destination, { directory = 'cad' } = {}) { + const target = join(destination, directory); mkdirSync(join(target, '_assets'), { recursive: true }); cpSync(join(engine.root, '_assets', engine.manifest.buildId), join(target, '_assets', engine.manifest.buildId), { recursive: true }); writeFileSync(join(target, 'engine.json'), JSON.stringify(engine.manifest, null, 2) + '\n'); // This worker only intercepts an exact public asset allowlist; never API, auth or signed URLs. diff --git a/scripts/lib/version-site-assets.mjs b/scripts/lib/version-site-assets.mjs index 6301775..6bbbbd7 100644 --- a/scripts/lib/version-site-assets.mjs +++ b/scripts/lib/version-site-assets.mjs @@ -7,9 +7,12 @@ const walk = dir => readdirSync(dir, { withFileTypes: true }).flatMap(entry => // Version the entire application module graph, including lazy imports. Versioning // only an HTML entry does not invalidate its unversioned dependencies in browsers. -export async function versionSiteAssets(root, buildId, pages) { +export async function versionSiteAssets(root, buildId, pages, { + moduleDirectory = 'js', externalDirectories = [], externalUrls = {}, publicPath = '/', +} = {}) { root = realpathSync(root); - const jsRoot = join(root, 'js'); + const jsRoot = join(root, moduleDirectory); + const externalRoots = externalDirectories.map(directory => ({ directory, root: resolve(root, directory) + sep })); const version = url => { const parsed = new URL(url, 'https://build.invalid/'); parsed.searchParams.set('v', buildId); @@ -25,7 +28,14 @@ export async function versionSiteAssets(root, buildId, pages) { if (args.kind === 'entry-point') return; const path = args.path.split(/[?#]/)[0]; if (path.startsWith('.') || path.startsWith('/')) { - const target = path.startsWith('/') ? resolve(root, '.' + path) : resolve(args.resolveDir, path); + if (path.startsWith('/') && !path.startsWith(publicPath)) return { path: args.path, external: true }; + const target = path.startsWith('/') ? resolve(root, path.slice(publicPath.length)) : resolve(args.resolveDir, path); + // Independently deployed modules retain their own release and cache identity. + const independent = externalRoots.find(directory => target.startsWith(directory.root)); + if (independent) { + const url = externalUrls[independent.directory]; + return { path: url ? url.replace(/\/$/, '') + '/' + relative(independent.root, target).split(sep).join('/') + args.path.slice(path.length) : args.path, external: true }; + } const rel = relative(jsRoot, target); if (!rel.startsWith('..' + sep) && !rel.startsWith(sep) && target.endsWith('.js')) { if (!existsSync(target)) throw new Error(`Missing application module: ${args.path} in ${args.importer}`); @@ -42,8 +52,11 @@ export async function versionSiteAssets(root, buildId, pages) { for (const page of pages) { const file = join(root, page); const html = readFileSync(file, 'utf8').replace( - /(<(?:script|link)\b[^>]*?\b(?:src|href)\s*=\s*)(["'])(\/?(?:js\/[^"']+\.js|css\/[^"']+\.css)(?:\?[^"'#]*)?(?:#[^"']*)?)\2/gi, - (_, prefix, quote, url) => `${prefix}${quote}${version(url)}${quote}`, + /(<(?:script|link)\b[^>]*?\b(?:src|href)\s*=\s*)(["'])([^"']+)\2/gi, + (_, prefix, quote, url) => { + const local = url.startsWith('/') ? (url.startsWith(publicPath) ? url.slice(publicPath.length) : '') : url; + return `${prefix}${quote}${/^(?:js\/[^?#]+\.js|css\/[^?#]+\.css)(?:[?#]|$)/i.test(local) ? version(url) : url}${quote}`; + }, ); writeFileSync(file, html); } diff --git a/scripts/server.mjs b/scripts/server.mjs index 8860275..4d07e15 100644 --- a/scripts/server.mjs +++ b/scripts/server.mjs @@ -120,6 +120,7 @@ function proxyPcb(req, res) { const PAGES = { '/': 'index.html', '/explore': 'explore.html', '/studio': 'studio.html', '/cad': 'cad.html', '/cad/editor': 'cad/editor/index.html', '/pcb': 'pcb/index.html', '/workspace': 'workspace.html' }; function pageFor(pathname) { pathname = pathname.length > 1 ? pathname.replace(/\/+$/, '') : pathname; // /explore/ 和 /explore 一样 + if (pathname === '/cad' && existsSync(join(ROOT, 'cad/index.html'))) return 'cad/index.html'; return PAGES[pathname] || (/^\/pcb(?:\/.*)?$/.test(pathname) && !extname(pathname) && 'pcb/index.html') || (/^\/project(\/[^/]+)?\/?$/.test(pathname) && 'project.html') diff --git a/tests/build-isolation.test.js b/tests/build-isolation.test.js new file mode 100644 index 0000000..7546710 --- /dev/null +++ b/tests/build-isolation.test.js @@ -0,0 +1,148 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'; +import { createHash } from 'node:crypto'; +import { execFileSync } from 'node:child_process'; +import { tmpdir } from 'node:os'; +import { dirname, join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const project = resolve(dirname(fileURLToPath(import.meta.url)), '..'); +const put = (root, path, value = '') => { + mkdirSync(dirname(join(root, path)), { recursive: true }); + writeFileSync(join(root, path), value); +}; +function fixture(t) { + const root = mkdtempSync(join(tmpdir(), 'vibemake-build-isolation-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + for (const script of ['build.mjs', 'build-cad.mjs', 'cad-engine.mjs', 'lib/version-site-assets.mjs']) { + const target = join(root, 'scripts', script); + mkdirSync(dirname(target), { recursive: true }); + cpSync(join(project, 'scripts', script), target); + } + symlinkSync(join(project, 'node_modules'), join(root, 'node_modules'), 'dir'); + put(root, 'scripts/meshes.mjs', 'export async function compressRobot() { return {files: 0, before: 0, after: 0}; }'); + for (const dir of ['assets', 'data', 'vendor', 'play']) mkdirSync(join(root, dir)); + for (const name of ['index.html', 'explore.html', 'project.html', 'studio.html', 'workspace.html']) { + put(root, name, ''); + } + put(root, 'js/api.js', "export const BUILD_ENV = 'auto'; export const auth = {};"); + put(root, 'js/workspace.js', "import { CadApi } from './cad/api.js'; console.log(CadApi);"); + put(root, 'css/style.css', 'body {}'); + for (const name of ['favicon.svg', 'favicon.ico', 'apple-touch-icon.png', 'site.webmanifest', 'icon-16.png', 'icon-32.png', 'icon-48.png', 'icon-64.png', 'icon-192.png', 'icon-512.png']) put(root, name); + put(root, 'robots/robots.json', '[{"id":"so101","urdf":"robots/so101/so101.urdf"}]'); + put(root, 'robots/so101/so101.urdf', ''); + return root; +} + +test('production and dev packages build without CAD or PCB sources and preserve deployed modules', t => { + const root = fixture(t); + const website = join(root, 'website'); + const protectedFiles = ['cad/index.html', 'cad/engine.json', 'pcb/index.html', 'js/cad/app.js', 'css/cad.css']; + for (const path of protectedFiles) put(website, path, `published:${path}`); + for (const environment of ['auto', 'dev']) { + // The first build has no CAD files. The second has stale/invalid local files. + if (environment === 'dev') { + put(root, 'cad/engine.json', 'invalid engine manifest'); + put(root, 'js/cad/app.js', 'stale CAD application'); + put(root, 'css/cad.css', 'stale CAD styles'); + put(root, 'pcb/index.html', 'stale PCB application'); + } + const output = environment === 'dev' ? 'dist-dev' : 'dist'; + for (const path of protectedFiles) put(root, `${output}/${path}`, 'stale previous package'); + execFileSync(process.execPath, [join(root, 'scripts/build.mjs'), `--env=${environment}`], { + env: { ...process.env, PCB_DIST: join(root, 'missing-pcb-build') }, stdio: 'pipe', + }); + const archive = join(root, `${output}.zip`); + const entries = execFileSync('unzip', ['-Z1', archive], { encoding: 'utf8' }).trim().split('\n'); + assert.ok(entries.includes('workspace/index.html')); + assert.ok(!entries.some(path => /^(?:cad\/|pcb\/|js\/cad\/|css\/cad\.css$)/.test(path))); + for (const path of protectedFiles) assert.equal(existsSync(join(root, output, path)), false); + assert.match(readFileSync(join(root, output, 'js/workspace.js'), 'utf8'), /["']\/cad\/js\/cad\/api\.js["']/); + execFileSync('unzip', ['-oq', archive, '-d', website]); + for (const path of protectedFiles) assert.equal(readFileSync(join(website, path), 'utf8'), `published:${path}`); + assert.equal(JSON.parse(readFileSync(join(root, output, 'build-info.json'))).scope, 'site'); + } + assert.ok(existsSync(join(root, 'dist.zip'))); + assert.ok(existsSync(join(root, 'dist-dev.zip'))); +}); + +test('the self-contained CAD package extracts directly into cad without replacing the main site or PCB', t => { + const root = fixture(t); + const prefix = '/cad/_assets/release/'; + const files = ['engine.js', 'engine.wasm', 'font.otf'].map(name => { + const bytes = `CAD ${name}`; + put(root, `cad/_assets/release/${name}`, bytes); + return { path: prefix + name, size: Buffer.byteLength(bytes), sha256: createHash('sha256').update(bytes).digest('hex') }; + }); + put(root, 'cad/engine.json', JSON.stringify({ bridgeVersion: 1, engineKind: 'solidcraft', kernel: 'smlib', buildId: 'release', files, js: files[0].path, wasm: files[1].path, chineseFont: files[2].path })); + put(root, 'index.html', ''); + const page = 'Workspace'; + put(root, 'cad.html', page); + put(root, 'cad/editor/index.html', page); + put(root, 'cad/manifest.webmanifest', '{"icons":[{"src":"/icon-192.png"}]}'); + put(root, 'cad/worker.js', "importScripts('/cad/sw.js');"); + put(root, 'js/cad/app.js', "import { auth } from '../api.js'; import('three'); import('../late.js'); console.log(auth);"); + put(root, 'js/late.js', "export const endpoint = '/api/cad/workspace/projects'; export const environment = new URL('../assets/environments/studio.hdr', import.meta.url);"); + put(root, 'js/shell.js', "document.body.dataset.logo = '/assets/brand/make-cad.svg';"); + put(root, 'css/fonts.css', '@font-face {src: url(../vendor/font.woff2)}'); + put(root, 'css/cad.css', '.cad-page {}'); + put(root, 'vendor/three.js', 'export const REVISION = 160;'); + put(root, 'vendor/font.woff2', 'font'); + put(root, 'assets/brand/make-cad.svg', ''); + put(root, 'assets/environments/studio.hdr', 'hdr'); + put(root, 'data/community.json', '{}'); + execFileSync(process.execPath, [join(root, 'scripts/build-cad.mjs')], { stdio: 'pipe' }); + const archive = join(root, 'dist-cad.zip'); + const entries = execFileSync('unzip', ['-Z1', archive], { encoding: 'utf8' }).trim().split('\n'); + for (const path of ['index.html', 'editor/index.html', 'engine.json', 'sw.js', '_assets/release/engine.wasm', 'js/cad/app.js', 'js/api.js', 'js/late.js', 'css/cad.css', 'css/style.css', 'css/fonts.css', 'vendor/font.woff2', 'assets/brand/make-cad.svg', 'favicon.ico', 'robots/robots.json', 'data/community.json']) assert.ok(entries.includes(path), path); + assert.ok(!entries.some(path => /^(?:cad\/|pcb\/|js\/workspace\.js$)/.test(path))); + const info = JSON.parse(readFileSync(join(root, 'dist-cad/build-info.json'), 'utf8')); + for (const path of ['index.html', 'editor/index.html']) { + const html = readFileSync(join(root, 'dist-cad', path), 'utf8'); + assert.match(html, /href="\/cad\/css\/style\.css\?v=/); + assert.match(html, /src="\/cad\/js\/cad\/app\.js\?v=/); + assert.match(html, /href="\/cad\/favicon.ico"/); + assert.match(html, /href="\/workspace\/"/); + assert.match(html, /"three":\s*"\/cad\/vendor\/three\.js"/); + assert.ok(html.includes(info.buildId)); + } + assert.match(readFileSync(join(root, 'dist-cad/js/cad/app.js'), 'utf8'), /api\.js\?v=/); + assert.match(readFileSync(join(root, 'dist-cad/js/shell.js'), 'utf8'), /\/cad\/assets\/brand\/make-cad\.svg/); + assert.match(readFileSync(join(root, 'dist-cad/js/late.js'), 'utf8'), /\/api\/cad\/workspace\/projects/); + assert.match(readFileSync(join(root, 'dist-cad/js/late.js'), 'utf8'), /\.\.\/assets\/environments\/studio\.hdr/); + assert.match(readFileSync(join(root, 'dist-cad/css/fonts.css'), 'utf8'), /\.\.\/vendor\/font\.woff2/); + assert.match(readFileSync(join(root, 'dist-cad/manifest.webmanifest'), 'utf8'), /\/cad\/icon-192\.png/); + const website = join(root, 'website'); + const protectedFiles = ['index.html', 'pcb/index.html', 'js/api.js', 'css/style.css', 'cad/_assets/previous/engine.wasm']; + for (const path of protectedFiles) put(website, path, `published:${path}`); + execFileSync('unzip', ['-oq', archive, '-d', join(website, 'cad')]); + for (const path of protectedFiles) assert.equal(readFileSync(join(website, path), 'utf8'), `published:${path}`); + assert.ok(existsSync(join(website, 'cad/index.html'))); + assert.ok(existsSync(join(website, 'cad/editor/index.html'))); + assert.equal(existsSync(join(website, 'cad/cad')), false); + + // SolidCraft supplies its current build directly; an old local install must not be used. + const freshEngine = join(root, 'fresh-engine'); + cpSync(join(root, 'cad/_assets'), join(freshEngine, '_assets'), { recursive: true }); + cpSync(join(root, 'cad/engine.json'), join(freshEngine, 'engine.json')); + put(root, 'cad/engine.json', 'invalid old local engine'); + const fullDirectory = join(root, 'solidcraft-output/vibemake-cad'); + const fullArchive = join(root, 'solidcraft-output/vibemake-cad.zip'); + const env = { + ...process.env, + VIBEMAKE_CAD_ENGINE_DIST: freshEngine, + VIBEMAKE_CAD_PACKAGE_DIR: fullDirectory, + VIBEMAKE_CAD_PACKAGE_ZIP: fullArchive, + }; + execFileSync(process.execPath, [join(root, 'scripts/build-cad.mjs')], { env, stdio: 'pipe' }); + const fullEntries = execFileSync('unzip', ['-Z1', fullArchive], { encoding: 'utf8' }).trim().split('\n'); + for (const path of ['index.html', 'editor/index.html', 'engine.json', 'js/cad/app.js', 'css/cad.css']) assert.ok(fullEntries.includes(path), path); + const fullInfo = JSON.parse(readFileSync(join(fullDirectory, 'build-info.json'), 'utf8')); + assert.equal(fullInfo.archive, 'vibemake-cad.zip'); + assert.equal(fullInfo.engineBuildId, 'release'); + const previousArchive = readFileSync(fullArchive); + rmSync(join(root, 'cad.html')); + assert.throws(() => execFileSync(process.execPath, [join(root, 'scripts/build-cad.mjs')], { env, stdio: 'pipe' })); + assert.deepEqual(readFileSync(fullArchive), previousArchive, 'missing HTML must not replace a successful release ZIP'); +}); diff --git a/tests/build-versions.test.js b/tests/build-versions.test.js index 30c8efb..7ddeb7e 100644 --- a/tests/build-versions.test.js +++ b/tests/build-versions.test.js @@ -48,3 +48,37 @@ test('missing app dependencies fail the build before packaging', async t => { writeFileSync(join(root, 'js/entry.js'), `import './missing.js';`); await assert.rejects(versionSiteAssets(root, 'test', []), /Missing application module/); }); + +test('the site leaves independently published CAD imports unversioned and does not require their sources', async t => { + const root = mkdtempSync(join(tmpdir(), 'make-version-external-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + mkdirSync(join(root, 'js')); + writeFileSync(join(root, 'js/workspace.js'), `import { CadApi } from './cad/api.js'; console.log(CadApi);`); + await versionSiteAssets(root, 'site-release', [], { externalDirectories: ['js/cad'] }); + const code = readFileSync(join(root, 'js/workspace.js'), 'utf8'); + assert.match(code, /["']\.\/cad\/api\.js["']/); + assert.doesNotMatch(code, /site-release/); + await versionSiteAssets(root, 'site-release', [], { + externalDirectories: ['js/cad'], externalUrls: { 'js/cad': '/cad/js/cad' }, + }); + assert.match(readFileSync(join(root, 'js/workspace.js'), 'utf8'), /["']\/cad\/js\/cad\/api\.js["']/); +}); + +test('self-contained CAD versions shared modules and HTML assets under its public mount', async t => { + const root = mkdtempSync(join(tmpdir(), 'make-version-cad-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + mkdirSync(join(root, 'js/cad'), { recursive: true }); + writeFileSync(join(root, 'js/cad/app.js'), `import { CAD } from './config.js'; import { auth } from '/cad/js/api.js'; console.log(CAD, auth);`); + writeFileSync(join(root, 'js/cad/config.js'), `export const CAD = {};`); + writeFileSync(join(root, 'js/api.js'), `export const auth = {};`); + writeFileSync(join(root, 'index.html'), ''); + await versionSiteAssets(root, 'cad-release', ['index.html'], { publicPath: '/cad/' }); + const code = readFileSync(join(root, 'js/cad/app.js'), 'utf8'); + assert.match(code, /config\.js\?v=cad-release/); + assert.match(code, /["']\/cad\/js\/api\.js\?v=cad-release["']/); + const html = readFileSync(join(root, 'index.html'), 'utf8'); + assert.match(html, /\/cad\/js\/cad\/app\.js\?v=cad-release/); + assert.match(html, /\/cad\/css\/cad\.css\?v=cad-release/); + assert.match(html, /href="\/cad\/vendor\/keep.css"/); + assert.match(html, /href="\/css\/site.css"/); +});