#!/usr/bin/env node

import * as FS from 'fs';
import * as PATH from 'path';
import Commander = require('commander');
import { AntCube } from './index';

const pkg = JSON.parse(FS.readFileSync(PATH.join(PATH.resolve(__dirname, '../'), 'package.json')).toString());

Commander.version(`${pkg.version}`);

Commander
    .command('build')
    .description('编译工程')
    .option('-p, --path <v>', '目标工程路径')
    .option('-d, --dist <v>', '编译结果路径')
    .action(cmd => {
        AntCube.pack.buildProject(cmd.path, cmd.dist).then(value => {
            if (value.success) {
                console.log(`success`);
                process.exit(0);
            } else {
                console.log(`${value.message}`);
                process.exit(1);
            }
        }).catch(reason => {
            console.error(`build project failure\n${reason.message}`);
            process.exit(1);
        });
    });

Commander.parse(process.argv);