forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.ts
138 lines (127 loc) · 3.51 KB
/
serve.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { BuildOptions } from '../models/build-options';
import { baseBuildCommandOptions } from './build';
import { CliConfig } from '../models/config';
import { Version } from '../upgrade/version';
import { ServeTaskOptions } from './serve';
import { checkPort } from '../utilities/check-port';
import { overrideOptions } from '../utilities/override-options';
const Command = require('../ember-cli/lib/models/command');
const config = CliConfig.fromProject() || CliConfig.fromGlobal();
const defaultPort = process.env.PORT || config.get('defaults.serve.port');
const defaultHost = config.get('defaults.serve.host');
const defaultSsl = config.get('defaults.serve.ssl');
const defaultSslKey = config.get('defaults.serve.sslKey');
const defaultSslCert = config.get('defaults.serve.sslCert');
export interface ServeTaskOptions extends BuildOptions {
port?: number;
host?: string;
proxyConfig?: string;
liveReload?: boolean;
publicHost?: string;
disableHostCheck?: boolean;
ssl?: boolean;
sslKey?: string;
sslCert?: string;
open?: boolean;
hmr?: boolean;
}
// Expose options unrelated to live-reload to other commands that need to run serve
export const baseServeCommandOptions: any = overrideOptions([
...baseBuildCommandOptions,
{
name: 'port',
type: Number,
default: defaultPort,
aliases: ['p'],
description: 'Port to listen to for serving.'
},
{
name: 'host',
type: String,
default: defaultHost,
aliases: ['H'],
description: `Listens only on ${defaultHost} by default.`
},
{
name: 'proxy-config',
type: 'Path',
aliases: ['pc'],
description: 'Proxy configuration file.'
},
{
name: 'ssl',
type: Boolean,
default: defaultSsl,
description: 'Serve using HTTPS.'
},
{
name: 'ssl-key',
type: String,
default: defaultSslKey,
description: 'SSL key to use for serving HTTPS.'
},
{
name: 'ssl-cert',
type: String,
default: defaultSslCert,
description: 'SSL certificate to use for serving HTTPS.'
},
{
name: 'open',
type: Boolean,
default: false,
aliases: ['o'],
description: 'Opens the url in default browser.',
},
{
name: 'live-reload',
type: Boolean,
default: true,
aliases: ['lr'],
description: 'Whether to reload the page on change, using live-reload.'
},
{
name: 'public-host',
type: String,
aliases: ['live-reload-client'],
description: 'Specify the URL that the browser client will use.'
},
{
name: 'disable-host-check',
type: Boolean,
default: false,
description: 'Don\'t verify connected clients are part of allowed hosts.',
},
{
name: 'hmr',
type: Boolean,
default: false,
description: 'Enable hot module replacement.',
}
], [
{
name: 'watch',
default: true,
description: 'Rebuild on change.'
}
]);
const ServeCommand = Command.extend({
name: 'serve',
description: 'Builds and serves your app, rebuilding on file changes.',
aliases: ['server', 's'],
availableOptions: baseServeCommandOptions,
run: function (commandOptions: ServeTaskOptions) {
const ServeTask = require('../tasks/serve').default;
Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
return checkPort(commandOptions.port, commandOptions.host, defaultPort)
.then(port => {
commandOptions.port = port;
const serve = new ServeTask({
ui: this.ui,
project: this.project,
});
return serve.run(commandOptions);
});
}
});
export default ServeCommand;