#!/usr/bin/env node
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
// Enable __dirname in ES module
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Get command-line arguments
const args = process.argv.slice(2);
if (args[0] !== 'configure') {
    console.log('Usage: ns-types-from-source configure');
    process.exit(1);
}
// Determine workspace root (assumes script is run from project root)
const workspaceRoot = process.cwd();
const vscodeDir = path.join(workspaceRoot, '.vscode');
const settingsPath = path.join(vscodeDir, 'settings.json');
// Resolve absolute path to the CLI tool's root (where platforms/ is located)
const toolRoot = __dirname;
// Ensure .vscode directory exists
if (!fs.existsSync(vscodeDir)) {
    fs.mkdirSync(vscodeDir);
}
// Load existing settings.json or start fresh
let settings = {};
if (fs.existsSync(settingsPath)) {
    try {
        settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
    }
    catch (err) {
        console.error(`Failed to parse ${settingsPath}:`, err);
        process.exit(1);
    }
}
// Configure run-on-save commands
settings['emeraldwalk.runonsave'] = {
    commands: [
        {
            match: 'App_Resources/iOS/.*\\.swift$',
            isAsync: true,
            cmd: `${toolRoot}/platforms/Swift2TS/Swift2TS \${file} \${workspaceFolder}/src/typings-from-source/ios`,
        },
        {
            match: 'App_Resources/Android/src/main/java/.*\\.java$',
            isAsync: true,
            cmd: `java -jar ${toolRoot}/platforms/Java2TS/java2TS.jar \${workspaceFolder}/App_Resources/Android/src/main/java \${file} \${workspaceFolder}/src/typings-from-source/java`,
        },
        {
            match: 'App_Resources/Android/src/main/java/.*\\.kt$',
            isAsync: true,
            cmd: `java -jar ${toolRoot}/platforms/Kotlin2TS/Kotlin2TS.jar \${workspaceFolder}/App_Resources/Android/src/main/java \${file} \${workspaceFolder}/src/typings-from-source/kotlin`,
        },
    ],
};
// Write updated settings
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf-8');
console.log(`✅ .vscode/settings.json updated successfully.`);
//# sourceMappingURL=index.js.map