import * as fs from 'fs/promises'; import * as path from 'path'; import { fileExistsAsync } from '../../utils/nevermore-cli-utils.js'; /** * Auto-detects the default deploy target name for a package. * * A package whose root `default.project.json` defines a full place * (`tree.$className === "DataModel"`) is treated as a game and defaults * to "integration". Otherwise (library — with or without a `test/` folder) * defaults to "test". */ export async function detectTargetNameAsync( packagePath: string ): Promise<'test' | 'integration'> { if (await _isRootProjectDataModelAsync(packagePath)) { return 'integration'; } return 'test'; } async function _isRootProjectDataModelAsync( packagePath: string ): Promise { const rootProject = path.join(packagePath, 'default.project.json'); try { const content = await fs.readFile(rootProject, 'utf-8'); const parsed = JSON.parse(content) as { tree?: { $className?: string } }; return parsed.tree?.$className === 'DataModel'; } catch { return false; } } export async function detectProjectFileAsync( packagePath: string ): Promise { const candidates = [ path.join(packagePath, 'test', 'default.project.json'), path.join(packagePath, 'default.project.json'), ]; for (const candidate of candidates) { if (await fileExistsAsync(candidate)) { return path.relative(packagePath, candidate).replace(/\\/g, '/'); } } return undefined; } export async function detectScriptFileAsync( packagePath: string ): Promise { // Both extensions for each, since a package may use either. The client // entry read `ClientMain.server.luau` and so matched nothing: every client // script in this repo is `ClientMain.client.lua`, and a `.server` client // script does not exist. const candidates = [ 'test/scripts/Server/ServerMain.server.lua', 'test/scripts/Server/ServerMain.server.luau', 'scripts/Server/ServerMain.server.lua', 'scripts/Server/ServerMain.server.luau', 'scripts/Client/ClientMain.client.lua', 'scripts/Client/ClientMain.client.luau', ]; for (const candidate of candidates) { if (await fileExistsAsync(path.join(packagePath, candidate))) { return candidate; } } return undefined; }