kimi-code/scripts/sync-web-to-kimi-code.mjs
liruifengv ada047e90e chore(scripts): require KIMI_CODE_REPO in sync:web, drop dead copy-web-dist
- sync-web-to-kimi-code.mjs: KIMI_CODE_REPO is now required (no more ../kimi-code-2 default), the target is validated as a kimi-code checkout, errors are in Chinese, and a reminder to open a PR in the kimi-code repo prints after a successful sync
- Remove apps/desktop/scripts/copy-web-dist.mjs and the web-dist .gitignore entry: the desktop renderer builds from src/renderer into desktop-dist, so the web-dist copy flow is dead
- README.md / AGENTS.md updated to match
2026-07-15 13:32:03 +08:00

54 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { cp, rm, stat } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const source = resolve(repoRoot, 'apps/web/dist');
// Target kimi-code checkout is REQUIRED via KIMI_CODE_REPO — there is no
// default, so a sync never lands in the wrong clone.
const kimiCodeRepo = process.env.KIMI_CODE_REPO
? resolve(process.env.KIMI_CODE_REPO)
: undefined;
if (kimiCodeRepo === undefined) {
throw new Error(
'请设置 KIMI_CODE_REPO 指向你的 kimi-code 仓 checkout例如KIMI_CODE_REPO=~/code/kimi-code-5 pnpm sync:web',
);
}
const appRoot = resolve(kimiCodeRepo, 'apps/kimi-code');
const target = resolve(appRoot, 'dist-web');
async function assertBuiltWeb() {
try {
const info = await stat(resolve(source, 'index.html'));
if (!info.isFile()) {
throw new Error('index.html is not a file');
}
} catch {
throw new Error(
`未找到 web 构建产物 ${source}/index.html请先运行 \`pnpm --filter @moonshot-ai/kimi-web run build\``,
);
}
}
async function assertKimiCodeRepo() {
try {
const info = await stat(appRoot);
if (!info.isDirectory()) {
throw new Error('apps/kimi-code is not a directory');
}
} catch {
throw new Error(
`KIMI_CODE_REPO 不像一个 kimi-code 仓 checkout未找到 ${appRoot}`,
);
}
}
await assertBuiltWeb();
await assertKimiCodeRepo();
await rm(target, { recursive: true, force: true });
await cp(source, target, { recursive: true });
console.log(`已同步 web 产物到:${target}`);
console.log('提醒:完成后在 kimi-code 仓提交 dist-web 变更并创建 PR该仓 gitignore dist-web需 `git add -f`)。');