@sasjs/cli 2.38.6 → 3.0.0
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.
- package/build/commands/add/addCredential.d.ts +2 -2
- package/build/commands/add/addCredential.js +26 -28
- package/build/commands/add/internal/input.js +15 -2
- package/build/commands/build/build.d.ts +1 -1
- package/build/commands/build/build.js +67 -56
- package/build/commands/build/internal/getLaunchPageCode.js +2 -1
- package/build/commands/compile/compile.js +18 -22
- package/build/commands/compile/internal/checkCompileStatus.js +6 -8
- package/build/commands/compile/internal/compileServiceFile.js +16 -15
- package/build/commands/compile/spec/loadDependencies.spec.js +3 -3
- package/build/commands/context/contextCommand.js +5 -5
- package/build/commands/deploy/deploy.d.ts +2 -1
- package/build/commands/deploy/deploy.js +92 -46
- package/build/commands/deploy/spec/cbd.spec.d.ts +1 -0
- package/build/commands/deploy/spec/cbd.spec.js +141 -0
- package/build/commands/deploy/spec/cbd.spec.server.js +6 -57
- package/build/commands/deploy/spec/utils.d.ts +6 -0
- package/build/commands/deploy/spec/utils.js +242 -0
- package/build/commands/docs/internal/getDocConfig.js +8 -3
- package/build/commands/docs/spec/generateDot.spec.js +0 -1
- package/build/commands/docs/spec/getDocConfig.spec.d.ts +1 -0
- package/build/commands/docs/spec/getDocConfig.spec.js +27 -0
- package/build/commands/flow/flowCommand.js +1 -1
- package/build/commands/flow/spec/flow.spec.server.js +1 -1
- package/build/commands/folder/folderCommand.js +2 -2
- package/build/commands/folder/spec/folder.spec.server.js +1 -1
- package/build/commands/job/internal/execute/index.d.ts +2 -0
- package/build/commands/job/internal/execute/index.js +14 -0
- package/build/commands/job/internal/execute/sasjs.d.ts +8 -0
- package/build/commands/job/internal/execute/sasjs.js +69 -0
- package/build/commands/job/{execute.d.ts → internal/execute/viya.d.ts} +1 -1
- package/build/commands/job/{execute.js → internal/execute/viya.js} +29 -68
- package/build/commands/job/internal/utils.d.ts +1 -0
- package/build/commands/job/internal/utils.js +81 -0
- package/build/commands/job/jobCommand.d.ts +2 -1
- package/build/commands/job/jobCommand.js +65 -23
- package/build/commands/job/spec/execute.spec.js +41 -21
- package/build/commands/job/spec/getContextName.spec.js +1 -1
- package/build/commands/job/spec/job.spec.server.js +4 -4
- package/build/commands/job/spec/jobCommand.spec.js +10 -10
- package/build/commands/request/request.js +1 -1
- package/build/commands/run/run.js +2 -2
- package/build/commands/servicepack/spec/servicepack.spec.server.js +0 -1
- package/build/commands/shared/dependencies.js +6 -9
- package/build/commands/shared/deployToSasViyaWithServicePack.js +1 -1
- package/build/commands/testing/test.js +1 -1
- package/build/commands/web/internal/createAssetServices.d.ts +5 -0
- package/build/commands/web/internal/createAssetServices.js +219 -0
- package/build/commands/web/internal/getTags.d.ts +4 -0
- package/build/commands/web/internal/getTags.js +21 -0
- package/build/commands/web/internal/getWebServiceContent.d.ts +2 -0
- package/build/commands/web/internal/getWebServiceContent.js +84 -0
- package/build/commands/web/{spec → internal/spec}/testFiles/script1.d.ts +0 -0
- package/build/commands/web/{spec → internal/spec}/testFiles/script1.js +0 -0
- package/build/commands/web/{spec → internal/spec}/testFiles/script2.d.ts +0 -0
- package/build/commands/web/{spec → internal/spec}/testFiles/script2.js +0 -0
- package/build/commands/web/{spec/updateTagSource.spec.d.ts → internal/spec/updateScriptTag.spec.d.ts} +0 -0
- package/build/commands/web/{spec/updateTagSource.spec.js → internal/spec/updateScriptTag.spec.js} +7 -7
- package/build/commands/web/internal/updateAllTags.d.ts +13 -0
- package/build/commands/web/internal/updateAllTags.js +94 -0
- package/build/commands/web/internal/updateLinkHref.d.ts +4 -0
- package/build/commands/web/internal/updateLinkHref.js +18 -0
- package/build/commands/web/internal/updateScriptTag.d.ts +5 -0
- package/build/commands/web/internal/updateScriptTag.js +85 -0
- package/build/commands/web/web.d.ts +0 -4
- package/build/commands/web/web.js +64 -378
- package/build/config.json +3 -1
- package/build/utils/config.d.ts +1 -1
- package/build/utils/config.js +106 -71
- package/build/utils/file.d.ts +1 -1
- package/build/utils/file.js +1 -1
- package/build/utils/spec/removeComments.spec.d.ts +1 -1
- package/build/utils/spec/removeComments.spec.js +1 -1
- package/build/utils/test.js +1 -1
- package/build/utils/utils.d.ts +1 -0
- package/build/utils/utils.js +8 -2
- package/package.json +14 -14
|
@@ -39,16 +39,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.getContextName = exports.
|
|
43
|
-
var displayResult_1 = require("
|
|
44
|
-
var file_1 = require("
|
|
45
|
-
var
|
|
46
|
-
var fetchLogFileContent_1 = require("../shared/fetchLogFileContent");
|
|
42
|
+
exports.getContextName = exports.executeJobViya = void 0;
|
|
43
|
+
var displayResult_1 = require("../../../../utils/displayResult");
|
|
44
|
+
var file_1 = require("../../../../utils/file");
|
|
45
|
+
var fetchLogFileContent_1 = require("../../../shared/fetchLogFileContent");
|
|
47
46
|
var path_1 = __importDefault(require("path"));
|
|
48
47
|
var node_1 = require("@sasjs/adapter/node");
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
48
|
+
var utils_1 = require("@sasjs/utils");
|
|
49
|
+
var utils_2 = require("../../../../utils/");
|
|
50
|
+
var command_1 = require("../../../../types/command");
|
|
51
|
+
var utils_3 = require("../utils");
|
|
52
52
|
/**
|
|
53
53
|
* Triggers existing job for execution.
|
|
54
54
|
* @param {object} sasjs - configuration object of SAS adapter.
|
|
@@ -64,7 +64,7 @@ var utils_3 = require("../../utils");
|
|
|
64
64
|
* @param {string | undefined} source - an optional path to a JSON file containing macro variables.
|
|
65
65
|
* @param {boolean} streamLog - a flag indicating if the logs should be streamed to the supplied log path during job execution. This is useful for getting feedback on long running jobs.
|
|
66
66
|
*/
|
|
67
|
-
function
|
|
67
|
+
function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog) {
|
|
68
68
|
var _a, _b;
|
|
69
69
|
return __awaiter(this, void 0, void 0, function () {
|
|
70
70
|
var pollOptions, result, startTime, contextName, macroVars, submittedJob, endTime, sessionLink, outputJson, currentDirPath, outputPath, folderPath, parentFolderPath, logObj, logUrl, logCount, logData, error_1;
|
|
@@ -92,18 +92,18 @@ function execute(sasjs, authConfig, jobPath, target, waitForJob, output, logFile
|
|
|
92
92
|
if (!source) return [3 /*break*/, 5];
|
|
93
93
|
if (!file_1.isJsonFile(source))
|
|
94
94
|
throw 'Source file has to be JSON.';
|
|
95
|
-
return [4 /*yield*/,
|
|
95
|
+
return [4 /*yield*/, utils_1.fileExists(source).catch(function (_) {
|
|
96
96
|
throw 'Error while checking if source file exists.';
|
|
97
97
|
})];
|
|
98
98
|
case 3:
|
|
99
99
|
_c.sent();
|
|
100
|
-
return [4 /*yield*/,
|
|
100
|
+
return [4 /*yield*/, utils_1.readFile(source).catch(function (_) {
|
|
101
101
|
throw 'Error while reading source file.';
|
|
102
102
|
})];
|
|
103
103
|
case 4:
|
|
104
104
|
source = _c.sent();
|
|
105
105
|
macroVars = JSON.parse(source);
|
|
106
|
-
if (!
|
|
106
|
+
if (!utils_1.isMacroVars(macroVars)) {
|
|
107
107
|
throw "Provided source is not valid. An example of valid source:\n{ macroVars: { name1: 'value1', name2: 'value2' } }";
|
|
108
108
|
}
|
|
109
109
|
_c.label = 5;
|
|
@@ -120,23 +120,23 @@ function execute(sasjs, authConfig, jobPath, target, waitForJob, output, logFile
|
|
|
120
120
|
return [4 /*yield*/, fetchLogFileContent_1.fetchLogFileContent(sasjs, authConfig.access_token, err.logUrl, 100000)];
|
|
121
121
|
case 1:
|
|
122
122
|
logData = _b.sent();
|
|
123
|
-
return [4 /*yield*/, saveLog(logData, logFile, jobPath, returnStatusOnly)];
|
|
123
|
+
return [4 /*yield*/, utils_3.saveLog(logData, logFile, jobPath, returnStatusOnly)];
|
|
124
124
|
case 2:
|
|
125
125
|
_b.sent();
|
|
126
126
|
_b.label = 3;
|
|
127
127
|
case 3:
|
|
128
128
|
displayResult_1.displayError(err);
|
|
129
|
-
terminateProcess(2);
|
|
129
|
+
utils_2.terminateProcess(2);
|
|
130
130
|
_b.label = 4;
|
|
131
131
|
case 4:
|
|
132
132
|
if (!(err === null || err === void 0 ? void 0 : err.log)) return [3 /*break*/, 6];
|
|
133
|
-
return [4 /*yield*/, saveLog(err.log, logFile, jobPath, returnStatusOnly)];
|
|
133
|
+
return [4 /*yield*/, utils_3.saveLog(err.log, logFile, jobPath, returnStatusOnly)];
|
|
134
134
|
case 5:
|
|
135
135
|
_b.sent();
|
|
136
136
|
_b.label = 6;
|
|
137
137
|
case 6:
|
|
138
138
|
if (returnStatusOnly)
|
|
139
|
-
terminateProcess(2);
|
|
139
|
+
utils_2.terminateProcess(2);
|
|
140
140
|
if ((err === null || err === void 0 ? void 0 : err.name) === 'NotFoundError') {
|
|
141
141
|
throw new Error("Job located at '" + jobPath + "' was not found.");
|
|
142
142
|
}
|
|
@@ -191,14 +191,14 @@ function execute(sasjs, authConfig, jobPath, target, waitForJob, output, logFile
|
|
|
191
191
|
folderPath = outputPath.split(path_1.default.sep);
|
|
192
192
|
folderPath.pop();
|
|
193
193
|
parentFolderPath = folderPath.join(path_1.default.sep);
|
|
194
|
-
return [4 /*yield*/,
|
|
194
|
+
return [4 /*yield*/, utils_1.folderExists(parentFolderPath)];
|
|
195
195
|
case 10:
|
|
196
196
|
if (!!(_c.sent())) return [3 /*break*/, 12];
|
|
197
|
-
return [4 /*yield*/,
|
|
197
|
+
return [4 /*yield*/, utils_1.createFolder(parentFolderPath)];
|
|
198
198
|
case 11:
|
|
199
199
|
_c.sent();
|
|
200
200
|
_c.label = 12;
|
|
201
|
-
case 12: return [4 /*yield*/,
|
|
201
|
+
case 12: return [4 /*yield*/, utils_1.createFile(outputPath, outputJson)];
|
|
202
202
|
case 13:
|
|
203
203
|
_c.sent();
|
|
204
204
|
if (!returnStatusOnly)
|
|
@@ -219,7 +219,7 @@ function execute(sasjs, authConfig, jobPath, target, waitForJob, output, logFile
|
|
|
219
219
|
return [4 /*yield*/, fetchLogFileContent_1.fetchLogFileContent(sasjs, authConfig.access_token, logUrl, logCount)];
|
|
220
220
|
case 16:
|
|
221
221
|
logData = _c.sent();
|
|
222
|
-
return [4 /*yield*/, saveLog(logData, logFile, jobPath, returnStatusOnly)];
|
|
222
|
+
return [4 /*yield*/, utils_3.saveLog(logData, logFile, jobPath, returnStatusOnly)];
|
|
223
223
|
case 17:
|
|
224
224
|
_c.sent();
|
|
225
225
|
_c.label = 18;
|
|
@@ -237,11 +237,11 @@ function execute(sasjs, authConfig, jobPath, target, waitForJob, output, logFile
|
|
|
237
237
|
if (waitForJob && returnStatusOnly && submittedJob.state) {
|
|
238
238
|
switch (submittedJob.state) {
|
|
239
239
|
case 'completed':
|
|
240
|
-
terminateProcess(0);
|
|
240
|
+
utils_2.terminateProcess(0);
|
|
241
241
|
case 'warning':
|
|
242
|
-
terminateProcess(ignoreWarnings ? 0 : 1);
|
|
242
|
+
utils_2.terminateProcess(ignoreWarnings ? 0 : 1);
|
|
243
243
|
case 'error':
|
|
244
|
-
terminateProcess(2);
|
|
244
|
+
utils_2.terminateProcess(2);
|
|
245
245
|
default:
|
|
246
246
|
break;
|
|
247
247
|
}
|
|
@@ -249,7 +249,7 @@ function execute(sasjs, authConfig, jobPath, target, waitForJob, output, logFile
|
|
|
249
249
|
return [3 /*break*/, 22];
|
|
250
250
|
case 21:
|
|
251
251
|
if (returnStatusOnly && result === 2) {
|
|
252
|
-
terminateProcess(2);
|
|
252
|
+
utils_2.terminateProcess(2);
|
|
253
253
|
}
|
|
254
254
|
_c.label = 22;
|
|
255
255
|
case 22:
|
|
@@ -261,12 +261,12 @@ function execute(sasjs, authConfig, jobPath, target, waitForJob, output, logFile
|
|
|
261
261
|
});
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
|
-
exports.
|
|
264
|
+
exports.executeJobViya = executeJobViya;
|
|
265
265
|
// REFACTOR: should be a utility
|
|
266
266
|
function getContextName(target, returnStatusOnly) {
|
|
267
267
|
var _a;
|
|
268
268
|
if (returnStatusOnly === void 0) { returnStatusOnly = false; }
|
|
269
|
-
var defaultContextName =
|
|
269
|
+
var defaultContextName = utils_2.contextName;
|
|
270
270
|
if (target === null || target === void 0 ? void 0 : target.contextName)
|
|
271
271
|
return target.contextName;
|
|
272
272
|
if (!returnStatusOnly) {
|
|
@@ -297,14 +297,14 @@ function displayStatus(submittedJob, statusFile, error, displayStatusFilePath) {
|
|
|
297
297
|
folderPath = statusFile.split(path_1.default.sep);
|
|
298
298
|
folderPath.pop();
|
|
299
299
|
parentFolderPath = folderPath.join(path_1.default.sep);
|
|
300
|
-
return [4 /*yield*/,
|
|
300
|
+
return [4 /*yield*/, utils_1.folderExists(parentFolderPath)];
|
|
301
301
|
case 1:
|
|
302
302
|
if (!!(_a.sent())) return [3 /*break*/, 3];
|
|
303
|
-
return [4 /*yield*/,
|
|
303
|
+
return [4 /*yield*/, utils_1.createFolder(parentFolderPath)];
|
|
304
304
|
case 2:
|
|
305
305
|
_a.sent();
|
|
306
306
|
_a.label = 3;
|
|
307
|
-
case 3: return [4 /*yield*/,
|
|
307
|
+
case 3: return [4 /*yield*/, utils_1.createFile(statusFile, status)];
|
|
308
308
|
case 4:
|
|
309
309
|
_a.sent();
|
|
310
310
|
if (displayStatusFilePath)
|
|
@@ -315,42 +315,3 @@ function displayStatus(submittedJob, statusFile, error, displayStatusFilePath) {
|
|
|
315
315
|
});
|
|
316
316
|
});
|
|
317
317
|
}
|
|
318
|
-
var saveLog = function (logData, logFile, jobPath, returnStatusOnly) { return __awaiter(void 0, void 0, void 0, function () {
|
|
319
|
-
var logPath, folderPath, parentFolderPath, logLines;
|
|
320
|
-
var _a;
|
|
321
|
-
return __generator(this, function (_b) {
|
|
322
|
-
switch (_b.label) {
|
|
323
|
-
case 0:
|
|
324
|
-
if (logFile) {
|
|
325
|
-
logPath = logFile;
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
logPath = path_1.default.join(process.projectDir, jobPath.split('/').slice(-1).pop() + ".log");
|
|
329
|
-
}
|
|
330
|
-
folderPath = logPath.split(path_1.default.sep);
|
|
331
|
-
folderPath.pop();
|
|
332
|
-
parentFolderPath = folderPath.join(path_1.default.sep);
|
|
333
|
-
return [4 /*yield*/, utils_2.folderExists(parentFolderPath)];
|
|
334
|
-
case 1:
|
|
335
|
-
if (!!(_b.sent())) return [3 /*break*/, 3];
|
|
336
|
-
return [4 /*yield*/, utils_2.createFolder(parentFolderPath)];
|
|
337
|
-
case 2:
|
|
338
|
-
_b.sent();
|
|
339
|
-
_b.label = 3;
|
|
340
|
-
case 3:
|
|
341
|
-
logLines = typeof logData === 'object' ? utils_1.parseLogLines(logData) : logData;
|
|
342
|
-
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Creating log file at " + logPath + " .");
|
|
343
|
-
return [4 /*yield*/, utils_2.createFile(logPath, logLines)];
|
|
344
|
-
case 4:
|
|
345
|
-
_b.sent();
|
|
346
|
-
if (!returnStatusOnly)
|
|
347
|
-
displayResult_1.displaySuccess("Log saved to " + logPath);
|
|
348
|
-
return [2 /*return*/];
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
}); };
|
|
352
|
-
var terminateProcess = function (status) {
|
|
353
|
-
var _a;
|
|
354
|
-
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Process will be terminated with the status code " + status + ".");
|
|
355
|
-
process.exit(status);
|
|
356
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const saveLog: (logData: any, logFile: string | undefined, jobPath: string, returnStatusOnly: boolean) => Promise<void>;
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.saveLog = void 0;
|
|
43
|
+
var path_1 = __importDefault(require("path"));
|
|
44
|
+
var utils_1 = require("@sasjs/utils");
|
|
45
|
+
var utils_2 = require("../../../utils/utils");
|
|
46
|
+
var displayResult_1 = require("../../../utils/displayResult");
|
|
47
|
+
var saveLog = function (logData, logFile, jobPath, returnStatusOnly) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
+
var logPath, folderPath, parentFolderPath, logLines;
|
|
49
|
+
var _a;
|
|
50
|
+
return __generator(this, function (_b) {
|
|
51
|
+
switch (_b.label) {
|
|
52
|
+
case 0:
|
|
53
|
+
if (logFile) {
|
|
54
|
+
logPath = logFile;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
logPath = path_1.default.join(process.projectDir, jobPath.split('/').slice(-1).pop() + ".log");
|
|
58
|
+
}
|
|
59
|
+
folderPath = logPath.split(path_1.default.sep);
|
|
60
|
+
folderPath.pop();
|
|
61
|
+
parentFolderPath = folderPath.join(path_1.default.sep);
|
|
62
|
+
return [4 /*yield*/, utils_1.folderExists(parentFolderPath)];
|
|
63
|
+
case 1:
|
|
64
|
+
if (!!(_b.sent())) return [3 /*break*/, 3];
|
|
65
|
+
return [4 /*yield*/, utils_1.createFolder(parentFolderPath)];
|
|
66
|
+
case 2:
|
|
67
|
+
_b.sent();
|
|
68
|
+
_b.label = 3;
|
|
69
|
+
case 3:
|
|
70
|
+
logLines = typeof logData === 'object' ? utils_2.parseLogLines(logData) : logData;
|
|
71
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Creating log file at " + logPath + " .");
|
|
72
|
+
return [4 /*yield*/, utils_1.createFile(logPath, logLines)];
|
|
73
|
+
case 4:
|
|
74
|
+
_b.sent();
|
|
75
|
+
if (!returnStatusOnly)
|
|
76
|
+
displayResult_1.displaySuccess("Log saved to " + logPath);
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}); };
|
|
81
|
+
exports.saveLog = saveLog;
|
|
@@ -5,5 +5,6 @@ import { TargetCommand } from '../../types/command/targetCommand';
|
|
|
5
5
|
export declare class JobCommand extends TargetCommand {
|
|
6
6
|
constructor(args: string[]);
|
|
7
7
|
execute(): Promise<ReturnCode>;
|
|
8
|
-
|
|
8
|
+
executeJobSasjs(sasjs: SASjs, target: Target): Promise<ReturnCode>;
|
|
9
|
+
executeJobViya(target: Target, sasjs: SASjs, authConfig: AuthConfig): Promise<ReturnCode>;
|
|
9
10
|
}
|
|
@@ -62,7 +62,7 @@ var command_1 = require("../../types/command");
|
|
|
62
62
|
var targetCommand_1 = require("../../types/command/targetCommand");
|
|
63
63
|
var utils_2 = require("../../utils");
|
|
64
64
|
var prefixAppLoc_1 = require("../../utils/prefixAppLoc");
|
|
65
|
-
var execute_1 = require("./execute");
|
|
65
|
+
var execute_1 = require("./internal/execute");
|
|
66
66
|
var JobSubCommand;
|
|
67
67
|
(function (JobSubCommand) {
|
|
68
68
|
JobSubCommand["Execute"] = "execute";
|
|
@@ -137,19 +137,22 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
137
137
|
JobCommand.prototype.execute = function () {
|
|
138
138
|
var _a;
|
|
139
139
|
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
-
var target, sasjs, authConfig,
|
|
141
|
-
return __generator(this, function (
|
|
142
|
-
switch (
|
|
140
|
+
var target, sasjs, _b, authConfig, _c, _d;
|
|
141
|
+
return __generator(this, function (_e) {
|
|
142
|
+
switch (_e.label) {
|
|
143
143
|
case 0: return [4 /*yield*/, this.getTargetInfo()];
|
|
144
144
|
case 1:
|
|
145
|
-
target = (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return [
|
|
145
|
+
target = (_e.sent()).target;
|
|
146
|
+
_b = target.serverType;
|
|
147
|
+
switch (_b) {
|
|
148
|
+
case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
|
|
149
|
+
case utils_1.ServerType.Sasjs: return [3 /*break*/, 7];
|
|
149
150
|
}
|
|
151
|
+
return [3 /*break*/, 11];
|
|
152
|
+
case 2:
|
|
150
153
|
sasjs = new node_1.default({
|
|
151
154
|
serverUrl: target.serverUrl,
|
|
152
|
-
|
|
155
|
+
httpsAgentOptions: target.httpsAgentOptions,
|
|
153
156
|
appLoc: target.appLoc,
|
|
154
157
|
serverType: target.serverType,
|
|
155
158
|
debug: true
|
|
@@ -159,25 +162,64 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
159
162
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
|
|
160
163
|
return null;
|
|
161
164
|
})];
|
|
162
|
-
case 2:
|
|
163
|
-
authConfig = _c.sent();
|
|
164
|
-
if (!authConfig) {
|
|
165
|
-
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
166
|
-
}
|
|
167
|
-
if (!(this.parsed.subCommand === JobSubCommand.Execute)) return [3 /*break*/, 4];
|
|
168
|
-
return [4 /*yield*/, this.executeJob(target, sasjs, authConfig)];
|
|
169
165
|
case 3:
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
authConfig = _e.sent();
|
|
167
|
+
if (!authConfig)
|
|
168
|
+
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
169
|
+
if (!(this.parsed.subCommand === JobSubCommand.Execute)) return [3 /*break*/, 5];
|
|
170
|
+
return [4 /*yield*/, this.executeJobViya(target, sasjs, authConfig)];
|
|
172
171
|
case 4:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
case 5:
|
|
172
|
+
_c = _e.sent();
|
|
173
|
+
return [3 /*break*/, 6];
|
|
174
|
+
case 5:
|
|
175
|
+
_c = command_1.ReturnCode.InvalidCommand;
|
|
176
|
+
_e.label = 6;
|
|
177
|
+
case 6: return [2 /*return*/, _c];
|
|
178
|
+
case 7:
|
|
179
|
+
sasjs = new node_1.default({
|
|
180
|
+
serverType: target.serverType,
|
|
181
|
+
serverUrl: target.serverUrl
|
|
182
|
+
});
|
|
183
|
+
if (typeof this.parsed.jobPath !== 'string')
|
|
184
|
+
return [2 /*return*/, command_1.ReturnCode.InvalidCommand];
|
|
185
|
+
if (!(this.parsed.subCommand === JobSubCommand.Execute)) return [3 /*break*/, 9];
|
|
186
|
+
return [4 /*yield*/, this.executeJobSasjs(sasjs, target)];
|
|
187
|
+
case 8:
|
|
188
|
+
_d = _e.sent();
|
|
189
|
+
return [3 /*break*/, 10];
|
|
190
|
+
case 9:
|
|
191
|
+
_d = command_1.ReturnCode.InvalidCommand;
|
|
192
|
+
_e.label = 10;
|
|
193
|
+
case 10: return [2 /*return*/, _d];
|
|
194
|
+
case 11:
|
|
195
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("This command is only supported for SAS Viya targets.\nPlease try again with a different target.");
|
|
196
|
+
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
JobCommand.prototype.executeJobSasjs = function (sasjs, target) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
var jobPath, returnCode;
|
|
204
|
+
return __generator(this, function (_a) {
|
|
205
|
+
switch (_a.label) {
|
|
206
|
+
case 0:
|
|
207
|
+
jobPath = prefixAppLoc_1.prefixAppLoc(target.appLoc, this.parsed.jobPath);
|
|
208
|
+
return [4 /*yield*/, execute_1.executeJobSasjs(sasjs, jobPath, this.parsed.log)
|
|
209
|
+
.then(function () { return command_1.ReturnCode.Success; })
|
|
210
|
+
.catch(function (err) {
|
|
211
|
+
var _a;
|
|
212
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
|
|
213
|
+
return command_1.ReturnCode.InternalError;
|
|
214
|
+
})];
|
|
215
|
+
case 1:
|
|
216
|
+
returnCode = _a.sent();
|
|
217
|
+
return [2 /*return*/, returnCode];
|
|
176
218
|
}
|
|
177
219
|
});
|
|
178
220
|
});
|
|
179
221
|
};
|
|
180
|
-
JobCommand.prototype.
|
|
222
|
+
JobCommand.prototype.executeJobViya = function (target, sasjs, authConfig) {
|
|
181
223
|
var _a, _b, _c;
|
|
182
224
|
return __awaiter(this, void 0, void 0, function () {
|
|
183
225
|
var jobPath, log, wait, output, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog, returnCode;
|
|
@@ -202,7 +244,7 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
202
244
|
if (ignoreWarnings && !returnStatusOnly) {
|
|
203
245
|
(_c = process.logger) === null || _c === void 0 ? void 0 : _c.warn("Using the 'ignoreWarnings' flag without 'returnStatusOnly' flag will not affect the sasjs job execute command.");
|
|
204
246
|
}
|
|
205
|
-
return [4 /*yield*/, execute_1.
|
|
247
|
+
return [4 /*yield*/, execute_1.executeJobViya(sasjs, authConfig, jobPath, target, wait, output, log, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog)
|
|
206
248
|
.then(function () {
|
|
207
249
|
return command_1.ReturnCode.Success;
|
|
208
250
|
})
|
|
@@ -44,42 +44,33 @@ var utils_1 = require("@sasjs/utils");
|
|
|
44
44
|
var types_1 = require("@sasjs/utils/types");
|
|
45
45
|
var path_1 = __importDefault(require("path"));
|
|
46
46
|
var utils_2 = require("../../../utils");
|
|
47
|
-
var execute_1 = require("../execute");
|
|
47
|
+
var execute_1 = require("../internal/execute");
|
|
48
48
|
var mocks_1 = require("./mocks");
|
|
49
49
|
var sasjs = new node_1.default();
|
|
50
50
|
var target = new types_1.Target({
|
|
51
51
|
name: 'test',
|
|
52
|
-
serverType: types_1.ServerType.
|
|
52
|
+
serverType: types_1.ServerType.Sasjs,
|
|
53
53
|
appLoc: '/test',
|
|
54
54
|
contextName: 'Mock Context'
|
|
55
55
|
});
|
|
56
56
|
var statusFile;
|
|
57
|
-
describe('
|
|
57
|
+
describe('executeJobViya', function () {
|
|
58
58
|
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
59
|
return __generator(this, function (_a) {
|
|
60
60
|
switch (_a.label) {
|
|
61
|
-
case 0: return [4 /*yield*/, setupMocks()];
|
|
62
|
-
case 1:
|
|
63
|
-
_a.sent();
|
|
64
|
-
statusFile = path_1.default.join(process.projectDir, 'test');
|
|
65
|
-
return [2 /*return*/];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}); });
|
|
69
|
-
afterEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
switch (_a.label) {
|
|
72
|
-
case 0: return [4 /*yield*/, utils_1.deleteFile(statusFile)];
|
|
61
|
+
case 0: return [4 /*yield*/, setupMocks(types_1.ServerType.SasViya)];
|
|
73
62
|
case 1:
|
|
74
63
|
_a.sent();
|
|
75
64
|
return [2 /*return*/];
|
|
76
65
|
}
|
|
77
66
|
});
|
|
78
67
|
}); });
|
|
68
|
+
var testFilePath = path_1.default.join(__dirname, 'test');
|
|
69
|
+
var testLogsPath = path_1.default.join(__dirname, 'logs');
|
|
79
70
|
it('should set streamLog to true when the flag is passed in', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
71
|
return __generator(this, function (_a) {
|
|
81
72
|
switch (_a.label) {
|
|
82
|
-
case 0: return [4 /*yield*/, execute_1.
|
|
73
|
+
case 0: return [4 /*yield*/, execute_1.executeJobViya(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, false, undefined, true)];
|
|
83
74
|
case 1:
|
|
84
75
|
_a.sent();
|
|
85
76
|
expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
|
|
@@ -88,8 +79,11 @@ describe('execute', function () {
|
|
|
88
79
|
maxPollCount: 24 * 60 * 60,
|
|
89
80
|
pollInterval: 1000,
|
|
90
81
|
streamLog: true,
|
|
91
|
-
logFolderPath:
|
|
82
|
+
logFolderPath: testLogsPath
|
|
92
83
|
}, true, undefined);
|
|
84
|
+
return [4 /*yield*/, utils_1.deleteFile(testFilePath)];
|
|
85
|
+
case 2:
|
|
86
|
+
_a.sent();
|
|
93
87
|
return [2 /*return*/];
|
|
94
88
|
}
|
|
95
89
|
});
|
|
@@ -97,7 +91,7 @@ describe('execute', function () {
|
|
|
97
91
|
it('should set streamLog to false when the flag is false', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
92
|
return __generator(this, function (_a) {
|
|
99
93
|
switch (_a.label) {
|
|
100
|
-
case 0: return [4 /*yield*/, execute_1.
|
|
94
|
+
case 0: return [4 /*yield*/, execute_1.executeJobViya(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, false, undefined, false)];
|
|
101
95
|
case 1:
|
|
102
96
|
_a.sent();
|
|
103
97
|
expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
|
|
@@ -106,14 +100,40 @@ describe('execute', function () {
|
|
|
106
100
|
maxPollCount: 24 * 60 * 60,
|
|
107
101
|
pollInterval: 1000,
|
|
108
102
|
streamLog: false,
|
|
109
|
-
logFolderPath:
|
|
103
|
+
logFolderPath: testLogsPath
|
|
110
104
|
}, true, undefined);
|
|
105
|
+
return [4 /*yield*/, utils_1.deleteFile(testFilePath)];
|
|
106
|
+
case 2:
|
|
107
|
+
_a.sent();
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}); });
|
|
112
|
+
});
|
|
113
|
+
describe('executeJobSasjs', function () {
|
|
114
|
+
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
115
|
+
return __generator(this, function (_a) {
|
|
116
|
+
switch (_a.label) {
|
|
117
|
+
case 0: return [4 /*yield*/, setupMocks(types_1.ServerType.Sasjs)];
|
|
118
|
+
case 1:
|
|
119
|
+
_a.sent();
|
|
120
|
+
return [2 /*return*/];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}); });
|
|
124
|
+
it('should pass job pass as a _program parameter', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
|
+
case 0: return [4 /*yield*/, execute_1.executeJobSasjs(sasjs, 'test/job', path_1.default.join(process.projectDir, 'logs'))];
|
|
128
|
+
case 1:
|
|
129
|
+
_a.sent();
|
|
130
|
+
expect(sasjs.executeJobSASjs).toHaveBeenCalledWith({ _program: 'test/job' });
|
|
111
131
|
return [2 /*return*/];
|
|
112
132
|
}
|
|
113
133
|
});
|
|
114
134
|
}); });
|
|
115
135
|
});
|
|
116
|
-
var setupMocks = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
136
|
+
var setupMocks = function (serverType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
117
137
|
return __generator(this, function (_a) {
|
|
118
138
|
switch (_a.label) {
|
|
119
139
|
case 0:
|
|
@@ -124,7 +144,7 @@ var setupMocks = function () { return __awaiter(void 0, void 0, void 0, function
|
|
|
124
144
|
jest.restoreAllMocks();
|
|
125
145
|
jest.mock('@sasjs/adapter');
|
|
126
146
|
jest
|
|
127
|
-
.spyOn(sasjs, 'startComputeJob')
|
|
147
|
+
.spyOn(sasjs, serverType === types_1.ServerType.SasViya ? 'startComputeJob' : 'executeJobSASjs')
|
|
128
148
|
.mockImplementation(function () { return Promise.resolve(); });
|
|
129
149
|
return [2 /*return*/];
|
|
130
150
|
}
|
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var utils_1 = require("../../../utils");
|
|
40
|
-
var execute_1 = require("../execute");
|
|
40
|
+
var execute_1 = require("../internal/execute");
|
|
41
41
|
describe('getContextName', function () {
|
|
42
42
|
it('should return the context name if specified in the target', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
43
|
var target;
|
|
@@ -65,7 +65,7 @@ var config_1 = require("../../../utils/config");
|
|
|
65
65
|
var test_1 = require("../../../utils/test");
|
|
66
66
|
var node_1 = __importStar(require("@sasjs/adapter/node"));
|
|
67
67
|
var utils_2 = require("../../../utils");
|
|
68
|
-
var execute_1 = require("../execute");
|
|
68
|
+
var execute_1 = require("../internal/execute");
|
|
69
69
|
var prefixAppLoc_1 = require("../../../utils/prefixAppLoc");
|
|
70
70
|
var build_1 = require("../../build/build");
|
|
71
71
|
var deploy_1 = require("../../deploy/deploy");
|
|
@@ -92,7 +92,7 @@ describe('sasjs job execute', function () {
|
|
|
92
92
|
_a.sent();
|
|
93
93
|
sasjs = new node_1.default({
|
|
94
94
|
serverUrl: target.serverUrl,
|
|
95
|
-
|
|
95
|
+
httpsAgentOptions: target.httpsAgentOptions,
|
|
96
96
|
appLoc: target.appLoc,
|
|
97
97
|
serverType: target.serverType,
|
|
98
98
|
debug: true
|
|
@@ -530,7 +530,7 @@ describe('sasjs job execute', function () {
|
|
|
530
530
|
case 0:
|
|
531
531
|
adapter = new node_1.default({
|
|
532
532
|
serverUrl: target.serverUrl,
|
|
533
|
-
|
|
533
|
+
httpsAgentOptions: target.httpsAgentOptions,
|
|
534
534
|
appLoc: target.appLoc,
|
|
535
535
|
serverType: target.serverType
|
|
536
536
|
});
|
|
@@ -611,7 +611,7 @@ var executeWrapper = function (_a) {
|
|
|
611
611
|
var _b = _a.adapter, adapter = _b === void 0 ? sasjs : _b, jobPath = _a.jobPath, _c = _a.waitForJob, waitForJob = _c === void 0 ? false : _c, _d = _a.output, output = _d === void 0 ? false : _d, _e = _a.logFile, logFile = _e === void 0 ? undefined : _e, _f = _a.statusFile, statusFile = _f === void 0 ? undefined : _f, _g = _a.returnStatusOnly, returnStatusOnly = _g === void 0 ? false : _g, _h = _a.ignoreWarnings, ignoreWarnings = _h === void 0 ? false : _h, _j = _a.source, source = _j === void 0 ? undefined : _j, _k = _a.streamLog, streamLog = _k === void 0 ? false : _k;
|
|
612
612
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
613
613
|
return __generator(this, function (_l) {
|
|
614
|
-
return [2 /*return*/, execute_1.
|
|
614
|
+
return [2 /*return*/, execute_1.executeJobViya(adapter, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog)];
|
|
615
615
|
});
|
|
616
616
|
});
|
|
617
617
|
};
|