UNPKG

hades-cli

Version:
59 lines (58 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const fs = require("fs"); const chalk = require("chalk"); const inquirer = require("inquirer"); const path = require("path"); const emoji = require("node-emoji"); const logSymbols = require("log-symbols"); const utils_1 = require("./../@cliter/utils"); const types_1 = require("./../@cliter/types"); class Delete extends command_1.Command { async run() { const { args, flags } = this.parse(Delete); if (args.elementType === 'b') args.elementType = 'bounded-context'; if (args.elementType === 'm') args.elementType = 'module'; if (args.elementType === types_1.TemplateElement.MODULE) { if (fs.existsSync(path.join(process.cwd(), 'src', '@hades', args.elementName))) { if ((await this.promptForDelete(args.elementName)).hasDelete) { utils_1.FsExtend.rmDir(path.join(process.cwd(), 'src', '@hades', args.elementName)); this.log(`%s %s Module ${args.elementName} has been deleted %s`, chalk.green.bold('DONE'), emoji.get('open_file_folder'), logSymbols.success); } } else { this.log(`%s Module ${args.elementName} not exist, be sure to enter the module in the format: bounded-context/module %s`, chalk.yellow.bold('WARNING'), logSymbols.warning); } } } async promptForDelete(elementName) { const questions = []; questions.push({ name: 'hasDelete', message: `Do you want delete the module ${elementName}?`, type: 'confirm' }); return await inquirer.prompt(questions); } } exports.default = Delete; Delete.description = 'Delete elements'; Delete.flags = { help: command_1.flags.help({ char: 'h' }) }; Delete.args = [ { name: 'elementType', required: true, description: 'Type element to delete', options: ['bounded-context', 'b', 'module', 'm'] }, { name: 'elementName', required: true, description: 'Name element to create' } ];