feat(tools): scaffold.mjs 种子复制/改身份/铺 game 骨架
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { cpSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
const CACHE_DIRS = ['library', 'temp', 'local', 'build'];
|
||||
|
||||
// 复制种子工程到 destDir,并清理可能残留的缓存目录
|
||||
export function copySeed(seedDir, destDir) {
|
||||
if (existsSync(destDir)) throw new Error(`目标已存在: ${destDir}`);
|
||||
cpSync(seedDir, destDir, { recursive: true });
|
||||
for (const c of CACHE_DIRS) {
|
||||
rmSync(join(destDir, c), { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
// 修改工程 package.json 的 name 并分配全新 uuid(保留 creator.version 等其它字段)
|
||||
export function setProjectIdentity(projectDir, name) {
|
||||
const pkgPath = join(projectDir, 'package.json');
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
||||
pkg.name = name;
|
||||
pkg.uuid = randomUUID();
|
||||
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
||||
return pkg;
|
||||
}
|
||||
|
||||
// 铺出子游戏私有 game/ 骨架:IGameModule 占位 + theme 占位 + override 目录
|
||||
export function scaffoldGameAssets(projectDir, name) {
|
||||
const gameDir = join(projectDir, 'assets', 'game');
|
||||
mkdirSync(join(gameDir, 'override'), { recursive: true });
|
||||
writeFileSync(join(gameDir, 'override', '.gitkeep'), '');
|
||||
writeFileSync(join(gameDir, 'GameModule.ts'), gameModuleStub(name));
|
||||
writeFileSync(join(gameDir, 'theme.ts'), themeStub(name));
|
||||
}
|
||||
|
||||
function gameModuleStub(name) {
|
||||
return `/**
|
||||
* ${name} 子游戏模块骨架。
|
||||
* TODO(Plan 5): 待 framework/sdk 的 IGameModule / GameContext 接口定稿后实现
|
||||
* (route / onEnter / onReceive / onReconnect 等)。
|
||||
* 协议字段一律参见 docs/protocol/(spec §0.1:只引用、不内联复制)。
|
||||
*/
|
||||
export const GAME_ROUTE = '${name}';
|
||||
`;
|
||||
}
|
||||
|
||||
function themeStub(name) {
|
||||
return `/**
|
||||
* ${name} 主题覆盖骨架。
|
||||
* TODO(Plan 4): 待 framework/ui 的皮肤变量清单定稿后填写主色/字体/图集映射等。
|
||||
*/
|
||||
export const theme = {};
|
||||
`;
|
||||
}
|
||||
Reference in New Issue
Block a user