@hpcc-js/comms 2.102.2 → 2.102.3

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 (103) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +50 -50
  3. package/dist/index.es6.js +2 -2
  4. package/dist/index.es6.js.map +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.min.js +1 -1
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/index.node.js +2 -2
  10. package/dist/index.node.js.map +1 -1
  11. package/dist/index.node.min.js +1 -1
  12. package/dist/index.node.min.js.map +1 -1
  13. package/lib-es6/__package__.js +2 -2
  14. package/package.json +4 -4
  15. package/src/__package__.ts +3 -3
  16. package/src/__tests__/dfuXRef.ts +22 -22
  17. package/src/__tests__/https.ts +69 -69
  18. package/src/__tests__/workunit.ts +35 -35
  19. package/src/clienttools/eclMeta.ts +506 -506
  20. package/src/clienttools/eclcc.ts +628 -628
  21. package/src/connection.ts +295 -295
  22. package/src/ecl/activity.ts +82 -82
  23. package/src/ecl/dfuWorkunit.ts +363 -363
  24. package/src/ecl/graph.ts +196 -196
  25. package/src/ecl/logicalFile.ts +195 -195
  26. package/src/ecl/machine.ts +63 -63
  27. package/src/ecl/query.ts +252 -252
  28. package/src/ecl/queryGraph.ts +813 -813
  29. package/src/ecl/resource.ts +39 -39
  30. package/src/ecl/result.ts +236 -236
  31. package/src/ecl/scope.ts +192 -192
  32. package/src/ecl/sourceFile.ts +34 -34
  33. package/src/ecl/store.ts +154 -154
  34. package/src/ecl/targetCluster.ts +149 -149
  35. package/src/ecl/timer.ts +42 -42
  36. package/src/ecl/topology.ts +131 -131
  37. package/src/ecl/workunit.ts +1314 -1314
  38. package/src/ecl/xsdParser.ts +268 -268
  39. package/src/espConnection.ts +172 -172
  40. package/src/index-common.ts +41 -41
  41. package/src/index.node.ts +68 -68
  42. package/src/index.ts +3 -3
  43. package/src/pem/trustwave.ts +909 -909
  44. package/src/services/fileSpray.ts +48 -48
  45. package/src/services/wsAccess.ts +8 -8
  46. package/src/services/wsAccount.ts +27 -27
  47. package/src/services/wsCloud.ts +73 -73
  48. package/src/services/wsCodesign.ts +94 -94
  49. package/src/services/wsDFU.ts +34 -34
  50. package/src/services/wsDFUXRef.ts +308 -308
  51. package/src/services/wsDali.ts +40 -40
  52. package/src/services/wsEcl.ts +123 -123
  53. package/src/services/wsElk.ts +8 -8
  54. package/src/services/wsLogaccess.ts +263 -263
  55. package/src/services/wsMachine.ts +89 -89
  56. package/src/services/wsPackageProcess.ts +8 -8
  57. package/src/services/wsResources.ts +8 -8
  58. package/src/services/wsSMC.ts +24 -24
  59. package/src/services/wsSasha.ts +7 -7
  60. package/src/services/wsStore.ts +230 -230
  61. package/src/services/wsTopology.ts +45 -45
  62. package/src/services/wsWorkunits.ts +160 -160
  63. package/src/services/wsdl/FileSpray/v1.23/FileSpray.ts +1008 -1008
  64. package/src/services/wsdl/FileSpray/v1.25/FileSpray.ts +1040 -1040
  65. package/src/services/wsdl/FileSpray/v1.26/FileSpray.ts +929 -929
  66. package/src/services/wsdl/WsCloud/v1/WsCloud.ts +38 -38
  67. package/src/services/wsdl/WsCloud/v1.02/WsCloud.ts +77 -77
  68. package/src/services/wsdl/WsDFUXRef/v1.02/WsDFUXRef.ts +224 -224
  69. package/src/services/wsdl/WsDali/v1.04/WsDali.ts +216 -216
  70. package/src/services/wsdl/WsDfu/v1.62/WsDfu.ts +1455 -1455
  71. package/src/services/wsdl/WsDfu/v1.63/WsDfu.ts +1465 -1465
  72. package/src/services/wsdl/WsDfu/v1.65/WsDfu.ts +1244 -1244
  73. package/src/services/wsdl/WsFileIO/v1.01/WsFileIO.ts +107 -107
  74. package/src/services/wsdl/WsPackageProcess/v1.04/WsPackageProcess.ts +519 -519
  75. package/src/services/wsdl/WsResources/v1.01/WsResources.ts +119 -119
  76. package/src/services/wsdl/WsSMC/v1.24/WsSMC.ts +665 -665
  77. package/src/services/wsdl/WsSMC/v1.27/WsSMC.ts +670 -670
  78. package/src/services/wsdl/WsTopology/v1.31/WsTopology.ts +856 -856
  79. package/src/services/wsdl/WsTopology/v1.32/WsTopology.ts +885 -885
  80. package/src/services/wsdl/WsWorkunits/v1.88/WsWorkunits.ts +2944 -2944
  81. package/src/services/wsdl/WsWorkunits/v1.94/WsWorkunits.ts +3072 -3072
  82. package/src/services/wsdl/WsWorkunits/v1.95/WsWorkunits.ts +3073 -3073
  83. package/src/services/wsdl/WsWorkunits/v1.97/WsWorkunits.ts +3134 -3134
  84. package/src/services/wsdl/WsWorkunits/v1.98/WsWorkunits.ts +3182 -3182
  85. package/src/services/wsdl/WsWorkunits/v1.99/WsWorkunits.ts +3162 -3162
  86. package/src/services/wsdl/WsWorkunits/v2/WsWorkunits.ts +3153 -3153
  87. package/src/services/wsdl/WsWorkunits/v2.02/WsWorkunits.ts +3157 -3157
  88. package/src/services/wsdl/ws_access/v1.16/ws_access.ts +1086 -1086
  89. package/src/services/wsdl/ws_access/v1.17/ws_access.ts +1023 -1023
  90. package/src/services/wsdl/ws_account/v1.05/ws_account.ts +111 -111
  91. package/src/services/wsdl/ws_account/v1.06/ws_account.ts +109 -109
  92. package/src/services/wsdl/ws_codesign/v1.1/ws_codesign.ts +100 -100
  93. package/src/services/wsdl/ws_elk/v1/ws_elk.ts +47 -47
  94. package/src/services/wsdl/ws_logaccess/v1/ws_logaccess.ts +83 -83
  95. package/src/services/wsdl/ws_logaccess/v1.02/ws_logaccess.ts +161 -161
  96. package/src/services/wsdl/ws_logaccess/v1.03/ws_logaccess.ts +190 -190
  97. package/src/services/wsdl/ws_logaccess/v1.04/ws_logaccess.ts +215 -215
  98. package/src/services/wsdl/ws_logaccess/v1.05/ws_logaccess.ts +219 -219
  99. package/src/services/wsdl/ws_logaccess/v1.08/ws_logaccess.ts +267 -267
  100. package/src/services/wsdl/ws_machine/v1.17/ws_machine.ts +567 -567
  101. package/src/services/wsdl/wsstore/v1.02/wsstore.ts +250 -250
  102. package/types/__package__.d.ts +2 -2
  103. package/types-3.4/__package__.d.ts +2 -2
@@ -1,628 +1,628 @@
1
- import * as cp from "child_process";
2
- import * as fs from "fs";
3
- import * as os from "os";
4
- import * as path from "path";
5
- import * as tmp from "tmp";
6
-
7
- import { exists, scopedLogger, xml2json, XMLNode } from "@hpcc-js/util";
8
- import { attachWorkspace, Workspace } from "./eclMeta";
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 = tmp.tmpNameSync({ prefix: "eclcc-wu-tmp", postfix: "" });
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) {
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) {
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 "child_process";
2
+ import * as fs from "fs";
3
+ import * as os from "os";
4
+ import * as path from "path";
5
+ import * as tmp from "tmp";
6
+
7
+ import { exists, scopedLogger, xml2json, XMLNode } from "@hpcc-js/util";
8
+ import { attachWorkspace, Workspace } from "./eclMeta";
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 = tmp.tmpNameSync({ prefix: "eclcc-wu-tmp", postfix: "" });
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) {
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) {
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
+ }