Files
youle_cocos/cocoscreator_projects/scripts/bump-cocos.mjs
T
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.4 KiB
JavaScript

#!/usr/bin/env node
import { join } from 'node:path';
import { readFileSync, writeFileSync } from 'node:fs';
import { pathToFileURL } from 'node:url';
import { HOST_PROJECT, GAMES_DIR, listGameProjects } from './lib/paths.mjs';
// 批量把若干工程的 creator.version 改为 version,返回每个工程的 from/to
export function bumpVersion(projectDirs, version) {
const changed = [];
for (const dir of projectDirs) {
const pkgPath = join(dir, 'package.json');
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
if (!pkg.creator) pkg.creator = {};
const from = pkg.creator.version ?? null;
pkg.creator.version = version;
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
changed.push({ dir, from, to: version });
}
return changed;
}
// CLI 入口:bump 宿主 + 所有子游戏到指定版本
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
const version = process.argv[2];
if (!version) {
console.error('用法: npm run bump-cocos <version> 例: npm run bump-cocos 3.8.9');
process.exit(1);
}
const targets = [HOST_PROJECT, ...listGameProjects(GAMES_DIR)];
const changed = bumpVersion(targets, version);
for (const c of changed) {
console.log(`${c.dir}: ${c.from} → ${c.to}`);
}
console.log('\n⚠️ 仍需用新版 Cocos Creator 逐个打开各工程执行迁移(library 重建)。');
}