UNPKG

hades-cli

Version:
67 lines (66 loc) 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("reflect-metadata"); const tsyringe_1 = require("tsyringe"); const command_1 = require("@oclif/command"); const utils_1 = require("./../@cliter/utils"); const state_service_1 = require("../@cliter/services/state.service"); const chalk = require("chalk"); const shell = require("shelljs"); const ora = require("ora"); class New extends command_1.Command { async run() { const { args, flags } = this.parse(New); // declare variables let gitFlags = ''; const gitCommand = 'git clone'; let repository = 'https://github.com/techedge-group/hades'; // get github credentials if (flags.credentials) { const { githubUsername, githubPassword } = await utils_1.Prompter.promptForGithubCredentials(); repository = `https://${githubUsername}:${githubPassword}@github.com/techedge-group/hades`; } // get bounded context const { branch } = await utils_1.Prompter.promptForNewApplication(); if (branch !== 'none') gitFlags += '--single-branch --branch ' + branch; // exec shell const installerSpinner = ora('Installing Hades project').start(); const githubThread = shell.exec(`${gitCommand} ${gitFlags} ${repository} ${args.appName}`, { silent: true, async: true }, async (code, stdout, stderr) => { if (code !== 0) { githubThread.kill(); installerSpinner.stop(); this.log(chalk.red.bold(`[ERROR ${code}]`), stderr); } // install dependencies else { installerSpinner.succeed('Project installed'); const dependenciesSpinner = ora('Installing dependencies').start(); shell.exec(`npm --prefix ${args.appName} install`, { silent: true, async: true }, () => { dependenciesSpinner.succeed('Dependencies installed'); // set stateService const stateService = tsyringe_1.container.resolve(state_service_1.StateService); stateService.command = this; stateService.flags = flags; stateService.appName = args.appName; const operations = new utils_1.Operations(); // generate env file operations.generateEnvFile(); }); } }); } } exports.default = New; New.description = 'Create new hades project'; New.flags = { help: command_1.flags.help({ char: 'h' }), credentials: command_1.flags.boolean({ char: 'c' }), }; New.args = [ { name: 'appName', required: true, description: 'Type app name to create' } ];