feat(scripts): PoC 阶段 1 - CLI + Layer00619 BackHall 端到端跑通
- scripts/legacy-layer-to-cocos-prefab-cli.mjs (CLI 入口: <inputXml> [<youlePrefab>] <outputDir>) - framework-tests/legacy-layer-migration/poc-iconbutton.test.mjs (1 个 node:test 端到端校验 cc.Prefab 头 + group-55 父节点) - YouleNexus/out/legacy-migration/BackHall_Layer.prefab (生成产物, 437 lines) - YouleNexus/out/legacy-migration/BackHall_Layer.prefab.diff (vs YouleNexus Layer619_BackOtherGame.prefab, 1244 lines) 累计: 30/30 PASS (29 prior + 1 PoC). Layer00619 (1 Spirit, type=3 ProgressBar, group=55) 是最简 PoC, diff 大是预期 (脚本首个端到端输出 vs 手写 prefab 必然差异大). Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env node
|
||||
// CLI 入口: Layer XML → Cocos prefab JSON (+ 对比 diff, 如提供 YouleNexus 现存 prefab).
|
||||
//
|
||||
// 用法: node legacy-layer-to-cocos-prefab-cli.mjs <input.xml> [<youle-prefab>] <output-dir>
|
||||
//
|
||||
// 设计要点 (Task 9 brief):
|
||||
// - 只输出到隔离目录 (out/legacy-migration/), 不直接覆盖 YouleNexus 现有 prefab.
|
||||
// - 必填参数: inputXml + outputDir; youlePrefab 可选, 提供且文件存在时生成 .diff.
|
||||
// - diff 命令来自 Git Bash / POSIX 环境 (Windows: Git for Windows 自带 diff).
|
||||
import { readLayerXml, emitPrefabJson } from './legacy-layer-to-cocos-prefab.mjs';
|
||||
import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const [, , inputXml, youlePrefab, outputDir] = process.argv;
|
||||
if (!inputXml || !outputDir) {
|
||||
console.error('Usage: node legacy-layer-to-cocos-prefab-cli.mjs <input.xml> <youle-prefab-path?> <output-dir>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const layer = readLayerXml(inputXml);
|
||||
const prefabJson = emitPrefabJson(layer);
|
||||
|
||||
if (!existsSync(outputDir)) mkdirSync(outputDir, { recursive: true });
|
||||
const outputPath = join(outputDir, `${layer.layerName}.prefab`);
|
||||
writeFileSync(outputPath, JSON.stringify(prefabJson, null, 2));
|
||||
console.log(`Generated: ${outputPath}`);
|
||||
|
||||
if (youlePrefab && existsSync(youlePrefab)) {
|
||||
const diffPath = `${outputPath}.diff`;
|
||||
// `|| true` 确保 diff 找到差异时返回非零退出码不致 CLI 崩溃.
|
||||
const diff = execSync(`diff -u "${youlePrefab}" "${outputPath}" || true`, { encoding: 'utf8' });
|
||||
writeFileSync(diffPath, diff);
|
||||
console.log(`Diff: ${diffPath} (${diff.split('\n').length} lines)`);
|
||||
}
|
||||
Reference in New Issue
Block a user