@hpcc-js/comms 3.15.4 → 3.15.6

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 (130) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +50 -50
  3. package/dist/browser/index.js +1 -1
  4. package/dist/browser/index.js.map +1 -1
  5. package/dist/browser/index.umd.cjs +1 -1
  6. package/dist/browser/index.umd.cjs.map +1 -1
  7. package/dist/node/index.cjs +10 -10
  8. package/dist/node/index.cjs.map +4 -4
  9. package/dist/node/index.js +9 -9
  10. package/dist/node/index.js.map +4 -4
  11. package/package.json +7 -7
  12. package/src/__package__.ts +3 -3
  13. package/src/clienttools/eclMeta.ts +506 -506
  14. package/src/clienttools/eclcc.ts +628 -628
  15. package/src/connection.ts +288 -288
  16. package/src/ecl/activity.ts +82 -82
  17. package/src/ecl/dfuWorkunit.ts +363 -363
  18. package/src/ecl/graph.ts +196 -196
  19. package/src/ecl/logicalFile.ts +196 -196
  20. package/src/ecl/machine.ts +63 -63
  21. package/src/ecl/query.ts +265 -265
  22. package/src/ecl/queryGraph.ts +813 -813
  23. package/src/ecl/resource.ts +39 -39
  24. package/src/ecl/result.ts +245 -245
  25. package/src/ecl/scope.ts +188 -188
  26. package/src/ecl/sourceFile.ts +34 -34
  27. package/src/ecl/store.ts +154 -154
  28. package/src/ecl/targetCluster.ts +149 -149
  29. package/src/ecl/timer.ts +42 -42
  30. package/src/ecl/topology.ts +131 -131
  31. package/src/ecl/workunit.ts +1340 -1340
  32. package/src/ecl/xsdParser.ts +267 -267
  33. package/src/espConnection.ts +164 -164
  34. package/src/index.browser.ts +1 -1
  35. package/src/index.common.ts +40 -40
  36. package/src/index.node.ts +48 -48
  37. package/src/pem/trustwave.ts +909 -909
  38. package/src/services/fileSpray.ts +73 -73
  39. package/src/services/wsAccess.ts +8 -8
  40. package/src/services/wsAccount.ts +27 -27
  41. package/src/services/wsCloud.ts +73 -73
  42. package/src/services/wsCodesign.ts +18 -18
  43. package/src/services/wsDFU.ts +34 -34
  44. package/src/services/wsDFUXRef.ts +121 -121
  45. package/src/services/wsDali.ts +8 -8
  46. package/src/services/wsEcl.ts +123 -123
  47. package/src/services/wsElk.ts +8 -8
  48. package/src/services/wsLogaccess.ts +270 -270
  49. package/src/services/wsMachine.ts +89 -89
  50. package/src/services/wsPackageProcess.ts +8 -8
  51. package/src/services/wsResources.ts +8 -8
  52. package/src/services/wsSMC.ts +80 -80
  53. package/src/services/wsSasha.ts +7 -7
  54. package/src/services/wsStore.ts +32 -32
  55. package/src/services/wsTopology.ts +45 -45
  56. package/src/services/wsWorkunits.ts +151 -151
  57. package/src/services/wsdl/FileSpray/v1.23/FileSpray.ts +1008 -1008
  58. package/src/services/wsdl/FileSpray/v1.25/FileSpray.ts +1040 -1040
  59. package/src/services/wsdl/FileSpray/v1.26/FileSpray.ts +929 -929
  60. package/src/services/wsdl/FileSpray/v1.27/FileSpray.ts +930 -930
  61. package/src/services/wsdl/WsCloud/v1/WsCloud.ts +38 -38
  62. package/src/services/wsdl/WsCloud/v1.02/WsCloud.ts +77 -77
  63. package/src/services/wsdl/WsDFUXRef/v1.02/WsDFUXRef.ts +224 -224
  64. package/src/services/wsdl/WsDFUXRef/v1.04/WsDFUXRef.ts +228 -227
  65. package/src/services/wsdl/WsDali/v1.04/WsDali.ts +216 -216
  66. package/src/services/wsdl/WsDali/v1.07/WsDali.ts +72 -72
  67. package/src/services/wsdl/WsDfu/v1.62/WsDfu.ts +1455 -1455
  68. package/src/services/wsdl/WsDfu/v1.63/WsDfu.ts +1465 -1465
  69. package/src/services/wsdl/WsDfu/v1.65/WsDfu.ts +1244 -1244
  70. package/src/services/wsdl/WsDfu/v1.66/WsDfu.ts +1267 -1267
  71. package/src/services/wsdl/WsDfu/v1.67/WsDfu.ts +1268 -1268
  72. package/src/services/wsdl/WsDfu/v1.68/WsDfu.ts +1301 -0
  73. package/src/services/wsdl/WsESDLConfig/v1.5/WsESDLConfig.ts +366 -0
  74. package/src/services/wsdl/WsFileIO/v1.01/WsFileIO.ts +104 -104
  75. package/src/services/wsdl/WsPackageProcess/v1.04/WsPackageProcess.ts +519 -519
  76. package/src/services/wsdl/WsPackageProcess/v1.07/WsPackageProcess.ts +500 -500
  77. package/src/services/wsdl/WsPackageProcess/v1.08/WsPackageProcess.ts +503 -0
  78. package/src/services/wsdl/WsResources/v1.01/WsResources.ts +119 -119
  79. package/src/services/wsdl/WsSMC/v1.24/WsSMC.ts +665 -665
  80. package/src/services/wsdl/WsSMC/v1.27/WsSMC.ts +591 -591
  81. package/src/services/wsdl/WsSMC/v1.28/WsSMC.ts +645 -645
  82. package/src/services/wsdl/WsSMC/v1.29/WsSMC.ts +660 -660
  83. package/src/services/wsdl/WsSasha/v1.01/WsSasha.ts +18 -18
  84. package/src/services/wsdl/WsTopology/v1.31/WsTopology.ts +856 -856
  85. package/src/services/wsdl/WsTopology/v1.32/WsTopology.ts +786 -786
  86. package/src/services/wsdl/WsTopology/v1.33/WsTopology.ts +835 -835
  87. package/src/services/wsdl/WsWorkunits/v1.88/WsWorkunits.ts +2944 -2944
  88. package/src/services/wsdl/WsWorkunits/v1.94/WsWorkunits.ts +3072 -3072
  89. package/src/services/wsdl/WsWorkunits/v1.95/WsWorkunits.ts +3073 -3073
  90. package/src/services/wsdl/WsWorkunits/v1.97/WsWorkunits.ts +3134 -3134
  91. package/src/services/wsdl/WsWorkunits/v1.98/WsWorkunits.ts +3182 -3182
  92. package/src/services/wsdl/WsWorkunits/v1.99/WsWorkunits.ts +3162 -3162
  93. package/src/services/wsdl/WsWorkunits/v2/WsWorkunits.ts +3153 -3153
  94. package/src/services/wsdl/WsWorkunits/v2.02/WsWorkunits.ts +3162 -3162
  95. package/src/services/wsdl/WsWorkunits/v2.03/WsWorkunits.ts +3164 -3164
  96. package/src/services/wsdl/WsWorkunits/v2.04/WsWorkunits.ts +3171 -3171
  97. package/src/services/wsdl/WsWorkunits/v2.05/WsWorkunits.ts +3177 -0
  98. package/src/services/wsdl/ws_access/v1.16/ws_access.ts +1086 -1086
  99. package/src/services/wsdl/ws_access/v1.17/ws_access.ts +1023 -1023
  100. package/src/services/wsdl/ws_account/v1.05/ws_account.ts +111 -111
  101. package/src/services/wsdl/ws_account/v1.06/ws_account.ts +109 -109
  102. package/src/services/wsdl/ws_account/v1.07/ws_account.ts +114 -114
  103. package/src/services/wsdl/ws_codesign/v1.1/ws_codesign.ts +95 -95
  104. package/src/services/wsdl/ws_elk/v1/ws_elk.ts +47 -47
  105. package/src/services/wsdl/ws_logaccess/v1/ws_logaccess.ts +83 -83
  106. package/src/services/wsdl/ws_logaccess/v1.02/ws_logaccess.ts +161 -161
  107. package/src/services/wsdl/ws_logaccess/v1.03/ws_logaccess.ts +190 -190
  108. package/src/services/wsdl/ws_logaccess/v1.04/ws_logaccess.ts +215 -215
  109. package/src/services/wsdl/ws_logaccess/v1.05/ws_logaccess.ts +219 -219
  110. package/src/services/wsdl/ws_logaccess/v1.08/ws_logaccess.ts +267 -267
  111. package/src/services/wsdl/ws_machine/v1.17/ws_machine.ts +567 -567
  112. package/src/services/wsdl/ws_machine/v1.18/ws_machine.ts +497 -497
  113. package/src/services/wsdl/ws_machine/v1.19/ws_machine.ts +497 -497
  114. package/src/services/wsdl/wsstore/v1.02/wsstore.ts +239 -239
  115. package/types/services/wsPackageProcess.d.ts +1 -1
  116. package/types/services/wsWorkunits.d.ts +1 -1
  117. package/types/services/wsdl/FileSpray/v1.27/FileSpray.d.ts +506 -506
  118. package/types/services/wsdl/WsCloud/v1.02/WsCloud.d.ts +18 -18
  119. package/types/services/wsdl/WsDFUXRef/v1.04/WsDFUXRef.d.ts +58 -57
  120. package/types/services/wsdl/WsDali/v1.07/WsDali.d.ts +42 -42
  121. package/types/services/wsdl/WsPackageProcess/{v1.07 → v1.08}/WsPackageProcess.d.ts +121 -118
  122. package/types/services/wsdl/WsSasha/v1.01/WsSasha.d.ts +13 -13
  123. package/types/services/wsdl/WsTopology/v1.33/WsTopology.d.ts +360 -360
  124. package/types/services/wsdl/WsWorkunits/v2.05/WsWorkunits.d.ts +2571 -0
  125. package/types/services/wsdl/ws_access/v1.17/ws_access.d.ts +268 -268
  126. package/types/services/wsdl/ws_account/v1.07/ws_account.d.ts +34 -34
  127. package/types/services/wsdl/ws_codesign/v1.1/ws_codesign.d.ts +22 -22
  128. package/types/services/wsdl/ws_elk/v1/ws_elk.d.ts +12 -12
  129. package/types/services/wsdl/wsstore/v1.02/wsstore.d.ts +61 -61
  130. package/types/services/wsdl/WsWorkunits/v2.04/WsWorkunits.d.ts +0 -2565
