@playcraft/devkit 1.0.31-beta.1 → 1.0.31-beta.11
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 +262 -0
- package/cli/bin/playable-scripts.js +53 -6
- package/cli/commands/build.js +241 -32
- package/cli/commands/builds.js +13 -2
- package/cli/commands/dev.js +22 -1
- package/cli/commands/pack.js +323 -41
- package/cli/commands/vite-dev.js +7 -1
- package/core/artifacts/emit.js +98 -1
- package/core/artifacts/fflate.js +31 -1
- package/core/artifacts/zip.js +39 -1
- package/core/batch-build.js +1261 -149
- package/core/constants.js +20 -2
- package/core/cos-uploader.js +289 -23
- package/core/engines/cocos/clean-cache.js +188 -0
- package/core/engines/cocos/clean-cache.test.js +75 -0
- package/core/engines/cocos/cli-build.js +116 -2
- package/core/engines/cocos/cli.js +38 -1
- package/core/engines/cocos/constants.js +21 -1
- package/core/engines/cocos/creator-cli.js +108 -1
- package/core/engines/cocos/dev-server.js +412 -2
- package/core/engines/cocos/fs.js +105 -1
- package/core/engines/cocos/injects/3x/init.js +438 -19
- package/core/engines/cocos/injects/3x/main.js +52 -2
- package/core/engines/cocos/injects/libs/pako.js +2 -1
- package/core/engines/cocos/mcp-refresh.js +76 -2
- package/core/engines/cocos/merge.js +147 -2
- package/core/engines/cocos/pack.js +187 -1
- package/core/engines/cocos/preview-cache.js +51 -0
- package/core/engines/cocos/preview-cache.test.js +32 -0
- package/core/engines/cocos/preview-concat.js +192 -0
- package/core/engines/cocos/preview-concat.test.js +73 -0
- package/core/engines/cocos/preview-json-hook.js +200 -0
- package/core/engines/cocos/preview-json-pack.js +379 -0
- package/core/engines/cocos/preview-json-pack.test.js +226 -0
- package/core/engines/cocos/preview-proxy.js +132 -0
- package/core/engines/cocos/rebundle-preview.js +56 -0
- package/core/engines/cocos/strip-social-share.js +115 -3
- package/core/engines/cocos/theme-assets.js +161 -2
- package/core/engines/cocos/writable-cli.js +250 -0
- package/core/engines/cocos/writable-cli.test.js +112 -0
- package/core/engines/web/index.js +20 -1
- package/core/engines/web/vite.dev.js +322 -17
- package/core/engines/web/webpack.build.js +522 -65
- package/core/engines/web/webpack.common.js +177 -11
- package/core/engines/web/webpack.dev.js +88 -6
- package/core/index.d.ts +3 -0
- package/core/index.js +101 -7
- package/core/injectors/apply.js +94 -1
- package/core/injectors/check-channel-matrix.js +130 -2
- package/core/injectors/spec.js +217 -9
- package/core/loaders/gltf-loader.js +74 -28
- package/core/options.js +353 -16
- package/core/plugins/AdikteevInjectorPlugin.js +26 -4
- package/core/plugins/BigoAdsInjectorPlugin.js +21 -4
- package/core/plugins/DAPIInjectorPlugin.js +25 -2
- package/core/plugins/DebuggerInjectionPlugin.js +31 -3
- package/core/plugins/ExitAPIInjectorPlugin.js +56 -3
- package/core/plugins/FflateCompressionPlugin.js +231 -40
- package/core/plugins/FontInjectionWebpackPlugin.js +46 -4
- package/core/plugins/LiftoffInjectorPlugin.js +26 -4
- package/core/plugins/MRAIDInjectorPlugin.js +24 -2
- package/core/plugins/MintegralInjectorPlugin.js +25 -2
- package/core/plugins/PangleInjectorPlugin.js +24 -2
- package/core/plugins/PlaycraftOrientationInjectorPlugin.js +29 -3
- package/core/plugins/SnapchatInjectorPlugin.js +26 -4
- package/core/plugins/SocialMediaInjectorPlugin.js +119 -7
- package/core/plugins/TikTokInjectorPlugin.js +24 -2
- package/core/plugins/UnityInjectorPlugin.js +37 -8
- package/core/plugins/ZipPlugin.js +154 -20
- package/core/plugins/socialMediaVitePlugin.js +108 -2
- package/core/utils/buildDefines.js +30 -2
- package/core/utils/buildTemplateString.js +39 -5
- package/core/utils/date.js +16 -1
- package/core/utils/fontRegistry.js +81 -13
- package/core/utils/fontResolver.js +335 -37
- package/core/utils/generateAdikteevHtmlWebpackPluginConfig.js +42 -7
- package/core/utils/generateBigabidHtmlWebpackPluginConfig.js +30 -3
- package/core/utils/generateInMobiHtmlWebpackPluginConfig.js +43 -7
- package/core/utils/getPlaycraftOrientationSuffix.js +9 -2
- package/core/utils/injectSDKPlugins.js +68 -13
- package/core/utils/logOptions.js +46 -5
- package/core/utils/mergeOptions.js +21 -2
- package/core/utils/parseArgvOptions.js +125 -5
- package/core/utils/resolveChannelFold2Zip.js +15 -3
- package/core/utils/validateThemeData.js +227 -26
- package/core/validators/index.d.ts +4 -0
- package/core/validators/pre-build-checker.js +287 -25
- package/core/validators/tracking-validator.js +444 -43
- package/core/validators/tracking-validator.test.js +92 -0
- package/core/vite.dev.js +1 -1
- package/core/webpack.build.js +1 -1
- package/core/webpack.common.js +1 -1
- package/core/webpack.dev.js +1 -1
- package/package.json +3 -2
|
@@ -1,19 +1,438 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
window.__adapter_init = function () {
|
|
3
|
+
// Utilities
|
|
4
|
+
function base64ToBlob(base64, type) {
|
|
5
|
+
let oriResBase64 = base64;
|
|
6
|
+
let base64Arr = oriResBase64.split(',');
|
|
7
|
+
let mime = type
|
|
8
|
+
|
|
9
|
+
// mime-type start
|
|
10
|
+
if (base64Arr.length === 2) {
|
|
11
|
+
let mimeStr = base64Arr.shift()
|
|
12
|
+
let regExp = new RegExp(':(.*?);')
|
|
13
|
+
let array = mimeStr.match(regExp);
|
|
14
|
+
mime = (array && array.length > 1 ? array[1] : type) || type;
|
|
15
|
+
}
|
|
16
|
+
// mime-type end
|
|
17
|
+
|
|
18
|
+
// arraybuffer start
|
|
19
|
+
let base64Str = base64Arr.shift()
|
|
20
|
+
let bytes = window.atob(base64Str);
|
|
21
|
+
let arrBuf = new ArrayBuffer(bytes.length);
|
|
22
|
+
// arraybuffer end
|
|
23
|
+
|
|
24
|
+
const u8arr = new Uint8Array(arrBuf);
|
|
25
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
26
|
+
u8arr[i] = bytes.charCodeAt(i);
|
|
27
|
+
}
|
|
28
|
+
return new Blob([arrBuf], {
|
|
29
|
+
type: mime
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function base64toArrayBuffer(base64) {
|
|
34
|
+
var bstr = window.atob(base64.substring(base64.indexOf(',') + 1));
|
|
35
|
+
let index = bstr.length;
|
|
36
|
+
let u8arr = new Uint8Array(index);
|
|
37
|
+
while (index--) {
|
|
38
|
+
u8arr[index] = bstr.charCodeAt(index);
|
|
39
|
+
}
|
|
40
|
+
return u8arr.buffer;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class AdapterFetch {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.response = null, this.status = 200, this.responseType = "", this.onload = function () {
|
|
46
|
+
console.log("onload")
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
open(e, t) {
|
|
50
|
+
const n = __adapter_get_resource(t);
|
|
51
|
+
n ? this.response = n : console.log("res", n, t)
|
|
52
|
+
}
|
|
53
|
+
send() {
|
|
54
|
+
switch (this.responseType) {
|
|
55
|
+
case "json":
|
|
56
|
+
this.response = JSON.parse(this.response);
|
|
57
|
+
break;
|
|
58
|
+
case "text":
|
|
59
|
+
this.response = this.response;
|
|
60
|
+
break;
|
|
61
|
+
case "arraybuffer":
|
|
62
|
+
this.response = base64toArrayBuffer(this.response);
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
this.response = this.response;
|
|
66
|
+
}
|
|
67
|
+
this.onload()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function __adapter_eval(name) {
|
|
72
|
+
if (!window.__adapter_js__[name]) {
|
|
73
|
+
console.warn('window.__adapter_js__ is not found ', name)
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
eval(window.__adapter_js__[name]);
|
|
77
|
+
delete window.__adapter_js__[name];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function __adapter_get_base_url() {
|
|
81
|
+
const hasDocument = typeof document !== 'undefined';
|
|
82
|
+
let baseUrl;
|
|
83
|
+
if (hasDocument) {
|
|
84
|
+
let baseEl = document.querySelector('base[href]');
|
|
85
|
+
if (baseEl)
|
|
86
|
+
baseUrl = baseEl.href;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!baseUrl && typeof location !== 'undefined') {
|
|
90
|
+
baseUrl = location.href.split('#')[0].split('?')[0];
|
|
91
|
+
var lastSepIndex = baseUrl.lastIndexOf('/');
|
|
92
|
+
if (lastSepIndex !== -1)
|
|
93
|
+
baseUrl = baseUrl.slice(0, lastSepIndex + 1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return baseUrl || ''
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function __adapter_get_res_path(url, target) {
|
|
100
|
+
if (target[url]) {
|
|
101
|
+
return url
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (let key in target) {
|
|
105
|
+
const index = url.indexOf(key);
|
|
106
|
+
if (index !== -1 && (index + key.length === url.length)) {
|
|
107
|
+
return key;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function __adapter_get_resource(url) {
|
|
114
|
+
return window.__adapter_resource__[__adapter_get_res_path(url, window.__adapter_resource__)];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function __adapter_get_imports() {
|
|
118
|
+
const json = JSON.parse(__adapter_get_resource("src/import-map.json"))
|
|
119
|
+
return json.imports
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function __adapter_get_script(url) {
|
|
123
|
+
if (url.indexOf('bullet.wasm') !== -1) {
|
|
124
|
+
for (let k2 in window.__adapter_js__) {
|
|
125
|
+
if (k2.indexOf('bullet.cocos') !== -1) {
|
|
126
|
+
url = k2;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let _key = __adapter_get_res_path(url, window.__adapter_js__);
|
|
132
|
+
const res = window.__adapter_js__[_key];
|
|
133
|
+
if (res) {
|
|
134
|
+
delete window.__adapter_js__[_key];
|
|
135
|
+
}
|
|
136
|
+
return res;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function __adapter_init_http() {
|
|
140
|
+
window.adapterFetch = AdapterFetch
|
|
141
|
+
|
|
142
|
+
const _fetch = window.fetch
|
|
143
|
+
window.fetch = function (url, options) {
|
|
144
|
+
const resource = __adapter_get_resource(url);
|
|
145
|
+
if (resource) {
|
|
146
|
+
// 模拟fetch响应结果
|
|
147
|
+
let response = {
|
|
148
|
+
ok: true,
|
|
149
|
+
status: 200,
|
|
150
|
+
statusText: 'OK',
|
|
151
|
+
headers: {
|
|
152
|
+
get: function (key) {
|
|
153
|
+
// 根据不同的资源url返回不同的content-type,json、css、wasm
|
|
154
|
+
if (key === 'content-type') {
|
|
155
|
+
if (url.indexOf('.json') !== -1) {
|
|
156
|
+
return 'application/json'
|
|
157
|
+
} else if (url.indexOf('.css') !== -1) {
|
|
158
|
+
return 'text/css'
|
|
159
|
+
} else if (url.indexOf('.wasm') !== -1) {
|
|
160
|
+
return 'application/wasm'
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return 'application/javascript';
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
url: url,
|
|
167
|
+
clone: function () {
|
|
168
|
+
return response;
|
|
169
|
+
},
|
|
170
|
+
text: function () {
|
|
171
|
+
return Promise.resolve(resource);
|
|
172
|
+
},
|
|
173
|
+
json: function () {
|
|
174
|
+
return Promise.resolve(JSON.parse(resource));
|
|
175
|
+
},
|
|
176
|
+
arrayBuffer: function () {
|
|
177
|
+
return Promise.resolve(base64toArrayBuffer(resource));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return Promise.resolve(response);
|
|
181
|
+
}
|
|
182
|
+
return _fetch(url, options)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function __adapter_init_js() {
|
|
187
|
+
const _createScript = System.__proto__.createScript
|
|
188
|
+
System.__proto__.createScript = function (url) {
|
|
189
|
+
let baseUrl = url.replace(__adapter_get_base_url(), '')
|
|
190
|
+
let res = __adapter_get_script(baseUrl)
|
|
191
|
+
if (!res) {
|
|
192
|
+
console.error(`${url} 找不到资源`)
|
|
193
|
+
return _createScript.call(this, url)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const blob = new Blob([res], { type: 'text/javascript' });
|
|
197
|
+
return _createScript.call(this, URL.createObjectURL(blob))
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function __adapter_init_cc() {
|
|
202
|
+
if (window.__adapter_cc_initialized__) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
window.__adapter_cc_initialized__ = true;
|
|
206
|
+
function loadScript(url, options, onComplete) {
|
|
207
|
+
let scriptStr = __adapter_get_resource(url)
|
|
208
|
+
if (!scriptStr) {
|
|
209
|
+
console.error(url + ' isn\'t load')
|
|
210
|
+
}
|
|
211
|
+
eval(scriptStr);
|
|
212
|
+
onComplete && onComplete(null);
|
|
213
|
+
}
|
|
214
|
+
// Json
|
|
215
|
+
function loadJson(url, options, onComplete) {
|
|
216
|
+
const data = JSON.parse(__adapter_get_resource(url));
|
|
217
|
+
onComplete(null, data);
|
|
218
|
+
}
|
|
219
|
+
function loadBundle(url, options, onComplete) {
|
|
220
|
+
const REGEX = new RegExp('^(?:\w+:\/\/|\.+\/).+')
|
|
221
|
+
let bundleName = cc.path.basename(url);
|
|
222
|
+
if (!REGEX.test(url)) {
|
|
223
|
+
url = 'assets/' + bundleName;
|
|
224
|
+
}
|
|
225
|
+
const version = options.version || cc.assetManager.downloader.bundleVers[bundleName];
|
|
226
|
+
let count = 0;
|
|
227
|
+
const config = `${url}/config.${version ? version + '.' : ''}json`;
|
|
228
|
+
let out = null, error = null;
|
|
229
|
+
loadJson(config, options, function (err, response) {
|
|
230
|
+
if (err) {
|
|
231
|
+
error = err;
|
|
232
|
+
}
|
|
233
|
+
out = response;
|
|
234
|
+
out && (out.base = url + '/');
|
|
235
|
+
count++;
|
|
236
|
+
if (count === 2) {
|
|
237
|
+
onComplete && onComplete(error, out);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
const js = `${url}/index.${version ? version + '.' : ''}js`;
|
|
241
|
+
loadScript(js, options, function (err) {
|
|
242
|
+
if (err) {
|
|
243
|
+
error = err;
|
|
244
|
+
}
|
|
245
|
+
count++;
|
|
246
|
+
if (count === 2) {
|
|
247
|
+
onComplete && onComplete(error, out);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
function loadFont(url, options, onComplete) {
|
|
252
|
+
const fontFamilyName = url.split('/').pop().split('.')[0]
|
|
253
|
+
const data = __adapter_get_resource(url);
|
|
254
|
+
if (data == null) {
|
|
255
|
+
onComplete();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const fontFace = new FontFace(fontFamilyName, 'url(' + data + ')');
|
|
259
|
+
document.fonts.add(fontFace);
|
|
260
|
+
fontFace.load();
|
|
261
|
+
fontFace.loaded.then(function () {
|
|
262
|
+
onComplete(null, fontFamilyName);
|
|
263
|
+
}, function () {
|
|
264
|
+
console.error('url(' + url + ') load fail');
|
|
265
|
+
onComplete(null, fontFamilyName);
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
// Image
|
|
269
|
+
function loadImage(url, options, onComplete) {
|
|
270
|
+
const data = __adapter_get_resource(url);
|
|
271
|
+
if (!data) {
|
|
272
|
+
console.error(url + ' isn\'t load')
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
let img = new Image();
|
|
276
|
+
const loadCallback = function () {
|
|
277
|
+
img.removeEventListener('load', loadCallback);
|
|
278
|
+
img.removeEventListener('error', errorCallback);
|
|
279
|
+
onComplete && onComplete(null, img);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const errorCallback = function () {
|
|
283
|
+
img.removeEventListener('load', loadCallback);
|
|
284
|
+
img.removeEventListener('error', errorCallback);
|
|
285
|
+
onComplete && onComplete(new Error(cc.debug.getError(4930, url)));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
img.addEventListener('load', loadCallback);
|
|
289
|
+
img.addEventListener('error', errorCallback);
|
|
290
|
+
img.src = data;
|
|
291
|
+
return img;
|
|
292
|
+
}
|
|
293
|
+
// Video
|
|
294
|
+
function loadVideo(url, options, onComplete) {
|
|
295
|
+
var video = document.createElement('video');
|
|
296
|
+
var source = document.createElement('source');
|
|
297
|
+
video.appendChild(source);
|
|
298
|
+
|
|
299
|
+
let res = __adapter_get_resource(url)
|
|
300
|
+
if (res) {
|
|
301
|
+
res = base64ToBlob(res);
|
|
302
|
+
res = URL.createObjectURL(res);
|
|
303
|
+
source.src = res
|
|
304
|
+
|
|
305
|
+
onComplete(null, video);
|
|
306
|
+
} else {
|
|
307
|
+
onComplete(new Error(url + "(no response)"));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Text
|
|
311
|
+
function loadText(url, options, onComplete) {
|
|
312
|
+
options.responseType = "text";
|
|
313
|
+
const data = __adapter_get_resource(url);
|
|
314
|
+
onComplete(null, data);
|
|
315
|
+
}
|
|
316
|
+
// ArrayBuffer
|
|
317
|
+
function loadArrayBuffer(url, options, onComplete) {
|
|
318
|
+
let data = __adapter_get_resource(url);
|
|
319
|
+
data = base64toArrayBuffer(data);
|
|
320
|
+
onComplete(null, data);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (cc.internal.VideoPlayerImplManager) {
|
|
324
|
+
const getImpl = cc.internal.VideoPlayerImplManager.getImpl;
|
|
325
|
+
cc.internal.VideoPlayerImplManager.getImpl = function (comp) {
|
|
326
|
+
const impl = getImpl.call(this, comp);
|
|
327
|
+
const createVideoPlayer = impl.createVideoPlayer;
|
|
328
|
+
impl.createVideoPlayer = function (url) {
|
|
329
|
+
var res = __adapter_get_resource(url);
|
|
330
|
+
if (res) {
|
|
331
|
+
res = base64ToBlob(res);
|
|
332
|
+
res = URL.createObjectURL(res);
|
|
333
|
+
return createVideoPlayer.call(this, res);
|
|
334
|
+
}
|
|
335
|
+
return createVideoPlayer.call(this, url);
|
|
336
|
+
};
|
|
337
|
+
return impl;
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const downloaderList = {
|
|
342
|
+
// Scripts
|
|
343
|
+
'.js': loadScript,
|
|
344
|
+
// Fonts
|
|
345
|
+
'.font': loadFont,
|
|
346
|
+
'.eot': loadFont,
|
|
347
|
+
'.ttf': loadFont,
|
|
348
|
+
'.woff': loadFont,
|
|
349
|
+
'.svg': loadFont,
|
|
350
|
+
'.ttc': loadFont,
|
|
351
|
+
// Images
|
|
352
|
+
'.png': loadImage,
|
|
353
|
+
'.jpg': loadImage,
|
|
354
|
+
'.bmp': loadImage,
|
|
355
|
+
'.jpeg': loadImage,
|
|
356
|
+
'.gif': loadImage,
|
|
357
|
+
'.ico': loadImage,
|
|
358
|
+
'.tiff': loadImage,
|
|
359
|
+
'.webp': loadImage,
|
|
360
|
+
'.image': loadImage,
|
|
361
|
+
// Videos
|
|
362
|
+
'.mp4': loadVideo,
|
|
363
|
+
'.avi': loadVideo,
|
|
364
|
+
'.mov': loadVideo,
|
|
365
|
+
'.mpg': loadVideo,
|
|
366
|
+
'.mpeg': loadVideo,
|
|
367
|
+
'.rm': loadVideo,
|
|
368
|
+
'.rmvb': loadVideo,
|
|
369
|
+
// Text
|
|
370
|
+
'.txt': loadText,
|
|
371
|
+
'.xml': loadText,
|
|
372
|
+
'.vsh': loadText,
|
|
373
|
+
'.fsh': loadText,
|
|
374
|
+
'.atlas': loadText,
|
|
375
|
+
'.tmx': loadText,
|
|
376
|
+
'.tsx': loadText,
|
|
377
|
+
'.plist': loadText,
|
|
378
|
+
'.fnt': loadText,
|
|
379
|
+
// ArrayBuffer
|
|
380
|
+
'.pvr': loadArrayBuffer,
|
|
381
|
+
'.pkm': loadArrayBuffer,
|
|
382
|
+
'.astc': loadArrayBuffer,
|
|
383
|
+
'.binary': loadArrayBuffer,
|
|
384
|
+
'.bin': loadArrayBuffer,
|
|
385
|
+
'.dbbin': loadArrayBuffer,
|
|
386
|
+
'.skel': loadArrayBuffer,
|
|
387
|
+
|
|
388
|
+
'bundle': loadBundle,
|
|
389
|
+
'default': loadText,
|
|
390
|
+
}
|
|
391
|
+
cc.assetManager.downloader.downloadScript = loadScript
|
|
392
|
+
Object.keys(downloaderList).forEach((extname) => {
|
|
393
|
+
cc.assetManager.downloader.register(extname, downloaderList[extname]);
|
|
394
|
+
})
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function __adapter_init_plugins() {
|
|
398
|
+
if (!window.__adapter_plugins__ || window.__adapter_plugins__.length === 0) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
window.__adapter_plugins__.forEach((scriptPath) => {
|
|
403
|
+
const fileName = 'src/' + scriptPath
|
|
404
|
+
__adapter_eval(fileName)
|
|
405
|
+
})
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function __adapter_get_path(key) {
|
|
409
|
+
for (var k in window.__adapter_resource__) {
|
|
410
|
+
if (k.indexOf(key) == 0) {
|
|
411
|
+
return k;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
throw Error("no find " + key);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
__adapter_init_http();
|
|
418
|
+
|
|
419
|
+
__adapter_eval(__adapter_get_path('src/polyfills.bundle'));
|
|
420
|
+
__adapter_eval(__adapter_get_path('src/system.bundle'));
|
|
421
|
+
|
|
422
|
+
__adapter_init_js();
|
|
423
|
+
|
|
424
|
+
let prepareLoad = Promise.resolve()
|
|
425
|
+
const importsKeys = Object.keys(__adapter_get_imports())
|
|
426
|
+
for (let index = importsKeys.length - 1; index >= 0; index--) {
|
|
427
|
+
const key = importsKeys[index];
|
|
428
|
+
prepareLoad = prepareLoad.then(() => System.import(key))
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
prepareLoad.then(() => {
|
|
432
|
+
__adapter_init_cc()
|
|
433
|
+
__adapter_init_plugins()
|
|
434
|
+
System.import('./' + __adapter_get_path('index')).catch((err) => {
|
|
435
|
+
console.error(err);
|
|
436
|
+
})
|
|
437
|
+
})
|
|
438
|
+
};
|
|
@@ -1,2 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
; (function () {
|
|
2
|
+
function base64toArrayBuffer(base64) {
|
|
3
|
+
var bstr = window.atob(base64.substring(base64.indexOf(',') + 1));
|
|
4
|
+
let index = bstr.length;
|
|
5
|
+
let u8arr = new Uint8Array(index);
|
|
6
|
+
while (index--) {
|
|
7
|
+
u8arr[index] = bstr.charCodeAt(index);
|
|
8
|
+
}
|
|
9
|
+
return u8arr.buffer;
|
|
10
|
+
}
|
|
11
|
+
function __adapter_unzip() {
|
|
12
|
+
console.time("load resource");
|
|
13
|
+
try {
|
|
14
|
+
const zipData = base64toArrayBuffer(window.__adapter_zip__);
|
|
15
|
+
const decompressed = pako.inflate(zipData, { to: 'string' });
|
|
16
|
+
window.__adapter_resource__ = JSON.parse(decompressed);
|
|
17
|
+
__adapter_exec_js();
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(error)
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
console.timeEnd("load resource");
|
|
23
|
+
}
|
|
24
|
+
function __adapter_exec_js() {
|
|
25
|
+
window.__adapter_js__ = {};
|
|
26
|
+
for (const filePath in window.__adapter_resource__) {
|
|
27
|
+
let dirArr = filePath.split('.');
|
|
28
|
+
if (dirArr[dirArr.length - 1] === 'js') {
|
|
29
|
+
window.__adapter_js__[filePath] = window.__adapter_resource__[filePath];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
__adapter_success();
|
|
33
|
+
}
|
|
34
|
+
function __adapter_console() {
|
|
35
|
+
if (window.__adapter_js__['vconsole.min.js']) {
|
|
36
|
+
eval(window.__adapter_js__['vconsole.min.js']);
|
|
37
|
+
delete window.__adapter_js__['vconsole.min.js'];
|
|
38
|
+
window.VConsole && (window.vConsole = new VConsole());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function __adapter_success() {
|
|
42
|
+
__adapter_console();
|
|
43
|
+
window.__adapter_init && window.__adapter_init();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 如果不存在pako,则直接运行js
|
|
47
|
+
if (!window['pako']) {
|
|
48
|
+
__adapter_exec_js();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
__adapter_unzip();
|
|
52
|
+
})();
|