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

28 lines
1.0 KiB
JavaScript

import { fileURLToPath } from 'node:url';
import { dirname, join, resolve } from 'node:path';
import { readFileSync, readdirSync, existsSync } from 'node:fs';
// 本文件位于 <monorepo>/scripts/lib/paths.mjs → 上溯两级为 monorepo 根
export const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
export const HOST_PROJECT = join(ROOT, 'YouleNexus');
export const FRAMEWORK_SRC = join(HOST_PROJECT, 'assets', 'framework');
export const GAMES_DIR = join(ROOT, 'games');
export const SEED_DIR = join(ROOT, 'templates', 'game-seed');
export function readCreatorVersion(projectDir) {
try {
const pkg = JSON.parse(readFileSync(join(projectDir, 'package.json'), 'utf8'));
return pkg?.creator?.version ?? null;
} catch {
return null;
}
}
export function listGameProjects(gamesDir = GAMES_DIR) {
if (!existsSync(gamesDir)) return [];
return readdirSync(gamesDir, { withFileTypes: true })
.filter((d) => d.isDirectory())
.map((d) => join(gamesDir, d.name))
.filter((dir) => existsSync(join(dir, 'package.json')));
}