-
Notifications
You must be signed in to change notification settings - Fork 404
/
Copy pathnew.command.ts
80 lines (76 loc) · 2.85 KB
/
new.command.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Command, CommanderStatic } from 'commander';
import { Collection } from '../lib/schematics';
import { AbstractCommand } from './abstract.command';
import { Input } from './command.input';
export class NewCommand extends AbstractCommand {
public load(program: CommanderStatic) {
program
.command('new [name]')
.alias('n')
.description('Generate Nest application.')
.option('--directory [directory]', 'Specify the destination directory')
.option(
'-d, --dry-run',
'Report actions that would be performed without writing out results.',
false,
)
.option('-g, --skip-git', 'Skip git repository initialization.', false)
.option('-s, --skip-install', 'Skip package installation.', false)
.option(
'-p, --package-manager [packageManager]',
'Specify package manager.',
)
.option(
'-l, --language [language]',
'Programming language to be used (TypeScript or JavaScript)',
'TypeScript',
)
.option(
'-c, --collection [collectionName]',
'Schematics collection to use',
Collection.NESTJS,
)
.option('--strict', 'Enables strict mode in TypeScript.', false)
.action(async (name: string, command: Command) => {
const options: Input[] = [];
const availableLanguages = ['js', 'ts', 'javascript', 'typescript'];
options.push({ name: 'directory', value: command.directory });
options.push({ name: 'dry-run', value: command.dryRun });
options.push({ name: 'skip-git', value: command.skipGit });
options.push({ name: 'skip-install', value: command.skipInstall });
options.push({ name: 'strict', value: command.strict });
options.push({
name: 'packageManager',
value: command.packageManager,
});
options.push({ name: 'collection', value: command.collection });
if (!!command.language) {
const lowercasedLanguage = command.language.toLowerCase();
const langMatch = availableLanguages.includes(lowercasedLanguage);
if (!langMatch) {
throw new Error(
`Invalid language "${command.language}" selected. Available languages are "typescript" or "javascript"`,
);
}
switch (lowercasedLanguage) {
case 'javascript':
command.language = 'js';
break;
case 'typescript':
command.language = 'ts';
break;
default:
command.language = lowercasedLanguage;
break;
}
}
options.push({
name: 'language',
value: command.language,
});
const inputs: Input[] = [];
inputs.push({ name: 'name', value: name });
await this.action.handle(inputs, options);
});
}
}