@sasjs/cli 3.2.0 → 3.5.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/internal/compileServiceFile.js +6 -6
- package/build/commands/deploy/spec/cbd.spec.js +2 -2
- package/build/commands/job/internal/utils.js +1 -1
- package/build/commands/job/jobCommand.js +2 -14
- package/build/commands/request/request.d.ts +1 -1
- package/build/commands/request/request.js +105 -34
- package/build/commands/request/requestCommand.js +23 -3
- package/build/commands/request/spec/request.spec.server.js +108 -0
- package/build/commands/request/spec/requestCommand.spec.js +16 -6
- package/build/commands/testing/internal/saveOutput.d.ts +1 -0
- package/build/commands/testing/internal/saveOutput.js +42 -2
- package/build/commands/testing/spec/testing.spec.server.js +10 -1
- package/build/commands/testing/test.js +5 -1
- package/build/utils/displayResult.js +1 -1
- package/build/utils/getLogFilePath.d.ts +1 -0
- package/build/utils/getLogFilePath.js +21 -0
- package/build/utils/saveLog.d.ts +1 -0
- package/build/utils/saveLog.js +80 -0
- package/package.json +3 -3
|
@@ -101,8 +101,8 @@ function getPreCodeForServicePack(serverType) {
|
|
|
101
101
|
'/* so we provide instead as __program */\n' +
|
|
102
102
|
'%global __program _program;\n' +
|
|
103
103
|
'%let _program=%sysfunc(coalescec(&__program,&_program));\n' +
|
|
104
|
-
'%macro webout(action,ds,dslabel=,fmt=);\n' +
|
|
105
|
-
'%mv_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt)\n' +
|
|
104
|
+
'%macro webout(action,ds,dslabel=,fmt=,missing=NULL);\n' +
|
|
105
|
+
'%mv_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing)\n' +
|
|
106
106
|
'%mend;\n';
|
|
107
107
|
return [3 /*break*/, 14];
|
|
108
108
|
case 5:
|
|
@@ -119,8 +119,8 @@ function getPreCodeForServicePack(serverType) {
|
|
|
119
119
|
case 8:
|
|
120
120
|
content = _g + _l.sent();
|
|
121
121
|
content +=
|
|
122
|
-
' %macro webout(action,ds,dslabel=,fmt=);\n' +
|
|
123
|
-
' %mm_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt)\n' +
|
|
122
|
+
' %macro webout(action,ds,dslabel=,fmt=,missing=NULL);\n' +
|
|
123
|
+
' %mm_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing)\n' +
|
|
124
124
|
' %mend;\n';
|
|
125
125
|
return [3 /*break*/, 14];
|
|
126
126
|
case 9:
|
|
@@ -137,8 +137,8 @@ function getPreCodeForServicePack(serverType) {
|
|
|
137
137
|
case 12:
|
|
138
138
|
content = _k + _l.sent();
|
|
139
139
|
content +=
|
|
140
|
-
' %macro webout(action,ds,dslabel=,fmt=);\n' +
|
|
141
|
-
' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt)\n' +
|
|
140
|
+
' %macro webout(action,ds,dslabel=,fmt=,missing=NULL);\n' +
|
|
141
|
+
' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing)\n' +
|
|
142
142
|
' %mend;\n';
|
|
143
143
|
return [3 /*break*/, 14];
|
|
144
144
|
case 13: throw new error_1.ServerTypeError();
|
|
@@ -119,8 +119,8 @@ describe('sasjs cbd with server type SASJS', function () {
|
|
|
119
119
|
return [4 /*yield*/, utils_1.readFile(macroCorePath + "/server/ms_webout.sas")];
|
|
120
120
|
case 7:
|
|
121
121
|
ms_webout = _a.sent();
|
|
122
|
-
webout = ' %macro webout(action,ds,dslabel=,fmt=);\n' +
|
|
123
|
-
' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt)\n' +
|
|
122
|
+
webout = ' %macro webout(action,ds,dslabel=,fmt=,missing=NULL);\n' +
|
|
123
|
+
' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing)\n' +
|
|
124
124
|
' %mend;\n';
|
|
125
125
|
expect(sasjs.deployToSASjs).toHaveBeenCalledWith({
|
|
126
126
|
members: [
|
|
@@ -53,7 +53,7 @@ var saveLog = function (logData, logFile, jobPath, returnStatusOnly) { return __
|
|
|
53
53
|
logPath = logFile;
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
logPath = path_1.default.join(process.projectDir, jobPath.split(
|
|
56
|
+
logPath = path_1.default.join(process.projectDir, jobPath.split(path_1.default.sep).slice(-1).pop() + ".log");
|
|
57
57
|
}
|
|
58
58
|
folderPath = logPath.split(path_1.default.sep);
|
|
59
59
|
folderPath.pop();
|
|
@@ -61,6 +61,7 @@ var path_1 = __importDefault(require("path"));
|
|
|
61
61
|
var command_1 = require("../../types/command");
|
|
62
62
|
var targetCommand_1 = require("../../types/command/targetCommand");
|
|
63
63
|
var utils_2 = require("../../utils");
|
|
64
|
+
var getLogFilePath_1 = require("../../utils/getLogFilePath");
|
|
64
65
|
var prefixAppLoc_1 = require("../../utils/prefixAppLoc");
|
|
65
66
|
var execute_1 = require("./internal/execute");
|
|
66
67
|
var JobSubCommand;
|
|
@@ -232,7 +233,7 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
232
233
|
switch (_d.label) {
|
|
233
234
|
case 0:
|
|
234
235
|
jobPath = prefixAppLoc_1.prefixAppLoc(target.appLoc, this.parsed.jobPath);
|
|
235
|
-
log = getLogFilePath(this.parsed.log, jobPath);
|
|
236
|
+
log = getLogFilePath_1.getLogFilePath(this.parsed.log, jobPath);
|
|
236
237
|
wait = this.parsed.wait || !!log;
|
|
237
238
|
output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
|
|
238
239
|
? this.parsed.output
|
|
@@ -268,19 +269,6 @@ var JobCommand = /** @class */ (function (_super) {
|
|
|
268
269
|
return JobCommand;
|
|
269
270
|
}(targetCommand_1.TargetCommand));
|
|
270
271
|
exports.JobCommand = JobCommand;
|
|
271
|
-
var getLogFilePath = function (logArg, jobPath) {
|
|
272
|
-
if (logArg === undefined) {
|
|
273
|
-
return undefined;
|
|
274
|
-
}
|
|
275
|
-
if (logArg) {
|
|
276
|
-
var currentDirPath = path_1.default.isAbsolute(logArg)
|
|
277
|
-
? ''
|
|
278
|
-
: process.projectDir;
|
|
279
|
-
return path_1.default.join(currentDirPath, logArg);
|
|
280
|
-
}
|
|
281
|
-
var logFileName = jobPath.split('/').slice(-1).pop() + ".log";
|
|
282
|
-
return path_1.default.join(process.projectDir, logFileName);
|
|
283
|
-
};
|
|
284
272
|
var getStatusFilePath = function (statusFileArg) {
|
|
285
273
|
if (statusFileArg) {
|
|
286
274
|
var currentDirPath = path_1.default.isAbsolute(statusFileArg)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AuthConfig, Target } from '@sasjs/utils/types';
|
|
2
|
-
export declare function runSasJob(target: Target, isLocal: boolean, sasJobLocation: string, dataFilePath?: string, configFilePath?: string, authConfig?: AuthConfig): Promise<undefined>;
|
|
2
|
+
export declare function runSasJob(target: Target, isLocal: boolean, sasJobLocation: string, dataFilePath?: string, configFilePath?: string, authConfig?: AuthConfig, logFile?: string, jobPath?: string | null, outputPathParam?: string | undefined): Promise<undefined>;
|
|
@@ -46,16 +46,19 @@ var utils_1 = require("@sasjs/utils");
|
|
|
46
46
|
var displayResult_1 = require("../../utils/displayResult");
|
|
47
47
|
var types_1 = require("@sasjs/utils/types");
|
|
48
48
|
var utils_2 = require("../../utils/utils");
|
|
49
|
-
|
|
49
|
+
var saveLog_1 = require("../../utils/saveLog");
|
|
50
|
+
var getLogFilePath_1 = require("../../utils/getLogFilePath");
|
|
51
|
+
function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath, authConfig, logFile, jobPath, outputPathParam) {
|
|
50
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var dataJson, configJson, dataFile, configFile, sas9CredentialsError, sasjs, result;
|
|
53
|
+
var dataJson, configJson, dataFile, configFile, sas9CredentialsError, sasjs, result, isError, sasRequests, currentRequestLog;
|
|
52
54
|
var _this = this;
|
|
53
55
|
return __generator(this, function (_a) {
|
|
54
56
|
switch (_a.label) {
|
|
55
57
|
case 0:
|
|
56
|
-
dataJson =
|
|
58
|
+
dataJson = null;
|
|
57
59
|
configJson = {};
|
|
58
60
|
if (!dataFilePath) return [3 /*break*/, 2];
|
|
61
|
+
dataJson = {};
|
|
59
62
|
if (dataFilePath.split('.').slice(-1)[0] !== 'json') {
|
|
60
63
|
throw new Error('Provided data file must be valid json.');
|
|
61
64
|
}
|
|
@@ -106,61 +109,129 @@ function runSasJob(target, isLocal, sasJobLocation, dataFilePath, configFilePath
|
|
|
106
109
|
appLoc: target.appLoc,
|
|
107
110
|
serverType: target.serverType,
|
|
108
111
|
contextName: target.contextName,
|
|
109
|
-
useComputeApi: false
|
|
112
|
+
useComputeApi: false,
|
|
113
|
+
debug: true
|
|
110
114
|
});
|
|
111
|
-
|
|
112
|
-
dataJson = null;
|
|
115
|
+
isError = false;
|
|
113
116
|
return [4 /*yield*/, sasjs
|
|
114
117
|
.request(sasJobLocation, dataJson, configJson, function () {
|
|
115
118
|
displayResult_1.displayError(null, 'Login callback called. Request failed.');
|
|
116
119
|
}, authConfig)
|
|
117
120
|
.then(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
118
|
-
var output
|
|
121
|
+
var output;
|
|
119
122
|
return __generator(this, function (_a) {
|
|
120
123
|
switch (_a.label) {
|
|
121
124
|
case 0:
|
|
125
|
+
if ((res && res.errorCode) || res.error)
|
|
126
|
+
isError = true;
|
|
122
127
|
if (res === null || res === void 0 ? void 0 : res.result)
|
|
123
128
|
res = res.result;
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
if (typeof res !== 'object') {
|
|
130
|
+
try {
|
|
131
|
+
output = JSON.stringify(res, null, 2);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
displayResult_1.displayError(error, 'Result parsing failed.');
|
|
135
|
+
return [2 /*return*/, error];
|
|
136
|
+
}
|
|
126
137
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return [2 /*return*/, error];
|
|
138
|
+
else {
|
|
139
|
+
output = res;
|
|
130
140
|
}
|
|
131
|
-
|
|
132
|
-
return [4 /*yield*/, utils_1.folderExists(outputPath)];
|
|
141
|
+
return [4 /*yield*/, writeOutput(outputPathParam, output, isLocal)];
|
|
133
142
|
case 1:
|
|
134
|
-
if (!!(_a.sent())) return [3 /*break*/, 3];
|
|
135
|
-
return [4 /*yield*/, utils_1.createFolder(outputPath)];
|
|
136
|
-
case 2:
|
|
137
|
-
_a.sent();
|
|
138
|
-
_a.label = 3;
|
|
139
|
-
case 3:
|
|
140
|
-
outputPath += '/output.json';
|
|
141
|
-
return [4 /*yield*/, utils_1.createFile(outputPath, output)];
|
|
142
|
-
case 4:
|
|
143
143
|
_a.sent();
|
|
144
144
|
result = true;
|
|
145
|
-
displayResult_1.displaySuccess("Request finished. Output is stored at '" + outputPath + "'");
|
|
146
145
|
return [2 /*return*/];
|
|
147
146
|
}
|
|
148
147
|
});
|
|
149
148
|
}); })
|
|
150
|
-
.catch(function (err) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
149
|
+
.catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
isError = true;
|
|
154
|
+
if (err && err.errorCode === 404) {
|
|
155
|
+
utils_2.displaySasjsRunnerError(configJson.username);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
displayResult_1.displayError('', 'An error occurred while executing the request.');
|
|
159
|
+
}
|
|
160
|
+
return [4 /*yield*/, writeOutput(outputPathParam, err, isLocal)];
|
|
161
|
+
case 1:
|
|
162
|
+
_a.sent();
|
|
163
|
+
result = err;
|
|
164
|
+
return [2 /*return*/];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}); })];
|
|
159
168
|
case 5:
|
|
160
169
|
_a.sent();
|
|
161
|
-
|
|
170
|
+
sasRequests = sasjs.getSasRequests();
|
|
171
|
+
currentRequestLog = sasRequests.find(function (x) { return x.serviceLink === sasJobLocation; });
|
|
172
|
+
if (!(currentRequestLog && ((logFile && jobPath) || isError))) return [3 /*break*/, 7];
|
|
173
|
+
if (!logFile)
|
|
174
|
+
logFile = getLogFilePath_1.getLogFilePath('', jobPath || '');
|
|
175
|
+
return [4 /*yield*/, saveLog_1.saveLog(currentRequestLog.logFile, logFile, jobPath || '', false)];
|
|
176
|
+
case 6:
|
|
177
|
+
_a.sent();
|
|
178
|
+
_a.label = 7;
|
|
179
|
+
case 7: return [2 /*return*/, result];
|
|
162
180
|
}
|
|
163
181
|
});
|
|
164
182
|
});
|
|
165
183
|
}
|
|
166
184
|
exports.runSasJob = runSasJob;
|
|
185
|
+
/**
|
|
186
|
+
* Writes output to the file
|
|
187
|
+
* @param outputPathParam path to output file
|
|
188
|
+
* @param output data to be written to output file
|
|
189
|
+
* @param isLocal is local target, othervise it is global
|
|
190
|
+
* @returns output path for the file created
|
|
191
|
+
*/
|
|
192
|
+
var writeOutput = function (outputPathParam, output, isLocal) { return __awaiter(void 0, void 0, void 0, function () {
|
|
193
|
+
var outputPath, outputFilename, outputPathArr, outputString;
|
|
194
|
+
return __generator(this, function (_a) {
|
|
195
|
+
switch (_a.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
outputPath = path_1.default.join(process.projectDir, isLocal ? '' : '');
|
|
198
|
+
if (outputPathParam && typeof outputPathParam === 'string') {
|
|
199
|
+
outputPathParam = path_1.default.join(process.projectDir, outputPathParam || '');
|
|
200
|
+
outputPathArr = outputPathParam.split(path_1.default.sep);
|
|
201
|
+
outputFilename = outputPathArr.pop();
|
|
202
|
+
outputPath = outputPathArr.join(path_1.default.sep);
|
|
203
|
+
}
|
|
204
|
+
return [4 /*yield*/, utils_1.folderExists(outputPath)];
|
|
205
|
+
case 1:
|
|
206
|
+
if (!!(_a.sent())) return [3 /*break*/, 3];
|
|
207
|
+
return [4 /*yield*/, utils_1.createFolder(outputPath)];
|
|
208
|
+
case 2:
|
|
209
|
+
_a.sent();
|
|
210
|
+
_a.label = 3;
|
|
211
|
+
case 3:
|
|
212
|
+
if (outputFilename) {
|
|
213
|
+
outputPath += "" + path_1.default.sep + outputFilename;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
outputPath += path_1.default.sep + "output.json";
|
|
217
|
+
}
|
|
218
|
+
outputString = '';
|
|
219
|
+
if (typeof output === 'object') {
|
|
220
|
+
outputString = JSON.stringify(output);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
outputString = output;
|
|
224
|
+
}
|
|
225
|
+
if (!outputString) return [3 /*break*/, 5];
|
|
226
|
+
return [4 /*yield*/, utils_1.createFile(outputPath, outputString)];
|
|
227
|
+
case 4:
|
|
228
|
+
_a.sent();
|
|
229
|
+
displayResult_1.displaySuccess("Request finished. Output is stored at '" + outputPath + "'");
|
|
230
|
+
return [3 /*break*/, 6];
|
|
231
|
+
case 5:
|
|
232
|
+
displayResult_1.displayError("There was a problem with writing output file. Data not present.");
|
|
233
|
+
_a.label = 6;
|
|
234
|
+
case 6: return [2 /*return*/];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}); };
|
|
@@ -57,8 +57,9 @@ var command_1 = require("../../types/command");
|
|
|
57
57
|
var targetCommand_1 = require("../../types/command/targetCommand");
|
|
58
58
|
var utils_2 = require("../../utils");
|
|
59
59
|
var request_1 = require("./request");
|
|
60
|
+
var getLogFilePath_1 = require("../../utils/getLogFilePath");
|
|
60
61
|
var syntax = 'request <sasProgramPath> [options]';
|
|
61
|
-
var usage = 'sasjs request <sasProgramPath> --data <path-to-datafile> --config <path-to-configfile> --target <target-name>';
|
|
62
|
+
var usage = 'sasjs request <sasProgramPath> --data <path-to-datafile> --config <path-to-configfile> --target <target-name> --output <path-to-outputfile> --log <path-to-logfile>';
|
|
62
63
|
var description = "Lets the user run a SAS job against a specified target.\n" +
|
|
63
64
|
"The target can exist either in the local project configuration or in the global .sasjsrc file.";
|
|
64
65
|
var examples = [
|
|
@@ -73,6 +74,10 @@ var examples = [
|
|
|
73
74
|
{
|
|
74
75
|
command: 'sasjs request ./path/run-job.sas -t targetName -d ./path/data.json -c ./path/config.json',
|
|
75
76
|
description: ''
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
command: 'sasjs request ./path/run-job.sas -t targetName -l ./jobLog.log -o ./jobOutput.json',
|
|
80
|
+
description: ''
|
|
76
81
|
}
|
|
77
82
|
];
|
|
78
83
|
var RequestCommand = /** @class */ (function (_super) {
|
|
@@ -89,6 +94,16 @@ var RequestCommand = /** @class */ (function (_super) {
|
|
|
89
94
|
type: 'string',
|
|
90
95
|
alias: 'c',
|
|
91
96
|
description: 'The path to a json file containting the config to be used when executing a request.'
|
|
97
|
+
},
|
|
98
|
+
log: {
|
|
99
|
+
type: 'string',
|
|
100
|
+
alias: 'l',
|
|
101
|
+
description: 'Path where the log of the finished job will be saved. If used, -w is implied.'
|
|
102
|
+
},
|
|
103
|
+
output: {
|
|
104
|
+
type: 'string',
|
|
105
|
+
alias: 'o',
|
|
106
|
+
description: 'path where output of the finished job execution will be saved.'
|
|
92
107
|
}
|
|
93
108
|
},
|
|
94
109
|
syntax: syntax,
|
|
@@ -99,12 +114,17 @@ var RequestCommand = /** @class */ (function (_super) {
|
|
|
99
114
|
}
|
|
100
115
|
RequestCommand.prototype.execute = function () {
|
|
101
116
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
-
var _a, target, isLocal, authConfig, _b, _c, sasProgramPath, data, config;
|
|
117
|
+
var _a, target, isLocal, jobPath, log, output, authConfig, _b, _c, sasProgramPath, data, config;
|
|
103
118
|
return __generator(this, function (_d) {
|
|
104
119
|
switch (_d.label) {
|
|
105
120
|
case 0: return [4 /*yield*/, this.getTargetInfo()];
|
|
106
121
|
case 1:
|
|
107
122
|
_a = _d.sent(), target = _a.target, isLocal = _a.isLocal;
|
|
123
|
+
jobPath = utils_2.prefixAppLoc(target.appLoc, process.currentDir);
|
|
124
|
+
log = this.parsed.log
|
|
125
|
+
? getLogFilePath_1.getLogFilePath(this.parsed.log || '', jobPath || '')
|
|
126
|
+
: undefined;
|
|
127
|
+
output = this.parsed.output || undefined;
|
|
108
128
|
if (!(target.serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 3];
|
|
109
129
|
return [4 /*yield*/, utils_2.getAuthConfig(target)];
|
|
110
130
|
case 2:
|
|
@@ -116,7 +136,7 @@ var RequestCommand = /** @class */ (function (_super) {
|
|
|
116
136
|
case 4:
|
|
117
137
|
authConfig = _b;
|
|
118
138
|
_c = this.parsed, sasProgramPath = _c.sasProgramPath, data = _c.data, config = _c.config;
|
|
119
|
-
return [4 /*yield*/, request_1.runSasJob(target, isLocal, sasProgramPath, data, config, authConfig)
|
|
139
|
+
return [4 /*yield*/, request_1.runSasJob(target, isLocal, sasProgramPath, data, config, authConfig, log, jobPath, output)
|
|
120
140
|
.then(function () {
|
|
121
141
|
return command_1.ReturnCode.Success;
|
|
122
142
|
})
|
|
@@ -59,6 +59,8 @@ var request_1 = require("../request");
|
|
|
59
59
|
var build_1 = require("../../build/build");
|
|
60
60
|
var deploy_1 = require("../../deploy/deploy");
|
|
61
61
|
var utils_3 = require("../../../utils");
|
|
62
|
+
var getLogFilePath_1 = require("../../../utils/getLogFilePath");
|
|
63
|
+
var fs_1 = require("fs");
|
|
62
64
|
var sampleDataJson = {
|
|
63
65
|
table1: [
|
|
64
66
|
{ col1: 'first col value1', col2: 'second col value1' },
|
|
@@ -222,6 +224,59 @@ describe('sasjs request without compute API', function () {
|
|
|
222
224
|
}
|
|
223
225
|
});
|
|
224
226
|
}); });
|
|
227
|
+
it("should execute service 'sendArr' with absolute path with output path", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
228
|
+
var rawData, output;
|
|
229
|
+
return __generator(this, function (_a) {
|
|
230
|
+
switch (_a.label) {
|
|
231
|
+
case 0: return [4 /*yield*/, expect(request_1.runSasJob(target, false, "/Public/app/cli-tests/" + target.name + "/services/runRequest/sendArr", dataPathRel, undefined, authConfig, undefined, undefined, './myoutput.json')).toResolve()];
|
|
232
|
+
case 1:
|
|
233
|
+
_a.sent();
|
|
234
|
+
return [4 /*yield*/, utils_1.readFile(process.projectDir + "/myoutput.json")];
|
|
235
|
+
case 2:
|
|
236
|
+
rawData = _a.sent();
|
|
237
|
+
output = JSON.parse(rawData);
|
|
238
|
+
expect(output.table1).toEqual(expectedDataArr.table1);
|
|
239
|
+
expect(output.table2).toEqual(expectedDataArr.table2);
|
|
240
|
+
return [2 /*return*/];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}); });
|
|
244
|
+
it("should execute service 'err' with absolute path with log path", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
245
|
+
var jobPath, log, rawLogDataStats, rawDataStats;
|
|
246
|
+
return __generator(this, function (_a) {
|
|
247
|
+
switch (_a.label) {
|
|
248
|
+
case 0:
|
|
249
|
+
jobPath = utils_3.prefixAppLoc(target.appLoc, process.currentDir);
|
|
250
|
+
log = getLogFilePath_1.getLogFilePath('./mylog.txt', jobPath || '');
|
|
251
|
+
return [4 /*yield*/, expect(request_1.runSasJob(target, false, "/Public/app/cli-tests/" + target.name + "/services/runRequest/err", dataPathRel, undefined, authConfig, log, jobPath)).toResolve()];
|
|
252
|
+
case 1:
|
|
253
|
+
_a.sent();
|
|
254
|
+
rawLogDataStats = fs_1.statSync(process.projectDir + "/mylog.txt");
|
|
255
|
+
rawDataStats = fs_1.statSync(process.projectDir + "/output.json");
|
|
256
|
+
expect(rawLogDataStats.size).toBeGreaterThan(10);
|
|
257
|
+
expect(rawDataStats.size).toBeGreaterThan(10);
|
|
258
|
+
return [2 /*return*/];
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}); });
|
|
262
|
+
it("should execute service 'err' with absolute path with default log path", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
263
|
+
var jobPath, log, rawLogDataStats, rawDataStats;
|
|
264
|
+
return __generator(this, function (_a) {
|
|
265
|
+
switch (_a.label) {
|
|
266
|
+
case 0:
|
|
267
|
+
jobPath = utils_3.prefixAppLoc(target.appLoc, process.currentDir);
|
|
268
|
+
log = getLogFilePath_1.getLogFilePath('', jobPath || '');
|
|
269
|
+
return [4 /*yield*/, expect(request_1.runSasJob(target, false, "/Public/app/cli-tests/" + target.name + "/services/runRequest/err", dataPathRel, undefined, authConfig, log, jobPath)).toResolve()];
|
|
270
|
+
case 1:
|
|
271
|
+
_a.sent();
|
|
272
|
+
rawLogDataStats = fs_1.statSync(process.projectDir + "/" + target.name + ".log");
|
|
273
|
+
rawDataStats = fs_1.statSync(process.projectDir + "/output.json");
|
|
274
|
+
expect(rawLogDataStats.size).toBeGreaterThan(10);
|
|
275
|
+
expect(rawDataStats.size).toBeGreaterThan(10);
|
|
276
|
+
return [2 /*return*/];
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}); });
|
|
225
280
|
});
|
|
226
281
|
describe('sasjs request with SAS9', function () {
|
|
227
282
|
var appName = 'cli-tests-request-sas9-' + utils_2.generateTimestamp();
|
|
@@ -351,6 +406,59 @@ describe('sasjs request with SAS9', function () {
|
|
|
351
406
|
}
|
|
352
407
|
});
|
|
353
408
|
}); });
|
|
409
|
+
it("should execute service 'sendArr' with absolute path with output path", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
410
|
+
var rawData, output;
|
|
411
|
+
return __generator(this, function (_a) {
|
|
412
|
+
switch (_a.label) {
|
|
413
|
+
case 0: return [4 /*yield*/, expect(request_1.runSasJob(target, false, "/Public/app/cli-tests/" + target.name + "/services/runRequest/sendArr", dataPathRel, undefined, undefined, undefined, undefined, './myoutput.json')).toResolve()];
|
|
414
|
+
case 1:
|
|
415
|
+
_a.sent();
|
|
416
|
+
return [4 /*yield*/, utils_1.readFile(process.projectDir + "/myoutput.json")];
|
|
417
|
+
case 2:
|
|
418
|
+
rawData = _a.sent();
|
|
419
|
+
output = JSON.parse(rawData);
|
|
420
|
+
expect(output.table1).toEqual(expectedDataArr.table1);
|
|
421
|
+
expect(output.table2).toEqual(expectedDataArr.table2);
|
|
422
|
+
return [2 /*return*/];
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
}); });
|
|
426
|
+
it("should execute service 'err' with absolute path with log path", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
427
|
+
var jobPath, log, rawLogDataStats, rawDataStats;
|
|
428
|
+
return __generator(this, function (_a) {
|
|
429
|
+
switch (_a.label) {
|
|
430
|
+
case 0:
|
|
431
|
+
jobPath = utils_3.prefixAppLoc(target.appLoc, process.currentDir);
|
|
432
|
+
log = getLogFilePath_1.getLogFilePath('./mylog.txt', jobPath || '');
|
|
433
|
+
return [4 /*yield*/, expect(request_1.runSasJob(target, false, "/Public/app/cli-tests/" + target.name + "/services/runRequest/err", dataPathRel, undefined, undefined, log, jobPath)).toResolve()];
|
|
434
|
+
case 1:
|
|
435
|
+
_a.sent();
|
|
436
|
+
rawLogDataStats = fs_1.statSync(process.projectDir + "/mylog.txt");
|
|
437
|
+
rawDataStats = fs_1.statSync(process.projectDir + "/output.json");
|
|
438
|
+
expect(rawLogDataStats.size).toBeGreaterThan(10);
|
|
439
|
+
expect(rawDataStats.size).toBeGreaterThan(10);
|
|
440
|
+
return [2 /*return*/];
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
}); });
|
|
444
|
+
it("should execute service 'err' with absolute path with default log path", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
445
|
+
var jobPath, log, rawLogDataStats, rawDataStats;
|
|
446
|
+
return __generator(this, function (_a) {
|
|
447
|
+
switch (_a.label) {
|
|
448
|
+
case 0:
|
|
449
|
+
jobPath = utils_3.prefixAppLoc(target.appLoc, process.currentDir);
|
|
450
|
+
log = getLogFilePath_1.getLogFilePath('', jobPath || '');
|
|
451
|
+
return [4 /*yield*/, expect(request_1.runSasJob(target, false, "/Public/app/cli-tests/" + target.name + "/services/runRequest/err", dataPathRel, undefined, undefined, log, jobPath)).toResolve()];
|
|
452
|
+
case 1:
|
|
453
|
+
_a.sent();
|
|
454
|
+
rawLogDataStats = fs_1.statSync(process.projectDir + "/" + target.name + ".log");
|
|
455
|
+
rawDataStats = fs_1.statSync(process.projectDir + "/output.json");
|
|
456
|
+
expect(rawLogDataStats.size).toBeGreaterThan(10);
|
|
457
|
+
expect(rawDataStats.size).toBeGreaterThan(10);
|
|
458
|
+
return [2 /*return*/];
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}); });
|
|
354
462
|
});
|
|
355
463
|
describe("sasjs request with compute API", function () {
|
|
356
464
|
var appName = 'cli-tests-request-' + utils_2.generateTimestamp();
|
|
@@ -92,6 +92,8 @@ var target = new utils_1.Target({
|
|
|
92
92
|
var sasProgramPath = 'path/to/soure.sas';
|
|
93
93
|
var dataFilePath = 'path/to/data.json';
|
|
94
94
|
var configFilePath = 'path/to/config.json';
|
|
95
|
+
var outputPath = './output.txt';
|
|
96
|
+
var logPath = './log.txt';
|
|
95
97
|
describe('RequestCommand', function () {
|
|
96
98
|
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
99
|
return __generator(this, function (_a) {
|
|
@@ -122,7 +124,7 @@ describe('RequestCommand', function () {
|
|
|
122
124
|
expect(command.name).toEqual('request');
|
|
123
125
|
expect(targetInfo.target).toEqual(target);
|
|
124
126
|
expect(targetInfo.isLocal).toBeTrue();
|
|
125
|
-
expect(requestModule.runSasJob).toHaveBeenCalledWith(target, true, sasProgramPath, undefined, undefined, undefined);
|
|
127
|
+
expect(requestModule.runSasJob).toHaveBeenCalledWith(target, true, sasProgramPath, undefined, undefined, undefined, undefined, null, undefined);
|
|
126
128
|
return [2 /*return*/];
|
|
127
129
|
}
|
|
128
130
|
});
|
|
@@ -166,7 +168,7 @@ describe('RequestCommand', function () {
|
|
|
166
168
|
expect(command.name).toEqual('request');
|
|
167
169
|
expect(targetInfo.target).toEqual(mockViyaTarget);
|
|
168
170
|
expect(targetInfo.isLocal).toBeTrue();
|
|
169
|
-
expect(requestModule.runSasJob).toHaveBeenCalledWith(mockViyaTarget, true, sasProgramPath, undefined, undefined, mockAuthConfig);
|
|
171
|
+
expect(requestModule.runSasJob).toHaveBeenCalledWith(mockViyaTarget, true, sasProgramPath, undefined, undefined, mockAuthConfig, undefined, null, undefined);
|
|
170
172
|
return [2 /*return*/];
|
|
171
173
|
}
|
|
172
174
|
});
|
|
@@ -184,7 +186,11 @@ describe('RequestCommand', function () {
|
|
|
184
186
|
'--data',
|
|
185
187
|
dataFilePath,
|
|
186
188
|
'--config',
|
|
187
|
-
configFilePath
|
|
189
|
+
configFilePath,
|
|
190
|
+
'--output',
|
|
191
|
+
outputPath,
|
|
192
|
+
'--log',
|
|
193
|
+
logPath
|
|
188
194
|
]);
|
|
189
195
|
command = new requestCommand_1.RequestCommand(args);
|
|
190
196
|
return [4 /*yield*/, command.execute()];
|
|
@@ -196,7 +202,7 @@ describe('RequestCommand', function () {
|
|
|
196
202
|
expect(command.name).toEqual('request');
|
|
197
203
|
expect(targetInfo.target).toEqual(target);
|
|
198
204
|
expect(targetInfo.isLocal).toBeTrue();
|
|
199
|
-
expect(requestModule.runSasJob).toHaveBeenCalledWith(target, true, sasProgramPath, dataFilePath, configFilePath, undefined);
|
|
205
|
+
expect(requestModule.runSasJob).toHaveBeenCalledWith(target, true, sasProgramPath, dataFilePath, configFilePath, undefined, undefined, null, outputPath);
|
|
200
206
|
return [2 /*return*/];
|
|
201
207
|
}
|
|
202
208
|
});
|
|
@@ -214,7 +220,11 @@ describe('RequestCommand', function () {
|
|
|
214
220
|
'-d',
|
|
215
221
|
dataFilePath,
|
|
216
222
|
'-c',
|
|
217
|
-
configFilePath
|
|
223
|
+
configFilePath,
|
|
224
|
+
'-o',
|
|
225
|
+
outputPath,
|
|
226
|
+
'-l',
|
|
227
|
+
logPath
|
|
218
228
|
]);
|
|
219
229
|
command = new requestCommand_1.RequestCommand(args);
|
|
220
230
|
return [4 /*yield*/, command.execute()];
|
|
@@ -226,7 +236,7 @@ describe('RequestCommand', function () {
|
|
|
226
236
|
expect(command.name).toEqual('request');
|
|
227
237
|
expect(targetInfo.target).toEqual(target);
|
|
228
238
|
expect(targetInfo.isLocal).toBeTrue();
|
|
229
|
-
expect(requestModule.runSasJob).toHaveBeenCalledWith(target, true, sasProgramPath, dataFilePath, configFilePath, undefined);
|
|
239
|
+
expect(requestModule.runSasJob).toHaveBeenCalledWith(target, true, sasProgramPath, dataFilePath, configFilePath, undefined, undefined, null, outputPath);
|
|
230
240
|
return [2 /*return*/];
|
|
231
241
|
}
|
|
232
242
|
});
|
|
@@ -6,3 +6,4 @@ export declare const saveResultCsv: (outDirectory: string, result: TestResults,
|
|
|
6
6
|
csvPath: string;
|
|
7
7
|
}>;
|
|
8
8
|
export declare const saveResultXml: (outDirectory: string, result: TestResults) => Promise<string>;
|
|
9
|
+
export declare const saveCoverageLcov: (outDirectory: string, tests: string[]) => Promise<string>;
|
|
@@ -60,7 +60,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
60
60
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
61
61
|
};
|
|
62
62
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
-
exports.saveResultXml = exports.saveResultCsv = exports.saveResultJson = exports.saveLog = void 0;
|
|
63
|
+
exports.saveCoverageLcov = exports.saveResultXml = exports.saveResultCsv = exports.saveResultJson = exports.saveLog = void 0;
|
|
64
64
|
var path_1 = __importDefault(require("path"));
|
|
65
65
|
var utils_1 = require("@sasjs/utils");
|
|
66
66
|
var file_1 = require("../../../utils/file");
|
|
@@ -76,7 +76,7 @@ var saveLog = function (outDirectory, test, log, lineBreak) {
|
|
|
76
76
|
return __generator(this, function (_a) {
|
|
77
77
|
switch (_a.label) {
|
|
78
78
|
case 0:
|
|
79
|
-
logPath = path_1.default.join(outDirectory, 'logs', test.replace(file_1.sasFileRegExp, '').split(
|
|
79
|
+
logPath = path_1.default.join(outDirectory, 'logs', test.replace(file_1.sasFileRegExp, '').split(path_1.default.sep).slice(1).join('_') + '.log');
|
|
80
80
|
return [4 /*yield*/, utils_1.createFile(logPath, log)];
|
|
81
81
|
case 1:
|
|
82
82
|
_a.sent();
|
|
@@ -262,3 +262,43 @@ var saveResultXml = function (outDirectory, result) { return __awaiter(void 0, v
|
|
|
262
262
|
});
|
|
263
263
|
}); };
|
|
264
264
|
exports.saveResultXml = saveResultXml;
|
|
265
|
+
var saveCoverageLcov = function (outDirectory, tests) { return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
+
var testsPrefixRegExp, coverageReport, coveringFile, filePath;
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
switch (_a.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
testsPrefixRegExp = new RegExp("^tests/");
|
|
271
|
+
coverageReport = [];
|
|
272
|
+
coveringFile = function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
273
|
+
return __generator(this, function (_a) {
|
|
274
|
+
switch (_a.label) {
|
|
275
|
+
case 0: return [4 /*yield*/, utils_1.fileExists(path_1.default.join(process.sasjsConstants.buildDestinationFolder, filePath))];
|
|
276
|
+
case 1: return [2 /*return*/, (_a.sent())
|
|
277
|
+
? filePath
|
|
278
|
+
: 'standalone'];
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}); };
|
|
282
|
+
return [4 /*yield*/, utils_1.asyncForEach(tests, function (test) { return __awaiter(void 0, void 0, void 0, function () {
|
|
283
|
+
var _a, _b, _c;
|
|
284
|
+
return __generator(this, function (_d) {
|
|
285
|
+
switch (_d.label) {
|
|
286
|
+
case 0:
|
|
287
|
+
_b = (_a = coverageReport).push;
|
|
288
|
+
_c = "TN:" + test.split('/').pop() + "\nSF:";
|
|
289
|
+
return [4 /*yield*/, coveringFile(test.replace(testsPrefixRegExp, '').replace(utils_1.testFileRegExp, '.sas'))];
|
|
290
|
+
case 1: return [2 /*return*/, _b.apply(_a, [_c + (_d.sent()) + "\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record"])];
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}); })];
|
|
294
|
+
case 1:
|
|
295
|
+
_a.sent();
|
|
296
|
+
filePath = path_1.default.join(outDirectory, 'coverage.lcov');
|
|
297
|
+
return [4 /*yield*/, utils_1.createFile(filePath, coverageReport.join('\n'))];
|
|
298
|
+
case 2:
|
|
299
|
+
_a.sent();
|
|
300
|
+
return [2 /*return*/, filePath];
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}); };
|
|
304
|
+
exports.saveCoverageLcov = saveCoverageLcov;
|
|
@@ -99,7 +99,7 @@ describe('sasjs test', function () {
|
|
|
99
99
|
});
|
|
100
100
|
}); });
|
|
101
101
|
it('should execute tests and create result CSV, XML and JSON files using default source and output locations', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
102
|
-
var expectedResultsJson, expectedResultsCsv, resultsFolderPath, resultsJsonPath, resultsJson, resultsCsvPath, parsedResults, resultsCsv, resultsXmlPath, resultsXml, expectedResultsXml;
|
|
102
|
+
var expectedResultsJson, expectedResultsCsv, resultsFolderPath, resultsJsonPath, resultsJson, resultsCsvPath, parsedResults, resultsCsv, resultsXmlPath, resultsXml, expectedResultsXml, coverageLcovPath, expectedCoverageLcov, coverageLcov;
|
|
103
103
|
return __generator(this, function (_a) {
|
|
104
104
|
switch (_a.label) {
|
|
105
105
|
case 0:
|
|
@@ -232,6 +232,15 @@ describe('sasjs test', function () {
|
|
|
232
232
|
resultsXml = resultsXml.replace(/testsuites id="[^ ]*"/gm, "testsuites id=\"\"");
|
|
233
233
|
resultsXml = resultsXml.replace(/testcase id="[^ ]*"/gm, "testcase id=\"\"");
|
|
234
234
|
expect(resultsXml).toEqual(expectedResultsXml);
|
|
235
|
+
coverageLcovPath = path_1.default.join(resultsFolderPath, 'coverage.lcov');
|
|
236
|
+
return [4 /*yield*/, expect(utils_1.fileExists(coverageLcovPath)).resolves.toEqual(true)];
|
|
237
|
+
case 9:
|
|
238
|
+
_a.sent();
|
|
239
|
+
expectedCoverageLcov = "TN:testsetup.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:exampleprogram.test.sas\nSF:jobs/jobs/exampleprogram.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:standalone.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:examplemacro.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:shouldFail.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:dostuff.test.0.sas\nSF:services/admin/dostuff.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:dostuff.test.1.sas\nSF:services/admin/dostuff.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:testteardown.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record";
|
|
240
|
+
return [4 /*yield*/, utils_1.readFile(coverageLcovPath)];
|
|
241
|
+
case 10:
|
|
242
|
+
coverageLcov = _a.sent();
|
|
243
|
+
expect(coverageLcov).toEqual(expectedCoverageLcov);
|
|
235
244
|
return [2 /*return*/];
|
|
236
245
|
}
|
|
237
246
|
});
|
|
@@ -86,7 +86,7 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
|
|
|
86
86
|
var _a, _b;
|
|
87
87
|
if (testRegExps === void 0) { testRegExps = []; }
|
|
88
88
|
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
-
var testFlowData, testFlow, flow, sasjs, authConfig, username, password, sas9CredentialsError, result, isCodeExamplePrinted, printCodeExample, jsonPath, xmlPath, _c, csvData, csvPath, resultTable, testsCount, passedTestsCount, testsWithResultsCount;
|
|
89
|
+
var testFlowData, testFlow, flow, sasjs, authConfig, username, password, sas9CredentialsError, result, isCodeExamplePrinted, printCodeExample, jsonPath, xmlPath, _c, csvData, csvPath, coverageReportPath, resultTable, testsCount, passedTestsCount, testsWithResultsCount;
|
|
90
90
|
var _this = this;
|
|
91
91
|
return __generator(this, function (_d) {
|
|
92
92
|
switch (_d.label) {
|
|
@@ -328,6 +328,9 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
|
|
|
328
328
|
return [4 /*yield*/, saveOutput_1.saveResultCsv(outDirectory, result)];
|
|
329
329
|
case 7:
|
|
330
330
|
_c = _d.sent(), csvData = _c.csvData, csvPath = _c.csvPath;
|
|
331
|
+
return [4 /*yield*/, saveOutput_1.saveCoverageLcov(outDirectory, flow)];
|
|
332
|
+
case 8:
|
|
333
|
+
coverageReportPath = _d.sent();
|
|
331
334
|
resultTable = {};
|
|
332
335
|
if (Array.isArray(csvData)) {
|
|
333
336
|
csvData.forEach(function (item) {
|
|
@@ -353,6 +356,7 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
|
|
|
353
356
|
testsWithResultsCount = Object.values(resultTable).filter(function (res) { return res.test_suite_result !== types_1.TestResultStatus.notProvided; }).length;
|
|
354
357
|
(_b = process.logger) === null || _b === void 0 ? void 0 : _b.info("Tests provided results: " + (testsWithResultsCount + '/' + testsCount) + " (" + chalk_1.default.greenBright(Math.round((testsWithResultsCount / testsCount) * 100 || 0) + '%') + ")\n Tests that pass: " + (passedTestsCount + '/' + testsWithResultsCount) + " (" + chalk_1.default.greenBright(Math.round((passedTestsCount / testsWithResultsCount) * 100 || 0) + '%') + ")\n ");
|
|
355
358
|
displayResult_1.displaySuccess("Tests execution finished. The results are stored at:\n " + jsonPath + "\n " + csvPath + "\n " + xmlPath);
|
|
359
|
+
displayResult_1.displaySuccess("Tests coverage report:\n " + coverageReportPath);
|
|
356
360
|
return [2 /*return*/];
|
|
357
361
|
}
|
|
358
362
|
});
|
|
@@ -12,7 +12,7 @@ function displayError(err, errorMessage) {
|
|
|
12
12
|
if (errorMessage === void 0) { errorMessage = ''; }
|
|
13
13
|
if (errorMessage)
|
|
14
14
|
errorMessage = errorMessage + "\n";
|
|
15
|
-
if (err) {
|
|
15
|
+
if (err !== undefined) {
|
|
16
16
|
var failureDetails = '';
|
|
17
17
|
if (err.hasOwnProperty('error')) {
|
|
18
18
|
var body = err.error || null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getLogFilePath: (logArg: unknown, jobPath: string) => string | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getLogFilePath = void 0;
|
|
7
|
+
var path_1 = __importDefault(require("path"));
|
|
8
|
+
var getLogFilePath = function (logArg, jobPath) {
|
|
9
|
+
if (logArg === undefined || !jobPath || jobPath === '') {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
if (logArg) {
|
|
13
|
+
var currentDirPath = path_1.default.isAbsolute(logArg)
|
|
14
|
+
? ''
|
|
15
|
+
: process.projectDir;
|
|
16
|
+
return path_1.default.join(currentDirPath, logArg);
|
|
17
|
+
}
|
|
18
|
+
var logFileName = jobPath.split('/').slice(-1).pop() + ".log";
|
|
19
|
+
return path_1.default.join(process.projectDir, logFileName);
|
|
20
|
+
};
|
|
21
|
+
exports.getLogFilePath = getLogFilePath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const saveLog: (logData: any, logFile: string | undefined, jobPath: string, returnStatusOnly: boolean) => Promise<void>;
|
|
@@ -0,0 +1,80 @@
|
|
|
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 utils_1 = require("@sasjs/utils");
|
|
44
|
+
var path_1 = __importDefault(require("path"));
|
|
45
|
+
var _1 = require(".");
|
|
46
|
+
var saveLog = function (logData, logFile, jobPath, returnStatusOnly) { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
var logPath, folderPath, parentFolderPath, logLines;
|
|
48
|
+
var _a;
|
|
49
|
+
return __generator(this, function (_b) {
|
|
50
|
+
switch (_b.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
if (logFile) {
|
|
53
|
+
logPath = logFile;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
logPath = path_1.default.join(process.projectDir, jobPath.split(path_1.default.sep).slice(-1).pop() + ".log");
|
|
57
|
+
}
|
|
58
|
+
folderPath = logPath.split(path_1.default.sep);
|
|
59
|
+
folderPath.pop();
|
|
60
|
+
parentFolderPath = folderPath.join(path_1.default.sep);
|
|
61
|
+
return [4 /*yield*/, utils_1.folderExists(parentFolderPath)];
|
|
62
|
+
case 1:
|
|
63
|
+
if (!!(_b.sent())) return [3 /*break*/, 3];
|
|
64
|
+
return [4 /*yield*/, utils_1.createFolder(parentFolderPath)];
|
|
65
|
+
case 2:
|
|
66
|
+
_b.sent();
|
|
67
|
+
_b.label = 3;
|
|
68
|
+
case 3:
|
|
69
|
+
logLines = typeof logData === 'object' ? _1.parseLogLines(logData) : logData;
|
|
70
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Creating log file at " + logPath + " .");
|
|
71
|
+
return [4 /*yield*/, utils_1.createFile(logPath, logLines)];
|
|
72
|
+
case 4:
|
|
73
|
+
_b.sent();
|
|
74
|
+
if (!returnStatusOnly)
|
|
75
|
+
_1.displaySuccess("Log saved to " + logPath);
|
|
76
|
+
return [2 /*return*/];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}); };
|
|
80
|
+
exports.saveLog = saveLog;
|
package/package.json
CHANGED
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@sasjs/adapter": "3.3.
|
|
53
|
-
"@sasjs/core": "
|
|
52
|
+
"@sasjs/adapter": "3.3.1",
|
|
53
|
+
"@sasjs/core": "^3.8.0",
|
|
54
54
|
"@sasjs/lint": "1.11.2",
|
|
55
55
|
"@sasjs/utils": "2.34.1",
|
|
56
56
|
"chalk": "4.1.2",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"typescript": "4.3.5",
|
|
98
98
|
"util": "0.12.4"
|
|
99
99
|
},
|
|
100
|
-
"version": "3.
|
|
100
|
+
"version": "3.5.0"
|
|
101
101
|
}
|