@sasjs/cli 3.21.0 → 3.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/build/commands/deploy/deploy.d.ts +3 -5
  2. package/build/commands/deploy/deploy.js +54 -300
  3. package/build/commands/deploy/internal/deployToSASJSWithServicePack.d.ts +7 -0
  4. package/build/commands/deploy/internal/deployToSASJSWithServicePack.js +95 -0
  5. package/build/commands/deploy/internal/executeDeployScript.d.ts +2 -0
  6. package/build/commands/deploy/internal/executeDeployScript.js +55 -0
  7. package/build/commands/deploy/internal/executeDeployScriptSas9.d.ts +12 -0
  8. package/build/commands/deploy/internal/executeDeployScriptSas9.js +106 -0
  9. package/build/commands/deploy/internal/executeDeployScriptSasViya.d.ts +12 -0
  10. package/build/commands/deploy/internal/executeDeployScriptSasViya.js +108 -0
  11. package/build/commands/deploy/internal/executeDeployScriptSasjs.d.ts +12 -0
  12. package/build/commands/deploy/internal/executeDeployScriptSasjs.js +109 -0
  13. package/build/commands/deploy/internal/executeNonSasScript.d.ts +1 -0
  14. package/build/commands/deploy/internal/executeNonSasScript.js +77 -0
  15. package/build/commands/deploy/internal/executeSasScript.d.ts +8 -0
  16. package/build/commands/deploy/internal/executeSasScript.js +109 -0
  17. package/build/commands/deploy/internal/getDeployScripts.js +8 -17
  18. package/build/commands/deploy/internal/index.d.ts +8 -0
  19. package/build/commands/deploy/internal/index.js +20 -0
  20. package/build/commands/deploy/spec/cbd.spec.js +2 -2
  21. package/build/commands/deploy/spec/deploy.spec.d.ts +1 -0
  22. package/build/commands/deploy/spec/deploy.spec.js +317 -0
  23. package/build/commands/deploy/spec/getDeployScripts.spec.js +35 -27
  24. package/build/utils/file.d.ts +1 -0
  25. package/build/utils/file.js +6 -2
  26. package/build/utils/utils.d.ts +1 -0
  27. package/build/utils/utils.js +66 -1
  28. package/package.json +4 -2
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.executeDeployScriptSas9 = void 0;
40
+ var config_1 = require("../../../utils/config");
41
+ var utils_1 = require("../../../utils/utils");
42
+ var utils_2 = require("@sasjs/utils");
43
+ var _1 = require("./");
44
+ /**
45
+ * Execute deployScript on `SAS9` server.
46
+ * @param {string} deployScriptName - name of deploy script.
47
+ * @param {Target} target - the target having deploy configuration.
48
+ * @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
49
+ * @param {string} logFolder - optional path to log folder,
50
+ * log file name will be <deploy-script-name>.log
51
+ * @param {object} streamConfig - optional configuration object of StreamConfig
52
+ * for printing web app url on console.
53
+ */
54
+ function executeDeployScriptSas9(deployScriptName, target, linesToExecute, logFilePath, streamConfig) {
55
+ var _a, _b, _c, _d;
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var _e, sasjs, authConfigSas9, userName, password, completedWithError, executionResult, logContent, appLoc, webAppStreamUrl;
58
+ return __generator(this, function (_f) {
59
+ switch (_f.label) {
60
+ case 0: return [4 /*yield*/, (0, config_1.getSASjsAndAuthConfig)(target)];
61
+ case 1:
62
+ _e = _f.sent(), sasjs = _e.sasjs, authConfigSas9 = _e.authConfigSas9;
63
+ userName = authConfigSas9.userName;
64
+ password = (0, utils_2.decodeFromBase64)(authConfigSas9.userName);
65
+ completedWithError = false;
66
+ return [4 /*yield*/, sasjs
67
+ .executeScript({
68
+ linesOfCode: linesToExecute,
69
+ authConfigSas9: { userName: userName, password: password }
70
+ })
71
+ .catch(function (err) {
72
+ var _a;
73
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.log((0, _1.formatErrorString)(err));
74
+ if (err && err.errorCode === 404) {
75
+ (0, utils_1.displaySasjsRunnerError)(userName);
76
+ }
77
+ completedWithError = true;
78
+ return err;
79
+ })];
80
+ case 2:
81
+ executionResult = _f.sent();
82
+ if (!executionResult) {
83
+ return [2 /*return*/, (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error getting execution log')];
84
+ }
85
+ logContent = completedWithError
86
+ ? executionResult.result
87
+ : executionResult;
88
+ return [4 /*yield*/, (0, utils_2.createFile)(logFilePath, logContent !== null && logContent !== void 0 ? logContent : '')];
89
+ case 3:
90
+ _f.sent();
91
+ if (completedWithError) {
92
+ (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("Deployment failed with errors! Log is available at ".concat(logFilePath));
93
+ throw new Error("Deployment failed.");
94
+ }
95
+ (_c = process.logger) === null || _c === void 0 ? void 0 : _c.success("Deployment completed! Log is available at ".concat(logFilePath));
96
+ if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.streamWeb) {
97
+ appLoc = encodeURI(target.appLoc);
98
+ webAppStreamUrl = "".concat(target.serverUrl, "/SASStoredProcess/?_PROGRAM=").concat(appLoc, "/services/").concat(streamConfig.streamServiceName);
99
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.info("Web app is available at ".concat(webAppStreamUrl));
100
+ }
101
+ return [2 /*return*/];
102
+ }
103
+ });
104
+ });
105
+ }
106
+ exports.executeDeployScriptSas9 = executeDeployScriptSas9;
@@ -0,0 +1,12 @@
1
+ import { Target, StreamConfig } from '@sasjs/utils';
2
+ /**
3
+ * Execute deployScript on `SASVIYA` server.
4
+ * @param {string} deployScriptName - name of deploy script.
5
+ * @param {Target} target - the target having deploy configuration.
6
+ * @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
7
+ * @param {string} logFilePath - path to log file,
8
+ * log file name will be <deploy-script-name>.log
9
+ * @param {object} streamConfig - optional configuration object of StreamConfig
10
+ * for printing web app url on console.
11
+ */
12
+ export declare function executeDeployScriptSasViya(deployScriptName: string, target: Target, linesToExecute: string[], logFilePath: string, streamConfig?: StreamConfig): Promise<void>;
@@ -0,0 +1,108 @@
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.executeDeployScriptSasViya = void 0;
43
+ var os_1 = __importDefault(require("os"));
44
+ var config_1 = require("../../../utils/config");
45
+ var utils_1 = require("@sasjs/utils");
46
+ /**
47
+ * Execute deployScript on `SASVIYA` server.
48
+ * @param {string} deployScriptName - name of deploy script.
49
+ * @param {Target} target - the target having deploy configuration.
50
+ * @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
51
+ * @param {string} logFilePath - path to log file,
52
+ * log file name will be <deploy-script-name>.log
53
+ * @param {object} streamConfig - optional configuration object of StreamConfig
54
+ * for printing web app url on console.
55
+ */
56
+ function executeDeployScriptSasViya(deployScriptName, target, linesToExecute, logFilePath, streamConfig) {
57
+ var _a, _b, _c, _d;
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var contextName, _e, sasjs, authConfig, executionResult, log, appLoc, webAppStreamUrl;
60
+ return __generator(this, function (_f) {
61
+ switch (_f.label) {
62
+ case 0:
63
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Sending ".concat(deployScriptName, " to SAS server for execution."));
64
+ contextName = target.contextName;
65
+ if (!contextName) {
66
+ throw new Error('Compute Context Name is required for SAS Viya deployments.\n Please ensure that `contextName` is present in your build target configuration or in your .env file, and try again.\n');
67
+ }
68
+ return [4 /*yield*/, (0, config_1.getSASjsAndAuthConfig)(target)];
69
+ case 1:
70
+ _e = _f.sent(), sasjs = _e.sasjs, authConfig = _e.authConfig;
71
+ return [4 /*yield*/, sasjs
72
+ .executeScript({
73
+ fileName: deployScriptName,
74
+ linesOfCode: linesToExecute,
75
+ contextName: contextName,
76
+ authConfig: authConfig
77
+ })
78
+ .catch(function (err) {
79
+ process.logger.error('executeScriptSASViya Error', err);
80
+ })];
81
+ case 2:
82
+ executionResult = _f.sent();
83
+ try {
84
+ log = executionResult.log.items
85
+ ? executionResult.log.items
86
+ .map(function (i) { return i.line; })
87
+ .join(os_1.default.EOL)
88
+ : JSON.stringify(executionResult.log).replace(/\\n/g, os_1.default.EOL);
89
+ }
90
+ catch (e) {
91
+ (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("An error occurred when parsing the execution response: ".concat(e.message));
92
+ log = executionResult;
93
+ }
94
+ return [4 /*yield*/, (0, utils_1.createFile)(logFilePath, log)];
95
+ case 3:
96
+ _f.sent();
97
+ (_c = process.logger) === null || _c === void 0 ? void 0 : _c.success("Deployment completed! Log is available at ".concat(logFilePath));
98
+ if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.streamWeb) {
99
+ appLoc = encodeURI(target.appLoc);
100
+ webAppStreamUrl = "".concat(target.serverUrl, "/SASJobExecution?_FILE=").concat(appLoc, "/services/").concat(streamConfig.streamServiceName, ".html&_debug=2");
101
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.info("Web app is available at ".concat(webAppStreamUrl));
102
+ }
103
+ return [2 /*return*/];
104
+ }
105
+ });
106
+ });
107
+ }
108
+ exports.executeDeployScriptSasViya = executeDeployScriptSasViya;
@@ -0,0 +1,12 @@
1
+ import { Target, StreamConfig } from '@sasjs/utils';
2
+ /**
3
+ * Execute deployScript on `SASJS` server.
4
+ * @param {string} deployScriptName - name of deploy script.
5
+ * @param {Target} target - the target having deploy configuration.
6
+ * @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
7
+ * @param {string} logFilePath - optional path to log folder,
8
+ * log file name will be <deploy-script-name>.log
9
+ * @param {object} streamConfig - optional configuration object of StreamConfig
10
+ * for printing web app url on console.
11
+ */
12
+ export declare function executeDeployScriptSasjs(deployScriptName: string, target: Target, linesToExecute: string[], logFilePath: string, streamConfig?: StreamConfig): Promise<void>;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.executeDeployScriptSasjs = void 0;
40
+ var utils_1 = require("@sasjs/utils");
41
+ var config_1 = require("../../../utils/config");
42
+ var utils_2 = require("../../../utils/utils");
43
+ var _1 = require(".");
44
+ /**
45
+ * Execute deployScript on `SASJS` server.
46
+ * @param {string} deployScriptName - name of deploy script.
47
+ * @param {Target} target - the target having deploy configuration.
48
+ * @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
49
+ * @param {string} logFilePath - optional path to log folder,
50
+ * log file name will be <deploy-script-name>.log
51
+ * @param {object} streamConfig - optional configuration object of StreamConfig
52
+ * for printing web app url on console.
53
+ */
54
+ function executeDeployScriptSasjs(deployScriptName, target, linesToExecute, logFilePath, streamConfig) {
55
+ var _a, _b, _c, _d;
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var authConfig, _e, sasjs, completedWithError, executionResult, logContent, webAppStreamUrl;
58
+ return __generator(this, function (_f) {
59
+ switch (_f.label) {
60
+ case 0:
61
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Sending ".concat(deployScriptName, " to SASJS server for execution."));
62
+ return [4 /*yield*/, (0, utils_2.isSasJsServerInServerMode)(target)];
63
+ case 1:
64
+ if (!(_f.sent())) return [3 /*break*/, 3];
65
+ return [4 /*yield*/, (0, config_1.getAuthConfig)(target)];
66
+ case 2:
67
+ _e = _f.sent();
68
+ return [3 /*break*/, 4];
69
+ case 3:
70
+ _e = undefined;
71
+ _f.label = 4;
72
+ case 4:
73
+ authConfig = _e;
74
+ sasjs = (0, config_1.getSASjs)(target);
75
+ completedWithError = false;
76
+ return [4 /*yield*/, sasjs
77
+ .executeScript({
78
+ linesOfCode: linesToExecute,
79
+ runTime: 'sas',
80
+ authConfig: authConfig
81
+ })
82
+ .catch(function (err) {
83
+ var errorString = (0, _1.formatErrorString)(err);
84
+ process.logger.error('executeScript Error:', errorString);
85
+ return errorString;
86
+ })];
87
+ case 5:
88
+ executionResult = _f.sent();
89
+ logContent = completedWithError
90
+ ? executionResult.result
91
+ : executionResult;
92
+ return [4 /*yield*/, (0, utils_1.createFile)(logFilePath, logContent !== null && logContent !== void 0 ? logContent : '')];
93
+ case 6:
94
+ _f.sent();
95
+ if (completedWithError) {
96
+ (_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("Deployment failed with errors! Log is available at ".concat(logFilePath));
97
+ throw new Error("Deployment failed.");
98
+ }
99
+ (_c = process.logger) === null || _c === void 0 ? void 0 : _c.success("Deployment completed! Log is available at ".concat(logFilePath));
100
+ if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.streamWeb) {
101
+ webAppStreamUrl = "".concat(target.serverUrl, "/AppStream/").concat(streamConfig.streamServiceName);
102
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.info("Web app is available at ".concat(webAppStreamUrl));
103
+ }
104
+ return [2 /*return*/];
105
+ }
106
+ });
107
+ });
108
+ }
109
+ exports.executeDeployScriptSasjs = executeDeployScriptSasjs;
@@ -0,0 +1 @@
1
+ export declare function executeNonSasScript(scriptPath: string): Promise<void>;
@@ -0,0 +1,77 @@
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.executeNonSasScript = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var utils_1 = require("../../../utils/utils");
45
+ var file_1 = require("../../../utils/file");
46
+ function executeNonSasScript(scriptPath) {
47
+ var _a, _b, _c, _d, _e;
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var fileExtension, logPath;
50
+ return __generator(this, function (_f) {
51
+ switch (_f.label) {
52
+ case 0:
53
+ fileExtension = path_1.default.extname(scriptPath);
54
+ logPath = path_1.default.join(process.projectDir, 'sasjsbuild', path_1.default.basename(scriptPath).replace(fileExtension, '.log'));
55
+ if (!(0, file_1.isShellScript)(scriptPath)) return [3 /*break*/, 2];
56
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Executing shell script ".concat(scriptPath, " ..."));
57
+ return [4 /*yield*/, (0, utils_1.executeShellScript)(scriptPath, logPath)];
58
+ case 1:
59
+ _f.sent();
60
+ (_b = process.logger) === null || _b === void 0 ? void 0 : _b.success("Shell script execution completed! Log is here: ".concat(logPath));
61
+ return [2 /*return*/];
62
+ case 2:
63
+ if (!(0, file_1.isPowerShellScript)(scriptPath)) return [3 /*break*/, 4];
64
+ (_c = process.logger) === null || _c === void 0 ? void 0 : _c.info("Executing powershell script ".concat(scriptPath, " ..."));
65
+ return [4 /*yield*/, (0, utils_1.executePowerShellScript)(scriptPath, logPath)];
66
+ case 3:
67
+ _f.sent();
68
+ (_d = process.logger) === null || _d === void 0 ? void 0 : _d.success("PowerShell script execution completed! Log is here: ".concat(logPath));
69
+ return [2 /*return*/];
70
+ case 4:
71
+ (_e = process.logger) === null || _e === void 0 ? void 0 : _e.error("Unable to process script located at ".concat(scriptPath));
72
+ return [2 /*return*/];
73
+ }
74
+ });
75
+ });
76
+ }
77
+ exports.executeNonSasScript = executeNonSasScript;
@@ -0,0 +1,8 @@
1
+ import { Target, StreamConfig } from '@sasjs/utils';
2
+ export declare function executeSasScript(scriptPath: string, target: Target, streamConfig: StreamConfig): Promise<void>;
3
+ /**
4
+ * this function formats the error string to dump error log on console
5
+ * @param error
6
+ * @returns returns a string
7
+ */
8
+ export declare function formatErrorString(error: any): string;
@@ -0,0 +1,109 @@
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.formatErrorString = exports.executeSasScript = void 0;
43
+ var path_1 = __importDefault(require("path"));
44
+ var utils_1 = require("@sasjs/utils");
45
+ var _1 = require("./");
46
+ function executeSasScript(scriptPath, target, streamConfig) {
47
+ var _a;
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var logFolder, deployScriptName, logFilePath, deployScriptContent, linesToExecute;
50
+ return __generator(this, function (_b) {
51
+ switch (_b.label) {
52
+ case 0:
53
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Processing SAS file ".concat(path_1.default.basename(scriptPath), " ..."));
54
+ logFolder = process.sasjsConstants.buildDestinationFolder;
55
+ deployScriptName = path_1.default.basename(scriptPath);
56
+ logFilePath = path_1.default.join(logFolder, deployScriptName.replace('.sas', '.log'));
57
+ return [4 /*yield*/, (0, utils_1.readFile)(scriptPath)
58
+ // split into lines
59
+ ];
60
+ case 1:
61
+ deployScriptContent = _b.sent();
62
+ linesToExecute = deployScriptContent.replace(/\r\n/g, '\n').split('\n');
63
+ if (!(target.serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 3];
64
+ return [4 /*yield*/, (0, _1.executeDeployScriptSasViya)(deployScriptName, target, linesToExecute, logFilePath, streamConfig)];
65
+ case 2: return [2 /*return*/, _b.sent()];
66
+ case 3:
67
+ if (!(target.serverType === utils_1.ServerType.Sas9)) return [3 /*break*/, 5];
68
+ return [4 /*yield*/, (0, _1.executeDeployScriptSas9)(deployScriptName, target, linesToExecute, logFilePath, streamConfig)];
69
+ case 4: return [2 /*return*/, _b.sent()];
70
+ case 5:
71
+ if (!(target.serverType === utils_1.ServerType.Sasjs)) return [3 /*break*/, 7];
72
+ return [4 /*yield*/, (0, _1.executeDeployScriptSasjs)(deployScriptName, target, linesToExecute, logFilePath, streamConfig)];
73
+ case 6:
74
+ _b.sent();
75
+ _b.label = 7;
76
+ case 7: return [2 /*return*/];
77
+ }
78
+ });
79
+ });
80
+ }
81
+ exports.executeSasScript = executeSasScript;
82
+ /**
83
+ * this function formats the error string to dump error log on console
84
+ * @param error
85
+ * @returns returns a string
86
+ */
87
+ function formatErrorString(error) {
88
+ var _a, _b, _c, _d;
89
+ var err = '';
90
+ err += "".concat(error.stack, "\n");
91
+ err += "url: ".concat(((_a = error.config) === null || _a === void 0 ? void 0 : _a.url) ? removePasswordFromUrl(error.config.url) : '', "\n");
92
+ err += "method: ".concat(((_b = error.config) === null || _b === void 0 ? void 0 : _b.method) ? error.config.method : '', "\n");
93
+ err += "headers: ".concat(((_c = error.config) === null || _c === void 0 ? void 0 : _c.headers) ? error.config.headers : '', "\n");
94
+ err += "data: ".concat(((_d = error.response) === null || _d === void 0 ? void 0 : _d.data) ? error.response.data : '');
95
+ return err;
96
+ }
97
+ exports.formatErrorString = formatErrorString;
98
+ /**
99
+ * removes password from url
100
+ * @param str parameter of type string
101
+ * @returns returns a string
102
+ */
103
+ function removePasswordFromUrl(str) {
104
+ var startingIndex = str.indexOf('_password');
105
+ if (startingIndex !== -1) {
106
+ return str.slice(0, startingIndex) + 'PASSWORD-REMOVED';
107
+ }
108
+ return str;
109
+ }
@@ -65,30 +65,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
65
65
  };
