@sasjs/cli 3.13.2 → 3.13.5

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 (25) hide show
  1. package/build/commands/compile/compile.js +33 -26
  2. package/build/commands/compile/compileSingleFile.js +8 -5
  3. package/build/commands/compile/internal/compileFile.d.ts +15 -0
  4. package/build/commands/compile/internal/{compileServiceFile.js → compileFile.js} +27 -5
  5. package/build/commands/compile/internal/compileTestFile.js +2 -2
  6. package/build/commands/compile/spec/compile.spec.js +24 -8
  7. package/build/commands/compile/spec/{compileJobFile.spec.d.ts → compileFile.spec.d.ts} +0 -0
  8. package/build/commands/compile/spec/{compileServiceFile.spec.js → compileFile.spec.js} +75 -37
  9. package/build/commands/deploy/deploy.js +6 -2
  10. package/build/commands/job/internal/execute/sasjs.d.ts +2 -1
  11. package/build/commands/job/internal/execute/sasjs.js +2 -2
  12. package/build/commands/job/jobCommand.d.ts +1 -1
  13. package/build/commands/job/jobCommand.js +23 -12
  14. package/build/commands/job/spec/execute.spec.js +1 -1
  15. package/build/commands/request/request.js +4 -4
  16. package/build/commands/request/requestCommand.js +21 -10
  17. package/build/commands/shared/deployToSasViyaWithServicePack.js +6 -1
  18. package/build/utils/displayResult.js +5 -1
  19. package/build/utils/utils.js +1 -1
  20. package/package.json +6 -5
  21. package/build/commands/compile/internal/compileJobFile.d.ts +0 -3
  22. package/build/commands/compile/internal/compileJobFile.js +0 -60
  23. package/build/commands/compile/internal/compileServiceFile.d.ts +0 -4
  24. package/build/commands/compile/spec/compileJobFile.spec.js +0 -140
  25. package/build/commands/compile/spec/compileServiceFile.spec.d.ts +0 -1
@@ -75,11 +75,11 @@ var config_1 = require("../../utils/config");
75
75
  var utils_1 = require("@sasjs/utils");
76
76
  var web_1 = require("../web/web");
77
77
  var file_1 = require("../../utils/file");
78
+ var types_1 = require("@sasjs/utils/types");
78
79
  var checkCompileStatus_1 = require("./internal/checkCompileStatus");
79
80
  var compileModule = __importStar(require("./compile"));
80
81
  var getAllFolders_1 = require("./internal/getAllFolders");
81
- var compileServiceFile_1 = require("./internal/compileServiceFile");
82
- var compileJobFile_1 = require("./internal/compileJobFile");
82
+ var compileFile_1 = require("./internal/compileFile");
83
83
  var compileTestFile_1 = require("./internal/compileTestFile");
84
84
  var getDestinationPath_1 = require("./internal/getDestinationPath");
85
85
  var loadDependencies_1 = require("./internal/loadDependencies");
