import * as util from "./util/index"; const { exec } = require('child_process'); const packageData = require("./../package.json"); const NODE_MODULE_SRC_CODE_PATH = `${__dirname.split("coda-mota/lib")[0]}coda-mota/`; // const PWD = process.cwd(); interface Cmd { name: string; found: boolean; opts?: { [x: string]: any }; tags?: string[], } const cmds: Cmd[] = [ { name: "status", found: util.terminal.wasCommandFound("check"), }, { name: "new", found: util.terminal.wasCommandFound("new"), opts: { js: util.terminal.wasOptionFound("js") }, tags: ["koa", "nodejs", "gulp"], }, ]; const runCmd: Cmd | undefined = cmds.find((element: Cmd) => element.found); switch (runCmd && runCmd.name) { case "status": process.stdout.write(`healthy. version: ${packageData.version} \n`); break; case "new": const commands = [ "git clone https://github.com/ijmeals/build-setup.git", "cp -nrf ./build-setup/.vscode/ .vscode/", "cp -nrf ./build-setup/gulp-tasks/ ./gulp-tasks/", "cp -nrf ./build-setup/.babelrc .", "cp -nrf ./build-setup/.eslintignore .", "cp -nrf ./build-setup/.eslintrc.json .", "cp -nrf ./build-setup/gulpfile.js .", "cp -nrf ./build-setup/jest.config.js .", `cp -nrf ${NODE_MODULE_SRC_CODE_PATH}/package.sample.json .`, "cp ./package.sample.json ./package.json", "cp -nrf ./build-setup/tsconfig.json .", "cp -nrf ./build-setup/tslint.json .", "mkdir ./src/", "rm -rf ./build-setup/", "npm run clean:install" ]; exec(commands.join(" && "), (err, stdout, stderr) => { if (err) { // node couldn't execute the command return; } process.stdout.write("completed \n"); }); break; default: break; }