66
66
  Object.defineProperty(exports, "__esModule", { value: true });
67
67
  exports.getDeployScripts = void 0;
68
- var utils_1 = require("@sasjs/utils");
69
68
  var path_1 = __importDefault(require("path"));
70
69
  var config_1 = require("../../../utils/config");
71
70
  function getDeployScripts(target) {
72
- var _a, _b, _c, _d;
71
+ var _a, _b;
73
72
  return __awaiter(this, void 0, void 0, function () {
74
- var _e, buildSourceFolder, buildDestinationFolder, configuration, allDeployScripts, buildOutputFileName, deployScriptPath;
75
- return __generator(this, function (_f) {
76
- switch (_f.label) {
73
+ var buildSourceFolder, configuration, allDeployScripts;
74
+ return __generator(this, function (_c) {
75
+ switch (_c.label) {
77
76
  case 0:
78
- _e = process.sasjsConstants, buildSourceFolder = _e.buildSourceFolder, buildDestinationFolder = _e.buildDestinationFolder;
77
+ buildSourceFolder = process.sasjsConstants.buildSourceFolder;
79
78
  return [4 /*yield*/, (0, config_1.getConfiguration)(path_1.default.join(buildSourceFolder, 'sasjs', 'sasjsconfig.json'))];
80
79
  case 1:
81
- configuration = _f.sent();
82
- allDeployScripts = __spreadArray([], __read((((_a = configuration === null || configuration === void 0 ? void 0 : configuration.deployConfig) === null || _a === void 0 ? void 0 : _a.deployScripts) || [])), false);
83
- allDeployScripts = __spreadArray(__spreadArray([], __read(allDeployScripts), false), __read((((_b = target.deployConfig) === null || _b === void 0 ? void 0 : _b.deployScripts) || [])), false);
84
- if (!!((_c = target.deployConfig) === null || _c === void 0 ? void 0 : _c.deployServicePack) &&
85
- target.serverType === utils_1.ServerType.Sas9) {
86
- buildOutputFileName = ((_d = target.buildConfig) === null || _d === void 0 ? void 0 : _d.buildOutputFileName) || "".concat(target.name, ".sas");
87
- deployScriptPath = path_1.default.join(buildDestinationFolder, buildOutputFileName);
88
- allDeployScripts = __spreadArray(__spreadArray([], __read(allDeployScripts), false), [deployScriptPath], false);
89
- }
90
- allDeployScripts = allDeployScripts.filter(function (d) { return !!d; });
91
- return [2 /*return*/, __spreadArray([], __read(new Set(allDeployScripts)), false)];
80
+ configuration = _c.sent();
81
+ allDeployScripts = __spreadArray(__spreadArray([], __read((((_a = configuration === null || configuration === void 0 ? void 0 : configuration.deployConfig) === null || _a === void 0 ? void 0 : _a.deployScripts) || [])), false), __read((((_b = target.deployConfig) === null || _b === void 0 ? void 0 : _b.deployScripts) || [])), false);
82
+ return [2 /*return*/, __spreadArray([], __read(new Set(allDeployScripts.filter(function (d) { return !!d; }))), false)];
92
83
  }
93
84
  });
94
85
  });
@@ -0,0 +1,8 @@
1
+ export * from './deployToSASJSWithServicePack';
2
+ export * from './getDeployScripts';
3
+ export * from './executeDeployScript';
4
+ export * from './executeSasScript';
5
+ export * from './executeNonSasScript';
6
+ export * from './executeDeployScriptSasViya';
7
+ export * from './executeDeployScriptSas9';
8
+ export * from './executeDeployScriptSasjs';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./deployToSASJSWithServicePack"), exports);
14
+ __exportStar(require("./getDeployScripts"), exports);
15
+ __exportStar(require("./executeDeployScript"), exports);
16
+ __exportStar(require("./executeSasScript"), exports);
17
+ __exportStar(require("./executeNonSasScript"), exports);
18
+ __exportStar(require("./executeDeployScriptSasViya"), exports);
19
+ __exportStar(require("./executeDeployScriptSas9"), exports);
20
+ __exportStar(require("./executeDeployScriptSasjs"), exports);
@@ -125,8 +125,8 @@ describe('sasjs cbd with server type SASJS', function () {
125
125
  jobConfig: undefined,
126
126
  serviceConfig: undefined,
127
127
  deployConfig: {
128
- deployServicePack: false,
129
- deployScripts: ["sasjsbuild/".concat(target.name, ".sas")]
128
+ deployServicePack: true,
129
+ deployScripts: []
130
130
  }
131
131
  })];
132
132
  case 2:
@@ -0,0 +1 @@
1
+ export {};