@sasjs/cli 3.7.7 → 3.8.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/compile/compile.js +5 -6
- package/build/commands/compile/internal/checkCompileStatus.js +3 -4
- package/build/commands/compile/internal/compileTestFile.d.ts +3 -2
- package/build/commands/compile/internal/compileTestFile.js +26 -13
- package/build/commands/compile/internal/getAllFolders.d.ts +6 -0
- package/build/commands/compile/internal/{getAllJobFolders.js → getAllFolders.js} +49 -23
- package/build/commands/compile/internal/identifySasFile.js +3 -4
- package/build/commands/compile/internal/spec/compileTestFile.spec.js +37 -0
- package/build/commands/compile/internal/spec/getAllFolders.spec.d.ts +1 -0
- package/build/commands/compile/internal/spec/getAllFolders.spec.js +184 -0
- package/build/commands/compile/spec/copyFilesToBuildFolder.spec.js +2 -4
- package/build/commands/deploy/deploy.js +27 -21
- package/build/commands/job/internal/execute/index.d.ts +1 -0
- package/build/commands/job/internal/execute/index.js +1 -0
- package/build/commands/job/internal/execute/sas9.d.ts +14 -0
- package/build/commands/job/internal/execute/sas9.js +139 -0
- package/build/commands/job/jobCommand.d.ts +4 -0
- package/build/commands/job/jobCommand.js +86 -32
- package/build/commands/job/spec/jobCommand.spec.js +406 -251
- package/build/commands/testing/test.js +3 -4
- package/build/utils/test.d.ts +2 -2
- package/build/utils/test.js +8 -5
- package/package.json +3 -3
- package/build/commands/compile/internal/getAllJobFolders.d.ts +0 -2
- package/build/commands/compile/internal/getAllServiceFolders.d.ts +0 -2
- package/build/commands/compile/internal/getAllServiceFolders.js +0 -91
|
@@ -0,0 +1,139 @@
|
|
|
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.executeJobSas9 = void 0;
|
|
43
|
+
var path_1 = __importDefault(require("path"));
|
|
44
|
+
var utils_1 = require("@sasjs/utils");
|
|
45
|
+
var file_1 = require("../../../../utils/file");
|
|
46
|
+
var displayResult_1 = require("../../../../utils/displayResult");
|
|
47
|
+
var utils_2 = require("../utils");
|
|
48
|
+
/**
|
|
49
|
+
* Triggers an existing Stored Process for execution as a "job". See online documentation here: https://cli.sasjs.io/job/
|
|
50
|
+
* @param {object} sasjs - Configuration object of the SASJS adapter.
|
|
51
|
+
* @param {object} config - An object containing the username and password for authentication.
|
|
52
|
+
* @param {string} jobPath - Location of the Stored Process in SAS metadata (_program).
|
|
53
|
+
* @param {string | undefined} logFile - If provided, the CLI will write the log here.
|
|
54
|
+
* @param {string | undefined} output - If provided, and valid JSON is returned (ie using the SASjs macros), it will be written to this file location.
|
|
55
|
+
* @param {string | undefined} source - An optional path to a JSON file containing input macro variables.
|
|
56
|
+
*/
|
|
57
|
+
function executeJobSas9(sasjs, config, jobPath, logFile, output, source) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var macroVars, currentDirPath, startTime, result, endTime, outputJson, currentDirPath, outputPath, folderPath, parentFolderPath, error_1;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
macroVars = null;
|
|
64
|
+
if (!source) return [3 /*break*/, 3];
|
|
65
|
+
currentDirPath = path_1.default.isAbsolute(source) ? '' : process.projectDir;
|
|
66
|
+
source = path_1.default.join(currentDirPath, source);
|
|
67
|
+
if (!(0, file_1.isJsonFile)(source))
|
|
68
|
+
throw 'Source file has to be JSON.';
|
|
69
|
+
return [4 /*yield*/, (0, utils_1.fileExists)(source).catch(function (_) {
|
|
70
|
+
throw 'Error while checking if source file exists.';
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
_a.sent();
|
|
74
|
+
return [4 /*yield*/, (0, utils_1.readFile)(source).catch(function (_) {
|
|
75
|
+
throw 'Error while reading source file.';
|
|
76
|
+
})];
|
|
77
|
+
case 2:
|
|
78
|
+
source = _a.sent();
|
|
79
|
+
macroVars = JSON.parse(source);
|
|
80
|
+
if (!(0, utils_1.isMacroVars)(macroVars)) {
|
|
81
|
+
throw "Provided source is not valid. An example of valid source:\n{ macroVars: { name1: 'value1', name2: 'value2' } }";
|
|
82
|
+
}
|
|
83
|
+
_a.label = 3;
|
|
84
|
+
case 3:
|
|
85
|
+
startTime = new Date().getTime();
|
|
86
|
+
return [4 /*yield*/, sasjs.request(jobPath, macroVars, config)];
|
|
87
|
+
case 4:
|
|
88
|
+
result = _a.sent();
|
|
89
|
+
endTime = new Date().getTime();
|
|
90
|
+
if (!result) return [3 /*break*/, 15];
|
|
91
|
+
if (!(result.status === 200)) return [3 /*break*/, 14];
|
|
92
|
+
process.logger.success("Job executed successfully! in ".concat((endTime - startTime) / 1000, " seconds"));
|
|
93
|
+
if (!(!!logFile && result.log)) return [3 /*break*/, 6];
|
|
94
|
+
return [4 /*yield*/, (0, utils_2.saveLog)(result.log, logFile, jobPath, false)];
|
|
95
|
+
case 5:
|
|
96
|
+
_a.sent();
|
|
97
|
+
_a.label = 6;
|
|
98
|
+
case 6:
|
|
99
|
+
if (!(!!output && result.result)) return [3 /*break*/, 13];
|
|
100
|
+
_a.label = 7;
|
|
101
|
+
case 7:
|
|
102
|
+
_a.trys.push([7, 12, , 13]);
|
|
103
|
+
outputJson = JSON.stringify(result.result, null, 2);
|
|
104
|
+
currentDirPath = path_1.default.isAbsolute(output)
|
|
105
|
+
? ''
|
|
106
|
+
: process.projectDir;
|
|
107
|
+
outputPath = path_1.default.join(currentDirPath, /\.[a-z]{3,4}$/i.test(output)
|
|
108
|
+
? output
|
|
109
|
+
: path_1.default.join(output, 'output.json'));
|
|
110
|
+
folderPath = outputPath.split(path_1.default.sep);
|
|
111
|
+
folderPath.pop();
|
|
112
|
+
parentFolderPath = folderPath.join(path_1.default.sep);
|
|
113
|
+
return [4 /*yield*/, (0, utils_1.folderExists)(parentFolderPath)];
|
|
114
|
+
case 8:
|
|
115
|
+
if (!!(_a.sent())) return [3 /*break*/, 10];
|
|
116
|
+
return [4 /*yield*/, (0, utils_1.createFolder)(parentFolderPath)];
|
|
117
|
+
case 9:
|
|
118
|
+
_a.sent();
|
|
119
|
+
_a.label = 10;
|
|
120
|
+
case 10: return [4 /*yield*/, (0, utils_1.createFile)(outputPath, outputJson)];
|
|
121
|
+
case 11:
|
|
122
|
+
_a.sent();
|
|
123
|
+
(0, displayResult_1.displaySuccess)("Output saved to: ".concat(outputPath));
|
|
124
|
+
return [3 /*break*/, 13];
|
|
125
|
+
case 12:
|
|
126
|
+
error_1 = _a.sent();
|
|
127
|
+
(0, displayResult_1.displayError)(error_1, 'An error has occurred when parsing an output of the job.');
|
|
128
|
+
return [3 /*break*/, 13];
|
|
129
|
+
case 13: return [3 /*break*/, 15];
|
|
130
|
+
case 14:
|
|
131
|
+
process.logger.error(result.message);
|
|
132
|
+
process.logger.error(JSON.stringify(result.error, null, 2));
|
|
133
|
+
_a.label = 15;
|
|
134
|
+
case 15: return [2 /*return*/, result];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
exports.executeJobSas9 = executeJobSas9;
|
|
@@ -7,5 +7,9 @@ export declare class JobCommand extends TargetCommand {
|
|
|
7
7
|
constructor(args: string[]);
|
|
8
8
|
execute(): Promise<ReturnCode>;
|
|
9
9
|
executeJobSasjs(sasjs: SASjs, target: Target): Promise<ReturnCode>;
|
|
10
|
+
executeJobSas9(sasjs: SASjs, target: Target, config: {
|
|
11
|
+
username: string;
|
|
12
|
+
password: string;
|
|
13
|
+
}): Promise<ReturnCode>;
|
|
10
14
|
executeJobViya(target: Target, sasjs: SASjs, authConfig: AuthConfig): Promise<ReturnCode>;
|
|
11
15
|
}
|
|
@@ -141,21 +141,14 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
141
141
|
return _this;
|
|
142
142
|
}
|
|
143
143
|
JobCommand.prototype.execute = function () {
|
|
144
|
-
var _a;
|
|
144
|
+
var _a, _b;
|
|
145
145
|
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
-
var target, sasjs,
|
|
147
|
-
return __generator(this, function (
|
|
148
|
-
switch (
|
|
146
|
+
var target, sasjs, _c, authConfig, _d, username, password, _e, _f;
|
|
147
|
+
return __generator(this, function (_g) {
|
|
148
|
+
switch (_g.label) {
|
|
149
149
|
case 0: return [4 /*yield*/, this.getTargetInfo()];
|
|
150
150
|
case 1:
|
|
151
|
-
target = (
|
|
152
|
-
_b = target.serverType;
|
|
153
|
-
switch (_b) {
|
|
154
|
-
case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
|
|
155
|
-
case utils_1.ServerType.Sasjs: return [3 /*break*/, 7];
|
|
156
|
-
}
|
|
157
|
-
return [3 /*break*/, 11];
|
|
158
|
-
case 2:
|
|
151
|
+
target = (_g.sent()).target;
|
|
159
152
|
sasjs = new node_1.default({
|
|
160
153
|
serverUrl: target.serverUrl,
|
|
161
154
|
httpsAgentOptions: target.httpsAgentOptions,
|
|
@@ -163,42 +156,74 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
163
156
|
serverType: target.serverType,
|
|
164
157
|
debug: true
|
|
165
158
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
_c = target.serverType;
|
|
160
|
+
switch (_c) {
|
|
161
|
+
case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
|
|
162
|
+
case utils_1.ServerType.Sas9: return [3 /*break*/, 7];
|
|
163
|
+
case utils_1.ServerType.Sasjs: return [3 /*break*/, 11];
|
|
164
|
+
}
|
|
165
|
+
return [3 /*break*/, 15];
|
|
166
|
+
case 2: return [4 /*yield*/, (0, utils_2.getAuthConfig)(target).catch(function (err) {
|
|
167
|
+
var _a;
|
|
168
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
|
|
169
|
+
return null;
|
|
170
|
+
})];
|
|
171
171
|
case 3:
|
|
172
|
-
authConfig =
|
|
172
|
+
authConfig = _g.sent();
|
|
173
173
|
if (!authConfig)
|
|
174
174
|
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
175
175
|
if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 5];
|
|
176
176
|
return [4 /*yield*/, this.executeJobViya(target, sasjs, authConfig)];
|
|
177
177
|
case 4:
|
|
178
|
-
|
|
178
|
+
_d = _g.sent();
|
|
179
179
|
return [3 /*break*/, 6];
|
|
180
180
|
case 5:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
case 6: return [2 /*return*/,
|
|
181
|
+
_d = command_1.ReturnCode.InvalidCommand;
|
|
182
|
+
_g.label = 6;
|
|
183
|
+
case 6: return [2 /*return*/, _d];
|
|
184
184
|
case 7:
|
|
185
|
+
username = void 0;
|
|
186
|
+
password = void 0;
|
|
187
|
+
if (target.authConfigSas9) {
|
|
188
|
+
username = target.authConfigSas9.userName;
|
|
189
|
+
password = target.authConfigSas9.password;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
username = process.env.SAS_USERNAME;
|
|
193
|
+
password = process.env.SAS_PASSWORD;
|
|
194
|
+
}
|
|
195
|
+
if (!username || !password) {
|
|
196
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. username and password not found');
|
|
197
|
+
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
198
|
+
}
|
|
199
|
+
password = (0, utils_1.decodeFromBase64)(password);
|
|
200
|
+
if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 9];
|
|
201
|
+
return [4 /*yield*/, this.executeJobSas9(sasjs, target, { username: username, password: password })];
|
|
202
|
+
case 8:
|
|
203
|
+
_e = _g.sent();
|
|
204
|
+
return [3 /*break*/, 10];
|
|
205
|
+
case 9:
|
|
206
|
+
_e = command_1.ReturnCode.InvalidCommand;
|
|
207
|
+
_g.label = 10;
|
|
208
|
+
case 10: return [2 /*return*/, _e];
|
|
209
|
+
case 11:
|
|
185
210
|
sasjs = new node_1.default({
|
|
186
211
|
serverType: target.serverType,
|
|
187
212
|
serverUrl: target.serverUrl
|
|
188
213
|
});
|
|
189
214
|
if (typeof this.parsed.jobPath !== 'string')
|
|
190
215
|
return [2 /*return*/, command_1.ReturnCode.InvalidCommand];
|
|
191
|
-
if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/,
|
|
216
|
+
if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 13];
|
|
192
217
|
return [4 /*yield*/, this.executeJobSasjs(sasjs, target)];
|
|
193
|
-
case
|
|
194
|
-
|
|
195
|
-
return [3 /*break*/,
|
|
196
|
-
case
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
case
|
|
200
|
-
case
|
|
201
|
-
(
|
|
218
|
+
case 12:
|
|
219
|
+
_f = _g.sent();
|
|
220
|
+
return [3 /*break*/, 14];
|
|
221
|
+
case 13:
|
|
222
|
+
_f = command_1.ReturnCode.InvalidCommand;
|
|
223
|
+
_g.label = 14;
|
|
224
|
+
case 14: return [2 /*return*/, _f];
|
|
225
|
+
case 15:
|
|
226
|
+
(_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.");
|
|
202
227
|
return [2 /*return*/, command_1.ReturnCode.InternalError];
|
|
203
228
|
}
|
|
204
229
|
});
|
|
@@ -225,6 +250,35 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
225
250
|
});
|
|
226
251
|
});
|
|
227
252
|
};
|
|
253
|
+
JobCommand.prototype.executeJobSas9 = function (sasjs, target, config) {
|
|
254
|
+
var _a;
|
|
255
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
256
|
+
var jobPath, log, output, source, returnCode;
|
|
257
|
+
return __generator(this, function (_b) {
|
|
258
|
+
switch (_b.label) {
|
|
259
|
+
case 0:
|
|
260
|
+
jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
|
|
261
|
+
log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
|
|
262
|
+
output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
|
|
263
|
+
? this.parsed.output
|
|
264
|
+
: undefined;
|
|
265
|
+
source = this.parsed.source;
|
|
266
|
+
return [4 /*yield*/, (0, execute_1.executeJobSas9)(sasjs, config, jobPath, log, output, source)
|
|
267
|
+
.then(function () {
|
|
268
|
+
return command_1.ReturnCode.Success;
|
|
269
|
+
})
|
|
270
|
+
.catch(function (err) {
|
|
271
|
+
var _a;
|
|
272
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
|
|
273
|
+
return command_1.ReturnCode.InternalError;
|
|
274
|
+
})];
|
|
275
|
+
case 1:
|
|
276
|
+
returnCode = _b.sent();
|
|
277
|
+
return [2 /*return*/, returnCode];
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
};
|
|
228
282
|
JobCommand.prototype.executeJobViya = function (target, sasjs, authConfig) {
|
|
229
283
|
var _a, _b, _c;
|
|
230
284
|
return __awaiter(this, void 0, void 0, function () {
|