#!/usr/bin/env node




var nodeVersions = process.version;
var versionArrStr = nodeVersions.split(".");
versionArrStr[0] = versionArrStr[0].replace("v", "");
var versionArray = versionArrStr.map(function (item) {
    return parseInt(item)
});
if (versionArray[0] < 8) {
    console.error('请您安装NodeJS v8.0 以上版本')
    process.exit(1);
}

import * as args from 'args';
import { create, install, publish, upgrade, check, wechat, build, info } from '../out/index'

args.command('create', 'create project', (name: string, sub: string[], options: any) => {

    create.run(name, sub, options).catch(e => console.log(e));
});

args.command('install', 'install a library', (name: string, sub: string[], options: any) => {
    install.run(name, sub, options).catch(e => console.log(e));
});


args.option('tag', 'which tag you want to publish')
    .command('publish', 'publish a library', (name, sub, option) => {
        publish.run(name, sub, option).catch(e => console.error(e));
    })

args.command('upgrade', 'upgrade your project', (name, sub, option) => {
    upgrade.run(name, sub, option).catch(e => console.error(e));
})

args.command("check", "check & remove unused resource", (name, sub, option) => {
    check.run(name, sub, option).catch(e => console.error(e));
})

args.command("wechat", 'execute wechat ide method', (name, sub, option) => {
    wechat.run(name, sub, option);
})


args.command("build", "build your project", (name, sub, option) => {
    const projectRoot = sub[0] || "."
    build.build({
        projectRoot,
        debug: true,
        target: "web"
    })
})

args.command("bake", "bake your project", (name, sub, option) => {
    const projectRoot = sub[0] || "."
    build.bake({
        projectRoot,
        debug: true,
        target: "web"
    }).then((bakeResult) => {
        const list = bakeResult.warn.concat(bakeResult.error);
        list.forEach((item) => {
            console.log(item)
        })
    })

})
args.command("info", "paper-cli info", (name, sub, option) => {
    info.run(name, sub, option).catch(e => console.log(e));
})
args.parse(process.argv)



