UNPKG

boil-cli-tool

Version:

CLI tool - boilerplate template manager and generator

35 lines (34 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); // utils const utils_1 = require("../utils"); const create_function_spec_1 = require("./create-function.spec"); class Create extends command_1.Command { async run() { const { args: { name }, } = 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 function name`)); this.log(`\nrun 'boil create-function ${utils_1.print("--help")}' for details`); return; } // 3. validate the template function name doesn't exist yet if (create_function_spec_1.templateExists(name)) { return this.log(utils_1.printError(`template function '${name}.js' already exists`)); } // 4. generate template function create_function_spec_1.generateTemplateFunction(name); } } exports.default = Create; Create.description = "create a new boilerplate template function"; Create.flags = { help: command_1.flags.help({ char: "h" }), }; Create.args = [{ name: "name", description: "template function name" }]; Create.examples = [`$ boil create-function ${utils_1.print("timestamp", "blue")}`];