@playcraft/devkit 1.0.1-8.beta.1 → 1.0.1-8.beta.3
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 +259 -0
- package/cli/bin/playable-scripts.js +44 -1
- package/cli/commands/build.js +130 -18
- package/cli/commands/builds.js +13 -2
- package/cli/commands/dev.js +7 -1
- package/cli/commands/pack.js +308 -39
- package/cli/commands/vite-dev.js +7 -1
- package/core/batch-build.js +1091 -125
- package/core/cos-uploader.js +264 -20
- package/core/index.js +71 -6
- package/core/loaders/gltf-loader.js +74 -28
- package/core/options.js +310 -15
- 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 +57 -3
- package/core/plugins/FflateCompressionPlugin.js +225 -37
- 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/SnapchatInjectorPlugin.js +26 -4
- package/core/plugins/TikTokInjectorPlugin.js +24 -2
- package/core/plugins/UnityInjectorPlugin.js +37 -8
- package/core/plugins/ZipPlugin.js +138 -19
- package/core/resources/fonts/maoken-regular.woff2 +0 -0
- package/core/resources/fonts/maoken-regular.woff2.chars +1 -0
- package/core/resources/fonts/maoken-zhuyuan.ttf +0 -0
- package/core/resources/fonts/pangmen-biaoti.ttf +0 -0
- package/core/resources/fonts/pangmen-regular.woff2 +0 -0
- package/core/resources/fonts/pangmen-regular.woff2.chars +1 -0
- package/core/utils/buildDefines.js +29 -2
- package/core/utils/buildTemplateString.js +40 -5
- package/core/utils/date.js +16 -1
- package/core/utils/fontRegistry.js +81 -12
- package/core/utils/fontResolver.js +335 -34
- package/core/utils/generateAdikteevHtmlWebpackPluginConfig.js +42 -7
- package/core/utils/generateBigabidHtmlWebpackPluginConfig.js +30 -3
- package/core/utils/generateInMobiHtmlWebpackPluginConfig.js +43 -7
- package/core/utils/injectSDKPlugins.js +58 -11
- package/core/utils/logOptions.js +37 -4
- package/core/utils/mergeOptions.js +19 -2
- package/core/utils/parseArgvOptions.js +110 -5
- package/core/utils/resolveChannelFold2Zip.js +15 -3
- package/core/utils/validateThemeData.js +220 -25
- package/core/validators/pre-build-checker.js +201 -21
- package/core/validators/tracking-validator.js +358 -40
- package/core/vite.dev.js +332 -18
- package/core/webpack.build.js +489 -56
- package/core/webpack.common.js +177 -11
- package/core/webpack.dev.js +82 -5
- package/package.json +3 -2
- package/core/resources/fonts/maoken/04e60956bbe055746aa7bca5c229ca8c.woff2 +0 -0
- package/core/resources/fonts/maoken/086a30eeaa0f5558062389361dca8685.woff2 +0 -0
- package/core/resources/fonts/maoken/1b1c9545aa1da01979d240f38f979b9e.woff2 +0 -0
- package/core/resources/fonts/maoken/1dd31fae60d98fcad0812cb4dc54afdd.woff2 +0 -0
- package/core/resources/fonts/maoken/1f08966635ca0dc4a64f519863df0dcc.woff2 +0 -0
- package/core/resources/fonts/maoken/26aab6a388b04c37fd5a4d066a512e14.woff2 +0 -0
- package/core/resources/fonts/maoken/29390db71394eb0d298fa1c339590e45.woff2 +0 -0
- package/core/resources/fonts/maoken/2b743d9f736c5cda9250fc8b85f69db8.woff2 +0 -0
- package/core/resources/fonts/maoken/2f16b1f8881909c4e65404610460797f.woff2 +0 -0
- package/core/resources/fonts/maoken/339dc88f6fd1b09336410154252f858f.woff2 +0 -0
- package/core/resources/fonts/maoken/3665591d2bd9a3f31a302a34a76c74dc.woff2 +0 -0
- package/core/resources/fonts/maoken/3b58ece5ff16a5addc9adc1c74717d12.woff2 +0 -0
- package/core/resources/fonts/maoken/3e3aacd6cd2255be39c97c4ed6eb978b.woff2 +0 -0
- package/core/resources/fonts/maoken/3e8cdd750fcbbfcf9a1101c7418eeb36.woff2 +0 -0
- package/core/resources/fonts/maoken/3f71b3c0ecb555f9fa88d1b2ae0ec77f.woff2 +0 -0
- package/core/resources/fonts/maoken/40f956d892d89a442992737448f0330b.woff2 +0 -0
- package/core/resources/fonts/maoken/47ecbb41501b6cb923aaa8b8324bb22f.woff2 +0 -0
- package/core/resources/fonts/maoken/4a6e704952e05d217e4f4d2c2a330094.woff2 +0 -0
- package/core/resources/fonts/maoken/4ec9fc653a6aaabd2296fac3fe906416.woff2 +0 -0
- package/core/resources/fonts/maoken/5d950afcbaac4bb8f44083e5f4572957.woff2 +0 -0
- package/core/resources/fonts/maoken/6505b718e31b5b2b29c4f50a2a2b5fe6.woff2 +0 -0
- package/core/resources/fonts/maoken/673405ebfdfebae1104f36efa778714d.woff2 +0 -0
- package/core/resources/fonts/maoken/695a686e27152d8e81b4459b64d7b6a1.woff2 +0 -0
- package/core/resources/fonts/maoken/6b5fb0c960eed7a53f39adb18d0ab28b.woff2 +0 -0
- package/core/resources/fonts/maoken/6f53ca6c761ff540e11d5f7111dad67c.woff2 +0 -0
- package/core/resources/fonts/maoken/7125e9df28437d053e56f85a908a7343.woff2 +0 -0
- package/core/resources/fonts/maoken/731865983ae51e2a4bdc6c194da0b82e.woff2 +0 -0
- package/core/resources/fonts/maoken/74d993e9aa68ef636eb1287439d06bb0.woff2 +0 -0
- package/core/resources/fonts/maoken/797653f0a72360cd584f625972b5d217.woff2 +0 -0
- package/core/resources/fonts/maoken/7af5930fe5e6dade3cf31d3287d6414c.woff2 +0 -0
- package/core/resources/fonts/maoken/7c6fe2ee55f924f00b097da208852a34.woff2 +0 -0
- package/core/resources/fonts/maoken/8cff8ef36a011ca7e6d103f29b22f98b.woff2 +0 -0
- package/core/resources/fonts/maoken/8ff8566257c5df17ddde67b2b48243a4.woff2 +0 -0
- package/core/resources/fonts/maoken/93988344f6df526a0033a05d2d927d76.woff2 +0 -0
- package/core/resources/fonts/maoken/99d1c5647f1ce540674bd32354c2038f.woff2 +0 -0
- package/core/resources/fonts/maoken/a328b132aac2a3f53d97b8e7ad940e1a.woff2 +0 -0
- package/core/resources/fonts/maoken/a7dc00c95dd1e7a8eca8053975b0c07c.woff2 +0 -0
- package/core/resources/fonts/maoken/ab93ca86fb3e7ad8e95b93f7de5d8f97.woff2 +0 -0
- package/core/resources/fonts/maoken/b1b83e931f7e2187786b87545a6ee842.woff2 +0 -0
- package/core/resources/fonts/maoken/bb31b8c0ccf2d93af7cc25f19a576970.woff2 +0 -0
- package/core/resources/fonts/maoken/bd4a61534e4a0f426dd0d396362b211d.woff2 +0 -0
- package/core/resources/fonts/maoken/bec7534be141c6473023f18f5aee7a0e.woff2 +0 -0
- package/core/resources/fonts/maoken/c133a76c68c645b46b20e7faf9894ab6.woff2 +0 -0
- package/core/resources/fonts/maoken/c2deab25bd23b63c794da537e208c61a.woff2 +0 -0
- package/core/resources/fonts/maoken/cf13611d9749dd23fd9737073d2110f6.woff2 +0 -0
- package/core/resources/fonts/maoken/d01182e5dd9f51dce713916e8f872bbf.woff2 +0 -0
- package/core/resources/fonts/maoken/d1d4c88b2a14e679d3cc9d0ad8e8abdb.woff2 +0 -0
- package/core/resources/fonts/maoken/df61c7f5fa45aa6156122c09653f6700.woff2 +0 -0
- package/core/resources/fonts/maoken/e1867d1454d8c903ba29bac70f88c211.woff2 +0 -0
- package/core/resources/fonts/maoken/ef912f41f9109c5d936005af5552f521.woff2 +0 -0
- package/core/resources/fonts/maoken/f0f119744871bb6bec7e0eef4e1ce8ba.woff2 +0 -0
- package/core/resources/fonts/maoken/f32a268245b50f6c19bd946239fd8cc0.woff2 +0 -0
- package/core/resources/fonts/maoken/f4735851e08da122f471100ecff5c4ae.woff2 +0 -0
- package/core/resources/fonts/maoken/f85b8f6994600622f767506ae55d6280.woff2 +0 -0
- package/core/resources/fonts/maoken/fc145bdf9c20b67db44156382155b465.woff2 +0 -0
- package/core/resources/fonts/maoken/fcd8571ec88b953c893d77c4fd5c6ebc.woff2 +0 -0
- package/core/resources/fonts/maoken/fcdcb3f4b26b5c1f45fdd151f45e0c6d.woff2 +0 -0
- package/core/resources/fonts/maoken/index.json +0 -59
- package/core/resources/fonts/pangmen/0047cd3053f8c06117a653b73e100391.woff2 +0 -0
- package/core/resources/fonts/pangmen/008870151036457b39ee8794f5bc7a64.woff2 +0 -0
- package/core/resources/fonts/pangmen/01b5355e45274055ad794cc1b1305e69.woff2 +0 -0
- package/core/resources/fonts/pangmen/0756361ea2445ec1c500d354fa0867d0.woff2 +0 -0
- package/core/resources/fonts/pangmen/091cf1201fbbda8dc98c01e775991bab.woff2 +0 -0
- package/core/resources/fonts/pangmen/0c854072dc9998bd02ea8b29b5f1f55e.woff2 +0 -0
- package/core/resources/fonts/pangmen/10f3f7f8da6ab5f882e816c97532a4c6.woff2 +0 -0
- package/core/resources/fonts/pangmen/141229a7039c633c894ea5168d0ae849.woff2 +0 -0
- package/core/resources/fonts/pangmen/1b0b982276f5f93b3c71b3f6b1b81184.woff2 +0 -0
- package/core/resources/fonts/pangmen/1e415e51c4efb3182b87665d726fc423.woff2 +0 -0
- package/core/resources/fonts/pangmen/1f5fb0c8d785813dc765ff889b491361.woff2 +0 -0
- package/core/resources/fonts/pangmen/1fe8065222947d67d4177fe3bdd782cd.woff2 +0 -0
- package/core/resources/fonts/pangmen/229674de0b8d208f607468537d10ca48.woff2 +0 -0
- package/core/resources/fonts/pangmen/27230f128a3708090bed2eb5bb6ad437.woff2 +0 -0
- package/core/resources/fonts/pangmen/2d8f78526cd5d63e22274b3f0e5c4e50.woff2 +0 -0
- package/core/resources/fonts/pangmen/2f441859584ca1d060378be9f1173a6a.woff2 +0 -0
- package/core/resources/fonts/pangmen/319ed7be5128268f3cf297464b305a55.woff2 +0 -0
- package/core/resources/fonts/pangmen/35a41344eec91ef694ca59fda4dc9ccc.woff2 +0 -0
- package/core/resources/fonts/pangmen/3715cbec78511ff67e44fdd363b5fd79.woff2 +0 -0
- package/core/resources/fonts/pangmen/37d468e8e898644f8fddc9f83f04a5b1.woff2 +0 -0
- package/core/resources/fonts/pangmen/384b560d66242e5c1062489020d8749c.woff2 +0 -0
- package/core/resources/fonts/pangmen/38ef10dd61436ebaeb8dada7b827595c.woff2 +0 -0
- package/core/resources/fonts/pangmen/3e8bdfd8597f723100ff7d6b54e803f9.woff2 +0 -0
- package/core/resources/fonts/pangmen/43d57e12e1ec85c68a289d88f920f62e.woff2 +0 -0
- package/core/resources/fonts/pangmen/4c4ee1006529ddcc67e7c195d5ddb2e0.woff2 +0 -0
- package/core/resources/fonts/pangmen/4f65210dd5014352f4c6eb1a791e56c9.woff2 +0 -0
- package/core/resources/fonts/pangmen/5179f5b92b71d655b9094b282ca39161.woff2 +0 -0
- package/core/resources/fonts/pangmen/5282fc1cc80a878d744621a36279a1fa.woff2 +0 -0
- package/core/resources/fonts/pangmen/57604d7bad494a118e0fa9a6c0f1035a.woff2 +0 -0
- package/core/resources/fonts/pangmen/5891eaedeb9999f6b71434efc42407db.woff2 +0 -0
- package/core/resources/fonts/pangmen/592e3b1817378c607c8b6b183c89019a.woff2 +0 -0
- package/core/resources/fonts/pangmen/5c7c16778cf226e25ef39e475a19afa0.woff2 +0 -0
- package/core/resources/fonts/pangmen/5eccbf1ee87f73db786ee0a8441df8a3.woff2 +0 -0
- package/core/resources/fonts/pangmen/606a4091be7a3307a2d9adc4d2206b04.woff2 +0 -0
- package/core/resources/fonts/pangmen/62da615f3cbb7d19ce02973b009ec5b9.woff2 +0 -0
- package/core/resources/fonts/pangmen/63f9972982226af9df16006408160e8a.woff2 +0 -0
- package/core/resources/fonts/pangmen/6702bbfff577fce5bc621a91fdcb78bc.woff2 +0 -0
- package/core/resources/fonts/pangmen/6cd32dbf440a9b7711cc293b19f4c2d7.woff2 +0 -0
- package/core/resources/fonts/pangmen/6ef49a0811c0a0892dfbca6602365e6f.woff2 +0 -0
- package/core/resources/fonts/pangmen/7194cb1fa135d58fee1611bb8915fe25.woff2 +0 -0
- package/core/resources/fonts/pangmen/71baf3daab3248b0748dd187ab2fbc45.woff2 +0 -0
- package/core/resources/fonts/pangmen/7457db009eff249ec587c7d912c5d347.woff2 +0 -0
- package/core/resources/fonts/pangmen/762d1c7a28837c08180123e98dbe8cbf.woff2 +0 -0
- package/core/resources/fonts/pangmen/76e3d855d8684a1ee4d12cf7a572ca78.woff2 +0 -0
- package/core/resources/fonts/pangmen/78a97efdf675a6dcf903b4725de01219.woff2 +0 -0
- package/core/resources/fonts/pangmen/7b42a8cbf34bd2a0820ed81bb4730b6d.woff2 +0 -0
- package/core/resources/fonts/pangmen/7d07b13e8fc6502f0d2e21a7bb87ddb1.woff2 +0 -0
- package/core/resources/fonts/pangmen/7e710c007a48e4410861c67a9a26d4fc.woff2 +0 -0
- package/core/resources/fonts/pangmen/7eb8fe8685f6f2d6f0e223337f3a2b2b.woff2 +0 -0
- package/core/resources/fonts/pangmen/7ec1b00b541c2c2817cf352e2634bf5b.woff2 +0 -0
- package/core/resources/fonts/pangmen/7ffdd7059669ad52af7995b515889eeb.woff2 +0 -0
- package/core/resources/fonts/pangmen/818c6b2f12623b5a43d1036cb7f71b61.woff2 +0 -0
- package/core/resources/fonts/pangmen/81983731abfefd6a400b83b93d9e3665.woff2 +0 -0
- package/core/resources/fonts/pangmen/821ad173f8fd8eccd214241cc651657b.woff2 +0 -0
- package/core/resources/fonts/pangmen/83ee6dce60a5f156da3ad18e5cfb3e6e.woff2 +0 -0
- package/core/resources/fonts/pangmen/87db73da676a2e7b3e640e84187a5c86.woff2 +0 -0
- package/core/resources/fonts/pangmen/89b2edc17dd7ab4332f18b038d268068.woff2 +0 -0
- package/core/resources/fonts/pangmen/8b3f89232252b80f6e12ab91d93fda96.woff2 +0 -0
- package/core/resources/fonts/pangmen/928a7b39a7c4efdca10f70dfcdb917ac.woff2 +0 -0
- package/core/resources/fonts/pangmen/945d03601ca6e8be5f7e6043ecb716a5.woff2 +0 -0
- package/core/resources/fonts/pangmen/97de16fa122ebcbff22956b7b2de2f77.woff2 +0 -0
- package/core/resources/fonts/pangmen/9882677dd482462a6c1c0a1d7efbb15d.woff2 +0 -0
- package/core/resources/fonts/pangmen/9c46188cc1e1711f860fa06d2c29dcc1.woff2 +0 -0
- package/core/resources/fonts/pangmen/a279650fd2f2f115ab30cbbf748f85f9.woff2 +0 -0
- package/core/resources/fonts/pangmen/a3bfd69906b38ab891501ac997bd577d.woff2 +0 -0
- package/core/resources/fonts/pangmen/a4cc4f73c30d1dca3f7abd656705e239.woff2 +0 -0
- package/core/resources/fonts/pangmen/a54d94633b077f678d15b96ad9e6a9c9.woff2 +0 -0
- package/core/resources/fonts/pangmen/ab9bd513cba626dee079d3f8f35da118.woff2 +0 -0
- package/core/resources/fonts/pangmen/b4b057c12d1e44681bdb5c5e92f8e070.woff2 +0 -0
- package/core/resources/fonts/pangmen/b8c1e4b1ab3beb334fa773a50c9221b0.woff2 +0 -0
- package/core/resources/fonts/pangmen/b93617eda1294f0696193c5237320892.woff2 +0 -0
- package/core/resources/fonts/pangmen/bac50a33e26632667ed330c817b37dcf.woff2 +0 -0
- package/core/resources/fonts/pangmen/c31e6efe815ccefa90bebc1fa64aba8b.woff2 +0 -0
- package/core/resources/fonts/pangmen/c75ff5aa44a05db009b0a38d05f4040b.woff2 +0 -0
- package/core/resources/fonts/pangmen/ca70255a9a388b3f33cff49d5abc31f2.woff2 +0 -0
- package/core/resources/fonts/pangmen/cb249c8c31a2bee3d6a68fd1c74c061a.woff2 +0 -0
- package/core/resources/fonts/pangmen/cb898d32532efe5a7933672228bc620c.woff2 +0 -0
- package/core/resources/fonts/pangmen/cc3c33c20e8abd03b9e5acc637985d63.woff2 +0 -0
- package/core/resources/fonts/pangmen/cca20bec40d1a11ede1ec496d22cd026.woff2 +0 -0
- package/core/resources/fonts/pangmen/cedee24be6ea34e35c53c0ce5edd7af0.woff2 +0 -0
- package/core/resources/fonts/pangmen/d42c580643039640037f5c63750ac711.woff2 +0 -0
- package/core/resources/fonts/pangmen/dbe1c94b8d92f8915c33fff55b625716.woff2 +0 -0
- package/core/resources/fonts/pangmen/dced2d67eceeefa7f45ba44854174b8b.woff2 +0 -0
- package/core/resources/fonts/pangmen/dee98b9b0545a42fd3aaa87ec1fa213e.woff2 +0 -0
- package/core/resources/fonts/pangmen/e6ac6bb1654d431fe62556a342b16e52.woff2 +0 -0
- package/core/resources/fonts/pangmen/eb9be6e3e450bf5706308fcec576c6df.woff2 +0 -0
- package/core/resources/fonts/pangmen/ee8cb027810ba5b5d9016774789f747b.woff2 +0 -0
- package/core/resources/fonts/pangmen/f0ecb29938306af8e9117a24eefad319.woff2 +0 -0
- package/core/resources/fonts/pangmen/f1a1a697d45d7f13a71a0a38424a98a7.woff2 +0 -0
- package/core/resources/fonts/pangmen/f203894451810a009d6795f1b0493989.woff2 +0 -0
- package/core/resources/fonts/pangmen/f53b808c0d5afb527499049ba225198e.woff2 +0 -0
- package/core/resources/fonts/pangmen/f6f69823eda331486d1d1a6e676e1d4a.woff2 +0 -0
- package/core/resources/fonts/pangmen/fb1ad0e1ba9ca84b66aa88867ce4109c.woff2 +0 -0
- package/core/resources/fonts/pangmen/index.json +0 -95
package/core/cos-uploader.js
CHANGED
|
@@ -1,17 +1,86 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
/**
|
|
3
6
|
* COS 上传模块
|
|
4
7
|
*
|
|
5
8
|
* 功能:上传文件到腾讯云 COS,并刷新 CDN 缓存
|
|
6
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const COS = require('cos-nodejs-sdk-v5');
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
/**
|
|
7
16
|
* 从远程 API 获取临时凭证
|
|
8
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
async function fetchTemporaryCredentials() {
|
|
19
|
+
const https = require('https');
|
|
20
|
+
const credentialsUrl = 'https://wd-act.woa.com/aix/playable/api/cos/credentials';
|
|
21
|
+
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
https.get(credentialsUrl, (response) => {
|
|
24
|
+
if (response.statusCode !== 200) {
|
|
25
|
+
reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let data = '';
|
|
30
|
+
response.on('data', chunk => data += chunk);
|
|
31
|
+
response.on('end', () => {
|
|
32
|
+
try {
|
|
33
|
+
const result = JSON.parse(data);
|
|
34
|
+
if (result.code === 'SUCCESS') {
|
|
35
|
+
resolve(result.data);
|
|
36
|
+
} else {
|
|
37
|
+
reject(new Error(result.message || 'Failed to get credentials'));
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
reject(new Error(`Failed to parse response: ${error.message}`));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}).on('error', reject)
|
|
44
|
+
.setTimeout(30000, function() {
|
|
45
|
+
this.destroy();
|
|
46
|
+
reject(new Error('Request timeout'));
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
9
52
|
* 创建 COS 客户端(使用临时凭证)
|
|
10
53
|
* @param {Object} cosConfig - COS 配置
|
|
11
54
|
* @param {Object} credentials - 已获取的临时凭证(可选,避免重复请求)
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
|
|
55
|
+
*/
|
|
56
|
+
async function createCOSClient(cosConfig, credentials = null) {
|
|
57
|
+
// 如果配置中提供了 SecretId 和 SecretKey,使用传统方式
|
|
58
|
+
if (cosConfig && cosConfig.SecretId && cosConfig.SecretKey) {
|
|
59
|
+
return new COS({
|
|
60
|
+
SecretId: cosConfig.SecretId,
|
|
61
|
+
SecretKey: cosConfig.SecretKey,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 使用已传入的凭证,或重新获取
|
|
66
|
+
if (!credentials) {
|
|
67
|
+
credentials = await fetchTemporaryCredentials();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return new COS({
|
|
71
|
+
getAuthorization: (options, callback) => {
|
|
72
|
+
callback({
|
|
73
|
+
TmpSecretId: credentials.credentials.tmpSecretId,
|
|
74
|
+
TmpSecretKey: credentials.credentials.tmpSecretKey,
|
|
75
|
+
SecurityToken: credentials.credentials.sessionToken,
|
|
76
|
+
StartTime: credentials.startTime,
|
|
77
|
+
ExpiredTime: credentials.expiredTime,
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
15
84
|
* 刷新 CDN 缓存
|
|
16
85
|
* 通过服务端 API 代理执行(STS 临时凭证无法携带 CDN 权限,需由服务端使用主账号凭证刷新)
|
|
17
86
|
*
|
|
@@ -19,9 +88,82 @@ if(!credentials){credentials=await fetchTemporaryCredentials()}return new COS({g
|
|
|
19
88
|
* @param {Array<string>} urls - 需要刷新的 URL 列表
|
|
20
89
|
* @param {Object} credentials - 未使用,保留参数兼容性
|
|
21
90
|
* @returns {Promise<void>}
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
91
|
+
*/
|
|
92
|
+
async function purgeCDNCache(cosConfig, urls, credentials = null) {
|
|
93
|
+
if (!urls || urls.length === 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const area = cosConfig?.CdnArea || 'overseas';
|
|
98
|
+
|
|
99
|
+
// 如果配置中有 SecretId/SecretKey,本地直接刷新
|
|
100
|
+
if (cosConfig && cosConfig.SecretId && cosConfig.SecretKey) {
|
|
101
|
+
try {
|
|
102
|
+
const tencentcloud = require('tencentcloud-sdk-nodejs-cdn');
|
|
103
|
+
const client = new tencentcloud.cdn.v20180606.Client({
|
|
104
|
+
credential: { secretId: cosConfig.SecretId, secretKey: cosConfig.SecretKey },
|
|
105
|
+
region: '',
|
|
106
|
+
profile: { httpProfile: { endpoint: 'cdn.tencentcloudapi.com' } },
|
|
107
|
+
});
|
|
108
|
+
const batchSize = 1000;
|
|
109
|
+
for (let i = 0; i < urls.length; i += batchSize) {
|
|
110
|
+
const batch = urls.slice(i, i + batchSize);
|
|
111
|
+
await client.PurgeUrlsCache({ Urls: batch, Area: area });
|
|
112
|
+
console.log(`✓ CDN 缓存已刷新 ${batch.length} 个 URL (区域: ${area})`);
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
116
|
+
console.warn('⚠️ 未安装 tencentcloud-sdk-nodejs-cdn,跳过 CDN 刷新');
|
|
117
|
+
} else {
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 否则通过服务端 API 代理刷新
|
|
125
|
+
const https = require('https');
|
|
126
|
+
const purgeUrl = 'https://wd-act.woa.com/aix/playable/api/cdn/purge';
|
|
127
|
+
|
|
128
|
+
const postData = JSON.stringify({ urls, area });
|
|
129
|
+
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
const req = https.request(purgeUrl, {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
headers: {
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
'Content-Length': Buffer.byteLength(postData),
|
|
136
|
+
},
|
|
137
|
+
}, (response) => {
|
|
138
|
+
let data = '';
|
|
139
|
+
response.on('data', chunk => data += chunk);
|
|
140
|
+
response.on('end', () => {
|
|
141
|
+
try {
|
|
142
|
+
const result = JSON.parse(data);
|
|
143
|
+
if (result.code === 'SUCCESS') {
|
|
144
|
+
console.log(`✓ CDN 缓存已刷新 ${urls.length} 个 URL (区域: ${area})`);
|
|
145
|
+
resolve();
|
|
146
|
+
} else {
|
|
147
|
+
reject(new Error(result.message || 'CDN purge failed'));
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
reject(new Error(`Failed to parse CDN purge response: ${error.message}`));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
req.on('error', reject);
|
|
156
|
+
req.setTimeout(30000, function() {
|
|
157
|
+
this.destroy();
|
|
158
|
+
reject(new Error('CDN purge request timeout'));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
req.write(postData);
|
|
162
|
+
req.end();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
25
167
|
* 上传单个文件到 COS
|
|
26
168
|
*
|
|
27
169
|
* @param {Object} cosConfig - COS 配置
|
|
@@ -29,12 +171,58 @@ const https=require("https");const purgeUrl="https://wd-act.woa.com/aix/playable
|
|
|
29
171
|
* @param {string} cosKey - COS 对象键(远程路径)
|
|
30
172
|
* @param {Object} credentials - 可选的凭证对象
|
|
31
173
|
* @returns {Promise<string>} - 上传成功返回访问链接
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
174
|
+
*/
|
|
175
|
+
async function uploadFileToCOS(cosConfig, filePath, cosKey, credentials = null) {
|
|
176
|
+
if (!fs.existsSync(filePath)) {
|
|
177
|
+
throw new Error(`文件不存在: ${filePath}`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 获取临时凭证和配置信息
|
|
181
|
+
let bucket, region, cdnDomain;
|
|
182
|
+
|
|
183
|
+
if (cosConfig && cosConfig.Bucket && cosConfig.Region) {
|
|
184
|
+
// 使用配置文件中的信息
|
|
185
|
+
bucket = cosConfig.Bucket;
|
|
186
|
+
region = cosConfig.Region;
|
|
187
|
+
cdnDomain = cosConfig.CdnDomain || 'static.aix.intlgame.com';
|
|
188
|
+
} else {
|
|
189
|
+
// 从临时凭证 API 获取配置(优先使用传入的凭证,否则重新获取)
|
|
190
|
+
if (!credentials) {
|
|
191
|
+
credentials = await fetchTemporaryCredentials();
|
|
192
|
+
}
|
|
193
|
+
bucket = credentials.bucket;
|
|
194
|
+
region = credentials.region;
|
|
195
|
+
cdnDomain = 'static.aix.intlgame.com';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const cos = await createCOSClient(cosConfig || null, credentials);
|
|
199
|
+
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
cos.putObject(
|
|
202
|
+
{
|
|
203
|
+
Bucket: bucket,
|
|
204
|
+
Region: region,
|
|
205
|
+
Key: cosKey,
|
|
206
|
+
Body: fs.createReadStream(filePath),
|
|
207
|
+
},
|
|
208
|
+
(err, data) => {
|
|
209
|
+
if (err) {
|
|
210
|
+
reject(new Error(`上传失败: ${err.message}`));
|
|
211
|
+
} else {
|
|
212
|
+
// 生成访问链接
|
|
213
|
+
// 对路径的每个部分分别进行 URL 编码
|
|
214
|
+
const pathParts = cosKey.split('/');
|
|
215
|
+
const encodedPath = pathParts.map(part => encodeURIComponent(part)).join('/');
|
|
216
|
+
|
|
217
|
+
const url = `https://${cdnDomain}/${encodedPath}`;
|
|
218
|
+
resolve(url);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
38
226
|
* 上传目录下的所有文件到 COS
|
|
39
227
|
*
|
|
40
228
|
* @param {Object} cosConfig - COS 配置
|
|
@@ -42,8 +230,64 @@ const pathParts=cosKey.split("/");const encodedPath=pathParts.map(part=>encodeUR
|
|
|
42
230
|
* @param {string} cosPrefix - COS 路径前缀
|
|
43
231
|
* @param {Object} credentials - 可选的凭证对象
|
|
44
232
|
* @returns {Promise<Array>} - 上传成功返回文件列表
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
233
|
+
*/
|
|
234
|
+
async function uploadDirectoryToCOS(cosConfig, localDir, cosPrefix, credentials = null) {
|
|
235
|
+
if (!fs.existsSync(localDir)) {
|
|
236
|
+
throw new Error(`目录不存在: ${localDir}`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 如果没有传入凭证且没有配置,获取一次凭证用于所有文件上传
|
|
240
|
+
if (!credentials && (!cosConfig || !cosConfig.Bucket || !cosConfig.Region)) {
|
|
241
|
+
try {
|
|
242
|
+
credentials = await fetchTemporaryCredentials();
|
|
243
|
+
console.log('✓ 获取临时凭证成功');
|
|
244
|
+
} catch (error) {
|
|
245
|
+
throw new Error(`获取临时凭证失败: ${error.message}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const files = fs.readdirSync(localDir);
|
|
250
|
+
const results = [];
|
|
251
|
+
const uploadedUrls = [];
|
|
252
|
+
|
|
253
|
+
for (const file of files) {
|
|
254
|
+
const filePath = path.join(localDir, file);
|
|
255
|
+
const stat = fs.statSync(filePath);
|
|
256
|
+
|
|
257
|
+
if (stat.isFile()) {
|
|
258
|
+
// 去掉文件名中的 -preview 或 _preview 后缀
|
|
259
|
+
let cleanFileName = file;
|
|
260
|
+
cleanFileName = cleanFileName.replace(/-preview\./i, '.');
|
|
261
|
+
cleanFileName = cleanFileName.replace(/_preview\./i, '.');
|
|
262
|
+
|
|
263
|
+
const cosKey = cosPrefix ? `${cosPrefix}/${cleanFileName}` : cleanFileName;
|
|
264
|
+
// 传入凭证,避免重复获取
|
|
265
|
+
const url = await uploadFileToCOS(cosConfig, filePath, cosKey, credentials);
|
|
266
|
+
results.push({
|
|
267
|
+
file: cleanFileName,
|
|
268
|
+
url,
|
|
269
|
+
});
|
|
270
|
+
uploadedUrls.push(url);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 上传完成后刷新 CDN 缓存,传入凭证
|
|
275
|
+
if (uploadedUrls.length > 0) {
|
|
276
|
+
try {
|
|
277
|
+
await purgeCDNCache(cosConfig, uploadedUrls, credentials);
|
|
278
|
+
console.log(`✓ CDN 缓存刷新成功 (${uploadedUrls.length} 个文件)`);
|
|
279
|
+
} catch (error) {
|
|
280
|
+
console.warn(`⚠️ CDN 刷新失败: ${error.message}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return results;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
module.exports = {
|
|
288
|
+
fetchTemporaryCredentials,
|
|
289
|
+
createCOSClient,
|
|
290
|
+
uploadFileToCOS,
|
|
291
|
+
uploadDirectoryToCOS,
|
|
292
|
+
purgeCDNCache,
|
|
293
|
+
};
|
package/core/index.js
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
const{
|
|
3
|
-
const{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const { allowedExtensions, webpackCommonConfig } = require('./webpack.common.js');
|
|
2
|
+
const { parseArgvOptions } = require('./utils/parseArgvOptions.js');
|
|
3
|
+
const { mergeOptions } = require('./utils/mergeOptions.js');
|
|
4
|
+
const { options } = require('./options.js');
|
|
5
|
+
const { DAPIInjectorPlugin } = require('./plugins/DAPIInjectorPlugin.js');
|
|
6
|
+
const { DebuggerInjectionPlugin } = require('./plugins/DebuggerInjectionPlugin.js');
|
|
7
|
+
const { ExitAPIInjectorPlugin } = require('./plugins/ExitAPIInjectorPlugin.js');
|
|
8
|
+
const { runBuild, makeWebpackBuildConfig } = require('./webpack.build.js');
|
|
9
|
+
const { runDev, makeWebpackDevConfig } = require('./webpack.dev.js');
|
|
10
|
+
const { runViteDev, makeViteDevConfig } = require('./vite.dev.js');
|
|
11
|
+
|
|
12
|
+
// 字体注入
|
|
13
|
+
const { FontInjectionWebpackPlugin } = require('./plugins/FontInjectionWebpackPlugin.js');
|
|
14
|
+
const { FONT_REGISTRY, getRegisteredFontKeys, isBuiltin: isBuiltinFont, getFontEntry } = require('./utils/fontRegistry.js');
|
|
15
|
+
const { getOrGenerateFontCSS } = require('./utils/fontResolver.js');
|
|
16
|
+
|
|
17
|
+
// 验证器
|
|
18
|
+
const {
|
|
19
|
+
runPreBuildChecks,
|
|
20
|
+
runTrackingCheck,
|
|
21
|
+
registerChecker,
|
|
22
|
+
toggleChecker,
|
|
23
|
+
listCheckers
|
|
24
|
+
} = require('./validators/pre-build-checker.js');
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
validateTracking,
|
|
28
|
+
printValidationResult,
|
|
29
|
+
TRACKING_METHODS,
|
|
30
|
+
SDK_TO_TRACKING_MAP
|
|
31
|
+
} = require('./validators/tracking-validator.js');
|
|
32
|
+
|
|
33
|
+
exports.mergeOptions = mergeOptions;
|
|
34
|
+
exports.parseArgvOptions = parseArgvOptions;
|
|
35
|
+
|
|
36
|
+
exports.options = options;
|
|
37
|
+
|
|
38
|
+
exports.allowedExtensions = allowedExtensions;
|
|
39
|
+
exports.webpackCommonConfig = webpackCommonConfig;
|
|
40
|
+
exports.makeWebpackDevConfig = makeWebpackDevConfig;
|
|
41
|
+
exports.makeWebpackBuildConfig = makeWebpackBuildConfig;
|
|
42
|
+
exports.runDev = runDev;
|
|
43
|
+
exports.runBuild = runBuild;
|
|
44
|
+
|
|
45
|
+
exports.DAPIInjectorPlugin = DAPIInjectorPlugin;
|
|
46
|
+
exports.ExitAPIInjectorPlugin = ExitAPIInjectorPlugin;
|
|
47
|
+
exports.DebuggerInjectionPlugin = DebuggerInjectionPlugin;
|
|
48
|
+
|
|
49
|
+
exports.makeViteDevConfig = makeViteDevConfig;
|
|
50
|
+
exports.runViteDev = runViteDev;
|
|
51
|
+
|
|
52
|
+
// 编译前检查器导出
|
|
53
|
+
exports.runPreBuildChecks = runPreBuildChecks;
|
|
54
|
+
exports.runTrackingCheck = runTrackingCheck;
|
|
55
|
+
exports.registerChecker = registerChecker;
|
|
56
|
+
exports.toggleChecker = toggleChecker;
|
|
57
|
+
exports.listCheckers = listCheckers;
|
|
58
|
+
|
|
59
|
+
// 埋点验证器导出
|
|
60
|
+
exports.validateTracking = validateTracking;
|
|
61
|
+
exports.printValidationResult = printValidationResult;
|
|
62
|
+
exports.TRACKING_METHODS = TRACKING_METHODS;
|
|
63
|
+
exports.SDK_TO_TRACKING_MAP = SDK_TO_TRACKING_MAP;
|
|
64
|
+
|
|
65
|
+
// 字体注入导出
|
|
66
|
+
exports.FontInjectionWebpackPlugin = FontInjectionWebpackPlugin;
|
|
67
|
+
exports.FONT_REGISTRY = FONT_REGISTRY;
|
|
68
|
+
exports.getRegisteredFontKeys = getRegisteredFontKeys;
|
|
69
|
+
exports.isBuiltinFont = isBuiltinFont;
|
|
70
|
+
exports.getFontEntry = getFontEntry;
|
|
71
|
+
exports.getOrGenerateFontCSS = getOrGenerateFontCSS;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const loaderUtils = require('loader-utils');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
const isObject = (value) => typeof value === 'object' && value !== null;
|
|
6
|
+
const isDataURI = (value) => /^data:/i.test(value);
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* A utility function that allows mapping the value for a given key in an object
|
|
3
10
|
* [in place](https://en.wikipedia.org/wiki/In-place_algorithm).
|
|
4
11
|
*
|
|
@@ -13,33 +20,72 @@
|
|
|
13
20
|
* @param {(value: unknown) => Promise<any>} callback
|
|
14
21
|
* The callback that either returns the mapped value, or returns a Promise
|
|
15
22
|
* that resolves to the new value.
|
|
16
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
async function mapDeep(obj, key, callback) {
|
|
25
|
+
if (Array.isArray(obj)) {
|
|
26
|
+
for (const item of obj) {
|
|
27
|
+
await mapDeep(item, key, callback);
|
|
28
|
+
}
|
|
29
|
+
} else if (isObject(obj)) {
|
|
30
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
31
|
+
if (k === key) {
|
|
32
|
+
obj[k] = await callback(v);
|
|
33
|
+
} else {
|
|
34
|
+
await mapDeep(v, key, callback);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
17
41
|
* @typedef {import(".").GLTFLoaderDefinition} GLTFLoader
|
|
18
42
|
* @this {ThisParameterType<GLTFLoader>}
|
|
19
43
|
* @type {GLTFLoader}
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
*/
|
|
45
|
+
async function gltfLoader(content) {
|
|
46
|
+
// Destructure loader options and set default values:
|
|
47
|
+
const {
|
|
48
|
+
// inline = true,
|
|
49
|
+
// useRelativePaths = true,
|
|
50
|
+
// uriResolver = (module) => String(module.default ?? module),
|
|
51
|
+
// fileName = '[name].[hash:8].[ext]',
|
|
52
|
+
// filePath = '/static/media',
|
|
53
|
+
// publicPath = this._compilation?.outputOptions.publicPath ?? '/',
|
|
54
|
+
context = this.context
|
|
55
|
+
} = this.getOptions();
|
|
56
|
+
|
|
57
|
+
// Parse the glTF data:
|
|
58
|
+
|
|
59
|
+
// console.log(content);
|
|
60
|
+
const data = JSON.parse(content);
|
|
61
|
+
// console.log(data);
|
|
62
|
+
// Iterate over the object and map any URIs:
|
|
63
|
+
await mapDeep(data, 'uri', async (uri) => {
|
|
64
|
+
// Resolve early if the URI cannot be imported as a module:
|
|
65
|
+
if (!loaderUtils.isUrlRequest(uri)) return uri;
|
|
66
|
+
// If the URI is a data URI, print a warning and resolve with the original value:
|
|
67
|
+
if (isDataURI(uri)) {
|
|
68
|
+
return uri;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const requestPath = path.join(context, uri);
|
|
72
|
+
// console.log(requestPath);
|
|
73
|
+
const binContent = fs.readFileSync(requestPath, { encoding: 'base64' });
|
|
74
|
+
return `data:application/octet-stream;base64,${binContent}`;
|
|
75
|
+
});
|
|
76
|
+
// Stringify the updated data:
|
|
77
|
+
const updatedContent = JSON.stringify(data);
|
|
78
|
+
// Interpolate any file name tokens:
|
|
79
|
+
// const interpolatedName = loaderUtils.interpolateName(this, fileName, { content: updatedContent });
|
|
80
|
+
// Join the file path and interpolated name:
|
|
81
|
+
// const interpolatedPath = path.join(filePath, interpolatedName);
|
|
82
|
+
// Emit the file:
|
|
83
|
+
// this.emitFile(interpolatedPath, updatedContent, null);
|
|
84
|
+
// Join all paths together:
|
|
85
|
+
// const fullPath = path.join(publicPath, interpolatedPath);
|
|
86
|
+
// Lastly, resolve with either the JSON data or the full output path:
|
|
87
|
+
// return `export default ${inline ? updatedContent : `"${fullPath}"`}`;
|
|
88
|
+
return `export default ${updatedContent}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = gltfLoader;
|