|
1 |
| -import * as denodeify from 'denodeify'; |
2 | 1 | import { BuildOptions } from '../models/build-options';
|
3 | 2 | import { baseBuildCommandOptions } from './build';
|
4 | 3 | import { CliConfig } from '../models/config';
|
5 | 4 | import { Version } from '../upgrade/version';
|
6 | 5 | import { ServeTaskOptions } from './serve';
|
| 6 | +import { checkPort } from '../utilities/check-port'; |
7 | 7 | import { overrideOptions } from '../utilities/override-options';
|
8 | 8 |
|
9 |
| -const SilentError = require('silent-error'); |
10 |
| -const PortFinder = require('portfinder'); |
11 | 9 | const Command = require('../ember-cli/lib/models/command');
|
12 |
| -const getPort = denodeify<{ host: string, port: number }, number>(PortFinder.getPort); |
13 | 10 |
|
14 | 11 | const config = CliConfig.fromProject() || CliConfig.fromGlobal();
|
15 | 12 | const defaultPort = process.env.PORT || config.get('defaults.serve.port');
|
16 | 13 | const defaultHost = config.get('defaults.serve.host');
|
17 |
| -PortFinder.basePort = defaultPort; |
18 | 14 |
|
19 | 15 | export interface ServeTaskOptions extends BuildOptions {
|
20 | 16 | port?: number;
|
@@ -79,34 +75,18 @@ const ServeCommand = Command.extend({
|
79 | 75 | const ServeTask = require('../tasks/serve').default;
|
80 | 76 |
|
81 | 77 | Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
|
| 78 | + return checkPort(commandOptions.port, commandOptions.host, defaultPort) |
| 79 | + .then(port => { |
| 80 | + commandOptions.port = port; |
82 | 81 |
|
83 |
| - return checkExpressPort(commandOptions) |
84 |
| - .then((opts: ServeTaskOptions) => { |
85 | 82 | const serve = new ServeTask({
|
86 | 83 | ui: this.ui,
|
87 | 84 | project: this.project,
|
88 | 85 | });
|
89 | 86 |
|
90 |
| - return serve.run(opts); |
| 87 | + return serve.run(commandOptions); |
91 | 88 | });
|
92 | 89 | }
|
93 | 90 | });
|
94 | 91 |
|
95 |
| -function checkExpressPort(commandOptions: ServeTaskOptions) { |
96 |
| - return getPort({ port: commandOptions.port, host: commandOptions.host }) |
97 |
| - .then((foundPort: number) => { |
98 |
| - |
99 |
| - if (commandOptions.port !== foundPort && commandOptions.port !== 0) { |
100 |
| - throw new SilentError( |
101 |
| - `Port ${commandOptions.port} is already in use. Use '--port' to specify a different port.` |
102 |
| - ); |
103 |
| - } |
104 |
| - |
105 |
| - // otherwise, our found port is good |
106 |
| - commandOptions.port = foundPort; |
107 |
| - return commandOptions; |
108 |
| - |
109 |
| - }); |
110 |
| -} |
111 |
| - |
112 | 92 | export default ServeCommand;
|
0 commit comments