"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
const path_1 = require("path");
async function update(tree) {
    devkit_1.logger.info('🔄 Ensuring .env-template exists in all applications...');
    if (!tree.exists('.unisphere')) {
        devkit_1.logger.warn('⚠️ No .unisphere file found, skipping');
        return;
    }
    const unisphereConfig = (0, devkit_1.readJson)(tree, '.unisphere');
    const applications = unisphereConfig.elements?.applications;
    if (!applications || Object.keys(applications).length === 0) {
        devkit_1.logger.info('ℹ️ No applications found, skipping');
        return;
    }
    let createdCount = 0;
    for (const [appName, appConfig] of Object.entries(applications)) {
        const envTemplatePath = (0, path_1.join)(appConfig.sourceRoot, '.env-template');
        if (tree.exists(envTemplatePath)) {
            devkit_1.logger.info(`ℹ️ ${appName}: .env-template already exists`);
            continue;
        }
        tree.write(envTemplatePath, '');
        createdCount++;
        devkit_1.logger.info(`✅ ${appName}: Created empty .env-template`);
    }
    devkit_1.logger.info(`\n✅ Done: ${createdCount} .env-template file(s) created`);
}
