"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const routing_controllers_1 = require("@gem-mine/routing-controllers");
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
const currentOs = os.platform();
const child_process = require('child_process');
const openExplorer = path => {
    if (currentOs === 'win32') {
        openExplorerWindows(path);
    }
    else if (currentOs === 'darwin') {
        openExplorerMac(path);
    }
    else {
        openExplorerLinux(path);
    }
};
const openExplorerWindows = path => {
    child_process.execSync(`cd ${path} && explorer .`);
};
const openExplorerMac = path => {
    child_process.execSync(`open ${path}`);
};
const openExplorerLinux = path => {
    child_process.execSync(`nautilus ${path}`);
};
let default_1 = class default_1 {
    openExplorer(modal) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const _path = path.resolve(modal.path);
            if (!fs.existsSync(_path)) {
                return {
                    success: false,
                    message: '文件夹打开失败，请检查本地文件夹路径是否存在！'
                };
            }
            try {
                openExplorer(_path);
                return {
                    success: true
                };
            }
            catch (error) {
                return {
                    success: true,
                    message: '文件夹打开失败！'
                };
            }
        });
    }
    gitLink(modal) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const { path, remote } = modal;
            if (!fs.existsSync(path)) {
                return {
                    success: false,
                    message: '请检查本地文件夹路径是否存在！'
                };
            }
            try {
                child_process.execSync(`git remote add origin ${remote}`, {
                    cwd: path,
                    stdio: ['pipe', 'pipe', 'pipe'],
                    windowsHide: true
                });
                return {
                    success: true
                };
            }
            catch (error) {
                return {
                    success: false,
                    message: 'git 关联失败！'
                };
            }
        });
    }
    getGitLink(_path) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const cwd = path.resolve(decodeURIComponent(_path));
            if (!fs.existsSync(cwd)) {
                return {
                    success: false,
                    message: '请检查本地文件夹路径是否存在！'
                };
            }
            try {
                const url = child_process.execSync('git remote get-url origin', {
                    cwd: cwd,
                    stdio: ['pipe', 'pipe', 'pipe'],
                    windowsHide: true
                }).toString();
                return {
                    url,
                    success: true
                };
            }
            catch (error) {
                return {
                    success: false,
                    message: 'git remote 获取失败！'
                };
            }
        });
    }
    uiVersion(_path, ui) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const cwd = path.resolve(_path);
            if (!fs.existsSync(cwd)) {
                return {
                    success: false,
                    message: '请检查本地文件夹路径是否存在！'
                };
            }
            try {
                const version = require(`${cwd}/node_modules/${ui}/package.json`).version;
                return {
                    version,
                    success: true
                };
            }
            catch (error) {
                return {
                    success: false,
                    message: `${ui} 版本获取失败！`
                };
            }
        });
    }
};
tslib_1.__decorate([
    routing_controllers_1.Post('/openExplorer'),
    tslib_1.__param(0, routing_controllers_1.Body()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [Object]),
    tslib_1.__metadata("design:returntype", Promise)
], default_1.prototype, "openExplorer", null);
tslib_1.__decorate([
    routing_controllers_1.Post('/gitLink'),
    tslib_1.__param(0, routing_controllers_1.Body()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [Object]),
    tslib_1.__metadata("design:returntype", Promise)
], default_1.prototype, "gitLink", null);
tslib_1.__decorate([
    routing_controllers_1.Get('/gitLink/:path'),
    tslib_1.__param(0, routing_controllers_1.Param('path')),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String]),
    tslib_1.__metadata("design:returntype", Promise)
], default_1.prototype, "getGitLink", null);
tslib_1.__decorate([
    routing_controllers_1.Get('/uiVersion'),
    tslib_1.__param(0, routing_controllers_1.QueryParam('path')), tslib_1.__param(1, routing_controllers_1.QueryParam('ui')),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String, String]),
    tslib_1.__metadata("design:returntype", Promise)
], default_1.prototype, "uiVersion", null);
default_1 = tslib_1.__decorate([
    routing_controllers_1.Controller('/os')
], default_1);
exports.default = default_1;
//# sourceMappingURL=data:application/json;base64, 