1 | "use strict";
|
2 | var __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 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.NewCommand = void 0;
|
13 | const schematics_1 = require("../lib/schematics");
|
14 | const abstract_command_1 = require("./abstract.command");
|
15 | class NewCommand extends abstract_command_1.AbstractCommand {
|
16 | load(program) {
|
17 | program
|
18 | .command('new [name]')
|
19 | .alias('n')
|
20 | .description('Generate Nest application.')
|
21 | .option('--directory [directory]', 'Specify the destination directory')
|
22 | .option('-d, --dry-run', 'Report actions that would be performed without writing out results.')
|
23 | .option('-g, --skip-git', 'Skip git repository initialization.')
|
24 | .option('-s, --skip-install', 'Skip package installation.')
|
25 | .option('-p, --package-manager [package-manager]', 'Specify package manager.')
|
26 | .option('-l, --language [language]', 'Programming language to be used (TypeScript or JavaScript).')
|
27 | .option('-c, --collection [collectionName]', 'Schematics collection to use.')
|
28 | .action((name, command) => __awaiter(this, void 0, void 0, function* () {
|
29 | const options = [];
|
30 | const availableLanguages = ['js', 'ts', 'javascript', 'typescript'];
|
31 | options.push({ name: 'directory', value: command.directory });
|
32 | options.push({ name: 'dry-run', value: !!command.dryRun });
|
33 | options.push({ name: 'skip-git', value: !!command.skipGit });
|
34 | options.push({ name: 'skip-install', value: !!command.skipInstall });
|
35 | options.push({
|
36 | name: 'package-manager',
|
37 | value: command.packageManager,
|
38 | });
|
39 | if (!!command.language) {
|
40 | const lowercasedLanguage = command.language.toLowerCase();
|
41 | const langMatch = availableLanguages.includes(lowercasedLanguage);
|
42 | if (!langMatch) {
|
43 | throw new Error(`Invalid language "${command.language}" selected. Available languages are "typescript" or "javascript"`);
|
44 | }
|
45 | switch (lowercasedLanguage) {
|
46 | case 'javascript':
|
47 | command.language = 'js';
|
48 | break;
|
49 | case 'typescript':
|
50 | command.language = 'ts';
|
51 | break;
|
52 | default:
|
53 | command.language = lowercasedLanguage;
|
54 | break;
|
55 | }
|
56 | }
|
57 | options.push({
|
58 | name: 'language',
|
59 | value: !!command.language ? command.language : 'ts',
|
60 | });
|
61 | options.push({
|
62 | name: 'collection',
|
63 | value: command.collection || schematics_1.Collection.NESTJS,
|
64 | });
|
65 | const inputs = [];
|
66 | inputs.push({ name: 'name', value: name });
|
67 | yield this.action.handle(inputs, options);
|
68 | }));
|
69 | }
|
70 | }
|
71 | exports.NewCommand = NewCommand;
|