@awayfl/awayfl-player 0.2.36 → 0.2.38
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/LICENSE +201 -201
- package/README.md +36 -36
- package/awayfl.config.js +85 -85
- package/builtins/playerglobal.json +2752 -2752
- package/builtins/playerglobal_new.json +4169 -4169
- package/bundle/awayfl-player.umd.js +30 -161
- package/bundle/awayfl-player.umd.js.gz +0 -0
- package/bundle/awayfl-player.umd.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +9 -9
- package/dist/lib/AVM1Player.d.ts +4 -4
- package/dist/lib/AVM1Player.js +13 -13
- package/dist/lib/AVM2Player.d.ts +4 -4
- package/dist/lib/AVM2Player.js +14 -14
- package/dist/lib/AVMDebugInterface.d.ts +21 -21
- package/dist/lib/AVMDebugInterface.js +279 -279
- package/dist/lib/AVMPlayer.d.ts +6 -6
- package/dist/lib/AVMPlayer.js +27 -27
- package/dist/src/Main.d.ts +1 -1
- package/dist/src/Main.js +19 -19
- package/index.ts +9 -9
- package/lib/AVM1Player.ts +9 -9
- package/lib/AVM2Player.ts +12 -12
- package/lib/AVMDebugInterface.ts +345 -345
- package/lib/AVMPlayer.ts +29 -29
- package/package.json +97 -97
- package/rollup.config.js +30 -30
- package/scripts/copyVersionToIndex.js +33 -33
- package/scripts/initAwayDev_mac.sh +177 -177
- package/scripts/initAwayDev_mac_pnpm.sh +177 -177
- package/scripts/initAwayDev_win.bat +198 -198
- package/scripts/unlinkAwayDev_mac.sh +140 -140
- package/scripts/unlinkAwayDev_mac_pnpm.sh +140 -140
- package/scripts/unlinkAwayDev_win.bat +140 -140
- package/scripts/updateAwayDev_mac.sh +86 -90
- package/scripts/updateAwayDev_win.bat +69 -69
- package/scripts/updateAway_any.bat +73 -73
- package/tsconfig.json +12 -12
- package/webpack.config.js +496 -450
package/webpack.config.js
CHANGED
|
@@ -1,450 +1,496 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const webpack = require('webpack');
|
|
4
|
-
const CopyWebPackPlugin = require('copy-webpack-plugin');
|
|
5
|
-
const HTMLWebPackPlugin = require('html-webpack-plugin');
|
|
6
|
-
const Terser = require('terser-webpack-plugin')
|
|
7
|
-
const rimraf = require("rimraf");
|
|
8
|
-
const tsloader = require.resolve('ts-loader');
|
|
9
|
-
const merge = require("webpack-merge").merge;
|
|
10
|
-
const config = require('./awayfl.config.js')
|
|
11
|
-
|
|
12
|
-
module.exports = (env = {}) => {
|
|
13
|
-
|
|
14
|
-
var isProd = !!env.prod;
|
|
15
|
-
|
|
16
|
-
// force some configs dependant on prod and dev
|
|
17
|
-
config.rt_debug = isProd ? false : config.rt_debug;
|
|
18
|
-
|
|
19
|
-
config.rt_showFPS = isProd ? false : config.rt_showFPS;
|
|
20
|
-
|
|
21
|
-
config.cacheBuster = isProd ? false : config.cacheBuster;
|
|
22
|
-
|
|
23
|
-
config.allowURLSearchParams = isProd ? false : config.allowURLSearchParams;
|
|
24
|
-
|
|
25
|
-
// split mode right now errors in watch mode
|
|
26
|
-
config.split = isProd ? config.split : false;
|
|
27
|
-
|
|
28
|
-
if (config.debugConfig) {
|
|
29
|
-
console.log("global config used for webpack:");
|
|
30
|
-
for (var key in config) {
|
|
31
|
-
console.log(" - config." + key, config[key]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const entry = {};
|
|
36
|
-
entry[config.entryName] = [config.entryPath];
|
|
37
|
-
|
|
38
|
-
let plugins = processConfig(config, __dirname, CopyWebPackPlugin, HTMLWebPackPlugin, webpack.BannerPlugin, fs, rimraf, path);
|
|
39
|
-
|
|
40
|
-
const common = {
|
|
41
|
-
|
|
42
|
-
entry: entry,
|
|
43
|
-
|
|
44
|
-
output: {
|
|
45
|
-
pathinfo: false,
|
|
46
|
-
path: path.join(__dirname, "bin"),
|
|
47
|
-
filename: 'js/[name].js'
|
|
48
|
-
},
|
|
49
|
-
resolve: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
var
|
|
401
|
-
var
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
//
|
|
437
|
-
var
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const webpack = require('webpack');
|
|
4
|
+
const CopyWebPackPlugin = require('copy-webpack-plugin');
|
|
5
|
+
const HTMLWebPackPlugin = require('html-webpack-plugin');
|
|
6
|
+
const Terser = require('terser-webpack-plugin')
|
|
7
|
+
const rimraf = require("rimraf");
|
|
8
|
+
const tsloader = require.resolve('ts-loader');
|
|
9
|
+
const merge = require("webpack-merge").merge;
|
|
10
|
+
const config = require('./awayfl.config.js')
|
|
11
|
+
|
|
12
|
+
module.exports = (env = {}) => {
|
|
13
|
+
|
|
14
|
+
var isProd = !!env.prod;
|
|
15
|
+
|
|
16
|
+
// force some configs dependant on prod and dev
|
|
17
|
+
config.rt_debug = isProd ? false : config.rt_debug;
|
|
18
|
+
|
|
19
|
+
config.rt_showFPS = isProd ? false : config.rt_showFPS;
|
|
20
|
+
|
|
21
|
+
config.cacheBuster = isProd ? false : config.cacheBuster;
|
|
22
|
+
|
|
23
|
+
config.allowURLSearchParams = isProd ? false : config.allowURLSearchParams;
|
|
24
|
+
|
|
25
|
+
// split mode right now errors in watch mode
|
|
26
|
+
config.split = isProd ? config.split : false;
|
|
27
|
+
|
|
28
|
+
if (config.debugConfig) {
|
|
29
|
+
console.log("global config used for webpack:");
|
|
30
|
+
for (var key in config) {
|
|
31
|
+
console.log(" - config." + key, config[key]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const entry = {};
|
|
36
|
+
entry[config.entryName] = [config.entryPath];
|
|
37
|
+
|
|
38
|
+
let plugins = processConfig(config, __dirname, CopyWebPackPlugin, HTMLWebPackPlugin, webpack.BannerPlugin, fs, rimraf, path);
|
|
39
|
+
|
|
40
|
+
const common = {
|
|
41
|
+
|
|
42
|
+
entry: entry,
|
|
43
|
+
|
|
44
|
+
output: {
|
|
45
|
+
pathinfo: false,
|
|
46
|
+
path: path.join(__dirname, "bin"),
|
|
47
|
+
filename: 'js/[name].js'
|
|
48
|
+
},
|
|
49
|
+
resolve: {
|
|
50
|
+
alias: {},
|
|
51
|
+
// Add `.ts` and `.tsx` as a resolvable extension.
|
|
52
|
+
extensions: ['.webpack.js', '.web.js', '.js', '.ts', '.tsx']
|
|
53
|
+
},
|
|
54
|
+
module: {
|
|
55
|
+
rules: [
|
|
56
|
+
{
|
|
57
|
+
test: /\.ts(x?)/,
|
|
58
|
+
exclude: /node_modules/,
|
|
59
|
+
loader: tsloader,
|
|
60
|
+
options: {
|
|
61
|
+
experimentalWatchApi: true,
|
|
62
|
+
transpileOnly: true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
plugins: plugins,
|
|
68
|
+
|
|
69
|
+
performance: {
|
|
70
|
+
hints: false // wp4
|
|
71
|
+
},
|
|
72
|
+
stats: {
|
|
73
|
+
cached: true, // wp4
|
|
74
|
+
errorDetails: true, // wp4
|
|
75
|
+
colors: true // wp4
|
|
76
|
+
},
|
|
77
|
+
devServer: {
|
|
78
|
+
client: {
|
|
79
|
+
progress: true, // wp5
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const dev = {
|
|
85
|
+
target: 'web',
|
|
86
|
+
mode: "development",// wp4
|
|
87
|
+
//devtool: 'source-map',
|
|
88
|
+
devtool: 'cheap-module-source-map',//use this option for recompiling libs
|
|
89
|
+
devServer: {
|
|
90
|
+
static: {
|
|
91
|
+
publicPath: "/",
|
|
92
|
+
},
|
|
93
|
+
open: false,
|
|
94
|
+
hot: false,
|
|
95
|
+
watchFiles: ['src/**/*.*'],
|
|
96
|
+
client: {
|
|
97
|
+
progress: true,
|
|
98
|
+
},
|
|
99
|
+
allowedHosts: "all",
|
|
100
|
+
port: 80,
|
|
101
|
+
},
|
|
102
|
+
optimization: {
|
|
103
|
+
//minimize: false // wp4
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const prod = {
|
|
108
|
+
mode: "production",// wp4
|
|
109
|
+
bail: true
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
if(Terser) {
|
|
113
|
+
prod.optimization = {
|
|
114
|
+
minimize: true,
|
|
115
|
+
minimizer: [
|
|
116
|
+
new Terser({
|
|
117
|
+
extractComments: {
|
|
118
|
+
condition: /^\**!|@preserve|@license|@cc_on/i,
|
|
119
|
+
filename: 'LICENSES.txt'
|
|
120
|
+
},
|
|
121
|
+
}),
|
|
122
|
+
],
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
console.warn("TERSER IS REQUIRE FOR REMOVING COMMENTS!");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return merge(common, isProd ? prod : dev);
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// process config
|
|
133
|
+
// return a list of webpack-plugins
|
|
134
|
+
const processConfig = (config, rootPath, CopyWebPackPlugin, HTMLWebPackPlugin, BannerPlugin, fs, rimraf, path) => {
|
|
135
|
+
|
|
136
|
+
var plugins = [];
|
|
137
|
+
|
|
138
|
+
// if no split, copy as3 buildins to asset folder
|
|
139
|
+
// if split, we will copy them for each game-config individually
|
|
140
|
+
if (config.buildinsPath && config.buildinsPath.length && !config.split) {
|
|
141
|
+
plugins.push(new CopyWebPackPlugin({
|
|
142
|
+
patterns: [
|
|
143
|
+
{ from: config.buildinsPath, to: 'assets/builtins' },
|
|
144
|
+
],
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// copy loader.js to js-folder
|
|
149
|
+
// if split, this will be copied to the subfolder together with webpack-bundel
|
|
150
|
+
plugins.push(new CopyWebPackPlugin({
|
|
151
|
+
patterns: [
|
|
152
|
+
{ from: config.loaderTemplate, to: 'js' },
|
|
153
|
+
],
|
|
154
|
+
}));
|
|
155
|
+
|
|
156
|
+
// collect all game-urls to create a index.html:
|
|
157
|
+
let gameURLS = {};
|
|
158
|
+
|
|
159
|
+
// map to collect copied resources, so we preent any redunant copies
|
|
160
|
+
let copiedResources = {};
|
|
161
|
+
|
|
162
|
+
var _loop_1 = function (i) {
|
|
163
|
+
|
|
164
|
+
var fileConfig = config.fileconfigs[i];
|
|
165
|
+
var folderName = fileConfig.rt_filename;
|
|
166
|
+
var outputPath = config.split ? folderName + "/" : "";
|
|
167
|
+
|
|
168
|
+
// if split, copy buildins to each output folder:
|
|
169
|
+
|
|
170
|
+
if (config.buildinsPath && config.buildinsPath.length && config.split) {
|
|
171
|
+
plugins.push(new CopyWebPackPlugin({
|
|
172
|
+
patterns: [
|
|
173
|
+
{ from: config.buildinsPath, to: outputPath + 'assets/builtins' },
|
|
174
|
+
],
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// get config for this file merged with default values from global config:
|
|
179
|
+
|
|
180
|
+
var configForHTML = getConfig(fileConfig, config);
|
|
181
|
+
|
|
182
|
+
// copy assets for this file-config:
|
|
183
|
+
|
|
184
|
+
swfPath = path.join(rootPath, "src", "assets", configForHTML.filename + ".swf");
|
|
185
|
+
if (!fs.existsSync(swfPath)) {
|
|
186
|
+
throw new Error("invalid filename path for fileconfig " + configForHTML.filename);
|
|
187
|
+
}
|
|
188
|
+
stats = fs.statSync(swfPath);
|
|
189
|
+
filesize = stats["size"];
|
|
190
|
+
if (!fs.existsSync(path.join(rootPath, "src", "assets", configForHTML.splash))) {
|
|
191
|
+
throw new Error("invalid splashscreen path for fileconfig " + configForHTML.splash);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
plugins.push(new CopyWebPackPlugin({
|
|
195
|
+
patterns: [
|
|
196
|
+
{ from: swfPath, to: outputPath + "assets" },
|
|
197
|
+
],
|
|
198
|
+
}));
|
|
199
|
+
|
|
200
|
+
plugins.push(new CopyWebPackPlugin({
|
|
201
|
+
patterns: [
|
|
202
|
+
{ from: path.join(rootPath, "src", "assets", configForHTML.splash), to: outputPath + "assets" },
|
|
203
|
+
],
|
|
204
|
+
}));
|
|
205
|
+
|
|
206
|
+
// optional copy loading image:
|
|
207
|
+
|
|
208
|
+
if (configForHTML.loading) {
|
|
209
|
+
if (!fs.existsSync(path.join(rootPath, "src", "assets", configForHTML.loading.image))) {
|
|
210
|
+
throw ("invalid loading image path for fileconfig " + configForHTML.loading.image);
|
|
211
|
+
}
|
|
212
|
+
plugins.push(new CopyWebPackPlugin({
|
|
213
|
+
patterns: [
|
|
214
|
+
{ from: path.join(rootPath, "src", "assets", configForHTML.loading.image), to: outputPath + "assets" },
|
|
215
|
+
],
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
// optional copy start image:
|
|
221
|
+
|
|
222
|
+
if (configForHTML.start) {
|
|
223
|
+
if (!fs.existsSync(path.join(rootPath, "src", "assets", configForHTML.start.image))) {
|
|
224
|
+
throw ("invalid start image path for fileconfig " + configForHTML.start.image);
|
|
225
|
+
}
|
|
226
|
+
plugins.push(new CopyWebPackPlugin({
|
|
227
|
+
patterns: [
|
|
228
|
+
{ from: path.join(rootPath, "src", "assets", configForHTML.start.image), to: outputPath + "assets" },
|
|
229
|
+
],
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// create/prepare config props needed for runtime
|
|
234
|
+
|
|
235
|
+
configForHTML.binary = [];
|
|
236
|
+
// copy and prepare resources for html
|
|
237
|
+
let resources = getConfigProp(fileConfig, config, "resources");
|
|
238
|
+
if (resources && resources.length > 0) {
|
|
239
|
+
for (let r = 0; r < resources.length; r++) {
|
|
240
|
+
let res_path = path.join(rootPath, resources[r]);
|
|
241
|
+
let res_name = path.basename(res_path);
|
|
242
|
+
let res_outputPath = "assets/" + res_name;
|
|
243
|
+
let res_unique_outputPath = outputPath + "assets/" + res_name;
|
|
244
|
+
let res_filesize = copiedResources[res_unique_outputPath];
|
|
245
|
+
if (!res_filesize) {
|
|
246
|
+
// only need to copy if it has not yet been done
|
|
247
|
+
if (!fs.existsSync(res_path)) {
|
|
248
|
+
throw new Error("invalid filename path for resource " + res_path);
|
|
249
|
+
}
|
|
250
|
+
plugins.push(new CopyWebPackPlugin({
|
|
251
|
+
patterns: [
|
|
252
|
+
{ from: res_path, to: outputPath + "assets" },
|
|
253
|
+
],
|
|
254
|
+
}));
|
|
255
|
+
stats = fs.statSync(res_path);
|
|
256
|
+
res_filesize = stats["size"];
|
|
257
|
+
copiedResources[res_unique_outputPath] = res_filesize;
|
|
258
|
+
}
|
|
259
|
+
configForHTML.binary.push({
|
|
260
|
+
name: res_name,
|
|
261
|
+
path: res_outputPath,
|
|
262
|
+
size: res_filesize,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
let assets = getConfigProp(fileConfig, config, "assets");
|
|
267
|
+
if (assets && assets.length > 0) {
|
|
268
|
+
for (let r = 0; r < assets.length; r++) {
|
|
269
|
+
let res_path = path.join(rootPath, assets[r]);
|
|
270
|
+
|
|
271
|
+
// extension is missing = is folder
|
|
272
|
+
if (!fs.existsSync(res_path)) {
|
|
273
|
+
throw new Error("invalid filename path for asset " + res_path);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let folder = fs.lstatSync(res_path).isDirectory();
|
|
277
|
+
let name = path.basename(res_path);
|
|
278
|
+
|
|
279
|
+
plugins.push(new CopyWebPackPlugin({
|
|
280
|
+
patterns: [
|
|
281
|
+
{ from: res_path, to: outputPath + "assets" + (folder ? "/" + name : "") },
|
|
282
|
+
],
|
|
283
|
+
}));
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
configForHTML.binary.push({
|
|
289
|
+
name: configForHTML.filename,
|
|
290
|
+
path: "assets/" + configForHTML.filename + ".swf",
|
|
291
|
+
size: filesize,
|
|
292
|
+
resourceType: "GAME",
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
if (configForHTML.splash)
|
|
296
|
+
configForHTML.splash = "assets/" + configForHTML.splash;
|
|
297
|
+
|
|
298
|
+
if (configForHTML.loading)
|
|
299
|
+
configForHTML.loading.image = "assets/" + configForHTML.loading.image;
|
|
300
|
+
|
|
301
|
+
if (configForHTML.start)
|
|
302
|
+
configForHTML.start.image = "assets/" + configForHTML.start.image;
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
var runtimePath = "js/" + config.entryName + ".js";
|
|
306
|
+
configForHTML["runtime"] = runtimePath;
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
// create string for html inject (incl hack to handle functions):
|
|
310
|
+
|
|
311
|
+
var collectedFunctions = collectAndReplaceFunctions({}, configForHTML);
|
|
312
|
+
var configStr = "\nconfig = " + JSON.stringify(configForHTML, null, 4) + ";\n";
|
|
313
|
+
var jsStringForHTML = "";
|
|
314
|
+
var allFunctions;
|
|
315
|
+
if (Object.keys(collectedFunctions).length > 0) {
|
|
316
|
+
jsStringForHTML = "\nlet allFunctions = {};\n";
|
|
317
|
+
for (var key in collectedFunctions) {
|
|
318
|
+
jsStringForHTML += "allFunctions['" + key + "'] = " + collectedFunctions[key].toString() + ";\n";
|
|
319
|
+
}
|
|
320
|
+
jsStringForHTML += configStr;
|
|
321
|
+
jsStringForHTML += "\nlet connectConfigToFunctions =" + (function (obj) {
|
|
322
|
+
for (var key in obj) {
|
|
323
|
+
if (typeof obj[key] == "string" && obj[key].indexOf("___") === 0) {
|
|
324
|
+
obj[key] = allFunctions[obj[key].replace("___", "")];
|
|
325
|
+
}
|
|
326
|
+
if (typeof obj[key] == "object")
|
|
327
|
+
connectConfigToFunctions(obj[key]);
|
|
328
|
+
}
|
|
329
|
+
}).toString() + ";\n";
|
|
330
|
+
jsStringForHTML += "\nconnectConfigToFunctions(config);\n";
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
jsStringForHTML += configStr;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// code to overwrite config by URLSearchParams
|
|
337
|
+
if (config.allowURLSearchParams) {
|
|
338
|
+
jsStringForHTML += `const q = new URLSearchParams(location.search);
|
|
339
|
+
|
|
340
|
+
for (let key of q.keys()){
|
|
341
|
+
let value = q.get(key);
|
|
342
|
+
|
|
343
|
+
if (value.includes("<boolean>") || value.includes("<bool>")) {
|
|
344
|
+
let valueWithoutClass = value.replace(/<boolean>/g,'').replace(/<bool>/g,'').toLowerCase();
|
|
345
|
+
if (["true", "t", "1"].includes(valueWithoutClass)) config[key] = true;
|
|
346
|
+
else if (["false", "f", "0"].includes(valueWithoutClass)) config[key] = false;
|
|
347
|
+
else console.warn("Unable to cast URLSearchParam '" + key + "'='" + valueWithoutClass + "' as boolean");
|
|
348
|
+
} else if (value.includes("<int>") || value.includes("<integer>") || value.includes("<number>")) {
|
|
349
|
+
let valueWithoutClass = value.replace(/<int>/g,'').replace(/<integer>/g,'').replace(/<number>/g,'');
|
|
350
|
+
config[key] = parseInt(valueWithoutClass, 10);
|
|
351
|
+
} else {
|
|
352
|
+
// treat this as string
|
|
353
|
+
config[key] = q.get(key);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// console.log({key, value, result: config[key]});
|
|
357
|
+
};
|
|
358
|
+
`;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// add cachebuster
|
|
362
|
+
if (config.cacheBuster) {
|
|
363
|
+
jsStringForHTML += "for (let key in config.binary){ config.binary[key].path = config.binary[key].path+'?v='+Math.random();};\n";
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
// copy and mod html:
|
|
368
|
+
|
|
369
|
+
var htmlOutputPath = (config.split ? folderName + "/" : "") + (config.split ? "index.html" : folderName + ".html");
|
|
370
|
+
gameURLS[fileConfig.rt_filename] = {
|
|
371
|
+
path: htmlOutputPath,
|
|
372
|
+
name: configForHTML.title,
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
var htmlSourcePath = getConfigProp(fileConfig, config, "gameTemplate");
|
|
376
|
+
|
|
377
|
+
if (config.debugConfig) {
|
|
378
|
+
console.log("### " + configForHTML.title + " CONFIG THAT WILL BE INJECTED INTO HTML");
|
|
379
|
+
for (var key in configForHTML) {
|
|
380
|
+
console.log(" - config." + key, configForHTML[key]);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
plugins.push(new CopyWebPackPlugin({
|
|
385
|
+
patterns: [
|
|
386
|
+
{
|
|
387
|
+
from: htmlSourcePath,
|
|
388
|
+
to: htmlOutputPath,
|
|
389
|
+
transform: function (content, src) {
|
|
390
|
+
return content.toString()
|
|
391
|
+
.replace(/INSERT_TITLE/g, configForHTML.title ? configForHTML.title : "UNTITLED")
|
|
392
|
+
.replace(/INSERT_SPLASHSCREEN/g, configForHTML.splash)
|
|
393
|
+
.replace(/INSERT_CODE/g, jsStringForHTML);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
],
|
|
397
|
+
}));
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
var swfPath, stats, filesize;
|
|
401
|
+
for (var i = 0; i < config.fileconfigs.length; i++) {
|
|
402
|
+
_loop_1(i);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
// Generate a listing html that links to all game-htmls:
|
|
407
|
+
plugins.push(new HTMLWebPackPlugin({
|
|
408
|
+
title: config.rt_title,
|
|
409
|
+
template: config.indexTemplate,
|
|
410
|
+
filename: 'index.html',
|
|
411
|
+
games: gameURLS,
|
|
412
|
+
inject: false
|
|
413
|
+
}));
|
|
414
|
+
|
|
415
|
+
if (config.split) {
|
|
416
|
+
// when webpack is finished, copy the js-folder to subfolders
|
|
417
|
+
// this errors with dev-server, so we only use "split" in prod
|
|
418
|
+
|
|
419
|
+
plugins.push({
|
|
420
|
+
apply: function (compiler) {
|
|
421
|
+
compiler.hooks.afterEmit.tap('MyPlugin', function (compilation) {
|
|
422
|
+
console.log("copy build to game-folders");
|
|
423
|
+
for (var i = 0; i < config.fileconfigs.length; i++) {
|
|
424
|
+
copyRecursiveSync(fs, path, path.join(rootPath, "bin", "js"), path.join(rootPath, "bin", config.fileconfigs[i].rt_filename, "js"));
|
|
425
|
+
}
|
|
426
|
+
rimraf.sync(path.join(rootPath, "bin", "js"));
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return plugins;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// get config prop from file-config, or from global-config if it doesnt eists
|
|
437
|
+
var getConfigProp = function (fileconfig, config, name) {
|
|
438
|
+
return fileconfig[name] ? fileconfig[name] : config[name];
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// get a config for a game-file.
|
|
442
|
+
// this filters out all props that are not prefixed by "rt_"
|
|
443
|
+
// also takes care that it uses props from global-config if file-config does not provide it
|
|
444
|
+
// this can probably be done better and cleaner
|
|
445
|
+
// but for now it should do the job
|
|
446
|
+
var getConfig = function (fileconfig, config) {
|
|
447
|
+
var newConfig = {};
|
|
448
|
+
for (var key in fileconfig) {
|
|
449
|
+
if (key.indexOf("rt_") == 0) {
|
|
450
|
+
newConfig[key.replace("rt_", "")] = fileconfig[key];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
for (var key in config) {
|
|
454
|
+
if (key.indexOf("rt_") == 0 && !newConfig.hasOwnProperty(key.replace("rt_", ""))) {
|
|
455
|
+
newConfig[key.replace("rt_", "")] = config[key];
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return newConfig;
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// collect all js-functions found in config obj and replace them with string-id
|
|
463
|
+
// we will inject the functions sepperatly, so we can inject config as json string
|
|
464
|
+
// we also inject a function that wires the collected functions back to the js-obj
|
|
465
|
+
// this way we can support injecting simple js-function into the html (dont use "this" in functions)
|
|
466
|
+
var collectAndReplaceFunctions = function (collectedFunctions, obj, path) {
|
|
467
|
+
if (path === void 0) { path = ""; }
|
|
468
|
+
if (path != "") { path += ""; }
|
|
469
|
+
if (typeof obj === "object") {
|
|
470
|
+
for (var key in obj) {
|
|
471
|
+
if (typeof obj[key] === "function") {
|
|
472
|
+
collectedFunctions[path + key] = obj[key];
|
|
473
|
+
obj[key] = "___" + path + key;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
collectedFunctions = collectAndReplaceFunctions(collectedFunctions, obj[key], path + key);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return collectedFunctions;
|
|
481
|
+
};
|
|
482
|
+
// used to copy the output to sub-folder when building in split mode
|
|
483
|
+
var copyRecursiveSync = function (fs, path, src, dest) {
|
|
484
|
+
var exists = fs.existsSync(src);
|
|
485
|
+
var stats = exists && fs.statSync(src);
|
|
486
|
+
var isDirectory = exists && stats.isDirectory();
|
|
487
|
+
if (isDirectory) {
|
|
488
|
+
fs.mkdirSync(dest);
|
|
489
|
+
fs.readdirSync(src).forEach(function (childItemName) {
|
|
490
|
+
copyRecursiveSync(fs, path, path.join(src, childItemName), path.join(dest, childItemName));
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
fs.copyFileSync(src, dest);
|
|
495
|
+
}
|
|
496
|
+
};
|