import os from 'os';
import { shell2, shell } from './util';
import fs from 'fs';
import path from 'path';

async function runWxIde(projectPath: string) {
    let wxPaths: string[] = [];
    let packagePath: string;
    switch (os.platform()) {
        case "darwin":
            wxPaths.push("/Applications/wechatwebdevtools.app/Contents/Resources/app.nw/bin/cli");
            break;
        case "win32":
            wxPaths = [
                "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat",
                "C:\\Program Files\\Tencent\\微信web开发者工具\\cli.bat"
            ];
    }
    const wxpath = wxPaths.find((wxpath) => fs.existsSync(wxpath));
    projectPath = path.join(process.cwd(), projectPath)
    if (wxpath) {
        try {
            await shell(wxpath, ["-o", projectPath, "-f", "egret"]);
        }
        catch (e) {
            await shell(wxpath, ["-o", projectPath]);
        }
    }
    else {
        throw '请安装最新微信开发者工具'
    }
}

export async function run(name: string, sub: string[], options: any) {
    const projectDir = sub[1];
    switch (sub[0]) {
        case "open":
            runWxIde(projectDir);
            break;
    }
    console.log(projectDir)
}


