"use strict";
/**
 * Migration: Add .gitignore to Documentation Sites
 *
 * Adds a standard .gitignore file to all documentation sites under unisphere/documentation/*.
 * This ensures documentation sites have proper ignore patterns for dependencies, build artifacts,
 * and generated files.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
async function update(tree) {
    devkit_1.logger.info('🔄 Adding .gitignore to documentation sites...');
    // Content specified by user
    const content = `# Dependencies
node_modules

# Production
build

# Generated files
.docusaurus
.cache-loader
`;
    const docsBasePath = 'unisphere/documentation';
    if (!tree.exists(docsBasePath)) {
        devkit_1.logger.info('ℹ️ No documentation sites found, skipping');
        return;
    }
    const docsSites = tree.children(docsBasePath);
    if (docsSites.length === 0) {
        devkit_1.logger.info('ℹ️ No documentation sites found, skipping');
        return;
    }
    let updatedCount = 0;
    let createdCount = 0;
    for (const site of docsSites) {
        const sitePath = `${docsBasePath}/${site}`;
        const filePath = `${sitePath}/.gitignore`;
        try {
            const exists = tree.exists(filePath);
            tree.write(filePath, content);
            if (exists) {
                devkit_1.logger.info(`✅ Updated ${filePath}`);
                updatedCount++;
            }
            else {
                devkit_1.logger.info(`✅ Created ${filePath}`);
                createdCount++;
            }
        }
        catch (error) {
            const errorMessage = error instanceof Error ? error.message : 'Unknown error';
            devkit_1.logger.warn(`⚠️ Failed to update ${filePath}: ${errorMessage}`);
        }
    }
    devkit_1.logger.info(`✅ Processed ${docsSites.length} documentation site(s): ${createdCount} created, ${updatedCount} updated`);
    await (0, devkit_1.formatFiles)(tree);
}
