UNPKG

4.01 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const Table = require("cli-table3");
13const schematics_1 = require("../lib/schematics");
14const nest_collection_1 = require("../lib/schematics/nest.collection");
15const abstract_command_1 = require("./abstract.command");
16class GenerateCommand extends abstract_command_1.AbstractCommand {
17 load(program) {
18 program
19 .command('generate <schematic> [name] [path]')
20 .alias('g')
21 .description(this.buildDescription())
22 .option('-d, --dry-run', 'Report actions that would be taken without writing out results.')
23 .option('-p, --project [project]', 'Project in which to generate files.')
24 .option('--flat', 'Enforce flat structure of generated element.')
25 .option('--spec', 'Enforce spec files generation.', () => {
26 return { value: true, passedAsInput: true };
27 }, true)
28 .option('--no-spec', 'Disable spec files generation.', () => {
29 return { value: false, passedAsInput: true };
30 })
31 .option('-c, --collection [collectionName]', 'Schematics collection to use.')
32 .action((schematic, name, path, command) => __awaiter(this, void 0, void 0, function* () {
33 const options = [];
34 options.push({ name: 'dry-run', value: !!command.dryRun });
35 options.push({ name: 'flat', value: command.flat });
36 options.push({
37 name: 'spec',
38 value: typeof command.spec === 'boolean'
39 ? command.spec
40 : command.spec.value,
41 options: {
42 passedAsInput: typeof command.spec === 'boolean'
43 ? false
44 : command.spec.passedAsInput,
45 },
46 });
47 options.push({
48 name: 'collection',
49 value: command.collection || schematics_1.Collection.NESTJS,
50 });
51 options.push({
52 name: 'project',
53 value: command.project,
54 });
55 const inputs = [];
56 inputs.push({ name: 'schematic', value: schematic });
57 inputs.push({ name: 'name', value: name });
58 inputs.push({ name: 'path', value: path });
59 yield this.action.handle(inputs, options);
60 }));
61 }
62 buildDescription() {
63 return ('Generate a Nest element.\n' +
64 ' Available schematics:\n' +
65 this.buildSchematicsListAsTable());
66 }
67 buildSchematicsListAsTable() {
68 const leftMargin = ' ';
69 const tableConfig = {
70 head: ['name', 'alias'],
71 chars: {
72 'left': leftMargin.concat('│'),
73 'top-left': leftMargin.concat('┌'),
74 'bottom-left': leftMargin.concat('└'),
75 'mid': '',
76 'left-mid': '',
77 'mid-mid': '',
78 'right-mid': '',
79 },
80 };
81 const table = new Table(tableConfig);
82 for (const schematic of nest_collection_1.NestCollection.getSchematics()) {
83 table.push([schematic.name, schematic.alias]);
84 }
85 return table.toString();
86 }
87}
88exports.GenerateCommand = GenerateCommand;