fix(scripts): final review Critical+Important fixes (Widget alignment, full readLayerXml, Label _string, atlas selection, hard-coded paths, exit code, dead code removal)

This commit is contained in:
2026-09-02 09:11:51 +08:00
parent 7e0a8b79a4
commit cb3bd54175
19 changed files with 5076 additions and 186 deletions
@@ -1,28 +1,47 @@
#!/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>
// 用法: node legacy-layer-to-cocos-prefab-cli.mjs <input.xml> [<youle-prefab>] <output-dir> [--target-name <name>]
//
// 设计要点 (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';
// 设计要点:
// - 只输出到隔离目录 (out/legacy-migration/), 不直接覆盖 YouleNexus 原 prefab.
// - targetName 只影响输出的 prefab/root 名称与 atlas 选择; 默认使用 XML layerName.
import { readLayerXml, emitPrefabJson, selectAtlasForLayerName } 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;
const args = process.argv.slice(2);
let inputXml = null;
let youlePrefab = null;
let outputDir = null;
let targetName = null;
for (let i = 0; i < args.length; i += 1) {
const arg = args[i];
if (arg === '--target-name') {
targetName = args[++i];
if (!targetName) throw new Error('--target-name requires a value');
continue;
}
if (!inputXml) inputXml = arg;
else if (!youlePrefab) youlePrefab = arg;
else if (!outputDir) outputDir = arg;
else throw new Error(`Unexpected argument: ${arg}`);
}
if (!inputXml || !outputDir) {
console.error('Usage: node legacy-layer-to-cocos-prefab-cli.mjs <input.xml> <youle-prefab-path?> <output-dir>');
console.error('Usage: node legacy-layer-to-cocos-prefab-cli.mjs <input.xml> <youle-prefab-path?> <output-dir> [--target-name <name>]');
process.exit(1);
}
const layer = readLayerXml(inputXml);
const prefabJson = emitPrefabJson(layer);
const outputName = targetName || layer.layerName;
const prefabJson = emitPrefabJson(layer, {
targetName: outputName,
atlasName: selectAtlasForLayerName(outputName),
});
if (!existsSync(outputDir)) mkdirSync(outputDir, { recursive: true });
const outputPath = join(outputDir, `${layer.layerName}.prefab`);
const outputPath = join(outputDir, `${outputName}.prefab`);
writeFileSync(outputPath, JSON.stringify(prefabJson, null, 2));
console.log(`Generated: ${outputPath}`);
@@ -32,4 +51,4 @@ if (youlePrefab && existsSync(youlePrefab)) {
const diff = execSync(`diff -u "${youlePrefab}" "${outputPath}" || true`, { encoding: 'utf8' });
writeFileSync(diffPath, diff);
console.log(`Diff: ${diffPath} (${diff.split('\n').length} lines)`);
}
}