| 78 | * A local Angular development server managed by the MCP server. |
| 79 | */ |
| 80 | export class LocalDevserver implements Devserver { |
| 81 | readonly host: Host; |
| 82 | readonly port: number; |
| 83 | readonly workspacePath: string; |
| 84 | readonly project: string; |
| 85 | |
| 86 | private devserverProcess: ChildProcess | null = null; |
| 87 | private serverLogs: string[] = []; |
| 88 | private buildInProgress = false; |
| 89 | private latestBuildLogStartIndex?: number = undefined; |
| 90 | private latestBuildStatus: BuildStatus = 'unknown'; |
| 91 | |
| 92 | constructor({ |
| 93 | host, |
| 94 | port, |
| 95 | workspacePath, |
| 96 | project, |
| 97 | }: { |
| 98 | host: Host; |
| 99 | port: number; |
| 100 | workspacePath: string; |
| 101 | project: string; |
| 102 | }) { |
| 103 | this.host = host; |
| 104 | this.port = port; |
| 105 | this.workspacePath = workspacePath; |
| 106 | this.project = project; |
| 107 | } |
| 108 | |
| 109 | start() { |
| 110 | if (this.devserverProcess) { |
| 111 | throw Error('Dev server already started.'); |
| 112 | } |
| 113 | |
| 114 | const args = ['serve']; |
| 115 | if (this.project) { |
| 116 | args.push(this.project); |
| 117 | } |
| 118 | |
| 119 | args.push(`--port=${this.port}`); |
| 120 | |
| 121 | this.devserverProcess = this.host.startNgProcess(args, { |
| 122 | stdio: 'pipe', |
| 123 | cwd: this.workspacePath, |
| 124 | }); |
| 125 | processStreamLines(this.devserverProcess.stdout, (line) => this.addLog(line)); |
| 126 | processStreamLines(this.devserverProcess.stderr, (line) => this.addLog(line)); |
| 127 | |
| 128 | this.devserverProcess.on('close', () => { |
| 129 | this.stop(); |
| 130 | }); |
| 131 | this.buildInProgress = true; |
| 132 | } |
| 133 | |
| 134 | private addLog(log: string) { |
| 135 | this.serverLogs.push(log); |
| 136 | |
| 137 | if (BUILD_START_MESSAGES.some((message) => log.startsWith(message))) { |
nothing calls this directly
no outgoing calls
no test coverage detected