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.', false)
|
23 | .option('-g, --skip-git', 'Skip git repository initialization.', false)
|
24 | .option('-s, --skip-install', 'Skip package installation.', false)
|
25 | .option('-p, --package-manager [packageManager]', 'Specify package manager.')
|
26 | .option('-l, --language [language]', 'Programming language to be used (TypeScript or JavaScript)', 'TypeScript')
|
27 | .option('-c, --collection [collectionName]', 'Schematics collection to use', schematics_1.Collection.NESTJS)
|
28 | .option('--strict', 'Enables strict mode in TypeScript.', false)
|
29 | .action((name, command) => __awaiter(this, void 0, void 0, function* () {
|
30 | const options = [];
|
31 | const availableLanguages = ['js', 'ts', 'javascript', 'typescript'];
|
32 | options.push({ name: 'directory', value: command.directory });
|
33 | options.push({ name: 'dry-run', value: command.dryRun });
|
34 | options.push({ name: 'skip-git', value: command.skipGit });
|
35 | options.push({ name: 'skip-install', value: command.skipInstall });
|
36 | options.push({ name: 'strict', value: command.strict });
|
37 | options.push({
|
38 | name: 'packageManager',
|
39 | value: command.packageManager,
|
40 | });
|
41 | options.push({ name: 'collection', value: command.collection });
|
42 | if (!!command.language) {
|
43 | const lowercasedLanguage = command.language.toLowerCase();
|
44 | const langMatch = availableLanguages.includes(lowercasedLanguage);
|
45 | if (!langMatch) {
|
46 | throw new Error(`Invalid language "${command.language}" selected. Available languages are "typescript" or "javascript"`);
|
47 | }
|
48 | switch (lowercasedLanguage) {
|
49 | case 'javascript':
|
50 | command.language = 'js';
|
51 | break;
|
52 | case 'typescript':
|
53 | command.language = 'ts';
|
54 | break;
|
55 | default:
|
56 | command.language = lowercasedLanguage;
|
57 | break;
|
58 | }
|
59 | }
|
60 | options.push({
|
61 | name: 'language',
|
62 | value: command.language,
|
63 | });
|
64 | const inputs = [];
|
65 | inputs.push({ name: 'name', value: name });
|
66 | yield this.action.handle(inputs, options);
|
67 | }));
|
68 | }
|
69 | }
|
70 | exports.NewCommand = NewCommand;
|