Files
youle_cocos/cocoscreator_projects/scripts/test/helpers.mjs
T
2026-06-28 12:04:28 +08:00

48 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
// 构造一个临时 monorepo:YouleNexus(host) + framework 真源 + 空 games/
export function makeTempMonorepo() {
const root = mkdtempSync(join(tmpdir(), 'youle-mono-'));
const host = join(root, 'YouleNexus');
const framework = join(host, 'assets', 'framework');
mkdirSync(framework, { recursive: true });
writeFileSync(
join(host, 'package.json'),
JSON.stringify({ name: 'YouleNexus', uuid: 'host-uuid', creator: { version: '3.8.8' } }, null, 2)
);
writeFileSync(join(framework, 'README.md'), '# framework src\n');
const games = join(root, 'games');
mkdirSync(games, { recursive: true });
return { root, host, framework, games };
}
// 在 gamesDir 下造一个子游戏工程(含 package.json)
export function makeGameProject(gamesDir, name, version = '3.8.8') {
const dir = join(gamesDir, name);
mkdirSync(join(dir, 'assets'), { recursive: true });
writeFileSync(
join(dir, 'package.json'),
JSON.stringify({ name, uuid: `${name}-uuid`, creator: { version } }, null, 2)
);
return dir;
}
// 造一个最小种子工程
export function makeSeed(root) {
const seed = join(root, 'templates', 'game-seed');
mkdirSync(join(seed, 'assets'), { recursive: true });
mkdirSync(join(seed, 'settings'), { recursive: true });
writeFileSync(
join(seed, 'package.json'),
JSON.stringify({ name: 'game-seed', uuid: 'seed-uuid', creator: { version: '3.8.8' } }, null, 2)
);
writeFileSync(join(seed, 'settings', 'v2.json'), '{}\n');
return seed;
}
export function cleanup(root) {
rmSync(root, { recursive: true, force: true });
}