'use strict';
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const vscode = require("vscode");
const fs = require("fs-extra");
const path = require("path");
const react_js_to_ts_1 = require("react-js-to-ts");
function activate(context) {
    let disposable = vscode.commands.registerCommand('extension.convertReactToTypeScript', () => __awaiter(this, void 0, void 0, function* () {
        const editor = vscode.window.activeTextEditor;
        if (!editor) {
            return;
        }
        const filePath = getFilePath();
        const tsxPath = getTSXFileName(filePath);
        yield fs.rename(filePath, tsxPath);
        const result = react_js_to_ts_1.run(tsxPath);
        yield fs.writeFile(tsxPath, result);
        const file = yield vscode.workspace.openTextDocument(tsxPath);
        vscode.window.showTextDocument(file);
    }));
    context.subscriptions.push(disposable);
}
exports.activate = activate;
function getFilePath() {
    const activeEditor = vscode.window.activeTextEditor;
    const document = activeEditor && activeEditor.document;
    return document && document.fileName;
}
function getTSXFileName(fileName) {
    const ext = path.extname(fileName).replace(/^\./, '');
    const extNameRegex = new RegExp(`${ext}$`);
    return fileName.replace(extNameRegex, 'tsx');
}
// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;
//# sourceMappingURL=extension.js.map