bep.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /**
  4. * @license
  5. * Copyright Google Inc. All Rights Reserved.
  6. *
  7. * Use of this source code is governed by an MIT-style license that can be
  8. * found in the LICENSE file at https://angular.io/license
  9. */
  10. const fs = require("fs");
  11. class BepGenerator {
  12. constructor() { }
  13. static createBuildStarted(command, time) {
  14. return {
  15. id: { started: {} },
  16. started: {
  17. command,
  18. start_time_millis: time == undefined ? Date.now() : time,
  19. },
  20. };
  21. }
  22. static createBuildFinished(code, time) {
  23. return {
  24. id: { finished: {} },
  25. finished: {
  26. finish_time_millis: time == undefined ? Date.now() : time,
  27. exit_code: { code },
  28. },
  29. };
  30. }
  31. }
  32. exports.BepGenerator = BepGenerator;
  33. class BepJsonWriter {
  34. constructor(filename) {
  35. this.filename = filename;
  36. this.stream = fs.createWriteStream(this.filename);
  37. }
  38. close() {
  39. this.stream.close();
  40. }
  41. writeEvent(event) {
  42. const raw = JSON.stringify(event);
  43. this.stream.write(raw + '\n');
  44. }
  45. writeBuildStarted(command, time) {
  46. const event = BepGenerator.createBuildStarted(command, time);
  47. this.writeEvent(event);
  48. }
  49. writeBuildFinished(code, time) {
  50. const event = BepGenerator.createBuildFinished(code, time);
  51. this.writeEvent(event);
  52. }
  53. }
  54. exports.BepJsonWriter = BepJsonWriter;