/**
 * Launch metadata generation for buildpack-compatible output.
 *
 * Generates the metadata that tells the runtime how to start the application.
 * This is analogous to CNB's launch.toml / Procfile / Docker CMD.
 */
import { join } from 'node:path';
import { mkdirSync, writeFileSync } from 'node:fs';
/**
 * Generate launch metadata from a build result and detected framework.
 */
export function generateLaunchMetadata(framework, buildResult) {
    const processes = [];
    // Primary web process
    const startCommand = buildResult.startCommand ?? framework.startCommand;
    if (startCommand) {
        processes.push({
            type: 'web',
            command: startCommand,
            default: true,
        });
    }
    return {
        processes,
        framework: {
            name: framework.name,
            version: framework.version,
        },
        runtime: {
            name: framework.runtime,
            port: buildResult.port ?? framework.port,
        },
        build: {
            date: new Date().toISOString(),
            duration: buildResult.duration,
        },
    };
}
/**
 * Write launch metadata to the output directory.
 *
 * Writes both:
 * - launch.json — machine-readable launch metadata
 * - Procfile — simple process definition for compatibility
 */
export function writeLaunchMetadata(outputDir, metadata) {
    mkdirSync(outputDir, { recursive: true });
    // Write JSON metadata
    const jsonPath = join(outputDir, 'launch.json');
    writeFileSync(jsonPath, JSON.stringify(metadata, null, 2), 'utf-8');
    // Write Procfile for broad compatibility (Heroku, Railway, Render, etc.)
    const procfilePath = join(outputDir, 'Procfile');
    const procfileLines = metadata.processes.map((p) => `${p.type}: ${p.command}`);
    writeFileSync(procfilePath, procfileLines.join('\n') + '\n', 'utf-8');
}
//# sourceMappingURL=launch.js.map