@sasjs/cli 3.6.3 → 3.6.7
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 +0 -3
- package/build/commands/deploy/deploy.d.ts +7 -0
- package/build/commands/deploy/deploy.js +105 -44
- package/build/commands/deploy/spec/cbd.spec.js +1 -1
- package/build/commands/help/help.js +4 -2
- package/build/commands/web/internal/getTags.d.ts +2 -0
- package/build/commands/web/internal/getTags.js +9 -1
- package/build/commands/web/internal/sasjsout.d.ts +1 -1
- package/build/commands/web/internal/sasjsout.js +1 -1
- package/build/commands/web/internal/spec/testFiles/script3.d.ts +23 -0
- package/build/commands/web/internal/spec/testFiles/script3.js +218 -0
- package/build/commands/web/internal/spec/updateLinkTag.spec.js +1 -1
- package/build/commands/web/internal/spec/updateScriptTag.spec.js +146 -1
- package/build/commands/web/internal/spec/updateStyleTag.spec.d.ts +4 -0
- package/build/commands/web/internal/spec/updateStyleTag.spec.js +131 -0
- package/build/commands/web/internal/updateAllTags.js +22 -8
- package/build/commands/web/internal/updateLinkTag.d.ts +2 -2
- package/build/commands/web/internal/updateScriptTag.d.ts +1 -1
- package/build/commands/web/internal/updateScriptTag.js +21 -10
- package/build/commands/web/internal/updateStyleTag.d.ts +5 -0
- package/build/commands/web/internal/updateStyleTag.js +96 -0
- package/build/utils/config.js +4 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# SASjs CLI
|
|
2
2
|
[![npm package][npm-image]][npm-url]
|
|
3
3
|
[![Github Workflow][githubworkflow-image]][githubworkflow-url]
|
|
4
|
-
[![Dependency Status][dependency-image]][dependency-url]
|
|
5
4
|
[]()
|
|
6
5
|

