@approval-tests/approvals 7.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/bin/help.md +31 -0
  2. package/bin/index.d.ts +2 -0
  3. package/bin/index.js +119 -0
  4. package/bin/index.ts +106 -0
  5. package/lib/AUtils.d.ts +9 -0
  6. package/lib/AUtils.js +175 -0
  7. package/lib/AUtils.ts +178 -0
  8. package/lib/Approvals.d.ts +104 -0
  9. package/lib/Approvals.js +280 -0
  10. package/lib/Approvals.ts +319 -0
  11. package/lib/Core/Namer.d.ts +5 -0
  12. package/lib/Core/Namer.js +11 -0
  13. package/lib/Core/Namer.ts +14 -0
  14. package/lib/Core/Options.d.ts +31 -0
  15. package/lib/Core/Options.js +74 -0
  16. package/lib/Core/Options.ts +94 -0
  17. package/lib/Core/Reporter.d.ts +6 -0
  18. package/lib/Core/Reporter.js +2 -0
  19. package/lib/Core/Reporter.ts +13 -0
  20. package/lib/Core/Writer.d.ts +4 -0
  21. package/lib/Core/Writer.js +2 -0
  22. package/lib/Core/Writer.ts +5 -0
  23. package/lib/DummyApprovedFiles/UnapprovedImage.png +0 -0
  24. package/lib/FileApprover.d.ts +9 -0
  25. package/lib/FileApprover.js +85 -0
  26. package/lib/FileApprover.ts +116 -0
  27. package/lib/FinalMessages.d.ts +5 -0
  28. package/lib/FinalMessages.js +17 -0
  29. package/lib/FinalMessages.ts +16 -0
  30. package/lib/Logs/ApprovedFileLog.d.ts +6 -0
  31. package/lib/Logs/ApprovedFileLog.js +68 -0
  32. package/lib/Logs/ApprovedFileLog.ts +38 -0
  33. package/lib/Logs/FailedFileLog.d.ts +7 -0
  34. package/lib/Logs/FailedFileLog.js +65 -0
  35. package/lib/Logs/FailedFileLog.ts +36 -0
  36. package/lib/Logs/LogUtils.d.ts +7 -0
  37. package/lib/Logs/LogUtils.js +56 -0
  38. package/lib/Logs/LogUtils.ts +44 -0
  39. package/lib/ManualNamer.d.ts +4 -0
  40. package/lib/ManualNamer.js +15 -0
  41. package/lib/ManualNamer.ts +12 -0
  42. package/lib/Namer.d.ts +9 -0
  43. package/lib/Namer.js +27 -0
  44. package/lib/Namer.ts +28 -0
  45. package/lib/Providers/BeforeEachVerifierBase.d.ts +2 -0
  46. package/lib/Providers/BeforeEachVerifierBase.js +82 -0
  47. package/lib/Providers/BeforeEachVerifierBase.ts +68 -0
  48. package/lib/Providers/Jest/CombinationApprovals.d.ts +14 -0
  49. package/lib/Providers/Jest/CombinationApprovals.js +44 -0
  50. package/lib/Providers/Jest/CombinationApprovals.ts +161 -0
  51. package/lib/Providers/Jest/JestApprovals.d.ts +4 -0
  52. package/lib/Providers/Jest/JestApprovals.js +73 -0
  53. package/lib/Providers/Jest/JestApprovals.ts +48 -0
  54. package/lib/Providers/Jest/JestNamer.d.ts +2 -0
  55. package/lib/Providers/Jest/JestNamer.js +18 -0
  56. package/lib/Providers/Jest/JestNamer.ts +15 -0
  57. package/lib/Providers/Jest/JestReporter.d.ts +7 -0
  58. package/lib/Providers/Jest/JestReporter.js +22 -0
  59. package/lib/Providers/Jest/JestReporter.ts +22 -0
  60. package/lib/Providers/Jest/JestSetup.d.ts +3 -0
  61. package/lib/Providers/Jest/JestSetup.js +41 -0
  62. package/lib/Providers/Jest/JestSetup.ts +40 -0
  63. package/lib/Providers/Mocha/MochaApprovals.d.ts +8 -0
  64. package/lib/Providers/Mocha/MochaApprovals.js +94 -0
  65. package/lib/Providers/Mocha/MochaApprovals.ts +70 -0
  66. package/lib/Providers/Mocha/MochaNamer.d.ts +9 -0
  67. package/lib/Providers/Mocha/MochaNamer.js +72 -0
  68. package/lib/Providers/Mocha/MochaNamer.ts +84 -0
  69. package/lib/Providers/Vitest/VitestApprovals.d.ts +4 -0
  70. package/lib/Providers/Vitest/VitestApprovals.js +62 -0
  71. package/lib/Providers/Vitest/VitestApprovals.ts +37 -0
  72. package/lib/Providers/Vitest/VitestNamer.d.ts +2 -0
  73. package/lib/Providers/Vitest/VitestNamer.js +17 -0
  74. package/lib/Providers/Vitest/VitestNamer.ts +21 -0
  75. package/lib/Providers/Vitest/VitestReporter.d.ts +7 -0
  76. package/lib/Providers/Vitest/VitestReporter.js +21 -0
  77. package/lib/Providers/Vitest/VitestReporter.ts +23 -0
  78. package/lib/Reporting/DiffReporterAggregate.d.ts +10 -0
  79. package/lib/Reporting/DiffReporterAggregate.js +28 -0
  80. package/lib/Reporting/DiffReporterAggregate.ts +36 -0
  81. package/lib/Reporting/GenericDiffReporterBase.d.ts +22 -0
  82. package/lib/Reporting/GenericDiffReporterBase.js +136 -0
  83. package/lib/Reporting/GenericDiffReporterBase.ts +154 -0
  84. package/lib/Reporting/ReportByOpeningTheReceivedFile.d.ts +7 -0
  85. package/lib/Reporting/ReportByOpeningTheReceivedFile.js +19 -0
  86. package/lib/Reporting/ReportByOpeningTheReceivedFile.ts +22 -0
  87. package/lib/Reporting/ReportLaunchingCircuitBreaker.d.ts +8 -0
  88. package/lib/Reporting/ReportLaunchingCircuitBreaker.js +37 -0
  89. package/lib/Reporting/ReportLaunchingCircuitBreaker.ts +40 -0
  90. package/lib/Reporting/ReporterFactory.d.ts +8 -0
  91. package/lib/Reporting/ReporterFactory.js +67 -0
  92. package/lib/Reporting/ReporterFactory.ts +85 -0
  93. package/lib/Reporting/Reporters/beyondcompareReporter.d.ts +4 -0
  94. package/lib/Reporting/Reporters/beyondcompareReporter.js +32 -0
  95. package/lib/Reporting/Reporters/beyondcompareReporter.ts +30 -0
  96. package/lib/Reporting/Reporters/codiumReporter.d.ts +5 -0
  97. package/lib/Reporting/Reporters/codiumReporter.js +25 -0
  98. package/lib/Reporting/Reporters/codiumReporter.ts +26 -0
  99. package/lib/Reporting/Reporters/copycommandReporter.d.ts +7 -0
  100. package/lib/Reporting/Reporters/copycommandReporter.js +40 -0
  101. package/lib/Reporting/Reporters/copycommandReporter.ts +46 -0
  102. package/lib/Reporting/Reporters/diffmergeReporter.d.ts +5 -0
  103. package/lib/Reporting/Reporters/diffmergeReporter.js +54 -0
  104. package/lib/Reporting/Reporters/diffmergeReporter.ts +25 -0
  105. package/lib/Reporting/Reporters/donothingReporter.d.ts +6 -0
  106. package/lib/Reporting/Reporters/donothingReporter.js +14 -0
  107. package/lib/Reporting/Reporters/donothingReporter.ts +13 -0
  108. package/lib/Reporting/Reporters/gitdiffReporter.d.ts +6 -0
  109. package/lib/Reporting/Reporters/gitdiffReporter.js +23 -0
  110. package/lib/Reporting/Reporters/gitdiffReporter.ts +28 -0
  111. package/lib/Reporting/Reporters/icdiffReporter.d.ts +4 -0
  112. package/lib/Reporting/Reporters/icdiffReporter.js +11 -0
  113. package/lib/Reporting/Reporters/icdiffReporter.ts +10 -0
  114. package/lib/Reporting/Reporters/kdiff3Reporter.d.ts +4 -0
  115. package/lib/Reporting/Reporters/kdiff3Reporter.js +11 -0
  116. package/lib/Reporting/Reporters/kdiff3Reporter.ts +10 -0
  117. package/lib/Reporting/Reporters/kompareReporter.d.ts +4 -0
  118. package/lib/Reporting/Reporters/kompareReporter.js +11 -0
  119. package/lib/Reporting/Reporters/kompareReporter.ts +10 -0
  120. package/lib/Reporting/Reporters/meldReporter.d.ts +4 -0
  121. package/lib/Reporting/Reporters/meldReporter.js +11 -0
  122. package/lib/Reporting/Reporters/meldReporter.ts +10 -0
  123. package/lib/Reporting/Reporters/multiReporter.d.ts +8 -0
  124. package/lib/Reporting/Reporters/multiReporter.js +49 -0
  125. package/lib/Reporting/Reporters/multiReporter.ts +55 -0
  126. package/lib/Reporting/Reporters/nodediffReporter.d.ts +7 -0
  127. package/lib/Reporting/Reporters/nodediffReporter.js +50 -0
  128. package/lib/Reporting/Reporters/nodediffReporter.ts +61 -0
  129. package/lib/Reporting/Reporters/opendiffReporter.d.ts +4 -0
  130. package/lib/Reporting/Reporters/opendiffReporter.js +11 -0
  131. package/lib/Reporting/Reporters/opendiffReporter.ts +10 -0
  132. package/lib/Reporting/Reporters/p4mergeReporter.d.ts +4 -0
  133. package/lib/Reporting/Reporters/p4mergeReporter.js +41 -0
  134. package/lib/Reporting/Reporters/p4mergeReporter.ts +39 -0
  135. package/lib/Reporting/Reporters/tortoisemergeReporter.d.ts +4 -0
  136. package/lib/Reporting/Reporters/tortoisemergeReporter.js +25 -0
  137. package/lib/Reporting/Reporters/tortoisemergeReporter.ts +25 -0
  138. package/lib/Reporting/Reporters/vimdiffReporter.d.ts +4 -0
  139. package/lib/Reporting/Reporters/vimdiffReporter.js +24 -0
  140. package/lib/Reporting/Reporters/vimdiffReporter.ts +25 -0
  141. package/lib/Reporting/Reporters/visualstudioReporter.d.ts +6 -0
  142. package/lib/Reporting/Reporters/visualstudioReporter.js +42 -0
  143. package/lib/Reporting/Reporters/visualstudioReporter.ts +48 -0
  144. package/lib/Reporting/Reporters/vscodeReporter.d.ts +5 -0
  145. package/lib/Reporting/Reporters/vscodeReporter.js +25 -0
  146. package/lib/Reporting/Reporters/vscodeReporter.ts +26 -0
  147. package/lib/Scrubbers/DateScrubber.d.ts +12 -0
  148. package/lib/Scrubbers/DateScrubber.js +67 -0
  149. package/lib/Scrubbers/DateScrubber.ts +83 -0
  150. package/lib/Scrubbers/Scrubbers.d.ts +20 -0
  151. package/lib/Scrubbers/Scrubbers.js +75 -0
  152. package/lib/Scrubbers/Scrubbers.ts +106 -0
  153. package/lib/StringWriter.d.ts +11 -0
  154. package/lib/StringWriter.js +82 -0
  155. package/lib/StringWriter.ts +73 -0
  156. package/lib/Utilities/ConsoleUtils.d.ts +4 -0
  157. package/lib/Utilities/ConsoleUtils.js +19 -0
  158. package/lib/Utilities/ConsoleUtils.ts +15 -0
  159. package/lib/Utilities/JestUtils.d.ts +3 -0
  160. package/lib/Utilities/JestUtils.js +9 -0
  161. package/lib/Utilities/JestUtils.ts +5 -0
  162. package/lib/Utilities/Logger/LoggingInstance.d.ts +32 -0
  163. package/lib/Utilities/Logger/LoggingInstance.js +214 -0
  164. package/lib/Utilities/Logger/LoggingInstance.ts +247 -0
  165. package/lib/Utilities/Logger/SimpleLogger.d.ts +23 -0
  166. package/lib/Utilities/Logger/SimpleLogger.js +61 -0
  167. package/lib/Utilities/Logger/SimpleLogger.ts +83 -0
  168. package/lib/Utilities/Logger/SimpleLoggerApprovals.d.ts +2 -0
  169. package/lib/Utilities/Logger/SimpleLoggerApprovals.js +12 -0
  170. package/lib/Utilities/Logger/SimpleLoggerApprovals.ts +15 -0
  171. package/lib/Utilities/Logger/StringWrapper.d.ts +6 -0
  172. package/lib/Utilities/Logger/StringWrapper.js +15 -0
  173. package/lib/Utilities/Logger/StringWrapper.ts +12 -0
  174. package/lib/Utilities/Logger/Wrapper.d.ts +14 -0
  175. package/lib/Utilities/Logger/Wrapper.js +27 -0
  176. package/lib/Utilities/Logger/Wrapper.ts +27 -0
  177. package/lib/Utilities/Printers.d.ts +4 -0
  178. package/lib/Utilities/Printers.js +52 -0
  179. package/lib/Utilities/Printers.ts +77 -0
  180. package/lib/Utilities/StringUtils.d.ts +3 -0
  181. package/lib/Utilities/StringUtils.js +12 -0
  182. package/lib/Utilities/StringUtils.ts +8 -0
  183. package/lib/Writers/BinaryWriter.d.ts +8 -0
  184. package/lib/Writers/BinaryWriter.js +63 -0
  185. package/lib/Writers/BinaryWriter.ts +31 -0
  186. package/lib/config.d.ts +22 -0
  187. package/lib/config.js +106 -0
  188. package/lib/config.ts +95 -0
  189. package/lib/osTools.d.ts +5 -0
  190. package/lib/osTools.js +11 -0
  191. package/lib/osTools.ts +11 -0
  192. package/lib/postRunCleanup.d.ts +1 -0
  193. package/lib/postRunCleanup.js +51 -0
  194. package/lib/postRunCleanup.ts +63 -0
  195. package/package.json +109 -0
  196. package/readme.md +557 -0
