forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbep.ts
More file actions
68 lines (53 loc) · 1.46 KB
/
bep.ts
File metadata and controls
68 lines (53 loc) · 1.46 KB
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
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as fs from 'fs';
export interface BuildEventMessage {
id: {};
[key: string]: {};
}
export class BepGenerator {
private constructor() {}
static createBuildStarted(command: string, time?: number): BuildEventMessage {
return {
id: { started: {} },
started: {
command,
start_time_millis: time == undefined ? Date.now() : time,
},
};
}
static createBuildFinished(code: number, time?: number): BuildEventMessage {
return {
id: { finished: {} },
finished: {
finish_time_millis: time == undefined ? Date.now() : time,
exit_code: { code },
},
};
}
}
export class BepJsonWriter {
private stream = fs.createWriteStream(this.filename);
constructor(public readonly filename: string) {
}
close(): void {
this.stream.close();
}
writeEvent(event: BuildEventMessage): void {
const raw = JSON.stringify(event);
this.stream.write(raw + '\n');
}
writeBuildStarted(command: string, time?: number): void {
const event = BepGenerator.createBuildStarted(command, time);
this.writeEvent(event);
}
writeBuildFinished(code: number, time?: number): void {
const event = BepGenerator.createBuildFinished(code, time);
this.writeEvent(event);
}
}