@@ -1,628 +1,628 @@
1
- import * as cp from "node:child_process";
2
- import * as crypto from "node:crypto";
3
- import * as fs from "node:fs";
4
- import * as os from "node:os";
5
- import * as path from "node:path";
6
-
7
- import { exists, scopedLogger, xml2json, XMLNode } from "@hpcc-js/util";
8
- import { attachWorkspace, Workspace } from "./eclMeta.ts";
9
-
10
- const logger = scopedLogger("clienttools/eclcc");
11
- const exeExt = os.type() === "Windows_NT" ? ".exe" : "";
12
-
13
- function tidyCRLF(inStr: string): string {
14
- return inStr.split("\r\n").join("\n").split("\r").join("\n");
15
- }
16
-
17
- export class Version {
18
- readonly prefix: string = "";
19
- readonly major: number = 0;
20
- readonly minor: number = 0;
21
- readonly patch: number = 0;
22
- readonly postfix: string = "";
23
-
24
- constructor(build: string) {
25
- const parts = build.split(" ");
26
- if (parts.length) {
27
- const match = /(?:(\w+)_)?(\d+)\.(\d+)\.(\d+)(?:-(.*))?/.exec(parts[parts.length - 1]);
28
- if (match) {
29
- this.prefix = match[1] || "";
30
- this.major = +match[2] || 0;
31
- this.minor = +match[3] || 0;
32
- this.patch = +match[4] || 0;
33
- this.postfix = match[5] || "";
34
- }
35
- }
36
- }
37
-
38
- parse(build: string) {
39
- }
40
-
41
- exists(): boolean {
42
- return this.major !== 0 || this.minor !== 0 || this.patch !== 0 || this.postfix !== "";
43
- }
44
-
45
- compare(other: Version): number {
46
- if (this.major > other.major) return 1;
47
- if (this.major < other.major) return -1;
48
- if (this.minor > other.minor) return 1;
49
- if (this.minor < other.minor) return -1;
50
- if (this.patch > other.patch) return 1;
51
- if (this.patch < other.patch) return -1;
52
- if (this.postfix === "" && other.postfix !== "") return 1;
53
- return this.postfix.localeCompare(other.postfix);
54
- }
55
-
56
- toString(): string {
57
- return `${this.prefix}_${this.major}.${this.minor}.${this.patch}-${this.postfix}`;
58
- }
59
- }
60
-
61
- interface IExecFile {
62
- code: number;
63
- stderr: string;
64
- stdout: string;
65
- }
66
-
67
- export interface IECLErrorWarning {
68
- filePath: string;
69
- line: number;
70
- col: number;
71
- msg: string;
72
- severity: string;
73
- }
74
-
75
- const ERROR = "error";
76
- const WARN = "warning";
77
-
78
- export class Errors {
79
- protected _checked: string[];
80
- protected errWarn: IECLErrorWarning[] = [];
81
- protected errOther: string[] = [];
82
-
83
- constructor(checked: string[]) {
84
- this._checked = checked;
85
- }
86
-
87
- checked(): string[] {
88
- return this._checked;
89
- }
90
-
91
- all(): IECLErrorWarning[] {
92
- return this.errWarn;
93
- }
94
-
95
- errors(): IECLErrorWarning[] {
96
- return this.errWarn.filter(e => e.severity === ERROR);
97
- }
98
-
99
- hasError(): boolean {
100
- return this.errors().length > 0;
101
- }
102
-
103
- warnings(): IECLErrorWarning[] {
104
- return this.errWarn.filter(e => e.severity === WARN);
105
- }
106
-
107
- hasWarning(): boolean {
108
- return this.warnings().length > 0;
109
- }
110
-
111
- info(): IECLErrorWarning[] {
112
- return this.errWarn.filter(e => [ERROR, WARN].indexOf(e.severity) < 0);
113
- }
114
-
115
- hasOther(): boolean {
116
- return this.info().length > 0;
117
- }
118
-
119
- unknown(): string[] {
120
- return this.errOther;
121
- }
122
-
123
- hasUnknown(): boolean {
124
- return this.unknown().length > 0;
125
- }
126
- }
127
-
128
- export class EclccErrors extends Errors {
129
-
130
- constructor(stdErr: string, checked: string[]) {
131
- super(checked);
132
- if (stdErr && stdErr.length) {
133
- for (const errLine of stdErr.split(os.EOL)) {
134
- let match = /([a-zA-Z]:\\(?:[- \w\.\d]+\\)*(?:[- \w\.\d]+)?|(?:\/[\w\.\-]+)+)\((\d*),(\d*)\) ?: ?(error|warning|info) C(\d*) ?: ?(.*)/.exec(errLine);
135
- if (match) {
136
- const [, filePath, row, _col, severity, code, _msg] = match;
137
- const line: number = +row;
138
- const col: number = +_col;
139
- const msg = code + ": " + _msg;
140
- this.errWarn.push({ filePath, line, col, msg, severity });
141
- continue;
142
- }
143
- match = /(error|warning|info): (.*)/i.exec(errLine);
144
- if (match) {
145
- const [, severity, msg] = match;
146
- this.errWarn.push({ filePath: "", line: 0, col: 0, msg, severity });
147
- continue;
148
- }
149
- match = /\d error(s?), \d warning(s?)/.exec(errLine);
150
- if (match) {
151
- continue;
152
- }
153
- logger.warning(`parseECLErrors: Unable to parse "${errLine}"`);
154
- this.errOther.push(errLine);
155
- }
156
- }
157
- this._checked = checked;
158
- }
159
- }
160
-
161
- export class EnvchkErrors extends Errors {
162
-
163
- private _lines: string[];
164
-
165
- constructor(filePath: string, stdErr: string, checked: string[]) {
166
- super(checked);
167
- let content: string = fs.readFileSync(filePath, "utf8");
168
- content = content.replace(/\r\n/g, "\n");
169
- this._lines = content.split("\n");
170
- if (stdErr && stdErr.length) {
171
- for (const errLine of stdErr.split(os.EOL)) {
172
- const match = /(Warning|Error) : Path\=(\S*?)(\[\S*\])? Message\=(.*)/.exec(errLine);
173
- if (match) {
174
- const [, severity, _path, _attr, _msg] = match;
175
- const msg = `${_path} ${_attr ? _attr : ""}: ${_msg}`;
176
- const [line, col] = this.locate(_path);
177
- this.errWarn.push({ filePath, line, col, msg, severity });
178
- continue;
179
- }
180
- if (match) {
181
- continue;
182
- }
183
- logger.warning(`parseECLErrors: Unable to parse "${errLine}"`);
184
- this.errOther.push(errLine);
185
- }
186
- }
187
- this._checked = checked;
188
- }
189
-
190
- locate(path: string): [number, number] {
191
- const pathParts = path.split("/");
192
- if (pathParts.length && pathParts[0] === "") {
193
- pathParts.shift();
194
- }
195
- if (pathParts.length > 0) {
196
- let lineIdx = 0;
197
- for (const line of this._lines) {
198
- const testStr = "<" + pathParts[0];
199
- if (line.indexOf(testStr + " ") >= 0 || line.indexOf(testStr + ">") >= 0) {
200
- pathParts.shift();
201
- if (pathParts.length === 0) {
202
- return [lineIdx + 1, line.indexOf(testStr) + 1];
203
- }
204
- }
205
- ++lineIdx;
206
- }
207
- }
208
- return [0, 0];
209
- }
210
- }
211
-
212
- export function walkXmlJson(node: any, callback: (key: string, childNode: any, stack: any[]) => void, stack?: any[]) {
213
- stack = stack || [];
214
- stack.push(node);
215
- for (const key in node) {
216
- if (node.hasOwnProperty(key)) {
217
- const childNode = node[key];
218
- callback(key, childNode, stack);
219
- if (childNode instanceof Array) {
220
- childNode.forEach(child => {
221
- walkXmlJson(child, callback, stack);
222
- });
223
- } else if (typeof childNode === "object") {
224
- walkXmlJson(childNode, callback, stack);
225
- }
226
- }
227
- }
228
- stack.pop();
229
- }
230
-
231
- export class LocalWorkunit {
232
- jsonWU: any;
233
-
234
- constructor(jsonWU: any) {
235
- this.jsonWU = jsonWU;
236
- }
237
-
238
- bpGetValidLocations(filePath: any) {
239
- const retVal: any[] = [];
240
- if (exists("W_LOCAL.Graphs", this.jsonWU)) {
241
- let id = "";
242
- walkXmlJson(this.jsonWU.W_LOCAL.Graphs, (key: string, item: any, _stack: any[]) => {
243
- if (key === "$" && item.id) {
244
- id = item.id;
245
- }
246
- if (key === "$" && item.name === "definition") {
247
- const match = /([a-z,A-Z]:\\(?:[-\w\.\d]+\\)*(?:[-\w\.\d]+)?|(?:\/[\w\.\-]+)+)\((\d*),(\d*)\)/.exec(item.value);
248
- if (match) {
249
- const [, file, row, _col] = match;
250
- const line: number = +row;
251
- const col: number = +_col;
252
- if (filePath === file) {
253
- retVal.push({ file, line, col, id });
254
- }
255
- }
256
- }
257
- // console.log(`${key}: ` + JSON.stringify(item));
258
- });
259
- }
260
- return retVal;
261
- }
262
- }
263
-
264
- export interface IArchive {
265
- content: string;
266
- err: EclccErrors;
267
- }
268
-
269
- export interface IBundle {
270
- name: string;
271
- description: string;
272
- url: string;
273
- props?: { [key: string]: string | number | boolean };
274
- }
275
-
276
- export class ClientTools {
277
- readonly eclccPath: string;
278
- readonly envchkPath: string;
279
- readonly eclBundlePath: string;
280
- readonly binPath: string;
281
- protected cwd: string;
282
- protected includeFolders: string[];
283
- protected _legacyMode: boolean;
284
- protected _args: string[];
285
- protected _version: Version;
286
-
287
- constructor(eclccPath: string, cwd?: string, includeFolders: string[] = [], legacyMode: boolean = false, args: string[] = [], version?: Version) {
288
- this.eclccPath = eclccPath;
289
- this.binPath = path.dirname(this.eclccPath);
290
- this.envchkPath = path.join(this.binPath, "envchk" + exeExt);
291
- this.eclBundlePath = path.join(this.binPath, "ecl-bundle" + exeExt);
292
- this.cwd = path.normalize(cwd || this.binPath);
293
- this.includeFolders = includeFolders;
294
- this._legacyMode = legacyMode;
295
- this._args = args;
296
- this._version = version!;
297
- }
298
-
299
- clone(cwd?: string, includeFolders?: string[], legacyMode: boolean = false, args: string[] = []) {
300
- return new ClientTools(this.eclccPath, cwd, includeFolders, legacyMode, args, this._version);
301
- }
302
-
303
- exists(filePath: string) {
304
- try {
305
- fs.accessSync(filePath);
306
- return true;
307
- } catch (e) { }
308
- return false;
309
- }
310
-
311
- args(additionalItems: string[] = []): string[] {
312
- const retVal: string[] = [...this._args];
313
- if (this._legacyMode) {
314
- retVal.push("-legacy");
315
- }
316
- return retVal.concat(this.includeFolders.map(includePath => {
317
- return "-I" + path.normalize(includePath);
318
- })).concat(additionalItems);
319
- }
320
-
321
- version(): Promise<Version> {
322
- if (this._version) {
323
- return Promise.resolve(this._version);
324
- }
325
- return this.execFile(this.eclccPath, this.binPath, this.args(["--version"]), "eclcc", `Cannot find ${this.eclccPath}`).then((response: IExecFile): Version => {
326
- this._version = new Version(response.stdout);
327
- return this._version;
328
- });
329
- }
330
-
331
- versionSync(): Version {
332
- return this._version;
333
- }
334
-
335
- _paths = {};
336
- paths() {
337
- return this.execFile(this.eclccPath, this.cwd, this.args(["-showpaths"]), "eclcc", `Cannot find ${this.eclccPath}`).then((response: IExecFile) => {
338
- if (response && response.stdout && response.stdout.length) {
339
- const paths = response.stdout.split(/\r?\n/);
340
- for (const path of paths) {
341
- const parts = path.split("=");
342
- if (parts.length === 2) {
343
- this._paths[parts[0]] = parts[1];
344
- }
345
- }
346
- }
347
- return this._paths;
348
- });
349
- }
350
-
351
- private loadXMLDoc(filePath: any, removeOnRead?: boolean): Promise<XMLNode> {
352
- return new Promise((resolve, _reject) => {
353
- const fileData = fs.readFileSync(filePath, "ascii");
354
- const retVal = xml2json(fileData as any);
355
- if (removeOnRead) {
356
- fs.unlink(filePath, (err) => { });
357
- }
358
- resolve(retVal);
359
- });
360
- }
361
-
362
- createWU(filename: string): Promise<LocalWorkunit> {
363
- const tmpName = path.join(os.tmpdir(), `eclcc-wu-tmp-${crypto.randomBytes(8).toString("hex")}`);
364
- const args = ["-o" + tmpName, "-wu"].concat([filename]);
365
- return this.execFile(this.eclccPath, this.cwd, this.args(args), "eclcc", `Cannot find ${this.eclccPath}`).then((_response: IExecFile) => {
366
- const xmlPath = path.normalize(tmpName + ".xml");
367
- const contentPromise = this.exists(xmlPath) ? this.loadXMLDoc(xmlPath, true) : Promise.resolve({});
368
- return contentPromise.then((content) => {
369
- return new LocalWorkunit(content);
370
- });
371
- });
372
- }
373
-
374
- createArchive(filename: string): Promise<IArchive> {
375
- const args = ["-E"].concat([filename]);
376
- return this.execFile(this.eclccPath, this.cwd, this.args(args), "eclcc", `Cannot find ${this.eclccPath}`).then((response: IExecFile): IArchive => {
377
- return {
378
- content: response.stdout,
379
- err: new EclccErrors(response.stderr, [])
380
- };
381
- });
382
- }
383
-
384
- attachWorkspace(): Workspace {
385
- return attachWorkspace(this.cwd);
386
- }
387
-
388
- fetchMeta(filePath: string): Promise<Workspace> {
389
- return Promise.all([
390
- attachWorkspace(this.cwd),
391
- this.execFile(this.eclccPath, this.cwd, this.args(["-M", filePath]), "eclcc", `Cannot find ${this.eclccPath}`)
392
- ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
393
- try {
394
- if (execFileResponse && execFileResponse.stdout && execFileResponse.stdout.length) {
395
- metaWorkspace.parseMetaXML(execFileResponse.stdout);
396
- }
397
- } catch (e: any) {
398
- logger.error(`fetchMeta: Error parsing XML - ${e?.message ?? "unknown"}`);
399
- }
400
- return metaWorkspace;
401
- });
402
- }
403
-
404
- syntaxCheck(filePath: string, args: string[] = ["-syntax"]): Promise<Errors> {
405
- return Promise.all([
406
- attachWorkspace(this.cwd),
407
- this.execFile(this.eclccPath, this.cwd, this.args([...args, "-M", filePath]), "eclcc", `Cannot find ${this.eclccPath}`)
408
- ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
409
- let checked: string[] = [];
410
- try {
411
- if (execFileResponse && execFileResponse.stdout && execFileResponse.stdout.length) {
412
- checked = metaWorkspace.parseMetaXML(execFileResponse.stdout);
413
- }
414
- } catch (e: any) {
415
- logger.error(`syntaxCheck: Error parsing XML - ${e?.message ?? "unknown"}`);
416
- }
417
- return new EclccErrors(execFileResponse ? execFileResponse.stderr : "", checked);
418
- });
419
- }
420
-
421
- envCheck(filePath: string, args: string[] = []): Promise<Errors> {
422
- return Promise.all([
423
- attachWorkspace(this.cwd),
424
- this.execFile(this.envchkPath, this.cwd, this.args([...args, filePath]), "envchk", `Cannot find ${this.envchkPath}`)
425
- ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
426
- return new EnvchkErrors(filePath, execFileResponse ? execFileResponse.stderr : "", []);
427
- });
428
- }
429
-
430
- bundleList(): Promise<IBundle[]> {
431
- const bundlesRegEx = /\|(.*)\|(.*)\|(.*)\|/g;
432
- return Promise.all([
433
- fetch("https://raw.githubusercontent.com/hpcc-systems/ecl-bundles/master/README.rst")
434
- .then(response => response.text())
435
- .then(readme => {
436
- const retVal: IBundle[] = [];
437
- let m = bundlesRegEx.exec(readme);
438
- while (m) {
439
- retVal.push({
440
- name: m[1].trim(),
441
- description: m[2].trim(),
442
- url: m[3].trim()
443
- });
444
- m = bundlesRegEx.exec(readme);
445
- }
446
- return retVal;
447
- }),
448
- this.execFile(this.eclBundlePath, this.cwd, this.args(["list"]), "ecl-bundle", `Cannot find ${this.eclBundlePath}`)
449
- .then(installedText => {
450
- return tidyCRLF(installedText.stdout).split("\n");
451
- }).then(installedItems => {
452
- const allProps = {};
453
- return Promise.all(installedItems.filter(ii => !!ii).map(ii => {
454
- return this.execFile(this.eclBundlePath, this.cwd, this.args(["info", ii]), "ecl-bundle", `Cannot find ${this.eclBundlePath}`)
455
- .then(infoText => {
456
- return tidyCRLF(infoText.stdout).split("\n");
457
- }).then(info => {
458
- const props = {};
459
- info.forEach(line => {
460
- const parts = line.split(":");
461
- props[parts.shift().trim()] = parts.join(":").trim();
462
- });
463
- allProps[ii] = {
464
- name: ii,
465
- props
466
- };
467
- });
468
- })).then(() => allProps);
469
- })
470
- ]).then(([bundles, installed]) => {
471
- bundles.forEach(b => {
472
- if (installed[b.name]) {
473
- b.props = installed[b.name].props;
474
- delete installed[b.name];
475
- }
476
- });
477
- for (const key in installed) {
478
- bundles.push({
479
- name: key,
480
- url: "",
481
- description: "",
482
- props: installed[key].props
483
- });
484
- }
485
- return bundles;
486
- }).catch(e => {
487
- return [];
488
- });
489
- }
490
-
491
- bundleInstall(bundleUrl) {
492
- return Promise.all([
493
- attachWorkspace(this.cwd),
494
- this.execFile(this.eclBundlePath, this.cwd, this.args(["install", bundleUrl]), "ecl-bundle", `Cannot find ${this.eclBundlePath}`)
495
- ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
496
- return execFileResponse;
497
- });
498
- }
499
-
500
- bundleUninstall(name) {
501
- return Promise.all([
502
- attachWorkspace(this.cwd),
503
- this.execFile(this.eclBundlePath, this.cwd, this.args(["uninstall", name]), "ecl-bundle", `Cannot find ${this.eclBundlePath}`)
504
- ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
505
- return execFileResponse;
506
- });
507
- }
508
-
509
- private execFile(cmd: string, cwd: string, args: string[], _toolName: string, _notFoundError?: string): Promise<{ code: number, stdout: string, stderr: string }> {
510
- return new Promise((resolve, _reject) => {
511
- logger.debug(`${cmd} ${args.join(" ")}`);
512
- const child = cp.spawn(cmd, args, { cwd });
513
- let stdOut = "";
514
- let stdErr = "";
515
- child.stdout.on("data", (data) => {
516
- stdOut += data.toString();
517
- });
518
- child.stderr.on("data", (data) => {
519
- stdErr += data.toString();
520
- });
521
- child.on("close", (_code, _signal) => {
522
- resolve({
523
- code: _code,
524
- stdout: stdOut.trim(),
525
- stderr: stdErr.trim()
526
- });
527
- });
528
- });
529
- }
530
- }
531
-
532
- function locateClientToolsInFolder(rootFolder: string, clientTools: ClientTools[]) {
533
- if (rootFolder) {
534
- const hpccSystemsFolder = path.join(rootFolder, "HPCCSystems");
535
- if (fs.existsSync(hpccSystemsFolder) && fs.statSync(hpccSystemsFolder).isDirectory()) {
536
- if (os.type() !== "Windows_NT") {
537
- const eclccPath = path.join(hpccSystemsFolder, "bin", "eclcc");
538
- if (fs.existsSync(eclccPath)) {
539
- clientTools.push(new ClientTools(eclccPath));
540
- }
541
- }
542
- fs.readdirSync(hpccSystemsFolder).forEach((versionFolder) => {
543
- const eclccPath = path.join(hpccSystemsFolder, versionFolder, "clienttools", "bin", "eclcc" + exeExt);
544
- if (fs.existsSync(eclccPath)) {
545
- const name = path.basename(versionFolder);
546
- const version = new Version(name);
547
- if (version.exists()) {
548
- clientTools.push(new ClientTools(eclccPath));
549
- }
550
- }
551
- });
552
- }
553
- }
554
- }
555
-
556
- let allClientToolsCache: Promise<ClientTools[]>;
557
- export function clearAllClientToolsCache() {
558
- allClientToolsCache = undefined;
559
- }
560
-
561
- export function locateAllClientTools() {
562
- if (allClientToolsCache) return allClientToolsCache;
563
- const clientTools: ClientTools[] = [];
564
- switch (os.type()) {
565
- case "Windows_NT":
566
- const rootFolder86 = process.env["ProgramFiles(x86)"] || "";
567
- if (rootFolder86) {
568
- locateClientToolsInFolder(rootFolder86, clientTools);
569
- }
570
- const rootFolder = process.env["ProgramFiles"] || "";
571
- if (rootFolder) {
572
- locateClientToolsInFolder(rootFolder, clientTools);
573
- }
574
- if (!rootFolder86 && !rootFolder) {
575
- locateClientToolsInFolder("c:\\Program Files (x86)", clientTools);
576
- }
577
- break;
578
- case "Linux":
579
- case "Darwin":
580
- locateClientToolsInFolder("/opt", clientTools);
581
- break;
582
- default:
583
- break;
584
- }
585
-
586
- allClientToolsCache = Promise.all(clientTools.map(ct => ct.version())).then(() => {
587
- clientTools.sort((l: ClientTools, r: ClientTools) => {
588
- return r.versionSync().compare(l.versionSync());
589
- });
590
- return clientTools;
591
- });
592
- return allClientToolsCache;
593
- }
594
-
595
- let eclccPathMsg = "";
596
- function logEclccPath(eclccPath: string) {
597
- const msg = `Using eclccPath setting: ${eclccPath}`;
598
- if (eclccPathMsg !== msg) {
599
- logger.info(msg);
600
- eclccPathMsg = msg;
601
- }
602
- }
603
-
604
- export function locateClientTools(overridePath: string = "", build: string = "", cwd: string = ".", includeFolders: string[] = [], legacyMode: boolean = false, args: string[] = []): Promise<ClientTools> {
605
- if (overridePath && fs.existsSync(overridePath)) {
606
- logEclccPath(overridePath);
607
- return Promise.resolve(new ClientTools(overridePath, cwd, includeFolders, legacyMode, args));
608
- }
609
- return locateAllClientTools().then((allClientToolsCache2) => {
610
- if (!allClientToolsCache2.length) {
611
- throw new Error("Unable to locate ECL Client Tools.");
612
- }
613
- const buildVersion = new Version(build);
614
- let latest: ClientTools | undefined;
615
- let bestMajor: ClientTools | undefined;
616
- for (const ct of allClientToolsCache2) {
617
- const ctVersion = ct.versionSync();
618
- if (ctVersion.exists()) {
619
- if (!latest) latest = ct;
620
- if (!bestMajor && buildVersion.major === ctVersion.major) bestMajor = ct;
621
- if (buildVersion.major === ctVersion.major && buildVersion.minor === ctVersion.minor) return ct.clone(cwd, includeFolders, legacyMode, args);
622
- }
623
- }
624
- const best: ClientTools = bestMajor || latest!;
625
- logEclccPath(best.eclccPath);
626
- return best.clone(cwd, includeFolders, legacyMode, args);
627
- });
628
- }
1
+ import * as cp from "node:child_process";
2
+ import * as crypto from "node:crypto";
3
+ import * as fs from "node:fs";
4
+ import * as os from "node:os";
5
+ import * as path from "node:path";
6
+
7
+ import { exists, scopedLogger, xml2json, XMLNode } from "@hpcc-js/util";
8
+ import { attachWorkspace, Workspace } from "./eclMeta.ts";
9
+
10
+ const logger = scopedLogger("clienttools/eclcc");
11
+ const exeExt = os.type() === "Windows_NT" ? ".exe" : "";
12
+
13
+ function tidyCRLF(inStr: string): string {
14
+ return inStr.split("\r\n").join("\n").split("\r").join("\n");
15
+ }
16
+
17
+ export class Version {
18
+ readonly prefix: string = "";
19
+ readonly major: number = 0;
20
+ readonly minor: number = 0;
21
+ readonly patch: number = 0;
22
+ readonly postfix: string = "";
23
+
24
+ constructor(build: string) {
25
+ const parts = build.split(" ");
26
+ if (parts.length) {
27
+ const match = /(?:(\w+)_)?(\d+)\.(\d+)\.(\d+)(?:-(.*))?/.exec(parts[parts.length - 1]);
28
+ if (match) {
29
+ this.prefix = match[1] || "";
30
+ this.major = +match[2] || 0;
31
+ this.minor = +match[3] || 0;
32
+ this.patch = +match[4] || 0;
33
+ this.postfix = match[5] || "";
34
+ }
35
+ }
36
+ }
37
+
38
+ parse(build: string) {
39
+ }
40
+
41
+ exists(): boolean {
42
+ return this.major !== 0 || this.minor !== 0 || this.patch !== 0 || this.postfix !== "";
43
+ }
44
+
45
+ compare(other: Version): number {
46
+ if (this.major > other.major) return 1;
47
+ if (this.major < other.major) return -1;
48
+ if (this.minor > other.minor) return 1;
49
+ if (this.minor < other.minor) return -1;
50
+ if (this.patch > other.patch) return 1;
51
+ if (this.patch < other.patch) return -1;
52
+ if (this.postfix === "" && other.postfix !== "") return 1;
53
+ return this.postfix.localeCompare(other.postfix);
54
+ }
55
+
56
+ toString(): string {
57
+ return `${this.prefix}_${this.major}.${this.minor}.${this.patch}-${this.postfix}`;
58
+ }
59
+ }
60
+
61
+ interface IExecFile {
62
+ code: number;
63
+ stderr: string;
64
+ stdout: string;
65
+ }
66
+
67
+ export interface IECLErrorWarning {
68
+ filePath: string;
69
+ line: number;
70
+ col: number;
71
+ msg: string;
72
+ severity: string;
73
+ }
74
+
75
+ const ERROR = "error";
76
+ const WARN = "warning";
77
+
78
+ export class Errors {
79
+ protected _checked: string[];
80
+ protected errWarn: IECLErrorWarning[] = [];
81
+ protected errOther: string[] = [];
82
+
83
+ constructor(checked: string[]) {
84
+ this._checked = checked;
85
+ }
86
+
87
+ checked(): string[] {
88
+ return this._checked;
89
+ }
90
+
91
+ all(): IECLErrorWarning[] {
92
+ return this.errWarn;
93
+ }
94
+
95
+ errors(): IECLErrorWarning[] {
96
+ return this.errWarn.filter(e => e.severity === ERROR);
97
+ }
98
+
99
+ hasError(): boolean {
100
+ return this.errors().length > 0;
101
+ }
102
+
103
+ warnings(): IECLErrorWarning[] {
104
+ return this.errWarn.filter(e => e.severity === WARN);
105
+ }
106
+
107
+ hasWarning(): boolean {
108
+ return this.warnings().length > 0;
109
+ }
110
+
111
+ info(): IECLErrorWarning[] {
112
+ return this.errWarn.filter(e => [ERROR, WARN].indexOf(e.severity) < 0);
113
+ }
114
+
115
+ hasOther(): boolean {
116
+ return this.info().length > 0;
117
+ }
118
+
119
+ unknown(): string[] {
120
+ return this.errOther;
121
+ }
122
+
123
+ hasUnknown(): boolean {
124
+ return this.unknown().length > 0;
125
+ }
126
+ }
127
+
128
+ export class EclccErrors extends Errors {
129
+
130
+ constructor(stdErr: string, checked: string[]) {
131
+ super(checked);
132
+ if (stdErr && stdErr.length) {
133
+ for (const errLine of stdErr.split(os.EOL)) {
134
+ let match = /([a-zA-Z]:\\(?:[- \w\.\d]+\\)*(?:[- \w\.\d]+)?|(?:\/[\w\.\-]+)+)\((\d*),(\d*)\) ?: ?(error|warning|info) C(\d*) ?: ?(.*)/.exec(errLine);
135
+ if (match) {
136
+ const [, filePath, row, _col, severity, code, _msg] = match;
137
+ const line: number = +row;
138
+ const col: number = +_col;
139
+ const msg = code + ": " + _msg;
140
+ this.errWarn.push({ filePath, line, col, msg, severity });
141
+ continue;
142
+ }
143
+ match = /(error|warning|info): (.*)/i.exec(errLine);
144
+ if (match) {
145
+ const [, severity, msg] = match;
146
+ this.errWarn.push({ filePath: "", line: 0, col: 0, msg, severity });
147
+ continue;
148
+ }
149
+ match = /\d error(s?), \d warning(s?)/.exec(errLine);
150
+ if (match) {
151
+ continue;
152
+ }
153
+ logger.warning(`parseECLErrors: Unable to parse "${errLine}"`);
154
+ this.errOther.push(errLine);
155
+ }
156
+ }
157
+ this._checked = checked;
158
+ }
159
+ }
160
+
161
+ export class EnvchkErrors extends Errors {
162
+
163
+ private _lines: string[];
164
+
165
+ constructor(filePath: string, stdErr: string, checked: string[]) {
166
+ super(checked);
167
+ let content: string = fs.readFileSync(filePath, "utf8");
168
+ content = content.replace(/\r\n/g, "\n");
169
+ this._lines = content.split("\n");
170
+ if (stdErr && stdErr.length) {
171
+ for (const errLine of stdErr.split(os.EOL)) {
172
+ const match = /(Warning|Error) : Path\=(\S*?)(\[\S*\])? Message\=(.*)/.exec(errLine);
173
+ if (match) {
174
+ const [, severity, _path, _attr, _msg] = match;
175
+ const msg = `${_path} ${_attr ? _attr : ""}: ${_msg}`;
176
+ const [line, col] = this.locate(_path);
177
+ this.errWarn.push({ filePath, line, col, msg, severity });
178
+ continue;
179
+ }
180
+ if (match) {
181
+ continue;
182
+ }
183
+ logger.warning(`parseECLErrors: Unable to parse "${errLine}"`);
184
+ this.errOther.push(errLine);
185
+ }
186
+ }
187
+ this._checked = checked;
188
+ }
189
+
190
+ locate(path: string): [number, number] {
191
+ const pathParts = path.split("/");
192
+ if (pathParts.length && pathParts[0] === "") {
193
+ pathParts.shift();
194
+ }
195
+ if (pathParts.length > 0) {
196
+ let lineIdx = 0;
197
+ for (const line of this._lines) {
198
+ const testStr = "<" + pathParts[0];
199
+ if (line.indexOf(testStr + " ") >= 0 || line.indexOf(testStr + ">") >= 0) {
200
+ pathParts.shift();
201
+ if (pathParts.length === 0) {
202
+ return [lineIdx + 1, line.indexOf(testStr) + 1];
203
+ }
204
+ }
205
+ ++lineIdx;
206
+ }
207
+ }
208
+ return [0, 0];
209
+ }
210
+ }
211
+
212
+ export function walkXmlJson(node: any, callback: (key: string, childNode: any, stack: any[]) => void, stack?: any[]) {
213
+ stack = stack || [];
214
+ stack.push(node);
215
+ for (const key in node) {
216
+ if (node.hasOwnProperty(key)) {
217
+ const childNode = node[key];
218
+ callback(key, childNode, stack);
219
+ if (childNode instanceof Array) {
220
+ childNode.forEach(child => {
221
+ walkXmlJson(child, callback, stack);
222
+ });
223
+ } else if (typeof childNode === "object") {
224
+ walkXmlJson(childNode, callback, stack);
225
+ }
226
+ }
227
+ }
228
+ stack.pop();
229
+ }
230
+
231
+ export class LocalWorkunit {
232
+ jsonWU: any;
233
+
234
+ constructor(jsonWU: any) {
235
+ this.jsonWU = jsonWU;
236
+ }
237
+
238
+ bpGetValidLocations(filePath: any) {
239
+ const retVal: any[] = [];
240
+ if (exists("W_LOCAL.Graphs", this.jsonWU)) {
241
+ let id = "";
242
+ walkXmlJson(this.jsonWU.W_LOCAL.Graphs, (key: string, item: any, _stack: any[]) => {
243
+ if (key === "$" && item.id) {
244
+ id = item.id;
245
+ }
246
+ if (key === "$" && item.name === "definition") {
247
+ const match = /([a-z,A-Z]:\\(?:[-\w\.\d]+\\)*(?:[-\w\.\d]+)?|(?:\/[\w\.\-]+)+)\((\d*),(\d*)\)/.exec(item.value);
248
+ if (match) {
249
+ const [, file, row, _col] = match;
250
+ const line: number = +row;
251
+ const col: number = +_col;
252
+ if (filePath === file) {
253
+ retVal.push({ file, line, col, id });
254
+ }
255
+ }
256
+ }
257
+ // console.log(`${key}: ` + JSON.stringify(item));
258
+ });
259
+ }
260
+ return retVal;
261
+ }
262
+ }
263
+
264
+ export interface IArchive {
265
+ content: string;
266
+ err: EclccErrors;
267
+ }
268
+
269
+ export interface IBundle {
270
+ name: string;
271
+ description: string;
272
+ url: string;
273
+ props?: { [key: string]: string | number | boolean };
274
+ }
275
+
276
+ export class ClientTools {
277
+ readonly eclccPath: string;
278
+ readonly envchkPath: string;
279
+ readonly eclBundlePath: string;
280
+ readonly binPath: string;
281
+ protected cwd: string;
282
+ protected includeFolders: string[];
283
+ protected _legacyMode: boolean;
284
+ protected _args: string[];
285
+ protected _version: Version;
286
+
287
+ constructor(eclccPath: string, cwd?: string, includeFolders: string[] = [], legacyMode: boolean = false, args: string[] = [], version?: Version) {
288
+ this.eclccPath = eclccPath;
289
+ this.binPath = path.dirname(this.eclccPath);
290
+ this.envchkPath = path.join(this.binPath, "envchk" + exeExt);
291
+ this.eclBundlePath = path.join(this.binPath, "ecl-bundle" + exeExt);
292
+ this.cwd = path.normalize(cwd || this.binPath);
293
+ this.includeFolders = includeFolders;
294
+ this._legacyMode = legacyMode;
295
+ this._args = args;
296
+ this._version = version!;
297
+ }
298
+
299
+ clone(cwd?: string, includeFolders?: string[], legacyMode: boolean = false, args: string[] = []) {
300
+ return new ClientTools(this.eclccPath, cwd, includeFolders, legacyMode, args, this._version);
301
+ }
302
+
303
+ exists(filePath: string) {
304
+ try {
305
+ fs.accessSync(filePath);
306
+ return true;
307
+ } catch (e) { }
308
+ return false;
309
+ }
310
+
311
+ args(additionalItems: string[] = []): string[] {
312
+ const retVal: string[] = [...this._args];
313
+ if (this._legacyMode) {
314
+ retVal.push("-legacy");
315
+ }
316
+ return retVal.concat(this.includeFolders.map(includePath => {
317
+ return "-I" + path.normalize(includePath);
318
+ })).concat(additionalItems);
319
+ }
320
+
321
+ version(): Promise<Version> {
322
+ if (this._version) {
323
+ return Promise.resolve(this._version);
324
+ }
325
+ return this.execFile(this.eclccPath, this.binPath, this.args(["--version"]), "eclcc", `Cannot find ${this.eclccPath}`).then((response: IExecFile): Version => {
326
+ this._version = new Version(response.stdout);
327
+ return this._version;
328
+ });
329
+ }
330
+
331
+ versionSync(): Version {
332
+ return this._version;
333
+ }
334
+
335
+ _paths = {};
336
+ paths() {
337
+ return this.execFile(this.eclccPath, this.cwd, this.args(["-showpaths"]), "eclcc", `Cannot find ${this.eclccPath}`).then((response: IExecFile) => {
338
+ if (response && response.stdout && response.stdout.length) {
339
+ const paths = response.stdout.split(/\r?\n/);
340
+ for (const path of paths) {
341
+ const parts = path.split("=");
342
+ if (parts.length === 2) {
343
+ this._paths[parts[0]] = parts[1];
344
+ }
345
+ }
346
+ }
347
+ return this._paths;
348
+ });
349
+ }
350
+
351
+ private loadXMLDoc(filePath: any, removeOnRead?: boolean): Promise<XMLNode> {
352
+ return new Promise((resolve, _reject) => {
353
+ const fileData = fs.readFileSync(filePath, "ascii");
354
+ const retVal = xml2json(fileData as any);
355
+ if (removeOnRead) {
356
+ fs.unlink(filePath, (err) => { });
357
+ }
358
+ resolve(retVal);
359
+ });
360
+ }
361
+
362
+ createWU(filename: string): Promise<LocalWorkunit> {
363
+ const tmpName = path.join(os.tmpdir(), `eclcc-wu-tmp-${crypto.randomBytes(8).toString("hex")}`);
364
+ const args = ["-o" + tmpName, "-wu"].concat([filename]);
365
+ return this.execFile(this.eclccPath, this.cwd, this.args(args), "eclcc", `Cannot find ${this.eclccPath}`).then((_response: IExecFile) => {
366
+ const xmlPath = path.normalize(tmpName + ".xml");
367
+ const contentPromise = this.exists(xmlPath) ? this.loadXMLDoc(xmlPath, true) : Promise.resolve({});
368
+ return contentPromise.then((content) => {
369
+ return new LocalWorkunit(content);
370
+ });
371
+ });
372
+ }
373
+
374
+ createArchive(filename: string): Promise<IArchive> {
375
+ const args = ["-E"].concat([filename]);
376
+ return this.execFile(this.eclccPath, this.cwd, this.args(args), "eclcc", `Cannot find ${this.eclccPath}`).then((response: IExecFile): IArchive => {
377
+ return {
378
+ content: response.stdout,
379
+ err: new EclccErrors(response.stderr, [])
380
+ };
381
+ });
382
+ }
383
+
384
+ attachWorkspace(): Workspace {
385
+ return attachWorkspace(this.cwd);
386
+ }
387
+
388
+ fetchMeta(filePath: string): Promise<Workspace> {
389
+ return Promise.all([
390
+ attachWorkspace(this.cwd),
391
+ this.execFile(this.eclccPath, this.cwd, this.args(["-M", filePath]), "eclcc", `Cannot find ${this.eclccPath}`)
392
+ ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
393
+ try {
394
+ if (execFileResponse && execFileResponse.stdout && execFileResponse.stdout.length) {
395
+ metaWorkspace.parseMetaXML(execFileResponse.stdout);
396
+ }
397
+ } catch (e: any) {
398
+ logger.error(`fetchMeta: Error parsing XML - ${e?.message ?? "unknown"}`);
399
+ }
400
+ return metaWorkspace;
401
+ });
402
+ }
403
+
404
+ syntaxCheck(filePath: string, args: string[] = ["-syntax"]): Promise<Errors> {
405
+ return Promise.all([
406
+ attachWorkspace(this.cwd),
407
+ this.execFile(this.eclccPath, this.cwd, this.args([...args, "-M", filePath]), "eclcc", `Cannot find ${this.eclccPath}`)
408
+ ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
409
+ let checked: string[] = [];
410
+ try {
411
+ if (execFileResponse && execFileResponse.stdout && execFileResponse.stdout.length) {
412
+ checked = metaWorkspace.parseMetaXML(execFileResponse.stdout);
413
+ }
414
+ } catch (e: any) {
415
+ logger.error(`syntaxCheck: Error parsing XML - ${e?.message ?? "unknown"}`);
416
+ }
417
+ return new EclccErrors(execFileResponse ? execFileResponse.stderr : "", checked);
418
+ });
419
+ }
420
+
421
+ envCheck(filePath: string, args: string[] = []): Promise<Errors> {
422
+ return Promise.all([
423
+ attachWorkspace(this.cwd),
424
+ this.execFile(this.envchkPath, this.cwd, this.args([...args, filePath]), "envchk", `Cannot find ${this.envchkPath}`)
425
+ ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
426
+ return new EnvchkErrors(filePath, execFileResponse ? execFileResponse.stderr : "", []);
427
+ });
428
+ }
429
+
430
+ bundleList(): Promise<IBundle[]> {
431
+ const bundlesRegEx = /\|(.*)\|(.*)\|(.*)\|/g;
432
+ return Promise.all([
433
+ fetch("https://raw.githubusercontent.com/hpcc-systems/ecl-bundles/master/README.rst")
434
+ .then(response => response.text())
435
+ .then(readme => {
436
+ const retVal: IBundle[] = [];
437
+ let m = bundlesRegEx.exec(readme);
438
+ while (m) {
439
+ retVal.push({
440
+ name: m[1].trim(),
441
+ description: m[2].trim(),
442
+ url: m[3].trim()
443
+ });
444
+ m = bundlesRegEx.exec(readme);
445
+ }
446
+ return retVal;
447
+ }),
448
+ this.execFile(this.eclBundlePath, this.cwd, this.args(["list"]), "ecl-bundle", `Cannot find ${this.eclBundlePath}`)
449
+ .then(installedText => {
450
+ return tidyCRLF(installedText.stdout).split("\n");
451
+ }).then(installedItems => {
452
+ const allProps = {};
453
+ return Promise.all(installedItems.filter(ii => !!ii).map(ii => {
454
+ return this.execFile(this.eclBundlePath, this.cwd, this.args(["info", ii]), "ecl-bundle", `Cannot find ${this.eclBundlePath}`)
455
+ .then(infoText => {
456
+ return tidyCRLF(infoText.stdout).split("\n");
457
+ }).then(info => {
458
+ const props = {};
459
+ info.forEach(line => {
460
+ const parts = line.split(":");
461
+ props[parts.shift().trim()] = parts.join(":").trim();
462
+ });
463
+ allProps[ii] = {
464
+ name: ii,
465
+ props
466
+ };
467
+ });
468
+ })).then(() => allProps);
469
+ })
470
+ ]).then(([bundles, installed]) => {
471
+ bundles.forEach(b => {
472
+ if (installed[b.name]) {
473
+ b.props = installed[b.name].props;
474
+ delete installed[b.name];
475
+ }
476
+ });
477
+ for (const key in installed) {
478
+ bundles.push({
479
+ name: key,
480
+ url: "",
481
+ description: "",
482
+ props: installed[key].props
483
+ });
484
+ }
485
+ return bundles;
486
+ }).catch(e => {
487
+ return [];
488
+ });
489
+ }
490
+
491
+ bundleInstall(bundleUrl) {
492
+ return Promise.all([
493
+ attachWorkspace(this.cwd),
494
+ this.execFile(this.eclBundlePath, this.cwd, this.args(["install", bundleUrl]), "ecl-bundle", `Cannot find ${this.eclBundlePath}`)
495
+ ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
496
+ return execFileResponse;
497
+ });
498
+ }
499
+
500
+ bundleUninstall(name) {
501
+ return Promise.all([
502
+ attachWorkspace(this.cwd),
503
+ this.execFile(this.eclBundlePath, this.cwd, this.args(["uninstall", name]), "ecl-bundle", `Cannot find ${this.eclBundlePath}`)
504
+ ]).then(([metaWorkspace, execFileResponse]: [Workspace, IExecFile]) => {
505
+ return execFileResponse;
506
+ });
507
+ }
508
+
509
+ private execFile(cmd: string, cwd: string, args: string[], _toolName: string, _notFoundError?: string): Promise<{ code: number, stdout: string, stderr: string }> {
510
+ return new Promise((resolve, _reject) => {
511
+ logger.debug(`${cmd} ${args.join(" ")}`);
512
+ const child = cp.spawn(cmd, args, { cwd });
513
+ let stdOut = "";
514
+ let stdErr = "";
515
+ child.stdout.on("data", (data) => {
516
+ stdOut += data.toString();
517
+ });
518
+ child.stderr.on("data", (data) => {
519
+ stdErr += data.toString();
520
+ });
521
+ child.on("close", (_code, _signal) => {
522
+ resolve({
523
+ code: _code,
524
+ stdout: stdOut.trim(),
525
+ stderr: stdErr.trim()
526
+ });
527
+ });
528
+ });
529
+ }
530
+ }
531
+
532
+ function locateClientToolsInFolder(rootFolder: string, clientTools: ClientTools[]) {
533
+ if (rootFolder) {
534
+ const hpccSystemsFolder = path.join(rootFolder, "HPCCSystems");
535
+ if (fs.existsSync(hpccSystemsFolder) && fs.statSync(hpccSystemsFolder).isDirectory()) {
536
+ if (os.type() !== "Windows_NT") {
537
+ const eclccPath = path.join(hpccSystemsFolder, "bin", "eclcc");
538
+ if (fs.existsSync(eclccPath)) {
539
+ clientTools.push(new ClientTools(eclccPath));
540
+ }
541
+ }
542
+ fs.readdirSync(hpccSystemsFolder).forEach((versionFolder) => {
543
+ const eclccPath = path.join(hpccSystemsFolder, versionFolder, "clienttools", "bin", "eclcc" + exeExt);
544
+ if (fs.existsSync(eclccPath)) {
545
+ const name = path.basename(versionFolder);
546
+ const version = new Version(name);
547
+ if (version.exists()) {
548
+ clientTools.push(new ClientTools(eclccPath));
549
+ }
550
+ }
551
+ });
552
+ }
553
+ }
554
+ }
555
+
556
+ let allClientToolsCache: Promise<ClientTools[]>;
557
+ export function clearAllClientToolsCache() {
558
+ allClientToolsCache = undefined;
559
+ }
560
+
561
+ export function locateAllClientTools() {
562
+ if (allClientToolsCache) return allClientToolsCache;
563
+ const clientTools: ClientTools[] = [];
564
+ switch (os.type()) {
565
+ case "Windows_NT":
566
+ const rootFolder86 = process.env["ProgramFiles(x86)"] || "";
567
+ if (rootFolder86) {
568
+ locateClientToolsInFolder(rootFolder86, clientTools);
569
+ }
570
+ const rootFolder = process.env["ProgramFiles"] || "";
571
+ if (rootFolder) {
572
+ locateClientToolsInFolder(rootFolder, clientTools);
573
+ }
574
+ if (!rootFolder86 && !rootFolder) {
575
+ locateClientToolsInFolder("c:\\Program Files (x86)", clientTools);
576
+ }
577
+ break;
578
+ case "Linux":
579
+ case "Darwin":
580
+ locateClientToolsInFolder("/opt", clientTools);
581
+ break;
582
+ default:
583
+ break;
584
+ }
585
+
586
+ allClientToolsCache = Promise.all(clientTools.map(ct => ct.version())).then(() => {
587
+ clientTools.sort((l: ClientTools, r: ClientTools) => {
588
+ return r.versionSync().compare(l.versionSync());
589
+ });
590
+ return clientTools;
591
+ });
592
+ return allClientToolsCache;
593
+ }
594
+
595
+ let eclccPathMsg = "";
596
+ function logEclccPath(eclccPath: string) {
597
+ const msg = `Using eclccPath setting: ${eclccPath}`;
598
+ if (eclccPathMsg !== msg) {
599
+ logger.info(msg);
600
+ eclccPathMsg = msg;
601
+ }
602
+ }
603
+
604
+ export function locateClientTools(overridePath: string = "", build: string = "", cwd: string = ".", includeFolders: string[] = [], legacyMode: boolean = false, args: string[] = []): Promise<ClientTools> {
605
+ if (overridePath && fs.existsSync(overridePath)) {
606
+ logEclccPath(overridePath);
607
+ return Promise.resolve(new ClientTools(overridePath, cwd, includeFolders, legacyMode, args));
608
+ }
609
+ return locateAllClientTools().then((allClientToolsCache2) => {
610
+ if (!allClientToolsCache2.length) {
611
+ throw new Error("Unable to locate ECL Client Tools.");
612
+ }
613
+ const buildVersion = new Version(build);
614
+ let latest: ClientTools | undefined;
615
+ let bestMajor: ClientTools | undefined;
616
+ for (const ct of allClientToolsCache2) {
617
+ const ctVersion = ct.versionSync();
618
+ if (ctVersion.exists()) {
619
+ if (!latest) latest = ct;
620
+ if (!bestMajor && buildVersion.major === ctVersion.major) bestMajor = ct;
621
+ if (buildVersion.major === ctVersion.major && buildVersion.minor === ctVersion.minor) return ct.clone(cwd, includeFolders, legacyMode, args);
622
+ }
623
+ }
624
+ const best: ClientTools = bestMajor || latest!;
625
+ logEclccPath(best.eclccPath);
626
+ return best.clone(cwd, includeFolders, legacyMode, args);
627
+ });
628
+ }