"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
async function update(tree) {
    devkit_1.logger.info('🔄 Updating .gitignore to add migration-related entries...');
    const gitignorePath = '.gitignore';
    if (!tree.exists(gitignorePath)) {
        devkit_1.logger.warn('⚠️ .gitignore file not found, creating one');
        tree.write(gitignorePath, '');
    }
    try {
        const currentContent = tree.read(gitignorePath, 'utf-8') || '';
        let updatedContent = currentContent;
        // Check if migrations.json is already in .gitignore
        const migrationsJsonRegex = /^\.env$/gm;
        if (!migrationsJsonRegex.test(updatedContent)) {
            updatedContent += '.env\n';
            tree.write(gitignorePath, updatedContent);
            devkit_1.logger.info(`✅ Successfully updated .gitignore (added .env entry)`);
        }
        else {
            devkit_1.logger.info('ℹ️ .env entry already exists in .gitignore');
        }
    }
    catch (error) {
        const errorMessage = error instanceof Error ? error.message : 'Unknown error';
        devkit_1.logger.error(`❌ Failed to update .gitignore: ${errorMessage}`);
        throw new Error(`Failed to update .gitignore: ${errorMessage}`);
    }
}