|
|
7
6
|
[](/LICENSE)
|
|
@@ -15,8 +14,6 @@
|
|
|
15
14
|
[npm-url]:http://npmjs.org/package/@sasjs/cli
|
|
16
15
|
[githubworkflow-image]:https://github.com/sasjs/cli/actions/workflows/run-tests.yml/badge.svg
|
|
17
16
|
[githubworkflow-url]:https://github.com/sasjs/cli/blob/main/.github/workflows/run-tests.yml
|
|
18
|
-
[dependency-image]:https://david-dm.org/sasjs/cli.svg
|
|
19
|
-
[dependency-url]:https://github.com/sasjs/cli/blob/main/package.json
|
|
20
17
|
|
|
21
18
|
`@sasjs/cli` is a Command-Line Interface to assist with creating, building, and deploying Data Science projects and HTML5 Web Applications on the SAS platform (both SAS 9 and Viya). Features include:
|
|
22
19
|
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import SASjs from '@sasjs/adapter/node';
|
|
2
2
|
import { Target } from '@sasjs/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Deploys app to serverUrl/appLoc mentioned in specified target.
|
|
5
|
+
* @param {Target} target- the target having deploy configuration.
|
|
6
|
+
* @param {boolean} isLocal- flag indicating if specified target is
|
|
7
|
+
* from local sasjsconfig or global sasjsconfig file.
|
|
8
|
+
* @param {object} sasjs - optional configuration object of SAS adapter.
|
|
9
|
+
*/
|
|
3
10
|
export declare function deploy(target: Target, isLocal: boolean, sasjs?: SASjs): Promise<void>;
|
|
@@ -49,6 +49,13 @@ var utils_2 = require("@sasjs/utils");
|
|
|
49
49
|
var file_1 = require("../../utils/file");
|
|
50
50
|
var getDeployScripts_1 = require("./internal/getDeployScripts");
|
|
51
51
|
var deployToSasViyaWithServicePack_1 = require("../shared/deployToSasViyaWithServicePack");
|
|
52
|
+
/**
|
|
53
|
+
* Deploys app to serverUrl/appLoc mentioned in specified target.
|
|
54
|
+
* @param {Target} target- the target having deploy configuration.
|
|
55
|
+
* @param {boolean} isLocal- flag indicating if specified target is
|
|
56
|
+
* from local sasjsconfig or global sasjsconfig file.
|
|
57
|
+
* @param {object} sasjs - optional configuration object of SAS adapter.
|
|
58
|
+
*/
|
|
52
59
|
function deploy(target, isLocal, sasjs) {
|
|
53
60
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
54
61
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -83,12 +90,12 @@ function deploy(target, isLocal, sasjs) {
|
|
|
83
90
|
buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
|
|
84
91
|
logFilePath = buildDestinationFolder;
|
|
85
92
|
if (!(target.serverType === utils_2.ServerType.Sasjs)) return [3 /*break*/, 5];
|
|
86
|
-
return [4 /*yield*/, deployToSasjs(target, sasjs)];
|
|
93
|
+
return [4 /*yield*/, deployToSasjs(target, isLocal, sasjs)];
|
|
87
94
|
case 4:
|
|
88
95
|
_k.sent();
|
|
89
96
|
return [3 /*break*/, 7];
|
|
90
97
|
case 5: return [4 /*yield*/, (0, utils_2.asyncForEach)(deployScripts, function (deployScript) { return __awaiter(_this, void 0, void 0, function () {
|
|
91
|
-
var deployScriptPath,
|
|
98
|
+
var deployScriptPath, deployScriptContent, linesToExecute, streamConfig, deployScriptName, logPath;
|
|
92
99
|
var _a, _b, _c;
|
|
93
100
|
return __generator(this, function (_d) {
|
|
94
101
|
switch (_d.label) {
|
|
@@ -100,19 +107,20 @@ function deploy(target, isLocal, sasjs) {
|
|
|
100
107
|
// split into lines
|
|
101
108
|
];
|
|
102
109
|
case 1:
|
|
103
|
-
|
|
104
|
-
linesToExecute =
|
|
110
|
+
deployScriptContent = _d.sent();
|
|
111
|
+
linesToExecute = deployScriptContent
|
|
105
112
|
.replace(/\r\n/g, '\n')
|
|
106
113
|
.split('\n');
|
|
107
114
|
return [4 /*yield*/, (0, config_1.getStreamConfig)(target)];
|
|
108
115
|
case 2:
|
|
109
116
|
streamConfig = _d.sent();
|
|
117
|
+
deployScriptName = path_1.default.basename(deployScript);
|
|
110
118
|
if (!(target.serverType === utils_2.ServerType.SasViya)) return [3 /*break*/, 4];
|
|
111
|
-
return [4 /*yield*/, deployToSasViya(
|
|
119
|
+
return [4 /*yield*/, deployToSasViya(deployScriptName, target, isLocal, linesToExecute, logFilePath, streamConfig)];
|
|
112
120
|
case 3:
|
|
113
121
|
_d.sent();
|
|
114
122
|
return [3 /*break*/, 6];
|
|
115
|
-
case 4: return [4 /*yield*/, deployToSas9(
|
|
123
|
+
case 4: return [4 /*yield*/, deployToSas9(deployScriptName, target, linesToExecute, logFilePath, streamConfig)];
|
|
116
124
|
case 5:
|
|
117
125
|
_d.sent();
|
|
118
126
|
_d.label = 6;
|
|
@@ -139,6 +147,14 @@ function deploy(target, isLocal, sasjs) {
|
|
|
139
147
|
});
|
|
140
148
|
}
|
|
141
149
|
exports.deploy = deploy;
|
|
150
|
+
/**
|
|
151
|
+
* Returns configuration object of SAS Adapter and authentication configuration
|
|
152
|
+
* @param {Target} target- the target to get auth configuration from.
|
|
153
|
+
* @param {boolean} isLocal- flag indicating if specified target is
|
|
154
|
+
* from local sasjsconfig or global sasjsconfig file.
|
|
155
|
+
* @returns an object containing a SAS Adapter configuration object `sasjs`
|
|
156
|
+
* and auth configuration `authConfig`.
|
|
157
|
+
*/
|
|
142
158
|
function getSASjsAndAuthConfig(target, isLocal) {
|
|
143
159
|
return __awaiter(this, void 0, void 0, function () {
|
|
144
160
|
var sasjs, authConfig, e_1;
|
|
@@ -171,14 +187,26 @@ function getSASjsAndAuthConfig(target, isLocal) {
|
|
|
171
187
|
});
|
|
172
188
|
});
|
|
173
189
|
}
|
|
174
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Deploys app to `SASVIYA` server through deployScript.
|
|
192
|
+
* @param {string} deployScriptName- name of deploy script.
|
|
193
|
+
* @param {Target} target- the target having deploy configuration.
|
|
194
|
+
* @param {boolean} isLocal- flag indicating if specified target is
|
|
195
|
+
* from local sasjsconfig or global sasjsconfig file.
|
|
196
|
+
* @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
|
|
197
|
+
* @param {string} logFolder - optional path to log folder,
|
|
198
|
+
* log file name will be <deploy-script-name>.log
|
|
199
|
+
* @param {object} streamConfig - optional configuration object of StreamConfig
|
|
200
|
+
* for printing web app url on console.
|
|
201
|
+
*/
|
|
202
|
+
function deployToSasViya(deployScriptName, target, isLocal, linesToExecute, logFolder, streamConfig) {
|
|
175
203
|
var _a, _b, _c, _d, _e;
|
|
176
204
|
return __awaiter(this, void 0, void 0, function () {
|
|
177
205
|
var contextName, _f, sasjs, authConfig, executionResult, log, appLoc, webAppStreamUrl;
|
|
178
206
|
return __generator(this, function (_g) {
|
|
179
207
|
switch (_g.label) {
|
|
180
208
|
case 0:
|
|
181
|
-
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Sending ".concat(
|
|
209
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.info("Sending ".concat(deployScriptName, " to SAS server for execution."));
|
|
182
210
|
contextName = target.contextName;
|
|
183
211
|
if (!contextName) {
|
|
184
212
|
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');
|
|
@@ -186,7 +214,7 @@ function deployToSasViya(deployScript, target, isLocal, linesToExecute, logFileP
|
|
|
186
214
|
return [4 /*yield*/, getSASjsAndAuthConfig(target, isLocal)];
|
|
187
215
|
case 1:
|
|
188
216
|
_f = _g.sent(), sasjs = _f.sasjs, authConfig = _f.authConfig;
|
|
189
|
-
return [4 /*yield*/, sasjs.executeScriptSASViya(
|
|
217
|
+
return [4 /*yield*/, sasjs.executeScriptSASViya(deployScriptName, linesToExecute, contextName, authConfig)];
|
|
190
218
|
case 2:
|
|
191
219
|
executionResult = _g.sent();
|
|
192
220
|
try {
|
|
@@ -200,26 +228,37 @@ function deployToSasViya(deployScript, target, isLocal, linesToExecute, logFileP
|
|
|
200
228
|
(_b = process.logger) === null || _b === void 0 ? void 0 : _b.error("An error occurred when parsing the execution response: ".concat(e.message));
|
|
201
229
|
log = executionResult;
|
|
202
230
|
}
|
|
203
|
-
if (!
|
|
204
|
-
return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(
|
|
231
|
+
if (!logFolder) return [3 /*break*/, 4];
|
|
232
|
+
return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log")), log)];
|
|
205
233
|
case 3:
|
|
206
234
|
_g.sent();
|
|
207
|
-
(_c = process.logger) === null || _c === void 0 ? void 0 : _c.success("Deployment completed! Log is available at ".concat(path_1.default.join(
|
|
235
|
+
(_c = process.logger) === null || _c === void 0 ? void 0 : _c.success("Deployment completed! Log is available at ".concat(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log"))));
|
|
236
|
+
return [3 /*break*/, 5];
|
|
237
|
+
case 4:
|
|
238
|
+
(_d = process.logger) === null || _d === void 0 ? void 0 : _d.error('Unable to create log file.');
|
|
239
|
+
_g.label = 5;
|
|
240
|
+
case 5:
|
|
208
241
|
if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.streamWeb) {
|
|
209
242
|
appLoc = target.appLoc.replace(/\ /g, '%20');
|
|
210
243
|
webAppStreamUrl = "".concat(target.serverUrl, "/SASJobExecution?_FILE=").concat(appLoc, "/services/").concat(streamConfig.streamServiceName, ".html&_debug=2");
|
|
211
|
-
(
|
|
244
|
+
(_e = process.logger) === null || _e === void 0 ? void 0 : _e.info("Web app is available at ".concat(webAppStreamUrl));
|
|
212
245
|
}
|
|
213
|
-
return [
|
|
214
|
-
case 4:
|
|
215
|
-
(_e = process.logger) === null || _e === void 0 ? void 0 : _e.error('Unable to create log file.');
|
|
216
|
-
_g.label = 5;
|
|
217
|
-
case 5: return [2 /*return*/];
|
|
246
|
+
return [2 /*return*/];
|
|
218
247
|
}
|
|
219
248
|
});
|
|
220
249
|
});
|
|
221
250
|
}
|
|
222
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Deploys app to `SAS9` server through deployScript.
|
|
253
|
+
* @param {string} deployScriptName- name of deploy script.
|
|
254
|
+
* @param {Target} target- the target having deploy configuration.
|
|
255
|
+
* @param {string[]} linesToExecute - array of SAS code lines of deploy script to execute.
|
|
256
|
+
* @param {string} logFolder - optional path to log folder,
|
|
257
|
+
* log file name will be <deploy-script-name>.log
|
|
258
|
+
* @param {object} streamConfig - optional configuration object of StreamConfig
|
|
259
|
+
* for printing web app url on console.
|
|
260
|
+
*/
|
|
261
|
+
function deployToSas9(deployScriptName, target, linesToExecute, logFolder, streamConfig) {
|
|
223
262
|
var _a, _b, _c, _d;
|
|
224
263
|
return __awaiter(this, void 0, void 0, function () {
|
|
225
264
|
var username, password, sas9CredentialsError, sasjs, executionResult, appLoc, webAppStreamUrl;
|
|
@@ -256,33 +295,42 @@ function deployToSas9(deployScript, target, linesToExecute, logFilePath, streamC
|
|
|
256
295
|
})];
|
|
257
296
|
case 1:
|
|
258
297
|
executionResult = _e.sent();
|
|
259
|
-
if (
|
|
260
|
-
(
|
|
261
|
-
return [
|
|
298
|
+
if (!executionResult) return [3 /*break*/, 5];
|
|
299
|
+
if (!logFolder) return [3 /*break*/, 3];
|
|
300
|
+
return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log")), executionResult !== null && executionResult !== void 0 ? executionResult : '')];
|
|
262
301
|
case 2:
|
|
263
|
-
if (!logFilePath) return [3 /*break*/, 4];
|
|
264
|
-
return [4 /*yield*/, (0, utils_2.createFile)(path_1.default.join(logFilePath, "".concat(path_1.default.basename(deployScript).replace('.sas', ''), ".log")), executionResult !== null && executionResult !== void 0 ? executionResult : '')];
|
|
265
|
-
case 3:
|
|
266
302
|
_e.sent();
|
|
267
|
-
(
|
|
303
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Deployment completed! Log is available at ".concat(path_1.default.join(logFolder, "".concat(deployScriptName.replace('.sas', ''), ".log"))));
|
|
304
|
+
return [3 /*break*/, 4];
|
|
305
|
+
case 3:
|
|
306
|
+
(_b = process.logger) === null || _b === void 0 ? void 0 : _b.error('Unable to create log file.');
|
|
307
|
+
_e.label = 4;
|
|
308
|
+
case 4:
|
|
268
309
|
if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.streamWeb) {
|
|
269
310
|
appLoc = target.appLoc.replace(/\ /g, '%20');
|
|
270
311
|
webAppStreamUrl = "".concat(target.serverUrl, "/SASStoredProcess/?_PROGRAM=").concat(appLoc, "/services/").concat(streamConfig.streamServiceName);
|
|
271
312
|
(_c = process.logger) === null || _c === void 0 ? void 0 : _c.info("Web app is available at ".concat(webAppStreamUrl));
|
|
272
313
|
}
|
|
273
|
-
return [3 /*break*/,
|
|
274
|
-
case
|
|
275
|
-
(_d = process.logger) === null || _d === void 0 ? void 0 : _d.error('
|
|
276
|
-
_e.label =
|
|
277
|
-
case
|
|
314
|
+
return [3 /*break*/, 6];
|
|
315
|
+
case 5:
|
|
316
|
+
(_d = process.logger) === null || _d === void 0 ? void 0 : _d.error('Error getting execution log');
|
|
317
|
+
_e.label = 6;
|
|
318
|
+
case 6: return [2 /*return*/];
|
|
278
319
|
}
|
|
279
320
|
});
|
|
280
321
|
});
|
|
281
322
|
}
|
|
282
|
-
|
|
323
|
+
/**
|
|
324
|
+
* Deploys app to `SASJS` server.
|
|
325
|
+
* @param {Target} target- the target having deploy configuration.
|
|
326
|
+
* @param {boolean} isLocal- flag indicating if specified target is
|
|
327
|
+
* from local sasjsconfig or global sasjsconfig file.
|
|
328
|
+
* @param {object} sasjs - optional configuration object of SAS adapter.
|
|
329
|
+
*/
|
|
330
|
+
function deployToSasjs(target, isLocal, sasjs) {
|
|
283
331
|
var _a, _b;
|
|
284
332
|
return __awaiter(this, void 0, void 0, function () {
|
|
285
|
-
var buildDestinationFolder, finalFilePathJSON, jsonContent, payload, result;
|
|
333
|
+
var buildDestinationFolder, finalFilePathJSON, jsonContent, payload, authConfig, e_2, result;
|
|
286
334
|
return __generator(this, function (_c) {
|
|
287
335
|
switch (_c.label) {
|
|
288
336
|
case 0:
|
|
@@ -292,18 +340,31 @@ function deployToSasjs(target, sasjs) {
|
|
|
292
340
|
case 1:
|
|
293
341
|
jsonContent = _c.sent();
|
|
294
342
|
payload = JSON.parse(jsonContent);
|
|
295
|
-
sasjs
|
|
296
|
-
|
|
297
|
-
:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(err);
|
|
305
|
-
})];
|
|
343
|
+
if (!!sasjs) return [3 /*break*/, 5];
|
|
344
|
+
sasjs = new node_1.default({
|
|
345
|
+
serverUrl: target.serverUrl,
|
|
346
|
+
appLoc: target.appLoc,
|
|
347
|
+
serverType: target.serverType,
|
|
348
|
+
httpsAgentOptions: target.httpsAgentOptions,
|
|
349
|
+
debug: true
|
|
350
|
+
});
|
|
351
|
+
_c.label = 2;
|
|
306
352
|
case 2:
|
|
353
|
+
_c.trys.push([2, 4, , 5]);
|
|
354
|
+
return [4 /*yield*/, (0, config_1.getAuthConfig)(target)];
|
|
355
|
+
case 3:
|
|
356
|
+
authConfig = _c.sent();
|
|
357
|
+
return [3 /*break*/, 5];
|
|
358
|
+
case 4:
|
|
359
|
+
e_2 = _c.sent();
|
|
360
|
+
return [3 /*break*/, 5];
|
|
361
|
+
case 5: return [4 /*yield*/, sasjs
|
|
362
|
+
.deployToSASjs(payload, undefined, authConfig)
|
|
363
|
+
.catch(function (err) {
|
|
364
|
+
var _a;
|
|
365
|
+
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(err);
|
|
366
|
+
})];
|
|
367
|
+
case 6:
|
|
307
368
|
result = _c.sent();
|
|
308
369
|
if ((result === null || result === void 0 ? void 0 : result.status) === 'failure') {
|
|
309
370
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(result.message);
|
|
@@ -217,12 +217,14 @@ function printHelpText() {
|
|
|
217
217
|
},
|
|
218
218
|
{
|
|
219
219
|
name: 'request',
|
|
220
|
-
title: 'request <sasProgramPath> -d <path/to/datafile> -c <path/to/configfile> -t <targetName>',
|
|
220
|
+
title: 'request <sasProgramPath> -d <path/to/datafile> -c <path/to/configfile> -t <targetName> -l <path/to/log> -o <path/to/output>',
|
|
221
221
|
description: [
|
|
222
222
|
"lets",
|
|
223
223
|
"the user run a SAS job against a specified target.",
|
|
224
224
|
"The target can exist either in the local project configuration or in the global .sasjsrc file.",
|
|
225
|
-
"<sasProgramPath> - if this has a leading slash (eg /Public/app/folder/servicename) then it must be the full path. If it is a relative path (eg path/servicename) then it will be pre-pended with the appLoc - which must then be defined in the sasjs config."
|
|
225
|
+
"<sasProgramPath> - if this has a leading slash (eg /Public/app/folder/servicename) then it must be the full path. If it is a relative path (eg path/servicename) then it will be pre-pended with the appLoc - which must then be defined in the sasjs config.",
|
|
226
|
+
"<path/to/log> - Location in which to store the log file. If not provided AND an error occurs, the log will be stored in the execution path.",
|
|
227
|
+
"<path/to/output> - Location to store the output file. If not provided, a file named output.json will be saved in the execution path."
|
|
226
228
|
]
|
|
227
229
|
},
|
|
228
230
|
{
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { JSDOM } from 'jsdom';
|
|
2
2
|
export declare const getScriptTags: (parsedHtml: JSDOM) => HTMLScriptElement[];
|
|
3
|
+
export declare const getStyleInPageTags: (parsedHtml: JSDOM) => HTMLStyleElement[];
|
|
3
4
|
export declare const getStyleTags: (parsedHtml: JSDOM) => HTMLLinkElement[];
|
|
4
5
|
export declare const getFaviconTags: (parsedHtml: JSDOM) => HTMLLinkElement[];
|
|
5
6
|
export declare const getImgTags: (parsedHtml: JSDOM) => HTMLImageElement[];
|
|
7
|
+
export declare const getSourceTags: (parsedHtml: JSDOM) => HTMLSourceElement[];
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getImgTags = exports.getFaviconTags = exports.getStyleTags = exports.getScriptTags = void 0;
|
|
3
|
+
exports.getSourceTags = exports.getImgTags = exports.getFaviconTags = exports.getStyleTags = exports.getStyleInPageTags = exports.getScriptTags = void 0;
|
|
4
4
|
var getScriptTags = function (parsedHtml) {
|
|
5
5
|
return Array.from(parsedHtml.window.document.getElementsByTagName('script'));
|
|
6
6
|
};
|
|
7
7
|
exports.getScriptTags = getScriptTags;
|
|
8
|
+
var getStyleInPageTags = function (parsedHtml) {
|
|
9
|
+
return Array.from(parsedHtml.window.document.getElementsByTagName('style'));
|
|
10
|
+
};
|
|
11
|
+
exports.getStyleInPageTags = getStyleInPageTags;
|
|
8
12
|
var getStyleTags = function (parsedHtml) {
|
|
9
13
|
return Array.from(parsedHtml.window.document.getElementsByTagName('link')).filter(function (s) { return s.getAttribute('rel') === 'stylesheet'; });
|
|
10
14
|
};
|
|
@@ -17,3 +21,7 @@ var getImgTags = function (parsedHtml) {
|
|
|
17
21
|
return Array.from(parsedHtml.window.document.getElementsByTagName('img')).filter(function (s) { return s.getAttribute('src'); });
|
|
18
22
|
};
|
|
19
23
|
exports.getImgTags = getImgTags;
|
|
24
|
+
var getSourceTags = function (parsedHtml) {
|
|
25
|
+
return Array.from(parsedHtml.window.document.getElementsByTagName('source')).filter(function (s) { return s.getAttribute('src'); });
|
|
26
|
+
};
|
|
27
|
+
exports.getSourceTags = getSourceTags;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const sasjsout = "\n%macro sasjsout(type,fref=sasjs);\n%global sysprocessmode SYS_JES_JOB_URI;\n%if \"&sysprocessmode\"=\"SAS Compute Server\" %then %do;\n %if &type=HTML %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name=\"_webout.json\"\n contenttype=\"text/html\";\n %end;\n %else %if &type=JS or &type=JS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.js'\n contenttype='application/javascript';\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.css'\n contenttype='text/css';\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n name=\"_webout.%lowcase(&type)\"\n contenttype=\"image/%lowcase(&type)\" lrecl=2000000 recfm=n;\n %end;\n %else %if &type=ICO %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ico'\n contenttype='image/vnd.microsoft.icon' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=JSON %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.json'\n contenttype='application/json' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=MP3 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.mp3'\n contenttype='audio/mpeg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WAV %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.wav'\n contenttype='audio/x-wav' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=OGG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ogg'\n contenttype='audio/ogg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"font/%lowcase(&
|
|
1
|
+
export declare const sasjsout = "\n%macro sasjsout(type,fref=sasjs);\n%global sysprocessmode SYS_JES_JOB_URI;\n%if \"&sysprocessmode\"=\"SAS Compute Server\" %then %do;\n %if &type=HTML %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name=\"_webout.json\"\n contenttype=\"text/html\";\n %end;\n %else %if &type=JS or &type=JS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.js'\n contenttype='application/javascript';\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.css'\n contenttype='text/css';\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n name=\"_webout.%lowcase(&type)\"\n contenttype=\"image/%lowcase(&type)\" lrecl=2000000 recfm=n;\n %end;\n %else %if &type=ICO %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ico'\n contenttype='image/vnd.microsoft.icon' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=JSON %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.json'\n contenttype='application/json' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=MP3 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.mp3'\n contenttype='audio/mpeg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WAV %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.wav'\n contenttype='audio/x-wav' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=OGG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ogg'\n contenttype='audio/ogg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"font/%lowcase(&type)\";\n %end;\n %else %if &type=MP4 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"video/mp4\";\n %end;\n%end;\n%else %do;\n %if &type=JS or &type=JS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(\n Content-type,application/javascript%str(;)charset=UTF-8\n ));\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,text/css));\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/%lowcase(&type)));\n %end;\n %else %if &type=ICO %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/vnd.microsoft.icon));\n %end;\n %else %if &type=JSON %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,application/json));\n %end;\n %else %if &type=MP3 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/mpeg));\n %end;\n %else %if &type=WAV %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/x-wav));\n %end;\n %else %if &type=OGG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/ogg));\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,font/%lowcase(&type)));\n %end;\n %else %if &type=MP4 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,video/mp4));\n %end;\n%end;\n%if &type=HTML %then %do;\n /*\n We need to perform some substitutions -eg to get the APPLOC and SERVERTYPE.\n Therefore the developer should avoid writing lines that exceed 32k\n characters (eg base64 encoded images) as they will get truncated when passing\n through the datastep. This could of course be re-written using LUA, removing\n the length restriction. Pull requests are welcome!\n */\n filename _sjs temp;\n data _null_;\n file _sjs lrecl=32767 encoding='utf-8';\n infile &fref lrecl=32767;\n input;\n length appLoc expanded_path $1048;\n if _n_=1 then do;\n retain pgm \"&_program\" appLoc expanded_path;\n /* index is deployed in the /services/ folder under the appLoc */\n appLoc=substr(pgm,1,find(pgm,'/services/')-1);\n expanded_path=cats('?_PROGRAM=',appLoc,'/services/');\n end;\n if find(_infile_,' appLoc: ') then put ' appLoc: ' apploc:$quote1048. ',';\n else if find(_infile_,' serverType: ') then do;\n if symexist('_metaperson') then put ' serverType: \"SAS9\" ,';\n else put ' serverType: \"SASVIYA\" ,';\n end;\n else if find(_infile_,' hostUrl: ') then do;\n /* nothing - we are streaming, so remove to default as hostname */\n end;\n else do;\n length newline $32767;\n /* during SAS9 compilation, dependencies are assigned three slashes /// */\n newline=tranwrd(_infile_,'?_PROGRAM=///',cats(expanded_path));\n put newline;\n end;\n run;\n %let fref=_sjs;\n%end;\n\n/**\n * In SAS9, JS & CSS files are base64 encoded to avoid UTF8 issues in WLATIN1\n * metadata - so in this case, decode and stream byte by byte.\n * */\n%if &type=GIF or &type=PNG or &type=JPG or &type=JPEG or &type=ICO or &type=MP3\nor &type=JS64 or &type=CSS64 or &type=WAV or &type=OGG or &type=WOFF\nor &type=WOFF2 or &type=TTF or &type=MP4\n%then %do;\n data _null_;\n length filein 8 fileout 8;\n filein = fopen(\"&fref\",'I',4,'B');\n fileout = fopen(\"_webout\",'A',1,'B');\n char= '20'x;\n do while(fread(filein)=0);\n length raw $4 ;\n do i=1 to 4;\n rc=fget(filein,char,1);\n substr(raw,i,1)=char;\n end;\n rc = fput(fileout, input(raw,$base64X4.));\n rc =fwrite(fileout);\n end;\n rc = fclose(filein);\n rc = fclose(fileout);\n run;\n%end;\n%else %do;\n data _null_;\n length filein 8 fileid 8;\n filein = fopen(\"&fref\",'I',1,'B');\n fileid = fopen(\"_webout\",'A',1,'B');\n rec = '20'x;\n do while(fread(filein)=0);\n rc = fget(filein,rec,1);\n rc = fput(fileid, rec);\n rc =fwrite(fileid);\n end;\n rc = fclose(filein);\n rc = fclose(fileid);\n run;\n%end;\n%mend;";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sasjsout = void 0;
|
|
4
|
-
exports.sasjsout = "\n%macro sasjsout(type,fref=sasjs);\n%global sysprocessmode SYS_JES_JOB_URI;\n%if \"&sysprocessmode\"=\"SAS Compute Server\" %then %do;\n %if &type=HTML %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name=\"_webout.json\"\n contenttype=\"text/html\";\n %end;\n %else %if &type=JS or &type=JS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.js'\n contenttype='application/javascript';\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.css'\n contenttype='text/css';\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n name=\"_webout.%lowcase(&type)\"\n contenttype=\"image/%lowcase(&type)\" lrecl=2000000 recfm=n;\n %end;\n %else %if &type=ICO %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ico'\n contenttype='image/vnd.microsoft.icon' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=JSON %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.json'\n contenttype='application/json' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=MP3 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.mp3'\n contenttype='audio/mpeg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WAV %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.wav'\n contenttype='audio/x-wav' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=OGG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ogg'\n contenttype='audio/ogg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"font/%lowcase(&
|
|
4
|
+
exports.sasjsout = "\n%macro sasjsout(type,fref=sasjs);\n%global sysprocessmode SYS_JES_JOB_URI;\n%if \"&sysprocessmode\"=\"SAS Compute Server\" %then %do;\n %if &type=HTML %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name=\"_webout.json\"\n contenttype=\"text/html\";\n %end;\n %else %if &type=JS or &type=JS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.js'\n contenttype='application/javascript';\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.css'\n contenttype='text/css';\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n name=\"_webout.%lowcase(&type)\"\n contenttype=\"image/%lowcase(&type)\" lrecl=2000000 recfm=n;\n %end;\n %else %if &type=ICO %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ico'\n contenttype='image/vnd.microsoft.icon' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=JSON %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.json'\n contenttype='application/json' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=MP3 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.mp3'\n contenttype='audio/mpeg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WAV %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.wav'\n contenttype='audio/x-wav' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=OGG %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\" name='_webout.ogg'\n contenttype='audio/ogg' lrecl=2000000 recfm=n;\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"font/%lowcase(&type)\";\n %end;\n %else %if &type=MP4 %then %do;\n filename _webout filesrvc parenturi=\"&SYS_JES_JOB_URI\"\n contenttype=\"video/mp4\";\n %end;\n%end;\n%else %do;\n %if &type=JS or &type=JS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(\n Content-type,application/javascript%str(;)charset=UTF-8\n ));\n %end;\n %else %if &type=CSS or &type=CSS64 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,text/css));\n %end;\n %else %if &type=PNG or &type=GIF or &type=JPEG or &type=JPG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/%lowcase(&type)));\n %end;\n %else %if &type=ICO %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,image/vnd.microsoft.icon));\n %end;\n %else %if &type=JSON %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,application/json));\n %end;\n %else %if &type=MP3 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/mpeg));\n %end;\n %else %if &type=WAV %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/x-wav));\n %end;\n %else %if &type=OGG %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,audio/ogg));\n %end;\n %else %if &type=WOFF or &type=WOFF2 or &type=TTF %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,font/%lowcase(&type)));\n %end;\n %else %if &type=MP4 %then %do;\n %let rc=%sysfunc(stpsrv_header(Content-type,video/mp4));\n %end;\n%end;\n%if &type=HTML %then %do;\n /*\n We need to perform some substitutions -eg to get the APPLOC and SERVERTYPE.\n Therefore the developer should avoid writing lines that exceed 32k\n characters (eg base64 encoded images) as they will get truncated when passing\n through the datastep. This could of course be re-written using LUA, removing\n the length restriction. Pull requests are welcome!\n */\n filename _sjs temp;\n data _null_;\n file _sjs lrecl=32767 encoding='utf-8';\n infile &fref lrecl=32767;\n input;\n length appLoc expanded_path $1048;\n if _n_=1 then do;\n retain pgm \"&_program\" appLoc expanded_path;\n /* index is deployed in the /services/ folder under the appLoc */\n appLoc=substr(pgm,1,find(pgm,'/services/')-1);\n expanded_path=cats('?_PROGRAM=',appLoc,'/services/');\n end;\n if find(_infile_,' appLoc: ') then put ' appLoc: ' apploc:$quote1048. ',';\n else if find(_infile_,' serverType: ') then do;\n if symexist('_metaperson') then put ' serverType: \"SAS9\" ,';\n else put ' serverType: \"SASVIYA\" ,';\n end;\n else if find(_infile_,' hostUrl: ') then do;\n /* nothing - we are streaming, so remove to default as hostname */\n end;\n else do;\n length newline $32767;\n /* during SAS9 compilation, dependencies are assigned three slashes /// */\n newline=tranwrd(_infile_,'?_PROGRAM=///',cats(expanded_path));\n put newline;\n end;\n run;\n %let fref=_sjs;\n%end;\n\n/**\n * In SAS9, JS & CSS files are base64 encoded to avoid UTF8 issues in WLATIN1\n * metadata - so in this case, decode and stream byte by byte.\n * */\n%if &type=GIF or &type=PNG or &type=JPG or &type=JPEG or &type=ICO or &type=MP3\nor &type=JS64 or &type=CSS64 or &type=WAV or &type=OGG or &type=WOFF\nor &type=WOFF2 or &type=TTF or &type=MP4\n%then %do;\n data _null_;\n length filein 8 fileout 8;\n filein = fopen(\"&fref\",'I',4,'B');\n fileout = fopen(\"_webout\",'A',1,'B');\n char= '20'x;\n do while(fread(filein)=0);\n length raw $4 ;\n do i=1 to 4;\n rc=fget(filein,char,1);\n substr(raw,i,1)=char;\n end;\n rc = fput(fileout, input(raw,$base64X4.));\n rc =fwrite(fileout);\n end;\n rc = fclose(filein);\n rc = fclose(fileout);\n run;\n%end;\n%else %do;\n data _null_;\n length filein 8 fileid 8;\n filein = fopen(\"&fref\",'I',1,'B');\n fileid = fopen(\"_webout\",'A',1,'B');\n rec = '20'x;\n do while(fread(filein)=0);\n rc = fget(filein,rec,1);\n rc = fput(fileid, rec);\n rc =fwrite(fileid);\n end;\n rc = fclose(filein);\n rc = fclose(fileid);\n run;\n%end;\n%mend;";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare function init(): void;
|
|
2
|
+
declare function main(): void;
|
|
3
|
+
declare function update(dt: any): void;
|
|
4
|
+
declare function handleInput(dt: any): void;
|
|
5
|
+
declare function updateEntities(dt: any, gameTime: any): void;
|
|
6
|
+
declare function checkCollisions(): void;
|
|
7
|
+
declare function render(): void;
|
|
8
|
+
declare function renderEntity(entity: any): void;
|
|
9
|
+
declare var requestAnimFrame: ((callback: FrameRequestCallback) => number) & typeof requestAnimationFrame;
|
|
10
|
+
declare var canvas: HTMLCanvasElement;
|
|
11
|
+
declare var ctx: CanvasRenderingContext2D | null;
|
|
12
|
+
declare var updateables: any[];
|
|
13
|
+
declare var fireballs: any[];
|
|
14
|
+
declare var player: any;
|
|
15
|
+
declare var vX: number;
|
|
16
|
+
declare var vY: number;
|
|
17
|
+
declare var vWidth: number;
|
|
18
|
+
declare var vHeight: number;
|
|
19
|
+
declare var level: any;
|
|
20
|
+
declare var sounds: any;
|
|
21
|
+
declare var music: any;
|
|
22
|
+
declare var lastTime: any;
|
|
23
|
+
declare var gameTime: number;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// game.js from SASjs/Mario
|
|
3
|
+
// https://github.com/sasjs/mario/blob/main/src/js/game.js
|
|
4
|
+
var requestAnimFrame = (function () {
|
|
5
|
+
return (window.requestAnimationFrame ||
|
|
6
|
+
window.webkitRequestAnimationFrame ||
|
|
7
|
+
window.mozRequestAnimationFrame ||
|
|
8
|
+
window.oRequestAnimationFrame ||
|
|
9
|
+
window.msRequestAnimationFrame ||
|
|
10
|
+
function (callback) {
|
|
11
|
+
window.setTimeout(callback, 1000 / 60);
|
|
12
|
+
});
|
|
13
|
+
})();
|
|
14
|
+
//create the canvas
|
|
15
|
+
var canvas = document.createElement('canvas');
|
|
16
|
+
var ctx = canvas.getContext('2d');
|
|
17
|
+
var updateables = [];
|
|
18
|
+
var fireballs = [];
|
|
19
|
+
var player = new Mario.Player([0, 0]);
|
|
20
|
+
//we might have to get the size and calculate the scaling
|
|
21
|
+
//but this method should let us make it however big.
|
|
22
|
+
//Cool!
|
|
23
|
+
//TODO: Automatically scale the game to work and look good on widescreen.
|
|
24
|
+
//TODO: fiddling with scaled sprites looks BETTER, but not perfect. Hmm.
|
|
25
|
+
canvas.width = 762;
|
|
26
|
+
canvas.height = 720;
|
|
27
|
+
ctx.scale(3, 3);
|
|
28
|
+
document.body.appendChild(canvas);
|
|
29
|
+
//viewport
|
|
30
|
+
var vX = 0, vY = 0, vWidth = 256, vHeight = 240;
|
|
31
|
+
//load our images
|
|
32
|
+
resources.load([
|
|
33
|
+
'sprites/player.png',
|
|
34
|
+
'sprites/enemy.png',
|
|
35
|
+
'sprites/tiles.png',
|
|
36
|
+
'sprites/playerl.png',
|
|
37
|
+
'sprites/items.png',
|
|
38
|
+
'sprites/enemyr.png'
|
|
39
|
+
]);
|
|
40
|
+
resources.onReady(init);
|
|
41
|
+
var level;
|
|
42
|
+
var sounds;
|
|
43
|
+
var music;
|
|
44
|
+
//initialize
|
|
45
|
+
var lastTime;
|
|
46
|
+
function init() {
|
|
47
|
+
music = {
|
|
48
|
+
overworld: new Audio('sounds/aboveground_bgm.ogg'),
|
|
49
|
+
underground: new Audio('sounds/underground_bgm.ogg'),
|
|
50
|
+
clear: new Audio('sounds/stage_clear.wav'),
|
|
51
|
+
death: new Audio('sounds/mariodie.wav')
|
|
52
|
+
};
|
|
53
|
+
sounds = {
|
|
54
|
+
smallJump: new Audio('sounds/jump-small.wav'),
|
|
55
|
+
bigJump: new Audio('sounds/jump-super.wav'),
|
|
56
|
+
breakBlock: new Audio('sounds/breakblock.wav'),
|
|
57
|
+
bump: new Audio('sounds/bump.wav'),
|
|
58
|
+
coin: new Audio('sounds/coin.wav'),
|
|
59
|
+
fireball: new Audio('sounds/fireball.wav'),
|
|
60
|
+
flagpole: new Audio('sounds/flagpole.wav'),
|
|
61
|
+
kick: new Audio('sounds/kick.wav'),
|
|
62
|
+
pipe: new Audio('sounds/pipe.wav'),
|
|
63
|
+
itemAppear: new Audio('sounds/itemAppear.wav'),
|
|
64
|
+
powerup: new Audio('sounds/powerup.wav'),
|
|
65
|
+
stomp: new Audio('sounds/stomp.wav')
|
|
66
|
+
};
|
|
67
|
+
Mario.oneone();
|
|
68
|
+
lastTime = Date.now();
|
|
69
|
+
main();
|
|
70
|
+
}
|
|
71
|
+
var gameTime = 0;
|
|
72
|
+
//set up the game loop
|
|
73
|
+
function main() {
|
|
74
|
+
var now = Date.now();
|
|
75
|
+
var dt = (now - lastTime) / 1000.0;
|
|
76
|
+
update(dt);
|
|
77
|
+
render();
|
|
78
|
+
lastTime = now;
|
|
79
|
+
requestAnimFrame(main);
|
|
80
|
+
}
|
|
81
|
+
function update(dt) {
|
|
82
|
+
gameTime += dt;
|
|
83
|
+
handleInput(dt);
|
|
84
|
+
updateEntities(dt, gameTime);
|
|
85
|
+
checkCollisions();
|
|
86
|
+
}
|
|
87
|
+
function handleInput(dt) {
|
|
88
|
+
if (player.piping || player.dying || player.noInput)
|
|
89
|
+
return; //don't accept input
|
|
90
|
+
if (input.isDown('RUN')) {
|
|
91
|
+
player.run();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
player.noRun();
|
|
95
|
+
}
|
|
96
|
+
if (input.isDown('JUMP')) {
|
|
97
|
+
player.jump();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
//we need this to handle the timing for how long you hold it
|
|
101
|
+
player.noJump();
|
|
102
|
+
}
|
|
103
|
+
if (input.isDown('DOWN')) {
|
|
104
|
+
player.crouch();
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
player.noCrouch();
|
|
108
|
+
}
|
|
109
|
+
if (input.isDown('LEFT')) {
|
|
110
|
+
// 'd' or left arrow
|
|
111
|
+
player.moveLeft();
|
|
112
|
+
}
|
|
113
|
+
else if (input.isDown('RIGHT')) {
|
|
114
|
+
// 'k' or right arrow
|
|
115
|
+
player.moveRight();
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
player.noWalk();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//update all the moving stuff
|
|
122
|
+
function updateEntities(dt, gameTime) {
|
|
123
|
+
player.update(dt, vX);
|
|
124
|
+
updateables.forEach(function (ent) {
|
|
125
|
+
ent.update(dt, gameTime);
|
|
126
|
+
});
|
|
127
|
+
//This should stop the jump when he switches sides on the flag.
|
|
128
|
+
if (player.exiting) {
|
|
129
|
+
if (player.pos[0] > vX + 96)
|
|
130
|
+
vX = player.pos[0] - 96;
|
|
131
|
+
}
|
|
132
|
+
else if (level.scrolling && player.pos[0] > vX + 80) {
|
|
133
|
+
vX = player.pos[0] - 80;
|
|
134
|
+
}
|
|
135
|
+
if (player.powering.length !== 0 || player.dying) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
level.items.forEach(function (ent) {
|
|
139
|
+
ent.update(dt);
|
|
140
|
+
});
|
|
141
|
+
level.enemies.forEach(function (ent) {
|
|
142
|
+
ent.update(dt, vX);
|
|
143
|
+
});
|
|
144
|
+
fireballs.forEach(function (fireball) {
|
|
145
|
+
fireball.update(dt);
|
|
146
|
+
});
|
|
147
|
+
level.pipes.forEach(function (pipe) {
|
|
148
|
+
pipe.update(dt);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
//scan for collisions
|
|
152
|
+
function checkCollisions() {
|
|
153
|
+
if (player.powering.length !== 0 || player.dying) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
player.checkCollisions();
|
|
157
|
+
//Apparently for each will just skip indices where things were deleted.
|
|
158
|
+
level.items.forEach(function (item) {
|
|
159
|
+
item.checkCollisions();
|
|
160
|
+
});
|
|
161
|
+
level.enemies.forEach(function (ent) {
|
|
162
|
+
ent.checkCollisions();
|
|
163
|
+
});
|
|
164
|
+
fireballs.forEach(function (fireball) {
|
|
165
|
+
fireball.checkCollisions();
|
|
166
|
+
});
|
|
167
|
+
level.pipes.forEach(function (pipe) {
|
|
168
|
+
pipe.checkCollisions();
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
//draw the game!
|
|
172
|
+
function render() {
|
|
173
|
+
updateables = [];
|
|
174
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
175
|
+
ctx.fillStyle = level.background;
|
|
176
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
177
|
+
//scenery gets drawn first to get layering right.
|
|
178
|
+
for (var i = 0; i < 15; i++) {
|
|
179
|
+
for (var j = Math.floor(vX / 16) - 1; j < Math.floor(vX / 16) + 20; j++) {
|
|
180
|
+
if (level.scenery[i][j]) {
|
|
181
|
+
renderEntity(level.scenery[i][j]);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//then items
|
|
186
|
+
level.items.forEach(function (item) {
|
|
187
|
+
renderEntity(item);
|
|
188
|
+
});
|
|
189
|
+
level.enemies.forEach(function (enemy) {
|
|
190
|
+
renderEntity(enemy);
|
|
191
|
+
});
|
|
192
|
+
fireballs.forEach(function (fireball) {
|
|
193
|
+
renderEntity(fireball);
|
|
194
|
+
});
|
|
195
|
+
//then we draw every static object.
|
|
196
|
+
for (var i = 0; i < 15; i++) {
|
|
197
|
+
for (var j = Math.floor(vX / 16) - 1; j < Math.floor(vX / 16) + 20; j++) {
|
|
198
|
+
if (level.statics[i][j]) {
|
|
199
|
+
renderEntity(level.statics[i][j]);
|
|
200
|
+
}
|
|
201
|
+
if (level.blocks[i][j]) {
|
|
202
|
+
renderEntity(level.blocks[i][j]);
|
|
203
|
+
updateables.push(level.blocks[i][j]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//then the player
|
|
208
|
+
if (player.invincibility % 2 === 0) {
|
|
209
|
+
renderEntity(player);
|
|
210
|
+
}
|
|
211
|
+
//Mario goes INTO pipes, so naturally they go after.
|
|
212
|
+
level.pipes.forEach(function (pipe) {
|
|
213
|
+
renderEntity(pipe);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function renderEntity(entity) {
|
|
217
|
+
entity.render(ctx, vX, vY);
|
|
218
|
+
}
|
|
@@ -26,7 +26,7 @@ describe('updateLinkTag', function () {
|
|
|
26
26
|
source: 'image.jpeg',
|
|
27
27
|
target: sasProgramPath
|
|
28
28
|
});
|
|
29
|
-
(0, updateLinkTag_1.updateLinkTag)(imgTag, assetPathMap, '
|
|
29
|
+
(0, updateLinkTag_1.updateLinkTag)(imgTag, assetPathMap, 'src');
|
|
30
30
|
expect(imgTag.getAttribute('src')).toEqual(sasProgramPath);
|
|
31
31
|
});
|
|
32
32
|
});
|
|
@@ -38,6 +38,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
42
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
43
|
+
if (!m) return o;
|
|
44
|
+
var i = m.call(o), r, ar = [], e;
|
|
45
|
+
try {
|
|
46
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
47
|
+
}
|
|
48
|
+
catch (error) { e = { error: error }; }
|
|
49
|
+
finally {
|
|
50
|
+
try {
|
|
51
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
52
|
+
}
|
|
53
|
+
finally { if (e) throw e.error; }
|
|
54
|
+
}
|
|
55
|
+
return ar;
|
|
56
|
+
};
|
|
57
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
58
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
59
|
+
if (ar || !(i in from)) {
|
|
60
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
61
|
+
ar[i] = from[i];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
65
|
+
};
|
|
41
66
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
67
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
68
|
};
|
|
@@ -79,7 +104,7 @@ describe('updateScriptTag', function () {
|
|
|
79
104
|
return __generator(this, function (_a) {
|
|
80
105
|
switch (_a.label) {
|
|
81
106
|
case 0:
|
|
82
|
-
scriptTag = document.createElement('
|
|
107
|
+
scriptTag = document.createElement('script');
|
|
83
108
|
sourcePath = path_1.default.join(__dirname, 'testFiles');
|
|
84
109
|
target = { serverType: utils_1.ServerType.Sas9 };
|
|
85
110
|
assetPathMap = [];
|
|
@@ -121,4 +146,124 @@ describe('updateScriptTag', function () {
|
|
|
121
146
|
}
|
|
122
147
|
});
|
|
123
148
|
}); });
|
|
149
|
+
it("should update links in js script", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
150
|
+
var sourcePath, gameTestFilePath, target, assetPathMap, scriptTag, _a, updatedContent;
|
|
151
|
+
return __generator(this, function (_b) {
|
|
152
|
+
switch (_b.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
sourcePath = path_1.default.join(__dirname, 'testFiles');
|
|
155
|
+
gameTestFilePath = path_1.default.join(sourcePath, 'script3.js');
|
|
156
|
+
target = { serverType: utils_1.ServerType.SasViya };
|
|
157
|
+
assetPathMap = __spreadArray(__spreadArray([], __read(gameJSSpriteLinks), false), __read(gameJSSoundLinks), false);
|
|
158
|
+
scriptTag = document.createElement('script');
|
|
159
|
+
_a = scriptTag;
|
|
160
|
+
return [4 /*yield*/, (0, utils_1.readFile)(gameTestFilePath)];
|
|
161
|
+
case 1:
|
|
162
|
+
_a.innerHTML = _b.sent();
|
|
163
|
+
return [4 /*yield*/, (0, updateScriptTag_1.updateScriptTag)(scriptTag, sourcePath, destinationPath, target.serverType, assetPathMap)];
|
|
164
|
+
case 2:
|
|
165
|
+
_b.sent();
|
|
166
|
+
updatedContent = scriptTag.innerHTML;
|
|
167
|
+
gameJSSpriteLinks.forEach(function (link) {
|
|
168
|
+
return expect(updatedContent).toContain(link.target);
|
|
169
|
+
});
|
|
170
|
+
gameJSSoundLinks.forEach(function (link) {
|
|
171
|
+
return expect(updatedContent).toContain(link.target);
|
|
172
|
+
});
|
|
173
|
+
return [2 /*return*/];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}); });
|
|
124
177
|
});
|
|
178
|
+
var gameJSSpriteLinks = [
|
|
179
|
+
{
|
|
180
|
+
source: 'sprites/enemy.png',
|
|
181
|
+
target: 'link-to-compiled-webv/sprites/enemy.png'
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
source: 'sprites/enemyr.png',
|
|
185
|
+
target: 'link-to-compiled-webv/sprites/enemyr.png'
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
source: 'sprites/items.png',
|
|
189
|
+
target: 'link-to-compiled-webv/sprites/items.png'
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
source: 'sprites/player.png',
|
|
193
|
+
target: 'link-to-compiled-webv/sprites/player.png'
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
source: 'sprites/playerl.png',
|
|
197
|
+
target: 'link-to-compiled-webv/sprites/playerl.png'
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
source: 'sprites/tiles.png',
|
|
201
|
+
target: 'link-to-compiled-webv/sprites/tiles.png'
|
|
202
|
+
}
|
|
203
|
+
];
|
|
204
|
+
var gameJSSoundLinks = [
|
|
205
|
+
{
|
|
206
|
+
source: 'sounds/aboveground_bgm.ogg',
|
|
207
|
+
target: 'link-to-compiled-webv/sounds/aboveground_bgm.ogg'
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
source: 'sounds/breakblock.wav',
|
|
211
|
+
target: 'link-to-compiled-webv/sounds/breakblock.wav'
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
source: 'sounds/bump.wav',
|
|
215
|
+
target: 'link-to-compiled-webv/sounds/bump.wav'
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
source: 'sounds/coin.wav',
|
|
219
|
+
target: 'link-to-compiled-webv/sounds/coin.wav'
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
source: 'sounds/fireball.wav',
|
|
223
|
+
target: 'link-to-compiled-webv/sounds/fireball.wav'
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
source: 'sounds/flagpole.wav',
|
|
227
|
+
target: 'link-to-compiled-webv/sounds/flagpole.wav'
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
source: 'sounds/itemAppear.wav',
|
|
231
|
+
target: 'link-to-compiled-webv/sounds/itemAppear.wav'
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
source: 'sounds/jump-small.wav',
|
|
235
|
+
target: 'link-to-compiled-webv/sounds/jump-small.wav'
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
source: 'sounds/jump-super.wav',
|
|
239
|
+
target: 'link-to-compiled-webv/sounds/jump-super.wav'
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
source: 'sounds/kick.wav',
|
|
243
|
+
target: 'link-to-compiled-webv/sounds/kick.wav'
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
source: 'sounds/mariodie.wav',
|
|
247
|
+
target: 'link-to-compiled-webv/sounds/mariodie.wav'
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
source: 'sounds/pipe.wav',
|
|
251
|
+
target: 'link-to-compiled-webv/sounds/pipe.wav'
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
source: 'sounds/powerup.wav',
|
|
255
|
+
target: 'link-to-compiled-webv/sounds/powerup.wav'
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
source: 'sounds/stage_clear.wav',
|
|
259
|
+
target: 'link-to-compiled-webv/sounds/stage_clear.wav'
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
source: 'sounds/stomp.wav',
|
|
263
|
+
target: 'link-to-compiled-webv/sounds/stomp.wav'
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
source: 'sounds/underground_bgm.ogg',
|
|
267
|
+
target: 'link-to-compiled-webv/sounds/underground_bgm.ogg'
|
|
268
|
+
}
|
|
269
|
+
];
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @jest-environment jsdom
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
16
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
+
function step(op) {
|
|
19
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
+
while (_) try {
|
|
21
|
+
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;
|
|
22
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
+
switch (op[0]) {
|
|
24
|
+
case 0: case 1: t = op; break;
|
|
25
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
+
default:
|
|
29
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
+
if (t[2]) _.ops.pop();
|
|
34
|
+
_.trys.pop(); continue;
|
|
35
|
+
}
|
|
36
|
+
op = body.call(thisArg, _);
|
|
37
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
42
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
43
|
+
if (!m) return o;
|
|
44
|
+
var i = m.call(o), r, ar = [], e;
|
|
45
|
+
try {
|
|
46
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
47
|
+
}
|
|
48
|
+
catch (error) { e = { error: error }; }
|
|
49
|
+
finally {
|
|
50
|
+
try {
|
|
51
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
52
|
+
}
|
|
53
|
+
finally { if (e) throw e.error; }
|
|
54
|
+
}
|
|
55
|
+
return ar;
|
|
56
|
+
};
|
|
57
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
58
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
59
|
+
if (ar || !(i in from)) {
|
|
60
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
61
|
+
ar[i] = from[i];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
65
|
+
};
|
|
66
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
67
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
68
|
+
};
|
|
69
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
+
var path_1 = __importDefault(require("path"));
|
|
71
|
+
var utils_1 = require("@sasjs/utils");
|
|
72
|
+
var updateStyleTag_1 = require("../updateStyleTag");
|
|
73
|
+
var utils_2 = require("../../../../utils");
|
|
74
|
+
describe('updateStyleTag', function () {
|
|
75
|
+
var destinationPath;
|
|
76
|
+
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0:
|
|
80
|
+
destinationPath = path_1.default.join(__dirname, "cli-test-web-updateStyleTag-".concat((0, utils_1.generateTimestamp)()));
|
|
81
|
+
return [4 /*yield*/, (0, utils_1.createFolder)(destinationPath)];
|
|
82
|
+
case 1:
|
|
83
|
+
_a.sent();
|
|
84
|
+
process.projectDir = destinationPath;
|
|
85
|
+
return [4 /*yield*/, (0, utils_2.setConstants)()];
|
|
86
|
+
case 2:
|
|
87
|
+
_a.sent();
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}); });
|
|
92
|
+
afterAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0: return [4 /*yield*/, (0, utils_1.deleteFolder)(destinationPath)];
|
|
96
|
+
case 1:
|
|
97
|
+
_a.sent();
|
|
98
|
+
return [2 /*return*/];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}); });
|
|
102
|
+
it("should update links in css script", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
103
|
+
var sourcePath, styleFilePath, target, assetPathMap, scriptTag, _a, updatedContent;
|
|
104
|
+
return __generator(this, function (_b) {
|
|
105
|
+
switch (_b.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
sourcePath = path_1.default.join(__dirname, 'testFiles');
|
|
108
|
+
styleFilePath = path_1.default.join(sourcePath, 'style1.css');
|
|
109
|
+
target = { serverType: utils_1.ServerType.SasViya };
|
|
110
|
+
assetPathMap = __spreadArray([], __read(assetLinks), false);
|
|
111
|
+
scriptTag = document.createElement('style');
|
|
112
|
+
_a = scriptTag;
|
|
113
|
+
return [4 /*yield*/, (0, utils_1.readFile)(styleFilePath)];
|
|
114
|
+
case 1:
|
|
115
|
+
_a.innerHTML = _b.sent();
|
|
116
|
+
return [4 /*yield*/, (0, updateStyleTag_1.updateStyleTag)(scriptTag, sourcePath, destinationPath, target.serverType, assetPathMap)];
|
|
117
|
+
case 2:
|
|
118
|
+
_b.sent();
|
|
119
|
+
updatedContent = scriptTag.innerHTML;
|
|
120
|
+
assetLinks.forEach(function (link) { return expect(updatedContent).toContain(link.target); });
|
|
121
|
+
return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}); });
|
|
125
|
+
});
|
|
126
|
+
var assetLinks = [
|
|
127
|
+
{
|
|
128
|
+
source: 'assets/fa-solid-900.ttf',
|
|
129
|
+
target: 'link-to-compiled-webv/assets/fa-solid-900.ttf'
|
|
130
|
+
}
|
|
131
|
+
];
|
|
@@ -66,10 +66,11 @@ var utils_1 = require("@sasjs/utils");
|
|
|
66
66
|
var getTags_1 = require("./getTags");
|
|
67
67
|
var updateScriptTag_1 = require("./updateScriptTag");
|
|
68
68
|
var updateLinkTag_1 = require("./updateLinkTag");
|
|
69
|
+
var updateStyleTag_1 = require("./updateStyleTag");
|
|
69
70
|
var updateAllTags = function (parsedHtml, _a) {
|
|
70
71
|
var webSourcePathFull = _a.webSourcePathFull, destinationPath = _a.destinationPath, serverType = _a.serverType, assetPathMap = _a.assetPathMap;
|
|
71
72
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
-
var assetsNotFound, scriptTags, styleTags, faviconTags,
|
|
73
|
+
var assetsNotFound, scriptTags, styleExternalTags, styleInPageTags, styleTags, faviconTags, imgTags, sourceTags, srcTags, notFoundErrors;
|
|
73
74
|
return __generator(this, function (_b) {
|
|
74
75
|
switch (_b.label) {
|
|
75
76
|
case 0:
|
|
@@ -87,25 +88,38 @@ var updateAllTags = function (parsedHtml, _a) {
|
|
|
87
88
|
}); })];
|
|
88
89
|
case 1:
|
|
89
90
|
_b.sent();
|
|
90
|
-
|
|
91
|
+
styleExternalTags = (0, getTags_1.getStyleTags)(parsedHtml);
|
|
92
|
+
styleInPageTags = (0, getTags_1.getStyleInPageTags)(parsedHtml);
|
|
93
|
+
styleTags = __spreadArray(__spreadArray([], __read(styleExternalTags), false), __read(styleInPageTags), false);
|
|
94
|
+
return [4 /*yield*/, (0, utils_1.asyncForEach)(styleTags, function (tag) { return __awaiter(void 0, void 0, void 0, function () {
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, (0, updateStyleTag_1.updateStyleTag)(tag, webSourcePathFull, destinationPath, serverType, assetPathMap).catch(function (e) { return assetsNotFound.push(e); })];
|
|
98
|
+
case 1:
|
|
99
|
+
_a.sent();
|
|
100
|
+
return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}); })];
|
|
104
|
+
case 2:
|
|
105
|
+
_b.sent();
|
|
91
106
|
faviconTags = (0, getTags_1.getFaviconTags)(parsedHtml);
|
|
92
|
-
|
|
93
|
-
linkTags.forEach(function (tag) {
|
|
107
|
+
faviconTags.forEach(function (tag) {
|
|
94
108
|
try {
|
|
95
109
|
(0, updateLinkTag_1.updateLinkTag)(tag, assetPathMap);
|
|
96
110
|
}
|
|
97
111
|
catch (error) {
|
|
98
|
-
console.log(tag, error);
|
|
99
112
|
assetsNotFound.push(error);
|
|
100
113
|
}
|
|
101
114
|
});
|
|
102
115
|
imgTags = (0, getTags_1.getImgTags)(parsedHtml);
|
|
103
|
-
|
|
116
|
+
sourceTags = (0, getTags_1.getSourceTags)(parsedHtml);
|
|
117
|
+
srcTags = __spreadArray(__spreadArray([], __read(imgTags), false), __read(sourceTags), false);
|
|
118
|
+
srcTags.forEach(function (tag) {
|
|
104
119
|
try {
|
|
105
|
-
(0, updateLinkTag_1.updateLinkTag)(tag, assetPathMap, '
|
|
120
|
+
(0, updateLinkTag_1.updateLinkTag)(tag, assetPathMap, 'src');
|
|
106
121
|
}
|
|
107
122
|
catch (error) {
|
|
108
|
-
console.log(tag, error);
|
|
109
123
|
assetsNotFound.push(error);
|
|
110
124
|
}
|
|
111
125
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const updateLinkTag: (linkTag: HTMLLinkElement | HTMLImageElement, assetPathMap: {
|
|
1
|
+
export declare const updateLinkTag: (linkTag: HTMLLinkElement | HTMLSourceElement | HTMLImageElement, assetPathMap: {
|
|
2
2
|
source: string;
|
|
3
3
|
target: string;
|
|
4
|
-
}[], tagType?: 'link' | '
|
|
4
|
+
}[], tagType?: 'link' | 'src') => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ServerType } from '@sasjs/utils';
|
|
2
|
-
export declare const updateScriptTag: (tag:
|
|
2
|
+
export declare const updateScriptTag: (tag: HTMLScriptElement, webSourcePathFull: string, destinationPath: string, serverType: ServerType, assetPathMap: {
|
|
3
3
|
source: string;
|
|
4
4
|
target: string;
|
|
5
5
|
}[]) => Promise<void>;
|
|
@@ -45,28 +45,26 @@ var utils_1 = require("@sasjs/utils");
|
|
|
45
45
|
var js_base64_1 = require("js-base64");
|
|
46
46
|
var getWebServiceContent_1 = require("./getWebServiceContent");
|
|
47
47
|
var updateScriptTag = function (tag, webSourcePathFull, destinationPath, serverType, assetPathMap) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
-
var scriptPath, isUrl,
|
|
48
|
+
var scriptPath, isUrl, _content, content, serviceContent, _content, content;
|
|
49
49
|
return __generator(this, function (_a) {
|
|
50
50
|
switch (_a.label) {
|
|
51
51
|
case 0:
|
|
52
52
|
scriptPath = tag.getAttribute('src');
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (!scriptPath) return [3 /*break*/, 8];
|
|
54
|
+
isUrl = scriptPath.startsWith('http') || scriptPath.startsWith('//');
|
|
55
55
|
if (!!isUrl) return [3 /*break*/, 7];
|
|
56
56
|
return [4 /*yield*/, (0, utils_1.readFile)(path_1.default.join(webSourcePathFull, scriptPath)).catch(function (_) {
|
|
57
57
|
throw new Error("Unable to find file: ".concat(scriptPath));
|
|
58
58
|
})];
|
|
59
59
|
case 1:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
content_1 = content_1.replace(new RegExp(pathEntry.source, 'g'), pathEntry.target);
|
|
63
|
-
});
|
|
60
|
+
_content = _a.sent();
|
|
61
|
+
content = modifyLinksInContent(_content, assetPathMap);
|
|
64
62
|
if (!(serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 3];
|
|
65
|
-
return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, scriptPath),
|
|
63
|
+
return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, scriptPath), content)];
|
|
66
64
|
case 2:
|
|
67
65
|
_a.sent();
|
|
68
66
|
return [3 /*break*/, 6];
|
|
69
|
-
case 3: return [4 /*yield*/, (0, getWebServiceContent_1.getWebServiceContent)((0, js_base64_1.encode)(
|
|
67
|
+
case 3: return [4 /*yield*/, (0, getWebServiceContent_1.getWebServiceContent)((0, js_base64_1.encode)(content), 'JS', serverType)];
|
|
70
68
|
case 4:
|
|
71
69
|
serviceContent = _a.sent();
|
|
72
70
|
return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(scriptPath.replace(/\.js$/, '-js'), ".sas")), serviceContent)];
|
|
@@ -78,8 +76,21 @@ var updateScriptTag = function (tag, webSourcePathFull, destinationPath, serverT
|
|
|
78
76
|
return entry.source === scriptPath || "./".concat(entry.source) === scriptPath;
|
|
79
77
|
}).target);
|
|
80
78
|
_a.label = 7;
|
|
81
|
-
case 7: return [
|
|
79
|
+
case 7: return [3 /*break*/, 9];
|
|
80
|
+
case 8:
|
|
81
|
+
_content = tag.innerHTML;
|
|
82
|
+
content = modifyLinksInContent(_content, assetPathMap);
|
|
83
|
+
tag.innerHTML = content;
|
|
84
|
+
_a.label = 9;
|
|
85
|
+
case 9: return [2 /*return*/];
|
|
82
86
|
}
|
|
83
87
|
});
|
|
84
88
|
}); };
|
|
85
89
|
exports.updateScriptTag = updateScriptTag;
|
|
90
|
+
var modifyLinksInContent = function (_content, assetPathMap) {
|
|
91
|
+
var content = _content;
|
|
92
|
+
assetPathMap.forEach(function (pathEntry) {
|
|
93
|
+
content = content.replace(new RegExp(pathEntry.source, 'g'), pathEntry.target);
|
|
94
|
+
});
|
|
95
|
+
return content;
|
|
96
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ServerType } from '@sasjs/utils';
|
|
2
|
+
export declare const updateStyleTag: (tag: HTMLStyleElement | HTMLLinkElement, webSourcePathFull: string, destinationPath: string, serverType: ServerType, assetPathMap: {
|
|
3
|
+
source: string;
|
|
4
|
+
target: string;
|
|
5
|
+
}[]) => Promise<void>;
|
|
@@ -0,0 +1,96 @@
|
|
|
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.updateStyleTag = void 0;
|
|
43
|
+
var path_1 = __importDefault(require("path"));
|
|
44
|
+
var utils_1 = require("@sasjs/utils");
|
|
45
|
+
var js_base64_1 = require("js-base64");
|
|
46
|
+
var getWebServiceContent_1 = require("./getWebServiceContent");
|
|
47
|
+
var updateStyleTag = function (tag, webSourcePathFull, destinationPath, serverType, assetPathMap) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
+
var scriptPath, isUrl, _content, content, serviceContent, _content, content;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
scriptPath = tag.getAttribute('href');
|
|
53
|
+
if (!scriptPath) return [3 /*break*/, 8];
|
|
54
|
+
isUrl = scriptPath.startsWith('http') || scriptPath.startsWith('//');
|
|
55
|
+
if (!!isUrl) return [3 /*break*/, 7];
|
|
56
|
+
return [4 /*yield*/, (0, utils_1.readFile)(path_1.default.join(webSourcePathFull, scriptPath)).catch(function (_) {
|
|
57
|
+
throw new Error("Unable to find file: ".concat(scriptPath));
|
|
58
|
+
})];
|
|
59
|
+
case 1:
|
|
60
|
+
_content = _a.sent();
|
|
61
|
+
content = modifyLinksInContent(_content, assetPathMap);
|
|
62
|
+
if (!(serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 3];
|
|
63
|
+
return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, scriptPath), content)];
|
|
64
|
+
case 2:
|
|
65
|
+
_a.sent();
|
|
66
|
+
return [3 /*break*/, 6];
|
|
67
|
+
case 3: return [4 /*yield*/, (0, getWebServiceContent_1.getWebServiceContent)((0, js_base64_1.encode)(content), 'CSS', serverType)];
|
|
68
|
+
case 4:
|
|
69
|
+
serviceContent = _a.sent();
|
|
70
|
+
return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(destinationPath, "".concat(scriptPath.replace(/\.js$/, '-js'), ".sas")), serviceContent)];
|
|
71
|
+
case 5:
|
|
72
|
+
_a.sent();
|
|
73
|
+
_a.label = 6;
|
|
74
|
+
case 6:
|
|
75
|
+
tag.setAttribute('href', assetPathMap.find(function (entry) {
|
|
76
|
+
return entry.source === scriptPath || "./".concat(entry.source) === scriptPath;
|
|
77
|
+
}).target);
|
|
78
|
+
_a.label = 7;
|
|
79
|
+
case 7: return [3 /*break*/, 9];
|
|
80
|
+
case 8:
|
|
81
|
+
_content = tag.innerHTML;
|
|
82
|
+
content = modifyLinksInContent(_content, assetPathMap);
|
|
83
|
+
tag.innerHTML = content;
|
|
84
|
+
_a.label = 9;
|
|
85
|
+
case 9: return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}); };
|
|
89
|
+
exports.updateStyleTag = updateStyleTag;
|
|
90
|
+
var modifyLinksInContent = function (_content, assetPathMap) {
|
|
91
|
+
var content = _content;
|
|
92
|
+
assetPathMap.forEach(function (pathEntry) {
|
|
93
|
+
content = content.replace(new RegExp(pathEntry.source, 'g'), pathEntry.target);
|
|
94
|
+
});
|
|
95
|
+
return content;
|
|
96
|
+
};
|
package/build/utils/config.js
CHANGED
|
@@ -830,7 +830,10 @@ function getAuthConfig(target) {
|
|
|
830
830
|
? undefined
|
|
831
831
|
: secret;
|
|
832
832
|
if (!secret) {
|
|
833
|
-
|
|
833
|
+
if (target.serverType === utils_1.ServerType.Sasjs)
|
|
834
|
+
secret = '';
|
|
835
|
+
else
|
|
836
|
+
throw new Error("Client secret was not found.\n Please make sure that the 'secret' property is set in your local .env file or in the correct target authConfig in your global ~".concat(path_1.default.sep, ".sasjsrc file."));
|
|
834
837
|
}
|
|
835
838
|
if (!(0, auth_1.isAccessTokenExpiring)(access_token)) return [3 /*break*/, 7];
|
|
836
839
|
sasjs = new node_1.default({
|
package/package.json
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@sasjs/adapter": "3.4.
|
|
52
|
+
"@sasjs/adapter": "3.4.2",
|
|
53
53
|
"@sasjs/core": "3.10.0",
|
|
54
54
|
"@sasjs/lint": "1.11.2",
|
|
55
55
|
"@sasjs/utils": "2.36.0",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"typescript": "4.5.4",
|
|
98
98
|
"util": "0.12.4"
|
|
99
99
|
},
|
|
100
|
-
"version": "3.6.
|
|
100
|
+
"version": "3.6.7"
|
|
101
101
|
}
|