Files
joywayerandClaude Opus 4.8 9cb5f11a33 fix(tools): CLI 守卫防 argv[1] 空崩溃 + check-cocos 宿主版本缺失早退
- C1: 4 个 CLI 脚本守卫加 process.argv[1] 空值短路,避免动态 import 时 pathToFileURL(undefined) 崩溃
- I1: check-cocos-version CLI 在宿主 creator.version 为 null 时报错 exit 1,避免 CI 虚假 OK
- M1: scaffold 测试收紧 UUID 正则
- 新增 cli-entry 测试覆盖动态 import 场景

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 12:31:58 +08:00

36 lines
1.2 KiB
JavaScript
Raw Permalink 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.
#!/usr/bin/env node
import { pathToFileURL } from 'node:url';
import { HOST_PROJECT, GAMES_DIR, readCreatorVersion, listGameProjects } from './lib/paths.mjs';
// 比对各子游戏工程与宿主工程的 creator.version
export function checkVersions(hostProject, gamesDir) {
const expected = readCreatorVersion(hostProject);
const mismatches = [];
for (const proj of listGameProjects(gamesDir)) {
const version = readCreatorVersion(proj);
if (version !== expected) {
mismatches.push({ project: proj, version, expected });
}
}
return { expected, mismatches };
}
// CLI 入口:有不一致则退出码 1
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
const { expected, mismatches } = checkVersions(HOST_PROJECT, GAMES_DIR);
if (expected == null) {
console.error('错误: 宿主工程缺少 creator.version');
process.exit(1);
}
console.log(`宿主 Cocos 版本: ${expected}`);
if (mismatches.length === 0) {
console.log('OK: 所有子游戏工程版本一致。');
process.exit(0);
}
console.error('版本不一致:');
for (const m of mismatches) {
console.error(` ${m.project}: ${m.version}(应为 ${m.expected})`);
}
process.exit(1);
}