"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BuildFeatureCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const scaffold_1 = require("../generator/scaffold");
class BuildFeatureCommand {
    register(program) {
        program
            .command("build:feature")
            .alias("bf")
            .description("Run the deterministic scaffold generator for a specific feature from its FSR.")
            .requiredOption("--feature <name>", "Name of the feature to build (e.g. add_todo)")
            .action(async (options) => {
            try {
                const featureId = options.feature;
                const fsrPath = path_1.default.join(process.cwd(), '.mycontext', 'features', `${featureId}.fsr.json`);
                if (!await fs_extra_1.default.pathExists(fsrPath)) {
                    console.error(chalk_1.default.red(`❌ FSR not found for feature: ${featureId}`));
                    console.error(chalk_1.default.gray(`Looked in: ${fsrPath}`));
                    console.error(chalk_1.default.gray(`Run 'mycontext plan ${featureId}' first.`));
                    process.exit(1);
                }
                const fsr = await fs_extra_1.default.readJson(fsrPath);
                const generator = new scaffold_1.DeterministicScaffoldGenerator();
                await generator.generate(fsr);
            }
            catch (error) {
                console.error(chalk_1.default.red("❌ Build failed:"), error);
                process.exit(1);
            }
        });
    }
}
exports.BuildFeatureCommand = BuildFeatureCommand;
//# sourceMappingURL=build-feature.js.map