"use strict";
/**
 * Migration: Add .gitignore to documentation sites
 *
 * Adds .gitignore files to all documentation sites with standard ignores for:
 * - Dependencies (node_modules)
 * - Production builds
 * - Generated files (.docusaurus, .cache-loader)
 * - Environment files
 * - Log files
 * - Claude Code local settings
 */
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 provided by user
    const content = `# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

.worktree

# Temporary symlink for API documentation
unisphere-core-link

# Note: API docs are now generated manually via scripts/generate-api-docs.sh
# and committed to the repository. They are NOT auto-generated during builds.

.claude/*
!.claude/skills
`;
    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);
}