@@ -0,0 +1,22 @@
1
+ import { ChildProcessWithoutNullStreams } from "child_process";
2
+ import { Reporter } from "../Core/Reporter";
3
+ import { Config } from "../config";
4
+ export declare class GenericDiffReporterBase implements Reporter {
5
+ name: string;
6
+ exePath: string;
7
+ private _reporterFileLookedUp;
8
+ setCommandArgs: (approved: string, received: string) => string[];
9
+ modifyCommandOptions: (commandOptions: any) => any;
10
+ private _reporterFileLookedUpAndFound;
11
+ constructor(name: string);
12
+ isReporterAvailable(): boolean;
13
+ canImageDiff(): boolean;
14
+ canReportOn(fileName: string): boolean;
15
+ spawn(exe: string, args: string[], cmdOptions?: any): ChildProcessWithoutNullStreams;
16
+ spawnSync(exe: string, args: string[], cmdOptions?: any): void;
17
+ report(approved: string, received: string, options?: Partial<Config>): void;
18
+ getCommandArguments(approved: string, received: string, options?: Partial<Config>): {
19
+ cmdOptions: any;
20
+ args: string[];
21
+ };
22
+ }
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.GenericDiffReporterBase = void 0;
40
+ const childProcess = __importStar(require("child_process"));
41
+ const fs = __importStar(require("fs"));
42
+ const autils = __importStar(require("../AUtils"));
43
+ const ReportLaunchingCircuitBreaker_1 = __importDefault(require("./ReportLaunchingCircuitBreaker"));
44
+ class GenericDiffReporterBase {
45
+ constructor(name) {
46
+ this.exePath = "";
47
+ this.setCommandArgs = (a, r) => [r, a];
48
+ this.modifyCommandOptions = (c) => c;
49
+ if (!name) {
50
+ throw new Error("Argument name missing");
51
+ }
52
+ this.name = name;
53
+ this._reporterFileLookedUp = false;
54
+ this._reporterFileLookedUpAndFound = false;
55
+ }
56
+ isReporterAvailable() {
57
+ if (this._reporterFileLookedUp) {
58
+ return this._reporterFileLookedUpAndFound;
59
+ }
60
+ this._reporterFileLookedUp = true;
61
+ if (!fs.existsSync(this.exePath)) {
62
+ return false;
63
+ }
64
+ this._reporterFileLookedUpAndFound = true;
65
+ return true;
66
+ }
67
+ canImageDiff() {
68
+ return false;
69
+ }
70
+ canReportOn(fileName) {
71
+ if (!this.isReporterAvailable()) {
72
+ return false;
73
+ }
74
+ autils.assertFileExists(fileName);
75
+ if (this.canImageDiff()) {
76
+ return true;
77
+ }
78
+ const isBinary = autils.isBinaryFile(fileName);
79
+ return !isBinary;
80
+ }
81
+ spawn(exe, args, cmdOptions) {
82
+ const process = childProcess.spawn(exe, args, cmdOptions);
83
+ let stdout = "";
84
+ let stderr = "";
85
+ process.stdout.on("data", (data) => {
86
+ stdout += data;
87
+ });
88
+ process.stderr.on("data", (data) => {
89
+ stderr += data;
90
+ });
91
+ process.on("close", () => {
92
+ if (stdout) {
93
+ console.log("\n============\nstdout:\n============\n" +
94
+ stdout +
95
+ "\n============\n");
96
+ }
97
+ if (stderr) {
98
+ console.log("\n============\nstderr:\n============\n" +
99
+ stderr +
100
+ "\n============\n");
101
+ }
102
+ });
103
+ return process;
104
+ }
105
+ spawnSync(exe, args, cmdOptions) {
106
+ const result = childProcess.spawnSync(exe, args, cmdOptions);
107
+ const stdout = result.stdout.toString();
108
+ const stderr = result.stderr.toString();
109
+ if (stdout) {
110
+ console.log("\n============\nstdout:\n============\n" + stdout + "\n============\n");
111
+ }
112
+ if (stderr) {
113
+ console.log("\n============\nstderr:\n============\n" + stderr + "\n============\n");
114
+ }
115
+ }
116
+ report(approved, received, options = {}) {
117
+ if (!options.blockUntilReporterExits) {
118
+ if (ReportLaunchingCircuitBreaker_1.default.check(approved, received, options)) {
119
+ return;
120
+ }
121
+ }
122
+ const spawnMethod = options.blockUntilReporterExits
123
+ ? this.spawnSync.bind(this)
124
+ : this.spawn.bind(this);
125
+ autils.createEmptyFileIfNotExists(approved);
126
+ const { cmdOptions, args } = this.getCommandArguments(approved, received, options);
127
+ console.log("CMD: ", this.exePath, args.join(" "));
128
+ spawnMethod(this.exePath, args, cmdOptions);
129
+ }
130
+ getCommandArguments(approved, received, options = {}) {
131
+ const cmdOptions = this.modifyCommandOptions(options.cmdOptionOverrides);
132
+ const args = options.cmdArgs || this.setCommandArgs(approved, received);
133
+ return { cmdOptions, args };
134
+ }
135
+ }
136
+ exports.GenericDiffReporterBase = GenericDiffReporterBase;
@@ -0,0 +1,154 @@
1
+ import * as childProcess from "child_process";
2
+ import * as fs from "fs";
3
+ import * as autils from "../AUtils";
4
+ import reportingLaunchingCircuitBreaker from "./ReportLaunchingCircuitBreaker";
5
+ import { ChildProcessWithoutNullStreams } from "child_process";
6
+ import { Reporter } from "../Core/Reporter";
7
+ import { Config } from "../config";
8
+
9
+ export class GenericDiffReporterBase implements Reporter {
10
+ name: string;
11
+ public exePath: string = "";
12
+ private _reporterFileLookedUp: boolean;
13
+ public setCommandArgs: (approved: string, received: string) => string[] = (
14
+ a: string,
15
+ r: string,
16
+ ) => [r, a];
17
+ public modifyCommandOptions: (commandOptions: any) => any = (c) => c;
18
+ private _reporterFileLookedUpAndFound: boolean;
19
+
20
+ constructor(name: string) {
21
+ if (!name) {
22
+ throw new Error("Argument name missing");
23
+ }
24
+
25
+ this.name = name;
26
+ this._reporterFileLookedUp = false;
27
+ this._reporterFileLookedUpAndFound = false;
28
+ }
29
+
30
+ isReporterAvailable(): boolean {
31
+ if (this._reporterFileLookedUp) {
32
+ return this._reporterFileLookedUpAndFound;
33
+ }
34
+
35
+ this._reporterFileLookedUp = true;
36
+
37
+ if (!fs.existsSync(this.exePath)) {
38
+ return false;
39
+ }
40
+ this._reporterFileLookedUpAndFound = true;
41
+ return true;
42
+ }
43
+
44
+ canImageDiff(): boolean {
45
+ return false;
46
+ }
47
+
48
+ canReportOn(fileName: string): boolean {
49
+ if (!this.isReporterAvailable()) {
50
+ return false;
51
+ }
52
+
53
+ autils.assertFileExists(fileName);
54
+
55
+ if (this.canImageDiff()) {
56
+ return true;
57
+ }
58
+
59
+ const isBinary = autils.isBinaryFile(fileName);
60
+ return !isBinary;
61
+ }
62
+
63
+ spawn(
64
+ exe: string,
65
+ args: string[],
66
+ cmdOptions?: any,
67
+ ): ChildProcessWithoutNullStreams {
68
+ const process = childProcess.spawn(exe, args, cmdOptions);
69
+
70
+ let stdout = "";
71
+ let stderr = "";
72
+
73
+ process.stdout.on("data", (data) => {
74
+ stdout += data;
75
+ });
76
+ process.stderr.on("data", (data) => {
77
+ stderr += data;
78
+ });
79
+
80
+ process.on("close", () => {
81
+ if (stdout) {
82
+ console.log(
83
+ "\n============\nstdout:\n============\n" +
84
+ stdout +
85
+ "\n============\n",
86
+ );
87
+ }
88
+ if (stderr) {
89
+ console.log(
90
+ "\n============\nstderr:\n============\n" +
91
+ stderr +
92
+ "\n============\n",
93
+ );
94
+ }
95
+ });
96
+
97
+ return process;
98
+ }
99
+
100
+ spawnSync(exe: string, args: string[], cmdOptions?: any): void {
101
+ const result = childProcess.spawnSync(exe, args, cmdOptions);
102
+
103
+ const stdout = result.stdout.toString();
104
+ const stderr = result.stderr.toString();
105
+
106
+ if (stdout) {
107
+ console.log(
108
+ "\n============\nstdout:\n============\n" + stdout + "\n============\n",
109
+ );
110
+ }
111
+ if (stderr) {
112
+ console.log(
113
+ "\n============\nstderr:\n============\n" + stderr + "\n============\n",
114
+ );
115
+ }
116
+ }
117
+
118
+ report(
119
+ approved: string,
120
+ received: string,
121
+ options: Partial<Config> = {},
122
+ ): void {
123
+ if (!options.blockUntilReporterExits) {
124
+ if (reportingLaunchingCircuitBreaker.check(approved, received, options)) {
125
+ return;
126
+ }
127
+ }
128
+
129
+ const spawnMethod = options.blockUntilReporterExits
130
+ ? this.spawnSync.bind(this)
131
+ : this.spawn.bind(this);
132
+ autils.createEmptyFileIfNotExists(approved);
133
+
134
+ const { cmdOptions, args } = this.getCommandArguments(
135
+ approved,
136
+ received,
137
+ options,
138
+ );
139
+
140
+ console.log("CMD: ", this.exePath, args.join(" "));
141
+
142
+ spawnMethod(this.exePath, args, cmdOptions);
143
+ }
144
+
145
+ getCommandArguments(
146
+ approved: string,
147
+ received: string,
148
+ options: Partial<Config> = {},
149
+ ) {
150
+ const cmdOptions = this.modifyCommandOptions(options.cmdOptionOverrides);
151
+ const args = options.cmdArgs || this.setCommandArgs(approved, received);
152
+ return { cmdOptions, args };
153
+ }
154
+ }
@@ -0,0 +1,7 @@
1
+ import { Reporter } from "../Core/Reporter";
2
+ import { Config } from "../config";
3
+ export declare class ReportByOpeningTheReceivedFile implements Reporter {
4
+ name: string;
5
+ canReportOn(_fileName: string): boolean;
6
+ report(_approvedFileName: string, receivedFileName: string, _options?: Partial<Config>): void;
7
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReportByOpeningTheReceivedFile = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const osTools_1 = require("../osTools");
6
+ class ReportByOpeningTheReceivedFile {
7
+ constructor() {
8
+ this.name = "ReportByOpeningTheReceivedFile";
9
+ }
10
+ canReportOn(_fileName) {
11
+ return true;
12
+ }
13
+ report(_approvedFileName, receivedFileName, _options) {
14
+ const openCommand = osTools_1.platform.isWindows ? "start" : "open";
15
+ const shell = `${openCommand} "${receivedFileName}"`;
16
+ (0, child_process_1.exec)(shell);
17
+ }
18
+ }
19
+ exports.ReportByOpeningTheReceivedFile = ReportByOpeningTheReceivedFile;
@@ -0,0 +1,22 @@
1
+ import { exec } from "child_process";
2
+ import { Reporter } from "../Core/Reporter";
3
+ import { Config } from "../config";
4
+ import { platform } from "../osTools";
5
+
6
+ export class ReportByOpeningTheReceivedFile implements Reporter {
7
+ name: string = "ReportByOpeningTheReceivedFile";
8
+
9
+ canReportOn(_fileName: string): boolean {
10
+ return true;
11
+ }
12
+
13
+ report(
14
+ _approvedFileName: string,
15
+ receivedFileName: string,
16
+ _options?: Partial<Config>,
17
+ ): void {
18
+ const openCommand = platform.isWindows ? "start" : "open";
19
+ const shell = `${openCommand} "${receivedFileName}"`;
20
+ exec(shell);
21
+ }
22
+ }
@@ -0,0 +1,8 @@
1
+ export declare class ReportLaunchingCircuitBreaker {
2
+ static setMaxLaunch(value: number): void;
3
+ static get currentCount(): number;
4
+ static notifyLaunched(): void;
5
+ static isLimitExceeded(): boolean;
6
+ static check(approved: string, received: string, options: any): boolean;
7
+ }
8
+ export default ReportLaunchingCircuitBreaker;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ReportLaunchingCircuitBreaker = void 0;
7
+ const FinalMessages_1 = require("../FinalMessages");
8
+ const nodediffReporter_1 = __importDefault(require("./Reporters/nodediffReporter"));
9
+ let maxLaunch = 10;
10
+ let currentCount = 0;
11
+ let reroutedCount = 0;
12
+ class ReportLaunchingCircuitBreaker {
13
+ static setMaxLaunch(value) {
14
+ maxLaunch = value;
15
+ }
16
+ static get currentCount() {
17
+ return currentCount;
18
+ }
19
+ static notifyLaunched() {
20
+ currentCount++;
21
+ }
22
+ static isLimitExceeded() {
23
+ return maxLaunch <= currentCount;
24
+ }
25
+ static check(approved, received, options) {
26
+ if (this.isLimitExceeded()) {
27
+ reroutedCount++;
28
+ FinalMessages_1.FinalMessages.addKeyMessage("maxLaunches", `config.maxLaunches (${maxLaunch}) exceeded: ${reroutedCount} diff(s) shown in console above...`);
29
+ new nodediffReporter_1.default().report(approved, received, options);
30
+ return true;
31
+ }
32
+ this.notifyLaunched();
33
+ return false;
34
+ }
35
+ }
36
+ exports.ReportLaunchingCircuitBreaker = ReportLaunchingCircuitBreaker;
37
+ exports.default = ReportLaunchingCircuitBreaker;
@@ -0,0 +1,40 @@
1
+ import { FinalMessages } from "../FinalMessages";
2
+ import NodeDiffReporter from "./Reporters/nodediffReporter";
3
+
4
+ let maxLaunch = 10;
5
+ let currentCount = 0;
6
+ let reroutedCount = 0;
7
+
8
+ export class ReportLaunchingCircuitBreaker {
9
+ static setMaxLaunch(value: number): void {
10
+ maxLaunch = value;
11
+ }
12
+
13
+ static get currentCount(): number {
14
+ return currentCount;
15
+ }
16
+
17
+ static notifyLaunched(): void {
18
+ currentCount++;
19
+ }
20
+
21
+ static isLimitExceeded(): boolean {
22
+ return maxLaunch <= currentCount;
23
+ }
24
+
25
+ static check(approved: string, received: string, options: any): boolean {
26
+ if (this.isLimitExceeded()) {
27
+ reroutedCount++;
28
+ FinalMessages.addKeyMessage(
29
+ "maxLaunches",
30
+ `config.maxLaunches (${maxLaunch}) exceeded: ${reroutedCount} diff(s) shown in console above...`,
31
+ );
32
+ new NodeDiffReporter().report(approved, received, options);
33
+ return true;
34
+ }
35
+ this.notifyLaunched();
36
+ return false;
37
+ }
38
+ }
39
+
40
+ export default ReportLaunchingCircuitBreaker;
@@ -0,0 +1,8 @@
1
+ import { Reporter } from "../Core/Reporter";
2
+ export type ReporterLoader = () => Reporter[];
3
+ export declare class ReporterFactory {
4
+ static loadReporter(name: string | (string | Reporter)[]): Reporter;
5
+ static throwUnknownReporterError(reporter: unknown): never;
6
+ static assertValidReporter(reporter: Partial<Reporter>): reporter is Reporter;
7
+ static loadAllReporters(reporters: (string | Reporter)[]): Reporter[];
8
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ReporterFactory = void 0;
7
+ const DiffReporterAggregate_1 = __importDefault(require("./DiffReporterAggregate"));
8
+ const fs_1 = require("fs");
9
+ class ReporterFactory {
10
+ static loadReporter(name) {
11
+ if (Array.isArray(name)) {
12
+ const reporters = ReporterFactory.loadAllReporters(name);
13
+ return new DiffReporterAggregate_1.default(reporters);
14
+ }
15
+ name = name.toLowerCase();
16
+ try {
17
+ const ReporterCtor = require(`./Reporters/${name}Reporter`);
18
+ if (!ReporterCtor.default) {
19
+ return new ReporterCtor();
20
+ }
21
+ return new ReporterCtor.default();
22
+ }
23
+ catch (e) {
24
+ const allFiles = (0, fs_1.readdirSync)(__dirname);
25
+ const availableReporters = allFiles
26
+ .map((item) => item.replace("Reporter.js", ""))
27
+ .join(", ");
28
+ throw new Error(`Error loading reporter or reporter not found [${name}]. Try one of the following [${availableReporters}]. Original Error: ${e}`);
29
+ }
30
+ }
31
+ static throwUnknownReporterError(reporter) {
32
+ throw new Error(`Unknown reporter: typeof= [${typeof reporter}]. Reporters are either a string like "gitdiff" or an object that conforms to the custom reporter interface.`);
33
+ }
34
+ static assertValidReporter(reporter) {
35
+ if (typeof reporter.name !== "string") {
36
+ console.error("invalid reporter", reporter);
37
+ throw new Error("A valid reporter should have a 'name' property. EX: { name: \"my-custom-reporter\" }");
38
+ }
39
+ if (typeof reporter.canReportOn !== "function") {
40
+ console.error("invalid reporter", reporter);
41
+ throw new Error("A valid reporter should have a '{ canReportOn: function(fileName) { return true; // Example } ' function");
42
+ }
43
+ if (typeof reporter.report !== "function") {
44
+ console.error("invalid reporter", reporter);
45
+ throw new Error("A valid reporter should have a ' { report: function (approvedFilePath, receivedFilePath) {...} }' function");
46
+ }
47
+ return true;
48
+ }
49
+ static loadAllReporters(reporters) {
50
+ const reporterInstances = [];
51
+ reporters.forEach((reporter) => {
52
+ if (typeof reporter === "object") {
53
+ ReporterFactory.assertValidReporter(reporter);
54
+ reporterInstances.push(reporter);
55
+ }
56
+ else if (typeof reporter === "string") {
57
+ const reporterInstance = ReporterFactory.loadReporter(reporter);
58
+ reporterInstances.push(reporterInstance);
59
+ }
60
+ else {
61
+ ReporterFactory.throwUnknownReporterError(reporter);
62
+ }
63
+ });
64
+ return reporterInstances;
65
+ }
66
+ }
67
+ exports.ReporterFactory = ReporterFactory;
@@ -0,0 +1,85 @@
1
+ import DiffReporterAggregate from "./DiffReporterAggregate";
2
+ import { readdirSync } from "fs";
3
+ import { Reporter } from "../Core/Reporter";
4
+
5
+ export type ReporterLoader = () => Reporter[];
6
+
7
+ export class ReporterFactory {
8
+ static loadReporter(name: string | (string | Reporter)[]): Reporter {
9
+ if (Array.isArray(name)) {
10
+ const reporters = ReporterFactory.loadAllReporters(name);
11
+ return new DiffReporterAggregate(reporters);
12
+ }
13
+
14
+ name = name.toLowerCase();
15
+
16
+ try {
17
+ const ReporterCtor = require(`./Reporters/${name}Reporter`);
18
+ if (!ReporterCtor.default) {
19
+ return new ReporterCtor();
20
+ }
21
+ return new ReporterCtor.default();
22
+ } catch (e) {
23
+ const allFiles = readdirSync(__dirname);
24
+ const availableReporters = allFiles
25
+ .map((item) => item.replace("Reporter.js", ""))
26
+ .join(", ");
27
+ throw new Error(
28
+ `Error loading reporter or reporter not found [${name}]. Try one of the following [${availableReporters}]. Original Error: ${e}`,
29
+ );
30
+ }
31
+ }
32
+
33
+ static throwUnknownReporterError(reporter: unknown): never {
34
+ throw new Error(
35
+ `Unknown reporter: typeof= [${typeof reporter}]. Reporters are either a string like "gitdiff" or an object that conforms to the custom reporter interface.`,
36
+ );
37
+ }
38
+
39
+ static assertValidReporter(
40
+ reporter: Partial<Reporter>,
41
+ ): reporter is Reporter {
42
+ if (typeof reporter.name !== "string") {
43
+ console.error("invalid reporter", reporter);
44
+ throw new Error(
45
+ "A valid reporter should have a 'name' property. EX: { name: \"my-custom-reporter\" }",
46
+ );
47
+ }
48
+
49
+ if (typeof reporter.canReportOn !== "function") {
50
+ console.error("invalid reporter", reporter);
51
+ throw new Error(
52
+ "A valid reporter should have a '{ canReportOn: function(fileName) { return true; // Example } ' function",
53
+ );
54
+ }
55
+
56
+ if (typeof reporter.report !== "function") {
57
+ console.error("invalid reporter", reporter);
58
+ throw new Error(
59
+ "A valid reporter should have a ' { report: function (approvedFilePath, receivedFilePath) {...} }' function",
60
+ );
61
+ }
62
+
63
+ return true;
64
+ }
65
+
66
+ static loadAllReporters(reporters: (string | Reporter)[]): Reporter[] {
67
+ const reporterInstances: Reporter[] = [];
68
+
69
+ reporters.forEach((reporter) => {
70
+ if (typeof reporter === "object") {
71
+ ReporterFactory.assertValidReporter(reporter);
72
+ reporterInstances.push(reporter as Reporter);
73
+ } else if (typeof reporter === "string") {
74
+ const reporterInstance = ReporterFactory.loadReporter(
75
+ reporter,
76
+ ) as Reporter;
77
+ reporterInstances.push(reporterInstance);
78
+ } else {
79
+ ReporterFactory.throwUnknownReporterError(reporter);
80
+ }
81
+ });
82
+
83
+ return reporterInstances;
84
+ }
85
+ }
@@ -0,0 +1,4 @@
1
+ import { GenericDiffReporterBase } from "../GenericDiffReporterBase";
2
+ export default class BeyondCompareReporter extends GenericDiffReporterBase {
3
+ constructor();
4
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const AUtils_1 = require("../../AUtils");
7
+ const osTools_1 = require("../../osTools");
8
+ const shelljs_1 = __importDefault(require("shelljs"));
9
+ const GenericDiffReporterBase_1 = require("../GenericDiffReporterBase");
10
+ class BeyondCompareReporter extends GenericDiffReporterBase_1.GenericDiffReporterBase {
11
+ constructor() {
12
+ super("BeyondCompare");
13
+ let app = "";
14
+ if (osTools_1.platform.isMac) {
15
+ try {
16
+ app = shelljs_1.default.ls("/Applications/Beyond Compare.app/Contents/MacOS/bcomp")[0];
17
+ }
18
+ catch (err) {
19
+ console.error(err);
20
+ }
21
+ app = app || (0, AUtils_1.searchForExecutable)("bcomp");
22
+ }
23
+ else if (osTools_1.platform.isWindows) {
24
+ app =
25
+ (0, AUtils_1.searchForExecutable)("Beyond Compare 4", "BCompare.exe") ||
26
+ (0, AUtils_1.searchForExecutable)("Beyond Compare 3", "BCompare.exe");
27
+ }
28
+ app = app || (0, AUtils_1.searchForExecutable)("bcomp");
29
+ this.exePath = app;
30
+ }
31
+ }
32
+ exports.default = BeyondCompareReporter;
@@ -0,0 +1,30 @@
1
+ import { searchForExecutable } from "../../AUtils";
2
+ import { platform } from "../../osTools";
3
+ import shelljs from "shelljs";
4
+ import { GenericDiffReporterBase } from "../GenericDiffReporterBase";
5
+
6
+ export default class BeyondCompareReporter extends GenericDiffReporterBase {
7
+ constructor() {
8
+ super("BeyondCompare");
9
+
10
+ let app: string = "";
11
+ if (platform.isMac) {
12
+ try {
13
+ app = shelljs.ls(
14
+ "/Applications/Beyond Compare.app/Contents/MacOS/bcomp",
15
+ )[0];
16
+ } catch (err) {
17
+ console.error(err);
18
+ }
19
+ app = app || searchForExecutable("bcomp");
20
+ } else if (platform.isWindows) {
21
+ app =
22
+ searchForExecutable("Beyond Compare 4", "BCompare.exe") ||
23
+ searchForExecutable("Beyond Compare 3", "BCompare.exe");
24
+ }
25
+
26
+ app = app || searchForExecutable("bcomp");
27
+
28
+ this.exePath = app;
29
+ }
30
+ }