Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|
import { join } from 'node:path';
|
|
import { mkdirSync, existsSync } from 'node:fs';
|
|
import { pathToFileURL } from 'node:url';
|
|
import { GAMES_DIR, FRAMEWORK_SRC, listGameProjects } from './lib/paths.mjs';
|
|
import { ensureJunction } from './lib/junction.mjs';
|
|
|
|
// 为 gamesDir 下每个工程在 assets/framework 建指向 frameworkSrc 的 junction
|
|
export function setupLinks(gamesDir, frameworkSrc) {
|
|
const results = [];
|
|
for (const proj of listGameProjects(gamesDir)) {
|
|
const assetsDir = join(proj, 'assets');
|
|
if (!existsSync(assetsDir)) mkdirSync(assetsDir, { recursive: true });
|
|
const link = join(assetsDir, 'framework');
|
|
const status = ensureJunction(link, frameworkSrc);
|
|
results.push({ project: proj, link, status });
|
|
}
|
|
return results;
|
|
}
|
|
|
|
// CLI 入口
|
|
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
const results = setupLinks(GAMES_DIR, FRAMEWORK_SRC);
|
|
if (results.length === 0) {
|
|
console.log('games/ 下暂无子游戏工程。');
|
|
}
|
|
for (const r of results) {
|
|
console.log(`[${r.status}] ${r.link}`);
|
|
}
|
|
}
|