This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
serve.component.ts
67 lines (57 loc) · 1.9 KB
/
serve.component.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
import { Component, Output, EventEmitter, Input } from '@angular/core';
//
import * as _ from 'lodash';
//
import { AngularCliCommand } from '../../models/angular-cli-command.interface';
import { NgserveOptions } from '../../default-values/ng-serve-options';
import { CommandService } from './../../services/command/command.service';
import { ErrorService } from './../../services/error/error.service';
@Component({
selector: 'app-serve',
templateUrl: './serve.component.html',
styleUrls: ['./serve.component.css']
})
export class ServeComponent {
private readonly MINIMUM_PORT = 1000;
private readonly MAXIMUM_PORT = 99999;
@Output() sendCommand = new EventEmitter<string>();
@Input() serveCommandId: string;
command: AngularCliCommand;
options = new NgserveOptions();
isStoppingServeCommand = false;
constructor(
private commandService: CommandService,
private errorService: ErrorService
) {}
startServing(): void {
this.sendCommand.emit(this.options.createCommandString());
}
stopServing(): void {
this.isStoppingServeCommand = true;
this.commandService.stopServing(this.serveCommandId)
.subscribe(
_.noop,
error => {
this.errorService.addError({
errorText: 'The "ng serve" command you\'re trying to stop was not found',
errorDescription: 'The server is offline or have been restarted since you\'ve run this command'
});
},
() => {
this.serveCommandId = null;
localStorage.removeItem('ngServeCommandId');
this.isStoppingServeCommand = false;
}
);
}
isPortValid(): boolean {
const port = this.options.optionalFlags.port.value;
return port >= this.MINIMUM_PORT && port <= this.MAXIMUM_PORT;
}
isHostnameValid(): boolean {
return !!this.options.optionalFlags.host.value;
}
isAllInputsValid(): boolean {
return this.isHostnameValid() && this.isPortValid();
}
}