@sasjs/cli 6.4.8 → 6.6.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/README.md +1 -0
- package/build/commands/build/build.js +66 -29
- package/build/commands/build/buildDeployCommand.d.ts +6 -0
- package/build/commands/build/buildDeployCommand.js +120 -0
- package/build/commands/build/spec/build.spec.js +31 -1
- package/build/commands/build/spec/buildDeployCommand.spec.d.ts +1 -0
- package/build/commands/build/spec/buildDeployCommand.spec.js +234 -0
- package/build/commands/compile/compile.js +168 -33
- package/build/commands/compile/compileCommand.js +1 -1
- package/build/commands/compile/internal/checkCompileStatus.js +30 -11
- package/build/commands/compile/internal/compileFile.js +16 -7
- package/build/commands/compile/internal/compileManifest.d.ts +36 -0
- package/build/commands/compile/internal/compileManifest.js +610 -0
- package/build/commands/compile/internal/index.d.ts +2 -0
- package/build/commands/compile/internal/index.js +2 -0
- package/build/commands/compile/internal/passThrough.d.ts +12 -0
- package/build/commands/compile/internal/passThrough.js +17 -0
- package/build/commands/compile/internal/spec/compileTestFile.spec.js +9 -6
- package/build/commands/compile/spec/checkCompileStatus.spec.d.ts +1 -0
- package/build/commands/compile/spec/checkCompileStatus.spec.js +221 -0
- package/build/commands/compile/spec/compileCommand.spec.js +9 -2
- package/build/commands/compile/spec/compileManifest.spec.d.ts +1 -0
- package/build/commands/compile/spec/compileManifest.spec.js +401 -0
- package/build/commands/compile/spec/passThrough.spec.d.ts +1 -0
- package/build/commands/compile/spec/passThrough.spec.js +160 -0
- package/build/commands/deploy/spec/cbd.spec.js +11 -7
- package/build/commands/help/help.js +11 -0
- package/build/commands/testing/spec/testCommand.spec.js +12 -0
- package/build/commands/testing/spec/testing.spec.js +8 -2
- package/build/commands/testing/testCommand.js +3 -1
- package/build/types/command/commandAliases.js +2 -0
- package/build/types/command/commandFactory.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
- Scaffold a new SAS App in seconds (`sasjs create myApp -t jobs`)
|
|
18
18
|
- Compile / Build SAS Jobs, Services & Macros _locally_ and deploy / execute _remotely_, in isolation from other developers (`sasjs cbd`)
|
|
19
|
+
- Build and deploy without recompiling - for when the services on disk are already the ones you want to ship (`sasjs bd`)
|
|
19
20
|
- Compile a single Job, Service or Test without touching the rest of the build (`sasjs compile identify --source sasjs/jobs/daily/load.sas`)
|
|
20
21
|
- Write the test coverage report to `sasjsbuild/coverage.json` on every compile, ready for a CI job to publish
|
|
21
22
|
- No dependency on the server filesystem
|
|
@@ -46,6 +46,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var __values = (this && this.__values) || function(o) {
|
|
50
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
+
if (m) return m.call(o);
|
|
52
|
+
if (o && typeof o.length === "number") return {
|
|
53
|
+
next: function () {
|
|
54
|
+
if (o && i >= o.length) o = void 0;
|
|
55
|
+
return { value: o && o[i++], done: !o };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
+
};
|
|
49
60
|
var __read = (this && this.__read) || function (o, n) {
|
|
50
61
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
62
|
if (!m) return o;
|
|
@@ -71,17 +82,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
71
82
|
}
|
|
72
83
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
84
|
};
|
|
74
|
-
var __values = (this && this.__values) || function(o) {
|
|
75
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
76
|
-
if (m) return m.call(o);
|
|
77
|
-
if (o && typeof o.length === "number") return {
|
|
78
|
-
next: function () {
|
|
79
|
-
if (o && i >= o.length) o = void 0;
|
|
80
|
-
return { value: o && o[i++], done: !o };
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
84
|
-
};
|
|
85
85
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
86
86
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
87
87
|
};
|
|
@@ -96,7 +96,6 @@ var types_1 = require("@sasjs/utils/types");
|
|
|
96
96
|
var compressAndSave_1 = require("../../utils/compressAndSave");
|
|
97
97
|
var config_1 = require("../../utils/config");
|
|
98
98
|
var file_1 = require("../../utils/file");
|
|
99
|
-
var compile_1 = require("../compile/compile");
|
|
100
99
|
var internal_1 = require("../compile/internal");
|
|
101
100
|
var config_2 = require("./internal/config");
|
|
102
101
|
var getLaunchPageCode_1 = require("./internal/getLaunchPageCode");
|
|
@@ -124,28 +123,65 @@ function build(target) {
|
|
|
124
123
|
_a = !(_d.sent());
|
|
125
124
|
_d.label = 2;
|
|
126
125
|
case 2:
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
// build packages the build folder, it does not produce it: compiling here
|
|
127
|
+
// would make `build` and `bd` compile on a fresh clone, where the documented
|
|
128
|
+
// workflow is to run compile (or cbd) first and treat the build folder as the
|
|
129
|
+
// input - including when it has been adjusted by hand.
|
|
130
|
+
if (_a) {
|
|
131
|
+
throw new Error("The build folder ".concat(process.sasjsConstants.buildDestinationFolder, " does not exist.\n") +
|
|
132
|
+
"Run 'sasjs compile' (or 'sasjs cbd') first.");
|
|
133
|
+
}
|
|
134
|
+
return [4 /*yield*/, createFinalSasFiles(target)
|
|
135
|
+
// streamConfig.mockWeb opts the target into a static site that runs the same
|
|
136
|
+
// services in a browser. It is built from what compile just produced, so it
|
|
137
|
+
// is only meaningful after the tree above exists.
|
|
138
|
+
];
|
|
129
139
|
case 3:
|
|
130
140
|
_d.sent();
|
|
131
|
-
|
|
132
|
-
case 4: return [4 /*yield*/, createFinalSasFiles(target)
|
|
133
|
-
// streamConfig.mockWeb opts the target into a static site that runs the same
|
|
134
|
-
// services in a browser. It is built from what compile just produced, so it
|
|
135
|
-
// is only meaningful after the tree above exists.
|
|
136
|
-
];
|
|
137
|
-
case 5:
|
|
138
|
-
_d.sent();
|
|
139
|
-
if (!((_c = target.streamConfig) === null || _c === void 0 ? void 0 : _c.mockWeb)) return [3 /*break*/, 7];
|
|
141
|
+
if (!((_c = target.streamConfig) === null || _c === void 0 ? void 0 : _c.mockWeb)) return [3 /*break*/, 5];
|
|
140
142
|
return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target)];
|
|
141
|
-
case
|
|
143
|
+
case 4:
|
|
142
144
|
_d.sent();
|
|
143
|
-
_d.label =
|
|
144
|
-
case
|
|
145
|
+
_d.label = 5;
|
|
146
|
+
case 5: return [2 /*return*/];
|
|
145
147
|
}
|
|
146
148
|
});
|
|
147
149
|
});
|
|
148
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Reports what the pack holds. A SASjs target can legitimately produce a pack
|
|
153
|
+
* with no SAS services at all - the services are stored programs for another
|
|
154
|
+
* runtime - and that is exactly the case where an unreported zero would look
|
|
155
|
+
* like a successful deploy.
|
|
156
|
+
*/
|
|
157
|
+
var logPackedFileCounts = function (tree) {
|
|
158
|
+
var _a;
|
|
159
|
+
var counts = { services: 0, files: 0 };
|
|
160
|
+
var walk = function (folder) {
|
|
161
|
+
var e_1, _a;
|
|
162
|
+
var _b;
|
|
163
|
+
try {
|
|
164
|
+
for (var _c = __values((_b = folder.members) !== null && _b !== void 0 ? _b : []), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
165
|
+
var member = _d.value;
|
|
166
|
+
if (member.type === types_1.MemberType.service)
|
|
167
|
+
counts.services++;
|
|
168
|
+
else if (member.type === types_1.MemberType.file)
|
|
169
|
+
counts.files++;
|
|
170
|
+
else
|
|
171
|
+
walk(member);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
175
|
+
finally {
|
|
176
|
+
try {
|
|
177
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
178
|
+
}
|
|
179
|
+
finally { if (e_1) throw e_1.error; }
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
walk(tree);
|
|
183
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Packing ".concat(counts.services, " SAS ").concat(counts.services === 1 ? 'service' : 'services', " and ").concat(counts.files, " ").concat(counts.files === 1 ? 'file' : 'files', "."));
|
|
184
|
+
};
|
|
149
185
|
function createFinalSasFiles(target) {
|
|
150
186
|
return __awaiter(this, void 0, void 0, function () {
|
|
151
187
|
var streamConfig, streamWeb, buildConfig, serverType, name, macroFolders, buildOutputFileName, buildDestinationFolder, finalSasFileContent, finalFilePath, finalFilePathJSON, finalFilePathZipped, buildInfo, buildInit, buildTerm, macroCorePath, dependencyFilePaths, dependenciesContent, _a, folderContent, folderContentJSON, servicePackSASjs, servicePack;
|
|
@@ -189,6 +225,7 @@ function createFinalSasFiles(target) {
|
|
|
189
225
|
return [4 /*yield*/, getFolderContent(serverType)];
|
|
190
226
|
case 8:
|
|
191
227
|
_a = _l.sent(), folderContent = _a.folderContent, folderContentJSON = _a.folderContentJSON;
|
|
228
|
+
logPackedFileCounts(folderContentJSON);
|
|
192
229
|
servicePackSASjs = {
|
|
193
230
|
appLoc: target.appLoc,
|
|
194
231
|
fileTree: folderContentJSON
|
|
@@ -549,7 +586,7 @@ function getBuildVars(target) {
|
|
|
549
586
|
});
|
|
550
587
|
}
|
|
551
588
|
var convertVarsToSasFormat = function (vars) {
|
|
552
|
-
var
|
|
589
|
+
var e_2, _a;
|
|
553
590
|
var entries = Object.entries(vars);
|
|
554
591
|
var varsContent = '\n';
|
|
555
592
|
try {
|
|
@@ -560,12 +597,12 @@ var convertVarsToSasFormat = function (vars) {
|
|
|
560
597
|
varsContent += "%let ".concat(name_1, "=").concat(chunkedString, ";\n");
|
|
561
598
|
}
|
|
562
599
|
}
|
|
563
|
-
catch (
|
|
600
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
564
601
|
finally {
|
|
565
602
|
try {
|
|
566
603
|
if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
|
|
567
604
|
}
|
|
568
|
-
finally { if (
|
|
605
|
+
finally { if (e_2) throw e_2.error; }
|
|
569
606
|
}
|
|
570
607
|
return varsContent;
|
|
571
608
|
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.BuildDeployCommand = void 0;
|
|
55
|
+
var command_1 = require("../../types/command");
|
|
56
|
+
var targetCommand_1 = require("../../types/command/targetCommand");
|
|
57
|
+
var utils_1 = require("../../utils");
|
|
58
|
+
var build_1 = require("./build");
|
|
59
|
+
var deploy_1 = require("../deploy/deploy");
|
|
60
|
+
var syntax = 'builddeploy';
|
|
61
|
+
var aliases = ['bd'];
|
|
62
|
+
var usage = 'sasjs builddeploy [options]';
|
|
63
|
+
var description = 'Builds the project and deploys the result to the server configured in the specified target. Unlike compilebuilddeploy it does not recompile first: it ships the compiled services already in the build folder, and the compile step only runs when that folder is missing.';
|
|
64
|
+
var examples = [
|
|
65
|
+
{
|
|
66
|
+
command: 'sasjs builddeploy -t myTarget',
|
|
67
|
+
description: ''
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
command: 'sasjs bd -t myTarget',
|
|
71
|
+
description: ''
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
var BuildDeployCommand = /** @class */ (function (_super) {
|
|
75
|
+
__extends(BuildDeployCommand, _super);
|
|
76
|
+
function BuildDeployCommand(args) {
|
|
77
|
+
return _super.call(this, args, { syntax: syntax, usage: usage, aliases: aliases, description: description, examples: examples }) || this;
|
|
78
|
+
}
|
|
79
|
+
BuildDeployCommand.prototype.execute = function () {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var _a, target, isLocal, buildReturnCode;
|
|
82
|
+
return __generator(this, function (_b) {
|
|
83
|
+
switch (_b.label) {
|
|
84
|
+
case 0: return [4 /*yield*/, this.getTargetInfo()];
|
|
85
|
+
case 1:
|
|
86
|
+
_a = _b.sent(), target = _a.target, isLocal = _a.isLocal;
|
|
87
|
+
return [4 /*yield*/, (0, build_1.build)(target)
|
|
88
|
+
.then(function () {
|
|
89
|
+
var _a;
|
|
90
|
+
var buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
|
|
91
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Services have been successfully built!\nThe build output is located in the ".concat(buildDestinationFolder, " directory."));
|
|
92
|
+
return command_1.ReturnCode.Success;
|
|
93
|
+
})
|
|
94
|
+
.catch(function (err) {
|
|
95
|
+
(0, utils_1.displayError)(err, 'An error has occurred when building services.');
|
|
96
|
+
return command_1.ReturnCode.InternalError;
|
|
97
|
+
})];
|
|
98
|
+
case 2:
|
|
99
|
+
buildReturnCode = _b.sent();
|
|
100
|
+
if (buildReturnCode === command_1.ReturnCode.InternalError)
|
|
101
|
+
return [2 /*return*/, buildReturnCode];
|
|
102
|
+
return [4 /*yield*/, (0, deploy_1.deploy)(target, isLocal)
|
|
103
|
+
.then(function () {
|
|
104
|
+
var _a;
|
|
105
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Services have been successfully deployed to ".concat(target.serverUrl, "."));
|
|
106
|
+
return command_1.ReturnCode.Success;
|
|
107
|
+
})
|
|
108
|
+
.catch(function (err) {
|
|
109
|
+
var _a;
|
|
110
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("An error has occurred when deploying services: ".concat(err));
|
|
111
|
+
return command_1.ReturnCode.InternalError;
|
|
112
|
+
})];
|
|
113
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
return BuildDeployCommand;
|
|
119
|
+
}(targetCommand_1.TargetCommand));
|
|
120
|
+
exports.BuildDeployCommand = BuildDeployCommand;
|
|
@@ -72,8 +72,11 @@ describe('sasjs build', function () {
|
|
|
72
72
|
return [4 /*yield*/, (0, utils_2.findTargetInConfiguration)('viya')];
|
|
73
73
|
case 2:
|
|
74
74
|
target = (_a.sent()).target;
|
|
75
|
-
return [4 /*yield*/,
|
|
75
|
+
return [4 /*yield*/, (0, __1.compile)(target)];
|
|
76
76
|
case 3:
|
|
77
|
+
_a.sent();
|
|
78
|
+
return [4 /*yield*/, expect((0, build_1.build)(target)).toResolve()];
|
|
79
|
+
case 4:
|
|
77
80
|
_a.sent();
|
|
78
81
|
return [2 /*return*/];
|
|
79
82
|
}
|
|
@@ -101,6 +104,33 @@ describe('sasjs build', function () {
|
|
|
101
104
|
}
|
|
102
105
|
});
|
|
103
106
|
}); }, 2 * 60 * 1000);
|
|
107
|
+
it('reports a missing build folder instead of compiling one', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
|
+
var target, buildDestinationFolder;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
switch (_a.label) {
|
|
111
|
+
case 0:
|
|
112
|
+
appName = "test-app-build-".concat((0, test_1.generateUniqueTimestamp)());
|
|
113
|
+
return [4 /*yield*/, (0, test_1.createTestApp)(__dirname, appName)];
|
|
114
|
+
case 1:
|
|
115
|
+
_a.sent();
|
|
116
|
+
return [4 /*yield*/, (0, utils_2.findTargetInConfiguration)('viya')];
|
|
117
|
+
case 2:
|
|
118
|
+
target = (_a.sent()).target;
|
|
119
|
+
buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
|
|
120
|
+
return [4 /*yield*/, (0, utils_1.folderExists)(buildDestinationFolder)];
|
|
121
|
+
case 3:
|
|
122
|
+
if (!_a.sent()) return [3 /*break*/, 5];
|
|
123
|
+
return [4 /*yield*/, (0, utils_1.deleteFolder)(buildDestinationFolder)];
|
|
124
|
+
case 4:
|
|
125
|
+
_a.sent();
|
|
126
|
+
_a.label = 5;
|
|
127
|
+
case 5: return [4 /*yield*/, expect((0, build_1.build)(target)).rejects.toThrow(/Run 'sasjs compile' \(or 'sasjs cbd'\) first/)];
|
|
128
|
+
case 6:
|
|
129
|
+
_a.sent();
|
|
130
|
+
return [2 /*return*/];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}); }, 2 * 60 * 1000);
|
|
104
134
|
it("should compile and build remaining multiline comments", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
105
135
|
var beforeComment, afterComment, commentLine1, commentLine2, testContent, macroPath, _a, _b, target, finalSasFilePath, finalSasFile;
|
|
106
136
|
return __generator(this, function (_c) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
45
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
46
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
+
function step(op) {
|
|
49
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
+
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;
|
|
52
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
+
switch (op[0]) {
|
|
54
|
+
case 0: case 1: t = op; break;
|
|
55
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
+
default:
|
|
59
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
+
if (t[2]) _.ops.pop();
|
|
64
|
+
_.trys.pop(); continue;
|
|
65
|
+
}
|
|
66
|
+
op = body.call(thisArg, _);
|
|
67
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
72
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
73
|
+
if (!m) return o;
|
|
74
|
+
var i = m.call(o), r, ar = [], e;
|
|
75
|
+
try {
|
|
76
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
77
|
+
}
|
|
78
|
+
catch (error) { e = { error: error }; }
|
|
79
|
+
finally {
|
|
80
|
+
try {
|
|
81
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
82
|
+
}
|
|
83
|
+
finally { if (e) throw e.error; }
|
|
84
|
+
}
|
|
85
|
+
return ar;
|
|
86
|
+
};
|
|
87
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
88
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
89
|
+
if (ar || !(i in from)) {
|
|
90
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
91
|
+
ar[i] = from[i];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
95
|
+
};
|
|
96
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
97
|
+
var buildModule = __importStar(require("../../build/build"));
|
|
98
|
+
var deployModule = __importStar(require("../../deploy/deploy"));
|
|
99
|
+
var buildDeployCommand_1 = require("../buildDeployCommand");
|
|
100
|
+
var utils_1 = require("@sasjs/utils");
|
|
101
|
+
var configUtils = __importStar(require("../../../utils/config"));
|
|
102
|
+
var setConstantsUtils = __importStar(require("../../../utils/setConstants"));
|
|
103
|
+
var utils_2 = require("../../../utils");
|
|
104
|
+
var command_1 = require("../../../types/command");
|
|
105
|
+
describe('BuildDeployCommand', function () {
|
|
106
|
+
var defaultArgs = ['node', 'sasjs'];
|
|
107
|
+
var target = new utils_1.Target({
|
|
108
|
+
name: 'test',
|
|
109
|
+
appLoc: '/Public/test/',
|
|
110
|
+
serverType: utils_1.ServerType.SasViya,
|
|
111
|
+
contextName: 'test context'
|
|
112
|
+
});
|
|
113
|
+
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
114
|
+
return __generator(this, function (_a) {
|
|
115
|
+
switch (_a.label) {
|
|
116
|
+
case 0: return [4 /*yield*/, (0, utils_2.setConstants)(false)];
|
|
117
|
+
case 1:
|
|
118
|
+
_a.sent();
|
|
119
|
+
return [2 /*return*/];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}); });
|
|
123
|
+
beforeEach(function () {
|
|
124
|
+
jest.resetAllMocks();
|
|
125
|
+
jest.mock('../../build/build');
|
|
126
|
+
jest.mock('../../deploy/deploy');
|
|
127
|
+
jest.mock('../../../utils/config');
|
|
128
|
+
jest.spyOn(buildModule, 'build').mockImplementation(function () { return Promise.resolve(); });
|
|
129
|
+
jest
|
|
130
|
+
.spyOn(deployModule, 'deploy')
|
|
131
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
132
|
+
jest
|
|
133
|
+
.spyOn(configUtils, 'findTargetInConfiguration')
|
|
134
|
+
.mockImplementation(function () { return Promise.resolve({ target: target, isLocal: true }); });
|
|
135
|
+
jest
|
|
136
|
+
.spyOn(configUtils, 'getLocalConfig')
|
|
137
|
+
.mockImplementation(function () { return Promise.resolve({}); });
|
|
138
|
+
jest
|
|
139
|
+
.spyOn(setConstantsUtils, 'setConstants')
|
|
140
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
141
|
+
process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
|
|
142
|
+
jest.spyOn(process.logger, 'success');
|
|
143
|
+
jest.spyOn(process.logger, 'error');
|
|
144
|
+
});
|
|
145
|
+
it('should parse a simple sasjs builddeploy command', function () {
|
|
146
|
+
var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['builddeploy'], false);
|
|
147
|
+
var command = new buildDeployCommand_1.BuildDeployCommand(args);
|
|
148
|
+
expect(command.name).toEqual('builddeploy');
|
|
149
|
+
expect(command.subCommand).toEqual('');
|
|
150
|
+
});
|
|
151
|
+
it('should parse the bd shorthand', function () {
|
|
152
|
+
var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['bd'], false);
|
|
153
|
+
var command = new buildDeployCommand_1.BuildDeployCommand(args);
|
|
154
|
+
expect(command.name).toEqual('builddeploy');
|
|
155
|
+
expect(command.subCommand).toEqual('');
|
|
156
|
+
});
|
|
157
|
+
it('should parse a sasjs builddeploy command with a target', function () {
|
|
158
|
+
var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['builddeploy', '--target', 'test'], false);
|
|
159
|
+
var command = new buildDeployCommand_1.BuildDeployCommand(args);
|
|
160
|
+
expect(command.name).toEqual('builddeploy');
|
|
161
|
+
expect(command.subCommand).toEqual('');
|
|
162
|
+
});
|
|
163
|
+
it('should build and then deploy against the resolved target', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
164
|
+
var args, command;
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
switch (_a.label) {
|
|
167
|
+
case 0:
|
|
168
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['bd', '-t', 'test'], false);
|
|
169
|
+
command = new buildDeployCommand_1.BuildDeployCommand(args);
|
|
170
|
+
return [4 /*yield*/, command.execute()];
|
|
171
|
+
case 1:
|
|
172
|
+
_a.sent();
|
|
173
|
+
expect(buildModule.build).toHaveBeenCalledWith(target);
|
|
174
|
+
expect(deployModule.deploy).toHaveBeenCalledWith(target, true);
|
|
175
|
+
return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}); });
|
|
179
|
+
it('should not deploy when the build fails', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
180
|
+
var args, command, returnCode;
|
|
181
|
+
return __generator(this, function (_a) {
|
|
182
|
+
switch (_a.label) {
|
|
183
|
+
case 0:
|
|
184
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['bd', '-t', 'test'], false);
|
|
185
|
+
jest
|
|
186
|
+
.spyOn(buildModule, 'build')
|
|
187
|
+
.mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
|
|
188
|
+
command = new buildDeployCommand_1.BuildDeployCommand(args);
|
|
189
|
+
return [4 /*yield*/, command.execute()];
|
|
190
|
+
case 1:
|
|
191
|
+
returnCode = _a.sent();
|
|
192
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
193
|
+
expect(deployModule.deploy).not.toHaveBeenCalled();
|
|
194
|
+
expect(process.logger.error).toHaveBeenCalledWith(expect.stringContaining('An error has occurred when building services'), 'Test Error');
|
|
195
|
+
return [2 /*return*/];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}); });
|
|
199
|
+
it('should return the success code when build and deploy succeed', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
200
|
+
var args, command, returnCode;
|
|
201
|
+
return __generator(this, function (_a) {
|
|
202
|
+
switch (_a.label) {
|
|
203
|
+
case 0:
|
|
204
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['builddeploy', '-t', 'test'], false);
|
|
205
|
+
command = new buildDeployCommand_1.BuildDeployCommand(args);
|
|
206
|
+
return [4 /*yield*/, command.execute()];
|
|
207
|
+
case 1:
|
|
208
|
+
returnCode = _a.sent();
|
|
209
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
210
|
+
expect(process.logger.success).toHaveBeenCalledWith(expect.stringContaining('Services have been successfully deployed'));
|
|
211
|
+
return [2 /*return*/];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}); });
|
|
215
|
+
it('should log the error and return the error code when deploy is unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
216
|
+
var args, command, returnCode;
|
|
217
|
+
return __generator(this, function (_a) {
|
|
218
|
+
switch (_a.label) {
|
|
219
|
+
case 0:
|
|
220
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['builddeploy', '-t', 'test'], false);
|
|
221
|
+
jest
|
|
222
|
+
.spyOn(deployModule, 'deploy')
|
|
223
|
+
.mockImplementation(function () { return Promise.reject(new Error('Test Error')); });
|
|
224
|
+
command = new buildDeployCommand_1.BuildDeployCommand(args);
|
|
225
|
+
return [4 /*yield*/, command.execute()];
|
|
226
|
+
case 1:
|
|
227
|
+
returnCode = _a.sent();
|
|
228
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
229
|
+
expect(process.logger.error).toHaveBeenCalledWith(expect.stringContaining('An error has occurred when deploying services'));
|
|
230
|
+
return [2 /*return*/];
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}); });
|
|
234
|
+
});
|