Skip to content

AI video skill for Claude Code & Codex — cinematic, editable product promos with Remotion: 124 shot recipe cards, 150 motion previews, beat sync, sound design, Motion Workbench & JianYing (CapCut CN) export.

fix(workbench): Windows 兼容性修复 — import 反斜杠 / 导出 rsync 与 .bin/remotion 崩溃 / parity rsync+python3 (#102)

xiaoliangWang202655359eb609ee
diff --git a/workbench/scripts/gen-index.mjs b/workbench/scripts/gen-index.mjs
index 0bf1956..4b438d4 100644
--- a/workbench/scripts/gen-index.mjs
+++ b/workbench/scripts/gen-index.mjs
@@ -10,7 +10,7 @@
import {
existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, symlinkSync, unlinkSync, writeFileSync,
} from "node:fs";
-import { dirname, extname, join, relative } from "node:path";
+import { dirname, extname, join, relative, sep } from "node:path";
import { fileURLToPath } from "node:url";
const wb = join(dirname(fileURLToPath(import.meta.url)), "..");
@@ -71,7 +71,7 @@ const walkDemos = (dir) => {
if (MATERIAL_REQUIRED.has(stem)) continue;
const src = readFileSync(p, "utf8");
if (!new RegExp(`export const ${stem}\\s*:\\s*React\\.FC\\s*=`).test(src)) continue;
- const rel = relative(demosDir, p).replace(/\.tsx$/, "");
+ const rel = relative(demosDir, p).replace(/\.tsx$/, "").split(sep).join("/");
const [category, slug] = rel.split("/");
const m = DUR_PAT.exec(src);
let durExport = m?.[1];
diff --git a/workbench/scripts/parity.mjs b/workbench/scripts/parity.mjs
index 24ba48e..9e9d61f 100644
--- a/workbench/scripts/parity.mjs
+++ b/workbench/scripts/parity.mjs
@@ -11,7 +11,7 @@
import { bundle } from "@remotion/bundler";
import { renderStill, selectComposition } from "@remotion/renderer";
import { spawnSync } from "node:child_process";
-import { existsSync, mkdirSync } from "node:fs";
+import { existsSync, mkdirSync, rmSync, cpSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
@@ -25,11 +25,12 @@ if (!existsSync(join(wb, "proj", "workbench.ts"))) {
console.error("未链接带清单的成片工程:先 node scripts/open.mjs <工程目录>");
process.exit(2);
}
-// 比对依赖先检查,别渲完一堆帧才发现比不了
+// 比对依赖先检查,别渲完一堆帧才发现比不了(Windows 上通常是 python 而非 python3)
{
- const r = spawnSync("python3", ["-c", "import PIL"], { encoding: "utf8" });
- if (r.status !== 0) {
- console.error("parity 需要 python3 + Pillow 做像素比对:pip install pillow(或 python3 -m pip install pillow)");
+ const py = process.platform === "win32" ? ["python", "python3"] : ["python3", "python"];
+ const ok = py.some((c) => spawnSync(c, ["-c", "import PIL"], { encoding: "utf8" }).status === 0);
+ if (!ok) {
+ console.error("parity 需要 python + Pillow 做像素比对:pip install pillow");
process.exit(2);
}
}
@@ -38,8 +39,18 @@ if (!existsSync(join(wb, "proj", "workbench.ts"))) {
const out = join(wb, ".parity");
mkdirSync(out, { recursive: true });
const renderPublic = join(wb, ".render-public");
-const rs = spawnSync("rsync", ["-aL", "--delete", "--exclude=cardpreviews", "public/", `${renderPublic}/`], { cwd: wb, stdio: "inherit" });
-if (rs.status !== 0) process.exit(2);
+try {
+ rmSync(renderPublic, { recursive: true, force: true });
+ mkdirSync(renderPublic, { recursive: true });
+ cpSync(join(wb, "public"), renderPublic, {
+ recursive: true,
+ dereference: true,
+ filter: (src) => !/[\\/]cardpreviews$/.test(src),
+ });
+} catch (e) {
+ console.error("素材同步失败(无法解引用 public/):", e);
+ process.exit(2);
+}
console.log("bundling…");
const serveUrl = await bundle({
diff --git a/workbench/vite.config.ts b/workbench/vite.config.ts
index 0eab354..61c655a 100644
--- a/workbench/vite.config.ts
+++ b/workbench/vite.config.ts
@@ -1,4 +1,4 @@
-import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync, cpSync } from "node:fs";
import { spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
import path from "node:path";
@@ -98,23 +98,35 @@ const renderExportPlugin = (): Plugin => {
// 而 public/ 下全是指向成片工程 / 仓库素材库的符号链接——渲染前先解引用同步成
// 真实文件目录,再用 --public-dir 指过去。cardpreviews 仅 UI 用,排除。
const renderPublic = path.join(root, ".render-public");
- const rsync = spawn(
- "rsync",
- ["-aL", "--delete", "--exclude=cardpreviews", "public/", `${renderPublic}/`],
- { cwd: root },
- );
- rsync.stderr.on("data", onChunk);
- rsync.on("close", (rc) => {
- if (rc !== 0) {
- dropProps();
- job.status = "error";
- job.lastLine = `素材同步失败(rsync 退出码 ${rc}):${job.lastLine}`;
- return;
+ // Windows 无 rsync:改用 fs.cpSync 做同等的「解引用同步」(dereference 展开符号链接)
+ const syncErr = (() => {
+ try {
+ rmSync(renderPublic, { recursive: true, force: true });
+ mkdirSync(renderPublic, { recursive: true });
+ cpSync(path.join(root, "public"), renderPublic, {
+ recursive: true,
+ dereference: true,
+ filter: (src: string) => path.basename(src) !== "cardpreviews",
+ });
+ return null;
+ } catch (e) {
+ return e instanceof Error ? e.message : String(e);
}
- const bin = path.join(root, "node_modules", ".bin", "remotion");
+ })();
+ if (syncErr) {
+ dropProps();
+ job.status = "error";
+ job.lastLine = `素材同步失败(无法解引用 public/):${syncErr}`;
+ return;
+ }
+ {
+ // Windows 上 .bin/remotion 是 shell 脚本,直接 spawn 会 ENOENT;
+ // 统一走 node + CLI 的 JS 入口,跨平台可靠。
+ const cliEntry = path.join(root, "node_modules", "@remotion", "cli", "remotion-cli.js");
const child = spawn(
- bin,
+ process.execPath,
[
+ cliEntry,
"render",
"src/remotion/index.ts",
"Main",
@@ -124,6 +136,11 @@ const renderExportPlugin = (): Plugin => {
],
{ cwd: root },
);
+ child.on("error", (e: Error) => {
+ dropProps();
+ job.status = "error";
+ job.lastLine = `渲染进程启动失败:${e.message}`;
+ });
child.stdout.on("data", onChunk);
child.stderr.on("data", onChunk);
child.on("close", (code) => {
@@ -136,7 +153,7 @@ const renderExportPlugin = (): Plugin => {
if (err) job.lastLine = err;
}
});
- });
+ }
send(200, { id });
});
return;