@sasjs/cli 3.22.0 → 3.23.1

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.
@@ -97,7 +97,7 @@ var CompileBuildCommand = /** @class */ (function (_super) {
97
97
  return [2 /*return*/, returnCode];
98
98
  }
99
99
  buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
100
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Services have been successfully compiled!\nThe compile output is located in the ".concat(buildDestinationFolder, " directory."));
100
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("The project was successfully compiled using the '".concat(target.name, "' target (serverType '").concat(target.serverType, "')!\nThe compile output is located in the ").concat(buildDestinationFolder, " directory."));
101
101
  return [4 /*yield*/, (0, build_1.build)(target)
102
102
  .then(function () { return command_1.ReturnCode.Success; })
103
103
  .catch(function (err) {
@@ -162,7 +162,7 @@ describe('CompileBuildCommand', function () {
162
162
  });
163
163
  }); });
164
164
  it('should log success and return the success code when execution is successful', function () { return __awaiter(void 0, void 0, void 0, function () {
165
- var args, command, returnCode;
165
+ var args, command, returnCode, buildDestinationFolder, expectedLoggedMessage;
166
166
  return __generator(this, function (_a) {
167
167
  switch (_a.label) {
168
168
  case 0:
@@ -171,8 +171,10 @@ describe('CompileBuildCommand', function () {
171
171
  return [4 /*yield*/, command.execute()];
172
172
  case 1:
173
173
  returnCode = _a.sent();
174
+ buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
175
+ expectedLoggedMessage = "The project was successfully compiled using the '".concat(target.name, "' target (serverType '").concat(target.serverType, "')!\nThe compile output is located in the ").concat(buildDestinationFolder, " directory.");
174
176
  expect(returnCode).toEqual(command_1.ReturnCode.Success);
175
- expect(process.logger.success).toHaveBeenCalled();
177
+ expect(process.logger.success).toHaveBeenNthCalledWith(1, expectedLoggedMessage);
176
178
  return [2 /*return*/];
177
179
  }
178
180
  });
@@ -167,7 +167,7 @@ var CompileCommand = /** @class */ (function (_super) {
167
167
  return [4 /*yield*/, (0, compile_1.compile)(target, true)
168
168
  .then(function () {
169
169
  var _a;
170
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Services have been successfully compiled!\nThe compile output is located in the ".concat(buildDestinationFolder, " directory."));
170
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("The project was successfully compiled using the '".concat(target.name, "' target (serverType '").concat(target.serverType, "')!\nThe compile output is located in the ").concat(buildDestinationFolder, " directory."));
171
171
  return command_1.ReturnCode.Success;
172
172
  })
173
173
  .catch(function (err) {
@@ -177,7 +177,7 @@ describe('CompileCommand', function () {
177
177
  });
178
178
  }); });
179
179
  it('should log success and return the success code when execution is successful', function () { return __awaiter(void 0, void 0, void 0, function () {
180
- var args, command, returnCode;
180
+ var args, command, returnCode, buildDestinationFolder, expectedLoggedMessage;
181
181
  return __generator(this, function (_a) {
182
182
  switch (_a.label) {
183
183
  case 0:
@@ -186,8 +186,10 @@ describe('CompileCommand', function () {
186
186
  return [4 /*yield*/, command.execute()];
187
187
  case 1:
188
188
  returnCode = _a.sent();
189
+ buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
190
+ expectedLoggedMessage = "The project was successfully compiled using the '".concat(target.name, "' target (serverType '").concat(target.serverType, "')!\nThe compile output is located in the ").concat(buildDestinationFolder, " directory.");
189
191
  expect(returnCode).toEqual(command_1.ReturnCode.Success);
190
- expect(process.logger.success).toHaveBeenCalled();
192
+ expect(process.logger.success).toHaveBeenNthCalledWith(1, expectedLoggedMessage);
191
193
  return [2 /*return*/];
192
194
  }
193
195
  });
@@ -98,7 +98,7 @@ var CompileBuildDeployCommand = /** @class */ (function (_super) {
98
98
  return [2 /*return*/, returnCode];
99
99
  }
100
100
  buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
101
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Services have been successfully compiled!\nThe compile output is located in the ".concat(buildDestinationFolder, " directory."));
101
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("The project was successfully compiled using the '".concat(target.name, "' target (serverType '").concat(target.serverType, "')!\nThe compile output is located in the ").concat(buildDestinationFolder, " directory."));
102
102
  return [4 /*yield*/, (0, build_1.build)(target)
103
103
  .then(function () { return command_1.ReturnCode.Success; })
104
104
  .catch(function (err) {
@@ -168,7 +168,7 @@ describe('CompileBuildDeployCommand', function () {
168
168
  });
169
169
  }); });
170
170
  it('should log success and return the success code when execution is successful', function () { return __awaiter(void 0, void 0, void 0, function () {
171
- var args, command, returnCode;
171
+ var args, command, returnCode, buildDestinationFolder, expectedLoggedMessage;
172
172
  return __generator(this, function (_a) {
173
173
  switch (_a.label) {
174
174
  case 0:
@@ -177,8 +177,10 @@ describe('CompileBuildDeployCommand', function () {
177
177
  return [4 /*yield*/, command.execute()];
178
178
  case 1:
179
179
  returnCode = _a.sent();
180
+ buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
181
+ expectedLoggedMessage = "The project was successfully compiled using the '".concat(target.name, "' target (serverType '").concat(target.serverType, "')!\nThe compile output is located in the ").concat(buildDestinationFolder, " directory.");
180
182
  expect(returnCode).toEqual(command_1.ReturnCode.Success);
181
- expect(process.logger.success).toHaveBeenCalled();
183
+ expect(process.logger.success).toHaveBeenNthCalledWith(1, expectedLoggedMessage);
182
184
  return [2 /*return*/];
183
185
  }
184
186
  });
@@ -7,5 +7,5 @@ export declare class FSCommand extends TargetCommand {
7
7
  getOutputPath(): Promise<string>;
8
8
  execute(): Promise<ReturnCode>;
9
9
  compile(): Promise<ReturnCode>;
10
- sync(): Promise<ReturnCode>;
10
+ sync(): Promise<ReturnCode.Success | ReturnCode.InternalError>;
11
11
  }
@@ -266,15 +266,15 @@ var FSCommand = /** @class */ (function (_super) {
266
266
  });
267
267
  };
268
268
  FSCommand.prototype.sync = function () {
269
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
269
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
270
270
  return __awaiter(this, void 0, void 0, function () {
271
- var _m, target, isLocal, remoteFolderPath, localFolderPath, syncDirectories, _o, _p, _q, _r, _loop_1, this_1, syncDirectories_1, syncDirectories_1_1, obj, state_1, e_1_1;
272
- var e_1, _s;
273
- return __generator(this, function (_t) {
274
- switch (_t.label) {
271
+ var _o, target, isLocal, remoteFolderPath, localFolderPath, syncDirectories, _p, _q, _r, _s, _loop_1, this_1, syncDirectories_1, syncDirectories_1_1, obj, state_1, e_1_1;
272
+ var e_1, _t;
273
+ return __generator(this, function (_u) {
274
+ switch (_u.label) {
275
275
  case 0: return [4 /*yield*/, this.getTargetInfo()];
276
276
  case 1:
277
- _m = _t.sent(), target = _m.target, isLocal = _m.isLocal;
277
+ _o = _u.sent(), target = _o.target, isLocal = _o.isLocal;
278
278
  remoteFolderPath = this.remoteFolder;
279
279
  localFolderPath = this.localFolder;
280
280
  syncDirectories = [];
@@ -282,88 +282,97 @@ var FSCommand = /** @class */ (function (_super) {
282
282
  syncDirectories.push({ remote: remoteFolderPath, local: localFolderPath });
283
283
  return [3 /*break*/, 4];
284
284
  case 2:
285
- _p = (_o = syncDirectories.push).apply;
286
- _q = [syncDirectories];
287
- _r = [[]];
285
+ _q = (_p = syncDirectories.push).apply;
286
+ _r = [syncDirectories];
287
+ _s = [[]];
288
288
  return [4 /*yield*/, (0, utils_1.getSyncDirectories)(target, isLocal)];
289
289
  case 3:
290
- _p.apply(_o, _q.concat([__spreadArray.apply(void 0, _r.concat([__read.apply(void 0, [(_t.sent())]), false]))]));
291
- _t.label = 4;
290
+ _q.apply(_p, _r.concat([__spreadArray.apply(void 0, _s.concat([__read.apply(void 0, [(_u.sent())]), false]))]));
291
+ _u.label = 4;
292
292
  case 4:
293
293
  if (!syncDirectories.length) {
294
294
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info('There are no directories to sync.');
295
295
  return [2 /*return*/, command_1.ReturnCode.Success];
296
296
  }
297
297
  _loop_1 = function (obj) {
298
- var outputFolder, program, log, remoteHashes, localHash, remoteHashMap, hashedDiff, syncProgram, syncLog, syncedHash, syncedHashMap, syncedResources, resourcesNotPresentLocally;
299
- return __generator(this, function (_u) {
300
- switch (_u.label) {
298
+ var outputFolder, program, log, remoteHashes, localHash, remoteHashMap_1, hashedDiff, syncProgram, syncLog, syncedHash, syncedHashMap, syncedResources_1, resourcesNotPresentLocally, error_1, logPath;
299
+ return __generator(this, function (_v) {
300
+ switch (_v.label) {
301
301
  case 0: return [4 /*yield*/, this_1.getOutputPath()];
302
302
  case 1:
303
- outputFolder = _u.sent();
303
+ outputFolder = _v.sent();
304
+ _v.label = 2;
305
+ case 2:
306
+ _v.trys.push([2, 15, , 17]);
304
307
  (_b = process.logger) === null || _b === void 0 ? void 0 : _b.info('generating program to get remote hash');
305
308
  return [4 /*yield*/, (0, utils_2.generateProgramToGetRemoteHash)(obj.remote)];
306
- case 2:
307
- program = _u.sent();
309
+ case 3:
310
+ program = _v.sent();
311
+ return [4 /*yield*/, createProgramFile(program, path_1.default.join(outputFolder, 'getRemoteHash.sas'))];
312
+ case 4:
313
+ _v.sent();
308
314
  (_c = process.logger) === null || _c === void 0 ? void 0 : _c.info('executing program to get remote hash');
309
315
  return [4 /*yield*/, (0, executeCode_1.executeCode)(target, program)];
310
- case 3:
311
- log = (_u.sent()).log;
316
+ case 5:
317
+ log = (_v.sent()).log;
312
318
  return [4 /*yield*/, (0, utils_1.saveLog)(log, path_1.default.join(outputFolder, 'getRemoteHash.log'), '', false)];
313
- case 4:
314
- _u.sent();
319
+ case 6:
320
+ _v.sent();
315
321
  (_d = process.logger) === null || _d === void 0 ? void 0 : _d.info('extracting hashes from log');
316
322
  remoteHashes = (0, extractHashArray_1.extractHashArray)(log);
317
323
  return [4 /*yield*/, createHashFile(JSON.stringify(remoteHashes, null, 2), path_1.default.join(outputFolder, 'hashesBeforeSync.json'))];
318
- case 5:
319
- _u.sent();
324
+ case 7:
325
+ _v.sent();
320
326
  (_e = process.logger) === null || _e === void 0 ? void 0 : _e.info('creating the hash of local folder');
321
327
  return [4 /*yield*/, (0, utils_2.getHash)(obj.local)];
322
- case 6:
323
- localHash = _u.sent();
324
- remoteHashMap = remoteHashes.reduce(function (map, item) {
328
+ case 8:
329
+ localHash = _v.sent();
330
+ remoteHashMap_1 = remoteHashes.reduce(function (map, item) {
325
331
  var relativePath = (0, utils_2.getRelativePath)(obj.remote, item.FILE_PATH);
326
332
  map[relativePath] = item.FILE_HASH;
327
333
  return map;
328
334
  }, {});
329
- if (remoteHashMap[localHash.relativePath] === localHash.hash) {
335
+ if (remoteHashMap_1[localHash.relativePath] === localHash.hash) {
330
336
  (_f = process.logger) === null || _f === void 0 ? void 0 : _f.info('There are no differences between Remote and Local directory. Already synced.');
331
337
  return [2 /*return*/, { value: command_1.ReturnCode.Success }];
332
338
  }
333
339
  (_g = process.logger) === null || _g === void 0 ? void 0 : _g.info('Extract differences from local and remote hash');
334
- hashedDiff = (0, utils_2.compareHashes)(localHash, remoteHashMap);
340
+ hashedDiff = (0, utils_2.compareHashes)(localHash, remoteHashMap_1);
335
341
  return [4 /*yield*/, createHashFile(JSON.stringify(hashedDiff, null, 2), path_1.default.join(outputFolder, 'hashesDiff.json'))];
336
- case 7:
337
- _u.sent();
342
+ case 9:
343
+ _v.sent();
338
344
  (_h = process.logger) === null || _h === void 0 ? void 0 : _h.info('generating program to sync differences');
339
345
  return [4 /*yield*/, (0, utils_2.generateProgramToSyncHashDiff)(hashedDiff, obj.remote)];
340
- case 8:
341
- syncProgram = _u.sent();
346
+ case 10:
347
+ syncProgram = _v.sent();
348
+ return [4 /*yield*/, createProgramFile(syncProgram, path_1.default.join(outputFolder, 'syncProgram.sas'))];
349
+ case 11:
350
+ _v.sent();
342
351
  (_j = process.logger) === null || _j === void 0 ? void 0 : _j.info('executing program to sync differences');
343
352
  return [4 /*yield*/, (0, executeCode_1.executeCode)(target, syncProgram)];
344
- case 9:
345
- syncLog = (_u.sent()).log;
353
+ case 12:
354
+ syncLog = (_v.sent()).log;
346
355
  return [4 /*yield*/, (0, utils_1.saveLog)(syncLog, path_1.default.join(outputFolder, 'sync.log'), '', false)];
347
- case 10:
348
- _u.sent();
356
+ case 13:
357
+ _v.sent();
349
358
  syncedHash = (0, extractHashArray_1.extractHashArray)(syncLog);
350
359
  return [4 /*yield*/, createHashFile(JSON.stringify(syncedHash, null, 2), path_1.default.join(outputFolder, 'hashesAfterSync.json'))];
351
- case 11:
352
- _u.sent();
360
+ case 14:
361
+ _v.sent();
353
362
  syncedHashMap = syncedHash.reduce(function (map, item) {
354
363
  var relativePath = (0, utils_2.getRelativePath)(obj.remote, item.FILE_PATH);
355
364
  map[relativePath] = item.FILE_HASH;
356
365
  return map;
357
366
  }, {});
358
- syncedResources = [];
367
+ syncedResources_1 = [];
359
368
  Object.entries(syncedHashMap).forEach(function (_a) {
360
369
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
361
- if (remoteHashMap[key] !== value)
362
- syncedResources.push(key);
370
+ if (remoteHashMap_1[key] !== value)
371
+ syncedResources_1.push(key);
363
372
  });
364
- if (syncedResources.length) {
365
- (_k = process.logger) === null || _k === void 0 ? void 0 : _k.log('The following resources were synced:');
366
- syncedResources.forEach(function (item) {
373
+ if (syncedResources_1.length) {
374
+ (_k = process.logger) === null || _k === void 0 ? void 0 : _k.log("The following resources were synced to: ".concat(obj.remote));
375
+ syncedResources_1.forEach(function (item) {
367
376
  var _a;
368
377
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.log("* ".concat(item));
369
378
  });
@@ -376,36 +385,45 @@ var FSCommand = /** @class */ (function (_super) {
376
385
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.log("* ".concat(item));
377
386
  });
378
387
  }
379
- return [2 /*return*/];
388
+ return [3 /*break*/, 17];
389
+ case 15:
390
+ error_1 = _v.sent();
391
+ logPath = path_1.default.join(outputFolder, 'error.log');
392
+ return [4 /*yield*/, createErrorLogFile(error_1, logPath)];
393
+ case 16:
394
+ _v.sent();
395
+ (_m = process.logger) === null || _m === void 0 ? void 0 : _m.error("An error has occurred. For more info see ".concat(logPath));
396
+ return [2 /*return*/, { value: command_1.ReturnCode.InternalError }];
397
+ case 17: return [2 /*return*/];
380
398
  }
381
399
  });
382
400
  };
383
401
  this_1 = this;
384
- _t.label = 5;
402
+ _u.label = 5;
385
403
  case 5:
386
- _t.trys.push([5, 10, 11, 12]);
404
+ _u.trys.push([5, 10, 11, 12]);
387
405
  syncDirectories_1 = __values(syncDirectories), syncDirectories_1_1 = syncDirectories_1.next();
388
- _t.label = 6;
406
+ _u.label = 6;
389
407
  case 6:
390
408
  if (!!syncDirectories_1_1.done) return [3 /*break*/, 9];
391
409
  obj = syncDirectories_1_1.value;
392
410
  return [5 /*yield**/, _loop_1(obj)];
393
411
  case 7:
394
- state_1 = _t.sent();
412
+ state_1 = _u.sent();
395
413
  if (typeof state_1 === "object")
396
414
  return [2 /*return*/, state_1.value];
397
- _t.label = 8;
415
+ _u.label = 8;
398
416
  case 8:
399
417
  syncDirectories_1_1 = syncDirectories_1.next();
400
418
  return [3 /*break*/, 6];
401
419
  case 9: return [3 /*break*/, 12];
402
420
  case 10:
403
- e_1_1 = _t.sent();
421
+ e_1_1 = _u.sent();
404
422
  e_1 = { error: e_1_1 };
405
423
  return [3 /*break*/, 12];
406
424
  case 11:
407
425
  try {
408
- if (syncDirectories_1_1 && !syncDirectories_1_1.done && (_s = syncDirectories_1.return)) _s.call(syncDirectories_1);
426
+ if (syncDirectories_1_1 && !syncDirectories_1_1.done && (_t = syncDirectories_1.return)) _t.call(syncDirectories_1);
409
427
  }
410
428
  finally { if (e_1) throw e_1.error; }
411
429
  return [7 /*endfinally*/];
@@ -431,3 +449,39 @@ var createHashFile = function (content, fileName) { return __awaiter(void 0, voi
431
449
  }
432
450
  });
433
451
  }); };
452
+ var createProgramFile = function (program, fileName) { return __awaiter(void 0, void 0, void 0, function () {
453
+ var _a, _b;
454
+ return __generator(this, function (_c) {
455
+ switch (_c.label) {
456
+ case 0:
457
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Creating program file at ".concat(fileName, " ."));
458
+ return [4 /*yield*/, (0, utils_2.createFile)(fileName, program)];
459
+ case 1:
460
+ _c.sent();
461
+ (_b = process.logger) === null || _b === void 0 ? void 0 : _b.success("Program saved to ".concat(fileName, " ."));
462
+ return [2 /*return*/];
463
+ }
464
+ });
465
+ }); };
466
+ var createErrorLogFile = function (error, logPath) { return __awaiter(void 0, void 0, void 0, function () {
467
+ return __generator(this, function (_a) {
468
+ switch (_a.label) {
469
+ case 0:
470
+ if (!error.log) return [3 /*break*/, 2];
471
+ return [4 /*yield*/, (0, utils_2.createFile)(logPath, error.log)];
472
+ case 1: return [2 /*return*/, _a.sent()];
473
+ case 2:
474
+ if (!(error instanceof Error)) return [3 /*break*/, 4];
475
+ return [4 /*yield*/, (0, utils_2.createFile)(logPath, error.toString())];
476
+ case 3: return [2 /*return*/, _a.sent()];
477
+ case 4:
478
+ if (!(typeof error === 'object')) return [3 /*break*/, 6];
479
+ return [4 /*yield*/, (0, utils_2.createFile)(logPath, JSON.stringify(error, null, 2))];
480
+ case 5: return [2 /*return*/, _a.sent()];
481
+ case 6: return [4 /*yield*/, (0, utils_2.createFile)(logPath, error)];
482
+ case 7:
483
+ _a.sent();
484
+ return [2 /*return*/];
485
+ }
486
+ });
487
+ }); };
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  "@sasjs/adapter": "4.1.0",
54
54
  "@sasjs/core": "4.45.2",
55
55
  "@sasjs/lint": "1.15.0",
56
- "@sasjs/utils": "2.51.1",
56
+ "@sasjs/utils": "2.51.2",
57
57
  "adm-zip": "0.5.9",
58
58
  "chalk": "4.1.2",
59
59
  "csv-stringify": "5.6.5",
@@ -72,7 +72,7 @@
72
72
  "shelljs": "0.8.5",
73
73
  "ssl-root-cas": "1.3.1",
74
74
  "xml": "1.0.1",
75
- "yargs": "17.2.1"
75
+ "yargs": "17.6.2"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@babel/preset-env": "7.15.6",
@@ -101,5 +101,5 @@
101
101
  "typescript": "4.5.4",
102
102
  "util": "0.12.4"
103
103
  },
104
- "version": "3.22.0"
104
+ "version": "3.23.1"
105
105
  }