@@ -138,7 +138,10 @@ function compile(target, forceCompile) {
138
138
  macroTestFiles = _c.sent();
139
139
  return [4 /*yield*/, (0, utils_1.asyncForEach)(macroTestFiles, function (macroTestFile) { return __awaiter(_this, void 0, void 0, function () {
140
140
  return __generator(this, function (_a) {
141
- return [2 /*return*/, (0, compileServiceFile_1.compileServiceFile)(target, path_1.default.join(buildMacroTestFolder_1, macroTestFile), macroFolders, programFolders_1, undefined, compileTree)];
141
+ switch (_a.label) {
142
+ case 0: return [4 /*yield*/, (0, compileFile_1.compileFile)(target, path_1.default.join(buildMacroTestFolder_1, macroTestFile), macroFolders, programFolders_1, undefined, compileTree, types_1.SASJsFileType.service, '')];
143
+ case 1: return [2 /*return*/, _a.sent()];
144
+ }
142
145
  });
143
146
  }); })];
144
147
  case 10:
@@ -326,7 +329,7 @@ function recreateBuildFolder() {
326
329
  }
327
330
  // REFACTOR: combine compileServiceFolder and compileJobFolder
328
331
  var compileServiceFolder = function (target, serviceFolder, macroFolders, programFolders, compileTree) { return __awaiter(void 0, void 0, void 0, function () {
329
- var destinationPath, subFolders, filesNamesInPath;
332
+ var destinationPath, subFolders, sourceFiles;
330
333
  return __generator(this, function (_a) {
331
334
  switch (_a.label) {
332
335
  case 0:
@@ -334,21 +337,21 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
334
337
  return [4 /*yield*/, (0, utils_1.listSubFoldersInFolder)(destinationPath)];
335
338
  case 1:
336
339
  subFolders = _a.sent();
337
- return [4 /*yield*/, (0, utils_1.listFilesInFolder)(destinationPath)
340
+ return [4 /*yield*/, (0, utils_1.listFilesInFolder)(serviceFolder)
338
341
  // Checks if file in sasjsbuild folder exists in source folder.
339
342
  // If not, it means that the file shouldn't be compiled.
340
343
  ];
341
344
  case 2:
342
- filesNamesInPath = _a.sent();
345
+ sourceFiles = _a.sent();
343
346
  // Checks if file in sasjsbuild folder exists in source folder.
344
347
  // If not, it means that the file shouldn't be compiled.
345
- return [4 /*yield*/, (0, utils_1.asyncForEach)(filesNamesInPath, function (fileName, i) { return __awaiter(void 0, void 0, void 0, function () {
348
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(sourceFiles, function (fileName, i) { return __awaiter(void 0, void 0, void 0, function () {
346
349
  return __generator(this, function (_a) {
347
350
  switch (_a.label) {
348
351
  case 0: return [4 /*yield*/, (0, utils_1.fileExists)(path_1.default.join(serviceFolder, fileName))];
349
352
  case 1:
350
353
  if (!(_a.sent())) {
351
- filesNamesInPath.splice(i, 1);
354
+ sourceFiles.splice(i, 1);
352
355
  }
353
356
  return [2 /*return*/];
354
357
  }
@@ -358,7 +361,7 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
358
361
  // Checks if file in sasjsbuild folder exists in source folder.
359
362
  // If not, it means that the file shouldn't be compiled.
360
363
  _a.sent();
361
- return [4 /*yield*/, (0, utils_1.asyncForEach)(filesNamesInPath, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
364
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(sourceFiles, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
362
365
  var filePath;
363
366
  return __generator(this, function (_a) {
364
367
  switch (_a.label) {
@@ -369,7 +372,7 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
369
372
  case 1:
370
373
  _a.sent();
371
374
  return [3 /*break*/, 4];
372
- case 2: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, filePath, macroFolders, programFolders, undefined, compileTree)];
375
+ case 2: return [4 /*yield*/, (0, compileFile_1.compileFile)(target, filePath, macroFolders, programFolders, undefined, compileTree, types_1.SASJsFileType.service, serviceFolder)];
373
376
  case 3:
374
377
  _a.sent();
375
378
  _a.label = 4;
@@ -380,13 +383,15 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
380
383
  case 4:
381
384
  _a.sent();
382
385
  return [4 /*yield*/, (0, utils_1.asyncForEach)(subFolders, function (subFolder) { return __awaiter(void 0, void 0, void 0, function () {
383
- var fileNames;
386
+ var sourceFolder, sourceFiles;
384
387
  return __generator(this, function (_a) {
385
388
  switch (_a.label) {
386
- case 0: return [4 /*yield*/, (0, utils_1.listFilesInFolder)(path_1.default.join(serviceFolder, subFolder))];
389
+ case 0:
390
+ sourceFolder = path_1.default.join(serviceFolder, subFolder);
391
+ return [4 /*yield*/, (0, utils_1.listFilesInFolder)(sourceFolder)];
387
392
  case 1:
388
- fileNames = _a.sent();
389
- return [4 /*yield*/, (0, utils_1.asyncForEach)(fileNames, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
393
+ sourceFiles = _a.sent();
394
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(sourceFiles, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
390
395
  var filePath;
391
396
  return __generator(this, function (_a) {
392
397
  switch (_a.label) {
@@ -397,7 +402,7 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
397
402
  case 1:
398
403
  _a.sent();
399
404
  return [3 /*break*/, 4];
400
- case 2: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, filePath, macroFolders, programFolders, undefined, compileTree)];
405
+ case 2: return [4 /*yield*/, (0, compileFile_1.compileFile)(target, filePath, macroFolders, programFolders, undefined, compileTree, types_1.SASJsFileType.service, sourceFolder)];
401
406
  case 3:
402
407
  _a.sent();
403
408
  _a.label = 4;
@@ -419,7 +424,7 @@ var compileServiceFolder = function (target, serviceFolder, macroFolders, progra
419
424
  });
420
425
  }); };
421
426
  var compileJobFolder = function (target, jobFolder, macroFolders, programFolders, compileTree) { return __awaiter(void 0, void 0, void 0, function () {
422
- var destinationPath, subFolders, filesNamesInPath;
427
+ var destinationPath, subFolders, sourceFiles;
423
428
  return __generator(this, function (_a) {
424
429
  switch (_a.label) {
425
430
  case 0:
@@ -432,16 +437,16 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
432
437
  // If not, it means that the file shouldn't be compiled.
433
438
  ];
434
439
  case 2:
435
- filesNamesInPath = _a.sent();
440
+ sourceFiles = _a.sent();
436
441
  // Checks if file in sasjsbuild folder exists in source folder.
437
442
  // If not, it means that the file shouldn't be compiled.
438
- return [4 /*yield*/, (0, utils_1.asyncForEach)(filesNamesInPath, function (fileName, i) { return __awaiter(void 0, void 0, void 0, function () {
443
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(sourceFiles, function (fileName, i) { return __awaiter(void 0, void 0, void 0, function () {
439
444
  return __generator(this, function (_a) {
440
445
  switch (_a.label) {
441
446
  case 0: return [4 /*yield*/, (0, utils_1.fileExists)(path_1.default.join(jobFolder, fileName))];
442
447
  case 1:
443
448
  if (!(_a.sent())) {
444
- filesNamesInPath.splice(i, 1);
449
+ sourceFiles.splice(i, 1);
445
450
  }
446
451
  return [2 /*return*/];
447
452
  }
@@ -451,7 +456,7 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
451
456
  // Checks if file in sasjsbuild folder exists in source folder.
452
457
  // If not, it means that the file shouldn't be compiled.
453
458
  _a.sent();
454
- return [4 /*yield*/, (0, utils_1.asyncForEach)(filesNamesInPath, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
459
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(sourceFiles, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
455
460
  var filePath;
456
461
  return __generator(this, function (_a) {
457
462
  switch (_a.label) {
@@ -462,7 +467,7 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
462
467
  case 1:
463
468
  _a.sent();
464
469
  return [3 /*break*/, 4];
465
- case 2: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, filePath, macroFolders, programFolders, undefined, compileTree)];
470
+ case 2: return [4 /*yield*/, (0, compileFile_1.compileFile)(target, filePath, macroFolders, programFolders, undefined, compileTree, types_1.SASJsFileType.job, jobFolder)];
466
471
  case 3:
467
472
  _a.sent();
468
473
  _a.label = 4;
@@ -473,13 +478,15 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
473
478
  case 4:
474
479
  _a.sent();
475
480
  return [4 /*yield*/, (0, utils_1.asyncForEach)(subFolders, function (subFolder) { return __awaiter(void 0, void 0, void 0, function () {
476
- var fileNames;
481
+ var sourcePath, sourceFiles;
477
482
  return __generator(this, function (_a) {
478
483
  switch (_a.label) {
479
- case 0: return [4 /*yield*/, (0, utils_1.listFilesInFolder)(path_1.default.join(jobFolder, subFolder))];
484
+ case 0:
485
+ sourcePath = path_1.default.join(jobFolder, subFolder);
486
+ return [4 /*yield*/, (0, utils_1.listFilesInFolder)(sourcePath)];
480
487
  case 1:
481
- fileNames = _a.sent();
482
- return [4 /*yield*/, (0, utils_1.asyncForEach)(fileNames, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
488
+ sourceFiles = _a.sent();
489
+ return [4 /*yield*/, (0, utils_1.asyncForEach)(sourceFiles, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
483
490
  var filePath;
484
491
  return __generator(this, function (_a) {
485
492
  switch (_a.label) {
@@ -490,7 +497,7 @@ var compileJobFolder = function (target, jobFolder, macroFolders, programFolders
490
497
  case 1:
491
498
  _a.sent();
492
499
  return [3 /*break*/, 4];
493
- case 2: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, filePath, macroFolders, programFolders, undefined, compileTree)];
500
+ case 2: return [4 /*yield*/, (0, compileFile_1.compileFile)(target, filePath, macroFolders, programFolders, undefined, compileTree, types_1.SASJsFileType.job, sourcePath)];
494
501
  case 3:
495
502
  _a.sent();
496
503
  _a.label = 4;
@@ -43,8 +43,7 @@ exports.compileSingleFile = void 0;
43
43
  var path_1 = __importDefault(require("path"));
44
44
  var config_1 = require("../../utils/config");
45
45
  var utils_1 = require("@sasjs/utils");
46
- var compileServiceFile_1 = require("./internal/compileServiceFile");
47
- var compileJobFile_1 = require("./internal/compileJobFile");
46
+ var compileFile_1 = require("./internal/compileFile");
48
47
  var identifySasFile_1 = require("./internal/identifySasFile");
49
48
  var loadDependencies_1 = require("./internal/loadDependencies");
50
49
  function compileSingleFile(target, subCommand, source, output, insertProgramVar) {
@@ -52,7 +51,7 @@ function compileSingleFile(target, subCommand, source, output, insertProgramVar)
52
51
  if (subCommand === void 0) { subCommand = 'identify'; }
53
52
  if (insertProgramVar === void 0) { insertProgramVar = false; }
54
53
  return __awaiter(this, void 0, void 0, function () {
55
- var subCommands, commandExample, sourcePath, outputPathParts, leafFolderName, parentOutputFolder, pathExists, sourceFileName, destinationPath, sourceFileNameWithoutExt, macroFolders, programFolders, psMaxOption, programVar, compileTree, _b;
54
+ var subCommands, commandExample, sourcePath, outputPathParts, leafFolderName, parentOutputFolder, pathExists, sourceFileName, destinationPath, sourceFileNameWithoutExt, macroFolders, programFolders, psMaxOption, programVar, compileTree, sourceFolder, _b;
56
55
  return __generator(this, function (_c) {
57
56
  switch (_c.label) {
58
57
  case 0:
@@ -113,17 +112,21 @@ function compileSingleFile(target, subCommand, source, output, insertProgramVar)
113
112
  ? "%let _program=".concat(target.appLoc, "/").concat(subCommand, "s/").concat(leafFolderName, "/").concat(sourceFileNameWithoutExt, ";\n").concat(psMaxOption)
114
113
  : "".concat(psMaxOption);
115
114
  compileTree = (0, loadDependencies_1.getCompileTree)(target);
115
+ sourceFolder = sourcePath
116
+ .split(path_1.default.sep)
117
+ .slice(0, sourcePath.split(path_1.default.sep).length - 1)
118
+ .join(path_1.default.sep);
116
119
  _b = subCommand;
117
120
  switch (_b) {
118
121
  case subCommands.service: return [3 /*break*/, 11];
119
122
  case subCommands.job: return [3 /*break*/, 13];
120
123
  }
121
124
  return [3 /*break*/, 15];
122
- case 11: return [4 /*yield*/, (0, compileServiceFile_1.compileServiceFile)(target, destinationPath, macroFolders, programFolders, programVar, compileTree)];
125
+ case 11: return [4 /*yield*/, (0, compileFile_1.compileFile)(target, destinationPath, macroFolders, programFolders, programVar, compileTree, utils_1.SASJsFileType.service, sourceFolder)];
123
126
  case 12:
124
127
  _c.sent();
125
128
  return [3 /*break*/, 16];
126
- case 13: return [4 /*yield*/, (0, compileJobFile_1.compileJobFile)(target, destinationPath, macroFolders, programFolders, programVar, compileTree)];
129
+ case 13: return [4 /*yield*/, (0, compileFile_1.compileFile)(target, destinationPath, macroFolders, programFolders, programVar, compileTree, utils_1.SASJsFileType.job, sourceFolder)];
127
130
  case 14:
128
131
  _c.sent();
129
132
  return [3 /*break*/, 16];
@@ -0,0 +1,15 @@
1
+ import { CompileTree } from '@sasjs/utils';
2
+ import { Target, ServerType, SASJsFileType } from '@sasjs/utils/types';
3
+ /**
4
+ * Compiles file dependencies.
5
+ * @param {Target} target - SAS server configuration.
6
+ * @param {string} filePath - file path of the file to be compiled.
7
+ * @param {string[]} macroFolders - macro folders paths.
8
+ * @param {string[]} programFolders - program folders paths.
9
+ * @param {string} programVar - program variable.
10
+ * @param {object} compileTree - compilation tree that stores used compilation assets.
11
+ * @param {SASJsFileType} fileType - sasjs file type.
12
+ * @param {string} sourceFolder - folder path of the source folder.
13
+ */
14
+ export declare function compileFile(target: Target, filePath: string, macroFolders: string[], programFolders: string[], programVar: string | undefined, compileTree: CompileTree, fileType: SASJsFileType, sourceFolder: string): Promise<void>;
15
+ export declare function getPreCodeForServicePack(serverType: ServerType): Promise<string>;
@@ -35,22 +35,40 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
38
41
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getPreCodeForServicePack = exports.compileServiceFile = void 0;
42
+ exports.getPreCodeForServicePack = exports.compileFile = void 0;
40
43
  var utils_1 = require("@sasjs/utils");
41
44
  var types_1 = require("@sasjs/utils/types");
42
45
  var error_1 = require("@sasjs/utils/error");
43
46
  var loadDependencies_1 = require("./loadDependencies");
44
47
  var getServerType_1 = require("./getServerType");
45
- function compileServiceFile(target, filePath, macroFolders, programFolders, programVar, compileTree) {
48
+ var path_1 = __importDefault(require("path"));
49
+ /**
50
+ * Compiles file dependencies.
51
+ * @param {Target} target - SAS server configuration.
52
+ * @param {string} filePath - file path of the file to be compiled.
53
+ * @param {string[]} macroFolders - macro folders paths.
54
+ * @param {string[]} programFolders - program folders paths.
55
+ * @param {string} programVar - program variable.
56
+ * @param {object} compileTree - compilation tree that stores used compilation assets.
57
+ * @param {SASJsFileType} fileType - sasjs file type.
58
+ * @param {string} sourceFolder - folder path of the source folder.
59
+ */
60
+ function compileFile(target, filePath, macroFolders, programFolders, programVar, compileTree, fileType, sourceFolder) {
46
61
  if (programVar === void 0) { programVar = ''; }
47
62
  return __awaiter(this, void 0, void 0, function () {
48
63
  var dependencies, serverType, preCode;
49
64
  return __generator(this, function (_a) {
50
65
  switch (_a.label) {
51
- case 0: return [4 /*yield*/, (0, loadDependencies_1.loadDependencies)(target, filePath, macroFolders, programFolders, (0, utils_1.isTestFile)(filePath) ? types_1.SASJsFileType.test : types_1.SASJsFileType.service, compileTree)];
66
+ case 0: return [4 /*yield*/, (0, loadDependencies_1.loadDependencies)(target, sourceFolder
67
+ ? path_1.default.join(sourceFolder, filePath.split(path_1.default.sep).pop())
68
+ : filePath, macroFolders, programFolders, (0, utils_1.isTestFile)(filePath) ? types_1.SASJsFileType.test : fileType, compileTree)];
52
69
  case 1:
53
70
  dependencies = _a.sent();
71
+ if (!(fileType === types_1.SASJsFileType.service)) return [3 /*break*/, 4];
54
72
  return [4 /*yield*/, (0, getServerType_1.getServerType)(target)];
55
73
  case 2:
56
74
  serverType = _a.sent();
@@ -58,15 +76,19 @@ function compileServiceFile(target, filePath, macroFolders, programFolders, prog
58
76
  case 3:
59
77
  preCode = _a.sent();
60
78
  dependencies = "".concat(programVar, "\n").concat(preCode, "\n").concat(dependencies);
61
- return [4 /*yield*/, (0, utils_1.createFile)(filePath, dependencies)];
79
+ return [3 /*break*/, 5];
62
80
  case 4:
81
+ dependencies = "".concat(programVar ? programVar + '\n' : '').concat(dependencies);
82
+ _a.label = 5;
83
+ case 5: return [4 /*yield*/, (0, utils_1.createFile)(filePath, dependencies)];
84
+ case 6:
63
85
  _a.sent();
64
86
  return [2 /*return*/];
65
87
  }
66
88
  });
67
89
  });
68
90
  }
69
- exports.compileServiceFile = compileServiceFile;
91
+ exports.compileFile = compileFile;
70
92
  function getPreCodeForServicePack(serverType) {
71
93
  return __awaiter(this, void 0, void 0, function () {
72
94
  var content, macroCorePath, _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -72,7 +72,7 @@ var loadDependencies_1 = require("./loadDependencies");
72
72
  var file_1 = require("../../../utils/file");
73
73
  var chalk_1 = __importDefault(require("chalk"));
74
74
  var config_1 = require("../../../utils/config");
75
- var compileServiceFile_1 = require("./compileServiceFile");
75
+ var compileFile_1 = require("./compileFile");
76
76
  var testsBuildFolder = function () {
77
77
  return path_1.default.join(process.projectDir, 'sasjsbuild', 'tests');
78
78
  };
@@ -97,7 +97,7 @@ function compileTestFile(target, filePath, testVar, saveToRoot, removeOriginalFi
97
97
  compileTree]))];
98
98
  case 3:
99
99
  dependencies = _c.sent();
100
- return [4 /*yield*/, (0, compileServiceFile_1.getPreCodeForServicePack)(target.serverType)];
100
+ return [4 /*yield*/, (0, compileFile_1.getPreCodeForServicePack)(target.serverType)];
101
101
  case 4:
102
102
  preCode = _c.sent();
103
103
  dependencies = "".concat(testVar ? testVar + '\n' : '', "\n").concat(preCode, "\n").concat(dependencies);
@@ -75,8 +75,7 @@ var config_1 = require("../../../utils/config");
75
75
  var test_1 = require("../../../utils/test");
76
76
  var compileModule = __importStar(require("../compile"));
77
77
  var compileSingleFile_1 = require("../compileSingleFile");
78
- var compileJobFile = __importStar(require("../internal/compileJobFile"));
79
- var compileServiceFile = __importStar(require("../internal/compileServiceFile"));
78
+ var compileFile = __importStar(require("../internal/compileFile"));
80
79
  var utils_2 = require("../../../utils");
81
80
  var compileCommand_1 = require("../compileCommand");
82
81
  describe('sasjs compile', function () {
@@ -302,7 +301,7 @@ describe('sasjs compile single file', function () {
302
301
  return [4 /*yield*/, (0, config_1.findTargetInConfiguration)('viya')];
303
302
  case 2:
304
303
  target = (_a.sent()).target;
305
- jest.spyOn(compileJobFile, 'compileJobFile');
304
+ jest.spyOn(compileFile, 'compileFile');
306
305
  return [2 /*return*/];
307
306
  }
308
307
  });
@@ -326,7 +325,7 @@ describe('sasjs compile single file', function () {
326
325
  return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(target, 'job', command.source, output)).toResolve()];
327
326
  case 2:
328
327
  _a.sent();
329
- expect(compileJobFile.compileJobFile).toHaveBeenCalled();
328
+ expect(compileFile.compileFile).toHaveBeenCalled();
330
329
  return [2 /*return*/];
331
330
  }
332
331
  });
@@ -350,7 +349,7 @@ describe('sasjs compile single file', function () {
350
349
  return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(target, 'job', command.source, output)).toResolve()];
351
350
  case 2:
352
351
  _a.sent();
353
- expect(compileJobFile.compileJobFile).toHaveBeenCalled();
352
+ expect(compileFile.compileFile).toHaveBeenCalled();
354
353
  return [2 /*return*/];
355
354
  }
356
355
  });
@@ -368,7 +367,7 @@ describe('sasjs compile single file', function () {
368
367
  return [4 /*yield*/, (0, config_1.findTargetInConfiguration)('viya')];
369
368
  case 2:
370
369
  target = (_a.sent()).target;
371
- jest.spyOn(compileServiceFile, 'compileServiceFile');
370
+ jest.spyOn(compileFile, 'compileFile');
372
371
  return [2 /*return*/];
373
372
  }
374
373
  });
@@ -392,7 +391,7 @@ describe('sasjs compile single file', function () {
392
391
  return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(target, 'service', command.source, output)).toResolve()];
393
392
  case 2:
394
393
  _a.sent();
395
- expect(compileServiceFile.compileServiceFile).toHaveBeenCalled();
394
+ expect(compileFile.compileFile).toHaveBeenCalled();
396
395
  return [2 /*return*/];
397
396
  }
398
397
  });
@@ -416,7 +415,24 @@ describe('sasjs compile single file', function () {
416
415
  return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(target, 'service', command.source, output)).toResolve()];
417
416
  case 2:
418
417
  _a.sent();
419
- expect(compileServiceFile.compileServiceFile).toHaveBeenCalled();
418
+ expect(compileFile.compileFile).toHaveBeenCalled();
419
+ return [2 /*return*/];
420
+ }
421
+ });
422
+ }); });
423
+ it('should compile service without duplicates', function () { return __awaiter(void 0, void 0, void 0, function () {
424
+ var compiledPath, compiledService;
425
+ return __generator(this, function (_a) {
426
+ switch (_a.label) {
427
+ case 0:
428
+ compiledPath = path_1.default.join(process.projectDir, 'sasjsbuild', 'services', 'admin', 'dostuff.sas');
429
+ return [4 /*yield*/, compileModule.compile(target)];
430
+ case 1:
431
+ _a.sent();
432
+ return [4 /*yield*/, (0, utils_1.readFile)(compiledPath)];
433
+ case 2:
434
+ compiledService = _a.sent();
435
+ expect(compiledService.match(/%macro mv_webout/g).length).toEqual(1);
420
436
  return [2 /*return*/];
421
437
  }
422
438
  });
@@ -63,7 +63,7 @@ var utils_1 = require("@sasjs/utils");
63
63
  var internalModule = __importStar(require("@sasjs/utils/sasjsCli/getInitTerm"));
64
64
  var getInitTerm_1 = require("@sasjs/utils/sasjsCli/getInitTerm");
65
65
  var test_1 = require("../../../utils/test");
66
- var compileServiceFile_1 = require("../internal/compileServiceFile");
66
+ var compileFile_1 = require("../internal/compileFile");
67
67
  var utils_2 = require("@sasjs/utils");
68
68
  var loadDependencies_1 = require("../internal/loadDependencies");
69
69
  var fakeJobInit = "/**\n @file\n @brief This code is inserted into the beginning of each Viya Job.\n @details Inserted during the `sasjs compile` step. Add any code here that\n should go at the beginning of every deployed job.\n\n The path to this file should be listed in the `jobInit` property of the\n sasjsconfig file.\n\n ".concat(utils_1.DependencyHeader.DeprecatedInclude, "\n @li test.sas TEST\n\n ").concat(utils_1.DependencyHeader.Macro, "\n @li examplemacro.sas\n\n**/\n\n%example(Job Init is executing!)\n\n%let mylib=WORK;");
@@ -76,7 +76,7 @@ var fakeProgramLines = [
76
76
  'run;'
77
77
  ];
78
78
  var preCode = '/* provide additional debug info */\n%global _program;\n%put &=syscc;\n%put user=%mf_getuser();\n%put pgm=&_program;\n%put timestamp=%sysfunc(datetime(),datetime19.);\n';
79
- describe('compileServiceFile', function () {
79
+ describe('compileFile', function () {
80
80
  var appName = "cli-tests-compile-service-file-".concat((0, utils_1.generateTimestamp)());
81
81
  var target = (0, test_1.generateTestTarget)(appName, '/Public/app', {
82
82
  serviceFolders: [path_1.default.join('sasjs', 'services')],
@@ -104,39 +104,77 @@ describe('compileServiceFile', function () {
104
104
  }
105
105
  });
106
106
  }); });
107
- test('it should compile and create file', function () { return __awaiter(void 0, void 0, void 0, function () {
108
- var filePath, buildPath, destinationPath, compileTree, compiledContent, macrosToTest;
109
- return __generator(this, function (_a) {
110
- switch (_a.label) {
111
- case 0:
112
- (0, getInitTerm_1.mockGetProgram)(internalModule, fakeJobInit, fakeJobTerm);
113
- filePath = path_1.default.join(__dirname, './service.sas');
114
- buildPath = path_1.default.join(process.projectDir, 'sasjsbuild');
115
- destinationPath = path_1.default.join(buildPath, 'service.sas');
116
- compileTree = (0, loadDependencies_1.getCompileTree)(target);
117
- return [4 /*yield*/, (0, utils_2.createFolder)(buildPath)];
118
- case 1:
119
- _a.sent();
120
- return [4 /*yield*/, (0, utils_2.copy)(filePath, destinationPath)];
121
- case 2:
122
- _a.sent();
123
- return [4 /*yield*/, expect((0, compileServiceFile_1.compileServiceFile)(target, destinationPath, [path_1.default.join(__dirname, './macros')], [path_1.default.join(__dirname, './'), path_1.default.join(__dirname, './services')], undefined, compileTree)).toResolve()];
124
- case 3:
125
- _a.sent();
126
- return [4 /*yield*/, expect((0, utils_2.fileExists)(destinationPath)).resolves.toEqual(true)];
127
- case 4:
128
- _a.sent();
129
- return [4 /*yield*/, (0, utils_2.readFile)(destinationPath)];
130
- case 5:
131
- compiledContent = _a.sent();
132
- macrosToTest = ['mf_abort', 'mf_existds'];
133
- return [4 /*yield*/, (0, test_1.verifyCompiledService)(compiledContent, macrosToTest)];
134
- case 6:
135
- _a.sent();
136
- expect(compiledContent).toEqual(expect.stringContaining(fakeProgramLines.join('\n')));
137
- expect(compiledContent).toEqual(expect.stringContaining(preCode));
138
- return [2 /*return*/];
139
- }
140
- });
141
- }); });
107
+ describe('service', function () {
108
+ test('it should compile and create file', function () { return __awaiter(void 0, void 0, void 0, function () {
109
+ var filePath, buildPath, destinationPath, compileTree, compiledContent, macrosToTest;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ (0, getInitTerm_1.mockGetProgram)(internalModule, fakeJobInit, fakeJobTerm);
114
+ filePath = path_1.default.join(__dirname, './service.sas');
115
+ buildPath = path_1.default.join(process.projectDir, 'sasjsbuild');
116
+ destinationPath = path_1.default.join(buildPath, 'service.sas');
117
+ compileTree = (0, loadDependencies_1.getCompileTree)(target);
118
+ return [4 /*yield*/, (0, utils_2.createFolder)(buildPath)];
119
+ case 1:
120
+ _a.sent();
121
+ return [4 /*yield*/, (0, utils_2.copy)(filePath, destinationPath)];
122
+ case 2:
123
+ _a.sent();
124
+ return [4 /*yield*/, expect((0, compileFile_1.compileFile)(target, destinationPath, [path_1.default.join(__dirname, './macros')], [path_1.default.join(__dirname, './'), path_1.default.join(__dirname, './services')], undefined, compileTree, utils_1.SASJsFileType.service, __dirname)).toResolve()];
125
+ case 3:
126
+ _a.sent();
127
+ return [4 /*yield*/, expect((0, utils_2.fileExists)(destinationPath)).resolves.toEqual(true)];
128
+ case 4:
129
+ _a.sent();
130
+ return [4 /*yield*/, (0, utils_2.readFile)(destinationPath)];
131
+ case 5:
132
+ compiledContent = _a.sent();
133
+ macrosToTest = ['mf_abort', 'mf_existds'];
134
+ return [4 /*yield*/, (0, test_1.verifyCompiledService)(compiledContent, macrosToTest)];
135
+ case 6:
136
+ _a.sent();
137
+ expect(compiledContent).toEqual(expect.stringContaining(fakeProgramLines.join('\n')));
138
+ expect(compiledContent).toEqual(expect.stringContaining(preCode));
139
+ return [2 /*return*/];
140
+ }
141
+ });
142
+ }); });
143
+ });
144
+ describe('job', function () {
145
+ test('it should compile and create file', function () { return __awaiter(void 0, void 0, void 0, function () {
146
+ var filePath, buildPath, destinationPath, compileTree, compiledContent, macrosToTest;
147
+ return __generator(this, function (_a) {
148
+ switch (_a.label) {
149
+ case 0:
150
+ (0, getInitTerm_1.mockGetProgram)(internalModule, fakeJobInit, fakeJobTerm);
151
+ filePath = path_1.default.join(__dirname, './service.sas');
152
+ buildPath = path_1.default.join(process.projectDir, 'sasjsbuild');
153
+ destinationPath = path_1.default.join(buildPath, 'service.sas');
154
+ compileTree = (0, loadDependencies_1.getCompileTree)(target);
155
+ return [4 /*yield*/, (0, utils_2.createFolder)(buildPath)];
156
+ case 1:
157
+ _a.sent();
158
+ return [4 /*yield*/, (0, utils_2.copy)(filePath, destinationPath)];
159
+ case 2:
160
+ _a.sent();
161
+ return [4 /*yield*/, expect((0, compileFile_1.compileFile)(target, destinationPath, [path_1.default.join(__dirname, './macros')], [path_1.default.join(__dirname, './'), path_1.default.join(__dirname, './services')], undefined, compileTree, utils_1.SASJsFileType.job, __dirname)).toResolve()];
162
+ case 3:
163
+ _a.sent();
164
+ return [4 /*yield*/, expect((0, utils_2.fileExists)(destinationPath)).resolves.toEqual(true)];
165
+ case 4:
166
+ _a.sent();
167
+ return [4 /*yield*/, (0, utils_2.readFile)(destinationPath)];
168
+ case 5:
169
+ compiledContent = _a.sent();
170
+ macrosToTest = ['mf_abort', 'mf_existds'];
171
+ return [4 /*yield*/, (0, test_1.verifyCompiledJob)(compiledContent, macrosToTest)];
172
+ case 6:
173
+ _a.sent();
174
+ expect(compiledContent).toEqual(expect.stringContaining(fakeProgramLines.join('\n')));
175
+ return [2 /*return*/];
176
+ }
177
+ });
178
+ }); });
179
+ });
142
180
  });
@@ -215,7 +215,11 @@ function deployToSasViya(deployScriptName, target, isLocal, linesToExecute, logF
215
215
  return [4 /*yield*/, getSASjsAndAuthConfig(target, isLocal)];
216
216
  case 1:
217
217
  _f = _g.sent(), sasjs = _f.sasjs, authConfig = _f.authConfig;
218
- return [4 /*yield*/, sasjs.executeScriptSASViya(deployScriptName, linesToExecute, contextName, authConfig)];
218
+ return [4 /*yield*/, sasjs
219
+ .executeScriptSASViya(deployScriptName, linesToExecute, contextName, authConfig)
220
+ .catch(function (err) {
221
+ process.logger.error('executeScriptSASViya Error', err);
222
+ })];
219
223
  case 2:
220
224
  executionResult = _g.sent();
221
225
  try {
@@ -368,7 +372,7 @@ function deployToSasjs(target, sasjs, streamConfig) {
368
372
  .deployToSASjs(payload, undefined, authConfig)
369
373
  .catch(function (err) {
370
374
  var _a;
371
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(err);
375
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('deployToSASjs Error', err);
372
376
  })];
373
377
  case 6:
374
378
  result = _d.sent();
@@ -1,5 +1,6 @@
1
1
  import SASjs from '@sasjs/adapter/node';
2
- export declare function executeJobSasjs(sasjs: SASjs, jobPath: string, logFile: string | undefined): Promise<{
2
+ import { AuthConfig } from '@sasjs/utils';
3
+ export declare function executeJobSasjs(sasjs: SASjs, jobPath: string, logFile: string | undefined, authConfig?: AuthConfig): Promise<{
3
4
  status: string;
4
5
  message: string;
5
6
  log?: string | undefined;
@@ -38,14 +38,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.executeJobSasjs = void 0;
40
40
  var utils_1 = require("../utils");
41
- function executeJobSasjs(sasjs, jobPath, logFile) {
41
+ function executeJobSasjs(sasjs, jobPath, logFile, authConfig) {
42
42
  return __awaiter(this, void 0, void 0, function () {
43
43
  var result;
44
44
  return __generator(this, function (_a) {
45
45
  switch (_a.label) {
46
46
  case 0: return [4 /*yield*/, sasjs.executeJobSASjs({
47
47
  _program: jobPath
48
- })];
48
+ }, authConfig)];
49
49
  case 1:
50
50
  result = _a.sent();
51
51
  if (!result) return [3 /*break*/, 5];
@@ -6,7 +6,7 @@ export declare class JobCommand extends TargetCommand {
6
6
  private jobSubCommands;
7
7
  constructor(args: string[]);
8
8
  execute(): Promise<ReturnCode>;
9
- executeJobSasjs(sasjs: SASjs, target: Target): Promise<ReturnCode>;
9
+ executeJobSasjs(sasjs: SASjs, target: Target, authConfig: AuthConfig | undefined): Promise<ReturnCode>;
10
10
  executeJobSas9(sasjs: SASjs, target: Target, config: {
11
11
  username: string;
12
12
  password: string;
@@ -143,7 +143,7 @@ var JobCommand = /** @class */ (function (_super) {
143
143
  JobCommand.prototype.execute = function () {
144
144
  var _a, _b;
145
145
  return __awaiter(this, void 0, void 0, function () {
146
- var target, sasjs, _c, authConfig, _d, username, password, _e, _f;
146
+ var target, sasjs, authConfig, _c, _d, username, password, _e, e_1, _f;
147
147
  return __generator(this, function (_g) {
148
148
  switch (_g.label) {
149
149
  case 0: return [4 /*yield*/, this.getTargetInfo()];
@@ -162,11 +162,11 @@ var JobCommand = /** @class */ (function (_super) {
162
162
  case utils_1.ServerType.Sas9: return [3 /*break*/, 7];
163
163
  case utils_1.ServerType.Sasjs: return [3 /*break*/, 11];
164
164
  }
165
- return [3 /*break*/, 15];
165
+ return [3 /*break*/, 19];
166
166
  case 2: return [4 /*yield*/, (0, utils_2.getAuthConfig)(target).catch(function (err) {
167
167
  var _a;
168
168
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
169
- return null;
169
+ return undefined;
170
170
  })];
171
171
  case 3:
172
172
  authConfig = _g.sent();
@@ -213,30 +213,41 @@ var JobCommand = /** @class */ (function (_super) {
213
213
  });
214
214
  if (typeof this.parsed.jobPath !== 'string')
215
215
  return [2 /*return*/, command_1.ReturnCode.InvalidCommand];
216
- if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 13];
217
- return [4 /*yield*/, this.executeJobSasjs(sasjs, target)];
216
+ _g.label = 12;
218
217
  case 12:
219
- _f = _g.sent();
220
- return [3 /*break*/, 14];
218
+ _g.trys.push([12, 14, , 15]);
219
+ return [4 /*yield*/, (0, utils_2.getAuthConfig)(target)];
221
220
  case 13:
222
- _f = command_1.ReturnCode.InvalidCommand;
223
- _g.label = 14;
224
- case 14: return [2 /*return*/, _f];
221
+ authConfig = _g.sent();
222
+ return [3 /*break*/, 15];
223
+ case 14:
224
+ e_1 = _g.sent();
225
+ return [3 /*break*/, 15];
225
226
  case 15:
227
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 17];
228
+ return [4 /*yield*/, this.executeJobSasjs(sasjs, target, authConfig)];
229
+ case 16:
230
+ _f = _g.sent();
231
+ return [3 /*break*/, 18];
232
+ case 17:
233
+ _f = command_1.ReturnCode.InvalidCommand;
234
+ _g.label = 18;
235
+ case 18: return [2 /*return*/, _f];
236
+ case 19:
226
237
  (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("This command is not supported for specified server type.\nPlease try again with a different server type.");
227
238
  return [2 /*return*/, command_1.ReturnCode.InternalError];
228
239
  }
229
240
  });
230
241
  });
231
242
  };
232
- JobCommand.prototype.executeJobSasjs = function (sasjs, target) {
243
+ JobCommand.prototype.executeJobSasjs = function (sasjs, target, authConfig) {
233
244
  return __awaiter(this, void 0, void 0, function () {
234
245
  var jobPath, returnCode;
235
246
  return __generator(this, function (_a) {
236
247
  switch (_a.label) {
237
248
  case 0:
238
249
  jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
239
- return [4 /*yield*/, (0, execute_1.executeJobSasjs)(sasjs, jobPath, this.parsed.log)
250
+ return [4 /*yield*/, (0, execute_1.executeJobSasjs)(sasjs, jobPath, this.parsed.log, authConfig)
240
251
  .then(function () { return command_1.ReturnCode.Success; })
241
252
  .catch(function (err) {
242
253
  var _a;
@@ -127,7 +127,7 @@ describe('executeJobSasjs', function () {
127
127
  case 0: return [4 /*yield*/, (0, execute_1.executeJobSasjs)(sasjs, 'test/job', path_1.default.join(process.projectDir, 'logs'))];
128
128
  case 1:
129
129
  _a.sent();
130
- expect(sasjs.executeJobSASjs).toHaveBeenCalledWith({ _program: 'test/job' });
130
+ expect(sasjs.executeJobSASjs).toHaveBeenCalledWith({ _program: 'test/job' }, undefined);
131
131
  return [2 /*return*/];
132
132
  }
133
133
  });
@@ -112,9 +112,7 @@ function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath
112
112
  debug: true
113
113
  });
114
114
  return [4 /*yield*/, sasjs
115
- .request(sasJobLocation, dataJson, configJson, function () {
116
- (0, displayResult_1.displayError)(null, 'Login callback called. Request failed.');
117
- }, authConfig)
115
+ .request(sasJobLocation, dataJson, configJson, undefined, authConfig)
118
116
  .then(function (res) { return __awaiter(_this, void 0, void 0, function () {
119
117
  var output;
120
118
  return __generator(this, function (_a) {
@@ -173,7 +171,9 @@ function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath
173
171
  error = {};
174
172
  if (err.message)
175
173
  error.message = err.message;
176
- (0, displayResult_1.displayError)(error, 'An error occurred while executing the request.');
174
+ if (err.error.message)
175
+ error.message = err.error.message;
176
+ (0, displayResult_1.displayError)(error, "An error occurred while executing the request.");
177
177
  }
178
178
  return [4 /*yield*/, saveLogFile(sasjs, sasJobLocation, logFile, jobPath)];
179
179
  case 1:
@@ -114,7 +114,7 @@ var RequestCommand = /** @class */ (function (_super) {
114
114
  }
115
115
  RequestCommand.prototype.execute = function () {
116
116
  return __awaiter(this, void 0, void 0, function () {
117
- var _a, target, isLocal, jobPath, log, output, authConfig, _b, _c, sasProgramPath, data, config;
117
+ var _a, target, isLocal, jobPath, log, output, authConfig, _b, e_1, _c, sasProgramPath, data, config;
118
118
  return __generator(this, function (_d) {
119
119
  switch (_d.label) {
120
120
  case 0: return [4 /*yield*/, this.getTargetInfo()];
@@ -125,16 +125,27 @@ var RequestCommand = /** @class */ (function (_super) {
125
125
  ? (0, getLogFilePath_1.getLogFilePath)(this.parsed.log || '', jobPath || '')
126
126
  : undefined;
127
127
  output = this.parsed.output || undefined;
128
- if (!(target.serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 3];
129
- return [4 /*yield*/, (0, utils_2.getAuthConfig)(target)];
130
- case 2:
131
- _b = _d.sent();
132
- return [3 /*break*/, 4];
128
+ _b = target.serverType;
129
+ switch (_b) {
130
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
131
+ case utils_1.ServerType.Sasjs: return [3 /*break*/, 4];
132
+ }
133
+ return [3 /*break*/, 8];
134
+ case 2: return [4 /*yield*/, (0, utils_2.getAuthConfig)(target)];
133
135
  case 3:
134
- _b = undefined;
135
- _d.label = 4;
136
+ authConfig = _d.sent();
137
+ return [3 /*break*/, 8];
136
138
  case 4:
137
- authConfig = _b;
139
+ _d.trys.push([4, 6, , 7]);
140
+ return [4 /*yield*/, (0, utils_2.getAuthConfig)(target)];
141
+ case 5:
142
+ authConfig = _d.sent();
143
+ return [3 /*break*/, 7];
144
+ case 6:
145
+ e_1 = _d.sent();
146
+ return [3 /*break*/, 7];
147
+ case 7: return [3 /*break*/, 8];
148
+ case 8:
138
149
  _c = this.parsed, sasProgramPath = _c.sasProgramPath, data = _c.data, config = _c.config;
139
150
  return [4 /*yield*/, (0, request_1.runSasJob)(target, isLocal, sasProgramPath, data, config, authConfig, log, jobPath, output)
140
151
  .then(function () {
@@ -144,7 +155,7 @@ var RequestCommand = /** @class */ (function (_super) {
144
155
  (0, utils_2.displayError)(err, 'An error has occurred when running your SAS job.');
145
156
  return command_1.ReturnCode.InternalError;
146
157
  })];
147
- case 5: return [2 /*return*/, _d.sent()];
158
+ case 9: return [2 /*return*/, _d.sent()];
148
159
  }
149
160
  });
150
161
  });
@@ -73,7 +73,12 @@ function deployToSasViyaWithServicePack(jsonFilePath, target, isLocal, isForced)
73
73
  serverUrl: target.serverUrl,
74
74
  useComputeApi: true
75
75
  });
76
- return [4 /*yield*/, sasjs.deployServicePack(jsonObject, undefined, undefined, access_token, isForced)];
76
+ return [4 /*yield*/, sasjs
77
+ .deployServicePack(jsonObject, undefined, undefined, access_token, isForced)
78
+ .catch(function (err) {
79
+ process.logger.error('deployServicePack error', err);
80
+ throw new Error('Deploy service pack error');
81
+ })];
77
82
  case 3:
78
83
  _a.sent();
79
84
  return [2 /*return*/, jsonObject];
@@ -8,7 +8,7 @@ function displaySuccess(message) {
8
8
  }
9
9
  exports.displaySuccess = displaySuccess;
10
10
  function displayError(err, errorMessage) {
11
- var _a, _b, _c;
11
+ var _a, _b, _c, _d;
12
12
  if (errorMessage === void 0) { errorMessage = ''; }
13
13
  if (errorMessage)
14
14
  errorMessage = "".concat(errorMessage, "\n");
@@ -47,5 +47,9 @@ function displayError(err, errorMessage) {
47
47
  }
48
48
  return "".concat(errorMessage).concat(failureDetails);
49
49
  }
50
+ else {
51
+ if (errorMessage)
52
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.error(errorMessage);
53
+ }
50
54
  }
51
55
  exports.displayError = displayError;
@@ -208,7 +208,7 @@ function createApp(folderPath, repoUrl, installDependencies) {
208
208
  if (installDependencies) {
209
209
  spinner.text = 'Installing dependencies...';
210
210
  spinner.start();
211
- shelljs_1.default.exec("cd \"".concat(folderPath, "\" && npm install"), {
211
+ shelljs_1.default.exec("cd \"".concat(folderPath, "\" && git init && npm install"), {
212
212
  silent: true
213
213
  });
214
214
  spinner.stop();
package/package.json CHANGED
@@ -47,10 +47,10 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@sasjs/adapter": "3.8.5",
51
- "@sasjs/core": "4.18.15",
50
+ "@sasjs/adapter": "3.9.4",
51
+ "@sasjs/core": "4.23.4",
52
52
  "@sasjs/lint": "1.11.2",
53
- "@sasjs/utils": "2.42.0",
53
+ "@sasjs/utils": "2.44.0",
54
54
  "chalk": "4.1.2",
55
55
  "csv-stringify": "5.6.5",
56
56
  "dotenv": "10.0.0",
@@ -65,7 +65,7 @@
65
65
  "ora": "5.4.1",
66
66
  "rimraf": "3.0.2",
67
67
  "shelljs": "0.8.5",
68
- "ssl-root-cas": "^1.3.1",
68
+ "ssl-root-cas": "1.3.1",
69
69
  "xml": "1.0.1",
70
70
  "yargs": "17.2.1"
71
71
  },
@@ -87,11 +87,12 @@
87
87
  "jest-cli": "27.4.7",
88
88
  "jest-extended": "1.1.0",
89
89
  "nodemon": "2.0.15",
90
+ "prettier": "2.6.2",
90
91
  "ts-jest": "27.1.2",
91
92
  "ts-node": "10.4.0",
92
93
  "tslib": "2.3.1",
93
94
  "typescript": "4.5.4",
94
95
  "util": "0.12.4"
95
96
  },
96
- "version": "3.13.2"
97
+ "version": "3.13.5"
97
98
  }
@@ -1,3 +0,0 @@
1
- import { Target } from '@sasjs/utils/types';
2
- import { CompileTree } from '@sasjs/utils';
3
- export declare function compileJobFile(target: Target, filePath: string, macroFolders: string[], programFolders: string[], programVar: string | undefined, compileTree: CompileTree): Promise<void>;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.compileJobFile = void 0;
40
- var utils_1 = require("@sasjs/utils");
41
- var loadDependencies_1 = require("./loadDependencies");
42
- function compileJobFile(target, filePath, macroFolders, programFolders, programVar, compileTree) {
43
- if (programVar === void 0) { programVar = ''; }
44
- return __awaiter(this, void 0, void 0, function () {
45
- var dependencies;
46
- return __generator(this, function (_a) {
47
- switch (_a.label) {
48
- case 0: return [4 /*yield*/, (0, loadDependencies_1.loadDependencies)(target, filePath, macroFolders, programFolders, (0, utils_1.isTestFile)(filePath) ? utils_1.SASJsFileType.test : utils_1.SASJsFileType.job, compileTree)];
49
- case 1:
50
- dependencies = _a.sent();
51
- dependencies = "".concat(programVar ? programVar + '\n' : '').concat(dependencies);
52
- return [4 /*yield*/, (0, utils_1.createFile)(filePath, dependencies)];
53
- case 2:
54
- _a.sent();
55
- return [2 /*return*/];
56
- }
57
- });
58
- });
59
- }
60
- exports.compileJobFile = compileJobFile;
@@ -1,4 +0,0 @@
1
- import { CompileTree } from '@sasjs/utils';
2
- import { Target, ServerType } from '@sasjs/utils/types';
3
- export declare function compileServiceFile(target: Target, filePath: string, macroFolders: string[], programFolders: string[], programVar: string | undefined, compileTree: CompileTree): Promise<void>;
4
- export declare function getPreCodeForServicePack(serverType: ServerType): Promise<string>;
@@ -1,140 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __generator = (this && this.__generator) || function (thisArg, body) {
31
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
- function verb(n) { return function (v) { return step([n, v]); }; }
34
- function step(op) {
35
- if (f) throw new TypeError("Generator is already executing.");
36
- while (_) try {
37
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
- if (y = 0, t) op = [op[0] & 2, t.value];
39
- switch (op[0]) {
40
- case 0: case 1: t = op; break;
41
- case 4: _.label++; return { value: op[1], done: false };
42
- case 5: _.label++; y = op[1]; op = [0]; continue;
43
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
- default:
45
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
- if (t[2]) _.ops.pop();
50
- _.trys.pop(); continue;
51
- }
52
- op = body.call(thisArg, _);
53
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
- }
56
- };
57
- var __importDefault = (this && this.__importDefault) || function (mod) {
58
- return (mod && mod.__esModule) ? mod : { "default": mod };
59
- };
60
- Object.defineProperty(exports, "__esModule", { value: true });
61
- var path_1 = __importDefault(require("path"));
62
- var utils_1 = require("@sasjs/utils");
63
- var internalModule = __importStar(require("@sasjs/utils/sasjsCli/getInitTerm"));
64
- var getInitTerm_1 = require("@sasjs/utils/sasjsCli/getInitTerm");
65
- var test_1 = require("../../../utils/test");
66
- var compileJobFile_1 = require("../internal/compileJobFile");
67
- var utils_2 = require("@sasjs/utils");
68
- var loadDependencies_1 = require("../internal/loadDependencies");
69
- var fakeJobInit = "/**\n @file\n @brief This code is inserted into the beginning of each Viya Job.\n @details Inserted during the `sasjs compile` step. Add any code here that\n should go at the beginning of every deployed job.\n\n The path to this file should be listed in the `jobInit` property of the\n sasjsconfig file.\n\n ".concat(utils_1.DependencyHeader.DeprecatedInclude, "\n @li test.sas TEST\n\n ").concat(utils_1.DependencyHeader.Macro, "\n @li examplemacro.sas\n\n**/\n\n%example(Job Init is executing!)\n\n%let mylib=WORK;");
70
- var fakeJobTerm = "/**\n @file serviceterm.sas\n @brief this file is called at the end of every service\n @details This file is included at the *end* of every service.\n\n ".concat(utils_1.DependencyHeader.Macro, "\n @li mf_abort.sas\n @li mf_existds.sas\n\n**/\n\n%put service is finishing. Thanks, SASjs!;");
71
- var fakeProgramLines = [
72
- 'filename TEST temp;',
73
- 'data _null_;',
74
- 'file TEST lrecl=32767;',
75
- "put '%put ''Hello, world!'';';",
76
- 'run;'
77
- ];
78
- describe('compileJobFile', function () {
79
- var appName = "cli-tests-compile-job-file-".concat((0, utils_1.generateTimestamp)());
80
- var target = (0, test_1.generateTestTarget)(appName, '/Public/app', {
81
- serviceFolders: [path_1.default.join('sasjs', 'services')],
82
- initProgram: '',
83
- termProgram: '',
84
- macroVars: {}
85
- }, utils_1.ServerType.SasViya);
86
- beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
89
- case 0: return [4 /*yield*/, (0, test_1.createTestMinimalApp)(__dirname, target.name)];
90
- case 1:
91
- _a.sent();
92
- return [2 /*return*/];
93
- }
94
- });
95
- }); });
96
- afterAll(function () { return __awaiter(void 0, void 0, void 0, function () {
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0: return [4 /*yield*/, (0, test_1.removeTestApp)(__dirname, target.name)];
100
- case 1:
101
- _a.sent();
102
- return [2 /*return*/];
103
- }
104
- });
105
- }); });
106
- test('it should compile and create file', function () { return __awaiter(void 0, void 0, void 0, function () {
107
- var filePath, buildPath, destinationPath, compileTree, compiledContent, macrosToTest;
108
- return __generator(this, function (_a) {
109
- switch (_a.label) {
110
- case 0:
111
- (0, getInitTerm_1.mockGetProgram)(internalModule, fakeJobInit, fakeJobTerm);
112
- filePath = path_1.default.join(__dirname, './service.sas');
113
- buildPath = path_1.default.join(process.projectDir, 'sasjsbuild');
114
- destinationPath = path_1.default.join(buildPath, 'service.sas');
115
- compileTree = (0, loadDependencies_1.getCompileTree)(target);
116
- return [4 /*yield*/, (0, utils_2.createFolder)(buildPath)];
117
- case 1:
118
- _a.sent();
119
- return [4 /*yield*/, (0, utils_2.copy)(filePath, destinationPath)];
120
- case 2:
121
- _a.sent();
122
- return [4 /*yield*/, expect((0, compileJobFile_1.compileJobFile)(target, destinationPath, [path_1.default.join(__dirname, './macros')], [path_1.default.join(__dirname, './'), path_1.default.join(__dirname, './services')], undefined, compileTree)).toResolve()];
123
- case 3:
124
- _a.sent();
125
- return [4 /*yield*/, expect((0, utils_2.fileExists)(destinationPath)).resolves.toEqual(true)];
126
- case 4:
127
- _a.sent();
128
- return [4 /*yield*/, (0, utils_2.readFile)(destinationPath)];
129
- case 5:
130
- compiledContent = _a.sent();
131
- macrosToTest = ['mf_abort', 'mf_existds'];
132
- return [4 /*yield*/, (0, test_1.verifyCompiledJob)(compiledContent, macrosToTest)];
133
- case 6:
134
- _a.sent();
135
- expect(compiledContent).toEqual(expect.stringContaining(fakeProgramLines.join('\n')));
136
- return [2 /*return*/];
137
- }
138
- });
139
- }); });
140
- });