Skip to content

Commit 335d1b3

Browse files
committed
refactor: get the port from the server field
1 parent ad4bc30 commit 335d1b3

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/command-manager.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,26 @@ export default class CommandManager {
1010
// Store the visual name in the node environment
1111
env.VISUAL_NAME = name;
1212

13+
const visualRoot = ngJson.projects[name].root;
14+
const pkgJson = readJsonFromVisual(`${visualRoot}/package.json`);
15+
16+
// Get the port from the server field in the package.json
17+
let port = '';
18+
try {
19+
port = pkgJson.server ? new URL(pkgJson.server).port : '';
20+
} catch (e) {
21+
console.error(e);
22+
}
23+
24+
const opts = Object.assign({ port }, options);
25+
1326
// --port=4201 => { port: '4201' } => ['--port=4201']
1427
// -p=4201 => { port: '=4201' } => ['--port=4201']
15-
const optsArr = Object.keys(options).map(key => {
16-
if (options[key].startsWith('=')) {
17-
return `--${key}${options[key]}`;
28+
const optsArr = Object.keys(opts).map(key => {
29+
if (opts[key].startsWith('=')) {
30+
return `--${key}${opts[key]}`;
1831
}
19-
return `--${key}=${options[key]}`;
32+
return `--${key}=${opts[key]}`;
2033
});
2134

2235
const ng = spawn('ng', ['serve', name, ...optsArr]);

0 commit comments

Comments
 (0)