feat(tools): check-cocos-version 引擎版本一致性校验
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#!/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 (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||
const { expected, mismatches } = checkVersions(HOST_PROJECT, GAMES_DIR);
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { makeTempMonorepo, makeGameProject, cleanup } from './helpers.mjs';
|
||||
import { checkVersions } from '../check-cocos-version.mjs';
|
||||
|
||||
test('checkVersions 全部一致时 mismatches 为空', () => {
|
||||
const mono = makeTempMonorepo();
|
||||
try {
|
||||
makeGameProject(mono.games, 'a', '3.8.8');
|
||||
makeGameProject(mono.games, 'b', '3.8.8');
|
||||
const r = checkVersions(mono.host, mono.games);
|
||||
assert.equal(r.expected, '3.8.8');
|
||||
assert.deepEqual(r.mismatches, []);
|
||||
} finally {
|
||||
cleanup(mono.root);
|
||||
}
|
||||
});
|
||||
|
||||
test('checkVersions 报告与宿主不一致的工程', () => {
|
||||
const mono = makeTempMonorepo();
|
||||
try {
|
||||
makeGameProject(mono.games, 'a', '3.8.8');
|
||||
makeGameProject(mono.games, 'b', '3.8.6');
|
||||
const r = checkVersions(mono.host, mono.games);
|
||||
assert.equal(r.mismatches.length, 1);
|
||||
assert.match(r.mismatches[0].project, /[\\/]b$/);
|
||||
assert.equal(r.mismatches[0].version, '3.8.6');
|
||||
assert.equal(r.mismatches[0].expected, '3.8.8');
|
||||
} finally {
|
||||
cleanup(mono.root);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user