@sasjs/cli 6.13.0 → 6.13.1
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.
|
@@ -241,4 +241,34 @@ describe('sasjs web', function () {
|
|
|
241
241
|
}
|
|
242
242
|
});
|
|
243
243
|
}); }, 2 * 60 * 1000);
|
|
244
|
+
it("should stamp the target's appLoc into the copied app for a SASjs target", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
245
|
+
var sourceFolder, sasjsTarget, copied;
|
|
246
|
+
return __generator(this, function (_a) {
|
|
247
|
+
switch (_a.label) {
|
|
248
|
+
case 0:
|
|
249
|
+
sourceFolder = 'websrc';
|
|
250
|
+
return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(__dirname, appName, sourceFolder, 'index.html'), '<html><head><sasjs appLoc="/Public/app/default" serverType="SASJS"></sasjs></head><body></body></html>')];
|
|
251
|
+
case 1:
|
|
252
|
+
_a.sent();
|
|
253
|
+
sasjsTarget = {
|
|
254
|
+
name: 'sasjs-loc',
|
|
255
|
+
serverType: utils_1.ServerType.Sasjs,
|
|
256
|
+
appLoc: '/Public/app/AnotherLoc',
|
|
257
|
+
streamConfig: __assign(__assign({}, streamConfig), { webSourcePath: sourceFolder, streamWebFolder: 'websas' })
|
|
258
|
+
};
|
|
259
|
+
return [4 /*yield*/, expect((0, web_1.createWebAppServices)(sasjsTarget)).toResolve()];
|
|
260
|
+
case 2:
|
|
261
|
+
_a.sent();
|
|
262
|
+
return [4 /*yield*/, (0, utils_1.readFile)(path_1.default.join(process.sasjsConstants.buildDestinationServicesFolder, 'websas', 'index.html'))
|
|
263
|
+
// jsdom serialises attribute names in lower case
|
|
264
|
+
];
|
|
265
|
+
case 3:
|
|
266
|
+
copied = _a.sent();
|
|
267
|
+
// jsdom serialises attribute names in lower case
|
|
268
|
+
expect(copied.toLowerCase()).toContain('apploc="/public/app/anotherloc"');
|
|
269
|
+
expect(copied.toLowerCase()).not.toContain('/public/app/default');
|
|
270
|
+
return [2 /*return*/];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}); }, 2 * 60 * 1000);
|
|
244
274
|
});
|
|
@@ -42,10 +42,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports.createWebAppServices = createWebAppServices;
|
|
43
43
|
var utils_1 = require("@sasjs/utils");
|
|
44
44
|
var config_1 = require("../../utils/config");
|
|
45
|
+
var fs_1 = __importDefault(require("fs"));
|
|
45
46
|
var path_1 = __importDefault(require("path"));
|
|
46
47
|
var jsdom_1 = __importDefault(require("jsdom"));
|
|
47
48
|
var createAssetServices_1 = require("./internal/createAssetServices");
|
|
48
49
|
var updateAllTags_1 = require("./internal/updateAllTags");
|
|
50
|
+
var getTags_1 = require("./internal/getTags");
|
|
51
|
+
var updateSasjsTag_1 = require("./internal/updateSasjsTag");
|
|
49
52
|
var sas9_1 = require("./internal/sas9");
|
|
50
53
|
var sasViya_1 = require("./internal/sasViya");
|
|
51
54
|
var exampleStreamConfig = {
|
|
@@ -57,70 +60,89 @@ var exampleStreamConfig = {
|
|
|
57
60
|
};
|
|
58
61
|
function createWebAppServices(target) {
|
|
59
62
|
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
var buildDestinationServicesFolder, streamConfig, _a, webSourcePathFull, indexHtmlPath, destinationPath, assetPathMap, indexHtml,
|
|
61
|
-
var
|
|
62
|
-
return __generator(this, function (
|
|
63
|
-
switch (
|
|
63
|
+
var buildDestinationServicesFolder, streamConfig, _a, webSourcePathFull, indexHtmlPath, destinationPath, copiedIndex, indexHtml_1, _b, _c, sasjsTags, assetPathMap, indexHtml, _d;
|
|
64
|
+
var _e, _f;
|
|
65
|
+
return __generator(this, function (_g) {
|
|
66
|
+
switch (_g.label) {
|
|
64
67
|
case 0:
|
|
65
68
|
buildDestinationServicesFolder = process.sasjsConstants.buildDestinationServicesFolder;
|
|
66
69
|
return [4 /*yield*/, (0, config_1.getStreamConfig)(target)];
|
|
67
70
|
case 1:
|
|
68
|
-
streamConfig =
|
|
71
|
+
streamConfig = _g.sent();
|
|
69
72
|
return [4 /*yield*/, validateStreamConfig(streamConfig)];
|
|
70
73
|
case 2:
|
|
71
|
-
_a =
|
|
74
|
+
_a = _g.sent(), webSourcePathFull = _a.webSourcePathFull, indexHtmlPath = _a.indexHtmlPath;
|
|
72
75
|
return [4 /*yield*/, createBuildDestinationFolder()];
|
|
73
76
|
case 3:
|
|
74
|
-
|
|
77
|
+
_g.sent();
|
|
75
78
|
destinationPath = path_1.default.join(buildDestinationServicesFolder, streamConfig.streamWebFolder);
|
|
76
79
|
return [4 /*yield*/, createTargetDestinationFolder(destinationPath)
|
|
77
80
|
// For server type SASjs, just need to copy webSourcePath
|
|
78
81
|
// to streamWebFolder, no need to create service files.
|
|
79
82
|
];
|
|
80
83
|
case 4:
|
|
81
|
-
|
|
82
|
-
if (!(target.serverType === utils_1.ServerType.Sasjs)) return [3 /*break*/,
|
|
83
|
-
(
|
|
84
|
-
return [4 /*yield*/, (0, utils_1.copy)(webSourcePathFull, destinationPath)
|
|
84
|
+
_g.sent();
|
|
85
|
+
if (!(target.serverType === utils_1.ServerType.Sasjs)) return [3 /*break*/, 9];
|
|
86
|
+
(_e = process.logger) === null || _e === void 0 ? void 0 : _e.info("Copying web app files for target ".concat(target.name, "..."));
|
|
87
|
+
return [4 /*yield*/, (0, utils_1.copy)(webSourcePathFull, destinationPath)
|
|
88
|
+
/*
|
|
89
|
+
The copied app carries whatever appLoc the frontend was built with, and
|
|
90
|
+
an AppStream app gets no appLoc from its URL - so a deployment to any
|
|
91
|
+
appLoc but that default sends every service call to the default one. The
|
|
92
|
+
tag is set from the target here, which is the value this build deploys to.
|
|
93
|
+
*/
|
|
94
|
+
];
|
|
85
95
|
case 5:
|
|
86
|
-
|
|
87
|
-
|
|
96
|
+
_g.sent();
|
|
97
|
+
copiedIndex = path_1.default.join(destinationPath, 'index.html');
|
|
98
|
+
_c = (_b = jsdom_1.default.JSDOM).bind;
|
|
99
|
+
return [4 /*yield*/, (0, utils_1.readFile)(copiedIndex)];
|
|
88
100
|
case 6:
|
|
89
|
-
|
|
101
|
+
indexHtml_1 = new (_c.apply(_b, [void 0, _g.sent()]))();
|
|
102
|
+
sasjsTags = (0, getTags_1.getSasjsTags)(indexHtml_1);
|
|
103
|
+
if (!sasjsTags.length) return [3 /*break*/, 8];
|
|
104
|
+
(0, updateSasjsTag_1.updateSasjsTag)(sasjsTags[0], target);
|
|
105
|
+
return [4 /*yield*/, fs_1.default.promises.writeFile(copiedIndex, indexHtml_1.serialize())];
|
|
106
|
+
case 7:
|
|
107
|
+
_g.sent();
|
|
108
|
+
_g.label = 8;
|
|
109
|
+
case 8: return [2 /*return*/];
|
|
110
|
+
case 9:
|
|
111
|
+
(_f = process.logger) === null || _f === void 0 ? void 0 : _f.info("Compiling web app services for target ".concat(target.name, "..."));
|
|
90
112
|
return [4 /*yield*/, (0, createAssetServices_1.createAssetServices)(target, destinationPath, streamConfig).then(function (map) {
|
|
91
113
|
var indexHtmlIndex = map.findIndex(function (assetPath) { return assetPath.source === 'index.html'; });
|
|
92
114
|
map.splice(indexHtmlIndex, 1);
|
|
93
115
|
return map;
|
|
94
116
|
})];
|
|
95
|
-
case
|
|
96
|
-
assetPathMap =
|
|
117
|
+
case 10:
|
|
118
|
+
assetPathMap = _g.sent();
|
|
97
119
|
return [4 /*yield*/, (0, utils_1.readFile)(indexHtmlPath).then(function (content) { return new jsdom_1.default.JSDOM(content); })];
|
|
98
|
-
case
|
|
99
|
-
indexHtml =
|
|
120
|
+
case 11:
|
|
121
|
+
indexHtml = _g.sent();
|
|
100
122
|
return [4 /*yield*/, (0, updateAllTags_1.updateAllTags)(indexHtml, target, {
|
|
101
123
|
webSourcePathFull: webSourcePathFull,
|
|
102
124
|
destinationPath: destinationPath,
|
|
103
125
|
serverType: target.serverType,
|
|
104
126
|
assetPathMap: assetPathMap
|
|
105
127
|
})];
|
|
106
|
-
case
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
switch (
|
|
110
|
-
case utils_1.ServerType.SasViya: return [3 /*break*/,
|
|
111
|
-
case utils_1.ServerType.Sas9: return [3 /*break*/,
|
|
128
|
+
case 12:
|
|
129
|
+
_g.sent();
|
|
130
|
+
_d = target.serverType;
|
|
131
|
+
switch (_d) {
|
|
132
|
+
case utils_1.ServerType.SasViya: return [3 /*break*/, 13];
|
|
133
|
+
case utils_1.ServerType.Sas9: return [3 /*break*/, 15];
|
|
112
134
|
}
|
|
113
|
-
return [3 /*break*/,
|
|
114
|
-
case
|
|
115
|
-
case
|
|
116
|
-
|
|
117
|
-
return [3 /*break*/,
|
|
118
|
-
case
|
|
119
|
-
case
|
|
120
|
-
|
|
121
|
-
return [3 /*break*/,
|
|
122
|
-
case
|
|
123
|
-
case
|
|
135
|
+
return [3 /*break*/, 17];
|
|
136
|
+
case 13: return [4 /*yield*/, (0, sasViya_1.createClickMeFile)(indexHtml.serialize(), streamConfig.streamServiceName)];
|
|
137
|
+
case 14:
|
|
138
|
+
_g.sent();
|
|
139
|
+
return [3 /*break*/, 18];
|
|
140
|
+
case 15: return [4 /*yield*/, (0, sas9_1.createClickMeService)(indexHtml.serialize(), streamConfig.streamServiceName)];
|
|
141
|
+
case 16:
|
|
142
|
+
_g.sent();
|
|
143
|
+
return [3 /*break*/, 18];
|
|
144
|
+
case 17: throw new Error("Server Type: ".concat(target.serverType, " is not supported for processing streaming index file."));
|
|
145
|
+
case 18: return [2 /*return*/];
|
|
124
146
|
}
|
|
125
147
|
});
|
|
126
148
|
});
|
package/package.json
CHANGED