const parseArgumentsIntoOptions =require("./utils/parseArgumentsIntoOptions");
const get =require("lodash/get");
const pjson = require("../package.json");
const chalk = require("chalk");
const createProject  = require("./create");
const build = require('./build');
// const path= require("path");
// const ROOT=path.resolve(__dirname,"../");
// import pjson from "../package.json";
// import chalk from "chalk";
// import createProject  from "./create";
// import build from './build';


module.exports=async (args)=> {
  let options = parseArgumentsIntoOptions(args);
  // 打印版本信息
  if (get(options, "version")) {
    let log = chalk.green(`当前cli版本为 : ${pjson.version}`)
    return console.log(log);
  }
  console.log(options);
  if(get(options,"install")){
    const req = await createProject(options);
    if(!req){
      process.exit(2);
    }
    return 1;
  }
  else if(get(options,"build")){
    const req = await build({type:'build'});
    if(!req){
      process.exit(2);
    }
    return 1;
  }
  else if(get(options,"dev")){
    const req = await build({type:'dev'});
    if(!req){
      process.exit(2);
    }
    return 1;
  }
  
}