/
start.command.ts
87 lines (82 loc) 路 3 KB
/
start.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
81
82
83
84
85
86
87
import { Command, CommanderStatic } from 'commander';
import { getRemainingFlags } from '../lib/utils/remaining-flags';
import { AbstractCommand } from './abstract.command';
import { Input } from './command.input';
export class StartCommand extends AbstractCommand {
public load(program: CommanderStatic): void {
program
.command('start [app]')
.option('-c, --config [path]', 'Path to nest-cli configuration file.')
.option('-p, --path [path]', 'Path to tsconfig file.')
.option('-w, --watch', 'Run in watch mode (live-reload).')
.option('--watchAssets', 'Watch non-ts (e.g., .graphql) files mode.')
.option(
'-d, --debug [hostport] ',
'Run in debug mode (with --inspect flag).',
)
.option('--webpack', 'Use webpack for compilation.')
.option('--webpackPath [path]', 'Path to webpack configuration.')
.option('--tsc', 'Use tsc for compilation.')
.option(
'--sourceRoot [sourceRoot]',
'Points at the root of the source code for the single project in standard mode structures, or the default project in monorepo mode structures.',
)
.option(
'--entryFile [entryFile]',
"Path to the entry file where this command will work with. Defaults to the one defined at your Nest's CLI config file.",
)
.option('-e, --exec [binary]', 'Binary to run (default: "node").')
.option(
'--preserveWatchOutput',
'Use "preserveWatchOutput" option when tsc watch mode.',
)
.description('Run Nest application.')
.action(async (app: string, command: Command) => {
const options: Input[] = [];
options.push({
name: 'config',
value: command.config,
});
const isWebpackEnabled = command.tsc ? false : command.webpack;
options.push({ name: 'webpack', value: isWebpackEnabled });
options.push({ name: 'debug', value: command.debug });
options.push({ name: 'watch', value: !!command.watch });
options.push({ name: 'watchAssets', value: !!command.watchAssets });
options.push({
name: 'path',
value: command.path,
});
options.push({
name: 'webpackPath',
value: command.webpackPath,
});
options.push({
name: 'exec',
value: command.exec,
});
options.push({
name: 'sourceRoot',
value: command.sourceRoot,
});
options.push({
name: 'entryFile',
value: command.entryFile,
});
options.push({
name: 'preserveWatchOutput',
value:
!!command.preserveWatchOutput &&
!!command.watch &&
!isWebpackEnabled,
});
const inputs: Input[] = [];
inputs.push({ name: 'app', value: app });
const flags = getRemainingFlags(program);
try {
await this.action.handle(inputs, options, flags);
} catch (err) {
process.exit(1);
}
});
}
}