UNPKG

boil-cli-tool

Version:

CLI tool - boilerplate template manager and generator

43 lines (42 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); // utils const utils_1 = require("../utils"); const create_spec_1 = require("./create.spec"); class Create extends command_1.Command { async run() { const { args: { name }, flags, } = this.parse(Create); // 1. check that '.boilerplate' directory exists if (!utils_1.boilerplateExists()) { return this.log(utils_1.printError(`looks like you don't have a '.boilerplate' directory - run 'boil init' to start a new project`)); } // 2. validate that the name argument has been provided if (!name) { this.log(utils_1.printError(`you need to provide a template name`)); this.log(`\nrun 'boil create ${utils_1.print("--help")}' for details`); return; } // 3. validate the template name doesn't exist yet if (create_spec_1.templateExists(name)) { return this.log(utils_1.printError(`template '${name}' already exists`)); } // 4. generate template const args = flags.args ? flags.args.split(",") : []; create_spec_1.generateTemplate(name, args); } } exports.default = Create; Create.description = "create a new boilerplate template"; Create.flags = { help: command_1.flags.help({ char: "h" }), args: command_1.flags.string({ char: "a", description: "local template args", }), }; Create.args = [{ name: "name", description: "template name" }]; Create.examples = [ `$ boil create ${utils_1.print("person", "blue")} ${utils_1.print("--args")} name,surname,age`, `$ boil create ${utils_1.print("person", "blue")} ${utils_1.print("-a")} name,surname,age`, ];