@sasjs/cli 6.13.0 → 6.13.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.
@@ -175,7 +175,8 @@ describe('browser runtime', function () {
175
175
  expect(result.error).toBeNull();
176
176
  parsed = JSON.parse(result.webout);
177
177
  expect(parsed.users).toEqual([{ name: 'ann' }, { name: 'bob' }]);
178
- expect(parsed.SYSDATE).toMatch(/^\d{2}[A-Z]{3}\d{4}$/);
178
+ // &SYSDATE is DATE7 - ddMMMyy - which is what %mm_webout writes
179
+ expect(parsed.SYSDATE).toMatch(/^\d{2}[A-Z]{3}\d{2}$/);
179
180
  expect(parsed.MF_GETUSER).toEqual('DEMO');
180
181
  expect(parsed.SYSPROCESSNAME).toEqual('Browser');
181
182
  expect(parsed.SYSSCPL).toEqual('browser');
@@ -215,7 +215,7 @@ describe('sasjs cbd with server type SASJS', function () {
215
215
  {
216
216
  name: 'appinit',
217
217
  type: 'service',
218
- code: getCode(appinit)
218
+ code: getCode((0, utils_1.removeHeader)(appinit))
219
219
  },
220
220
  {
221
221
  name: 'getdata.js',
@@ -225,7 +225,7 @@ describe('sasjs cbd with server type SASJS', function () {
225
225
  {
226
226
  name: 'getdata',
227
227
  type: 'service',
228
- code: getCode(getdata)
228
+ code: getCode((0, utils_1.removeHeader)(getdata))
229
229
  }
230
230
  ]
231
231
  }
@@ -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, _b;
61
- var _c, _d;
62
- return __generator(this, function (_e) {
63
- switch (_e.label) {
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 = _e.sent();
71
+ streamConfig = _g.sent();
69
72
  return [4 /*yield*/, validateStreamConfig(streamConfig)];
70
73
  case 2:
71
- _a = _e.sent(), webSourcePathFull = _a.webSourcePathFull, indexHtmlPath = _a.indexHtmlPath;
74
+ _a = _g.sent(), webSourcePathFull = _a.webSourcePathFull, indexHtmlPath = _a.indexHtmlPath;
72
75
  return [4 /*yield*/, createBuildDestinationFolder()];
73
76
  case 3:
74
- _e.sent();
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
- _e.sent();
82
- if (!(target.serverType === utils_1.ServerType.Sasjs)) return [3 /*break*/, 6];
83
- (_c = process.logger) === null || _c === void 0 ? void 0 : _c.info("Copying web app files for target ".concat(target.name, "..."));
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
- _e.sent();
87
- return [2 /*return*/];
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
- (_d = process.logger) === null || _d === void 0 ? void 0 : _d.info("Compiling web app services for target ".concat(target.name, "..."));
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 7:
96
- assetPathMap = _e.sent();
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 8:
99
- indexHtml = _e.sent();
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 9:
107
- _e.sent();
108
- _b = target.serverType;
109
- switch (_b) {
110
- case utils_1.ServerType.SasViya: return [3 /*break*/, 10];
111
- case utils_1.ServerType.Sas9: return [3 /*break*/, 12];
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*/, 14];
114
- case 10: return [4 /*yield*/, (0, sasViya_1.createClickMeFile)(indexHtml.serialize(), streamConfig.streamServiceName)];
115
- case 11:
116
- _e.sent();
117
- return [3 /*break*/, 15];
118
- case 12: return [4 /*yield*/, (0, sas9_1.createClickMeService)(indexHtml.serialize(), streamConfig.streamServiceName)];
119
- case 13:
120
- _e.sent();
121
- return [3 /*break*/, 15];
122
- case 14: throw new Error("Server Type: ".concat(target.serverType, " is not supported for processing streaming index file."));
123
- case 15: return [2 /*return*/];
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
@@ -70,11 +70,11 @@
70
70
  "registry": "https://registry.npmjs.org"
71
71
  },
72
72
  "dependencies": {
73
- "@sasjs/adapter": "^5.1.3",
73
+ "@sasjs/adapter": "5.1.3",
74
74
  "@sasjs/api": "0.2.1",
75
- "@sasjs/core": "^6.1.1",
75
+ "@sasjs/core": "6.1.1",
76
76
  "@sasjs/lint": "5.0.0",
77
- "@sasjs/utils": "^4.7.0",
77
+ "@sasjs/utils": "4.9.0",
78
78
  "axios": "1.20.0",
79
79
  "chalk": "4.1.2",
80
80
  "dotenv": "18.0.8",
@@ -124,5 +124,5 @@
124
124
  "ws": "8.21.0",
125
125
  "nanoid": "3.3.18"
126
126
  },
127
- "version": "6.13.0"
127
+ "version": "6.13.2"
128
128
  }