@sasjs/cli 3.6.6 → 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/build/commands/deploy/deploy.js +24 -13
- package/build/commands/web/internal/getTags.d.ts +2 -0
- package/build/commands/web/internal/getTags.js +9 -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/package.json +1 -1
|
@@ -330,31 +330,42 @@ function deployToSas9(deployScriptName, target, linesToExecute, logFolder, strea
|
|
|
330
330
|
function deployToSasjs(target, isLocal, sasjs) {
|
|
331
331
|
var _a, _b;
|
|
332
332
|
return __awaiter(this, void 0, void 0, function () {
|
|
333
|
-
var buildDestinationFolder, finalFilePathJSON, jsonContent, payload, authConfig, result;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
switch (_d.label) {
|
|
333
|
+
var buildDestinationFolder, finalFilePathJSON, jsonContent, payload, authConfig, e_2, result;
|
|
334
|
+
return __generator(this, function (_c) {
|
|
335
|
+
switch (_c.label) {
|
|
337
336
|
case 0:
|
|
338
337
|
buildDestinationFolder = process.sasjsConstants.buildDestinationFolder;
|
|
339
338
|
finalFilePathJSON = path_1.default.join(buildDestinationFolder, "".concat(target.name, ".json"));
|
|
340
339
|
return [4 /*yield*/, (0, utils_2.readFile)(finalFilePathJSON)];
|
|
341
340
|
case 1:
|
|
342
|
-
jsonContent =
|
|
341
|
+
jsonContent = _c.sent();
|
|
343
342
|
payload = JSON.parse(jsonContent);
|
|
344
|
-
if (!!sasjs) return [3 /*break*/,
|
|
345
|
-
|
|
346
|
-
|
|
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;
|
|
347
352
|
case 2:
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
case 3:
|
|
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
|
|
351
362
|
.deployToSASjs(payload, undefined, authConfig)
|
|
352
363
|
.catch(function (err) {
|
|
353
364
|
var _a;
|
|
354
365
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(err);
|
|
355
366
|
})];
|
|
356
|
-
case
|
|
357
|
-
result =
|
|
367
|
+
case 6:
|
|
368
|
+
result = _c.sent();
|
|
358
369
|
if ((result === null || result === void 0 ? void 0 : result.status) === 'failure') {
|
|
359
370
|
(_a = process.logger) === null || _a === void 0 ? void 0 : _a.error(result.message);
|
|
360
371
|
if (result.example) {
|
|
@@ -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;
|
|
@@ -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/package.json
CHANGED