@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/cli/commands/pack.js
CHANGED
|
@@ -1,33 +1,145 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const yazl = require('yazl');
|
|
6
|
+
|
|
7
|
+
// ==================== 配置 ====================
|
|
8
|
+
|
|
9
|
+
const projectRoot = process.cwd();
|
|
10
|
+
|
|
11
|
+
/**
|
|
3
12
|
* 解析 appName,依次从 builds.config.js、build.json 或 CLI 参数中获取。
|
|
4
13
|
* 优先级: CLI --app-name > builds.config.js > build.json > 文件夹名称
|
|
5
14
|
* @returns {string}
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
15
|
+
*/
|
|
16
|
+
function resolveAppName() {
|
|
17
|
+
// 1. CLI 参数: --app-name=xxx
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
for (const arg of args) {
|
|
20
|
+
if (arg.startsWith('--app-name=')) {
|
|
21
|
+
return arg.split('=')[1].trim();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 2. builds.config.js → appName 或 title
|
|
26
|
+
const buildsConfigPath = path.join(projectRoot, 'builds.config.js');
|
|
27
|
+
if (fs.existsSync(buildsConfigPath)) {
|
|
28
|
+
try {
|
|
29
|
+
delete require.cache[buildsConfigPath];
|
|
30
|
+
const config = require(buildsConfigPath);
|
|
31
|
+
if (config.appName) return config.appName;
|
|
32
|
+
if (config.title) return config.title;
|
|
33
|
+
} catch (e) {
|
|
34
|
+
// 忽略错误
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 3. build.json → app
|
|
39
|
+
const buildJsonPath = path.join(projectRoot, 'build.json');
|
|
40
|
+
if (fs.existsSync(buildJsonPath)) {
|
|
41
|
+
try {
|
|
42
|
+
const data = JSON.parse(fs.readFileSync(buildJsonPath, 'utf8'));
|
|
43
|
+
if (data.app) return data.app;
|
|
44
|
+
} catch (e) {
|
|
45
|
+
// 忽略错误
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 4. 兜底: 使用项目文件夹名称
|
|
50
|
+
return path.basename(projectRoot);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
13
54
|
* 从 CLI 参数中解析输出目录。
|
|
14
55
|
* @returns {string}
|
|
15
|
-
*/
|
|
56
|
+
*/
|
|
57
|
+
function resolveOutputDir() {
|
|
58
|
+
const args = process.argv.slice(2);
|
|
59
|
+
for (const arg of args) {
|
|
60
|
+
if (arg.startsWith('--out-dir=')) {
|
|
61
|
+
return arg.split('=')[1].trim();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return 'dist';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ==================== 忽略规则解析 ====================
|
|
68
|
+
|
|
16
69
|
/**
|
|
17
70
|
* 解析单个忽略文件,返回规范化后的模式数组。
|
|
18
71
|
* @param {string} filePath - 忽略文件的绝对路径
|
|
19
72
|
* @returns {string[]} 规范化后的忽略模式数组
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
if(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
73
|
+
*/
|
|
74
|
+
function parseSingleIgnoreFile(filePath) {
|
|
75
|
+
if (!fs.existsSync(filePath)) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
80
|
+
const patterns = [];
|
|
81
|
+
|
|
82
|
+
for (const rawLine of content.split(/\r?\n/)) {
|
|
83
|
+
const line = rawLine.trim();
|
|
84
|
+
|
|
85
|
+
// 跳过空行和注释
|
|
86
|
+
if (!line || line.startsWith('#')) continue;
|
|
87
|
+
|
|
88
|
+
// 不支持取反模式,给出警告并跳过
|
|
89
|
+
if (line.startsWith('!')) {
|
|
90
|
+
console.log(`\x1b[33m⚠️ 不支持取反模式,已跳过: ${line}\x1b[0m`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 规范化:
|
|
95
|
+
// - 移除尾部斜杠(用于目录匹配)
|
|
96
|
+
// - 移除前导 ./(gitignore 中 ./foo 等同于 foo)
|
|
97
|
+
let normalized = line.replace(/\/+$/, '');
|
|
98
|
+
normalized = normalized.replace(/^\.\//g, '');
|
|
99
|
+
patterns.push(normalized);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return patterns;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
26
106
|
* 解析 .gitignore 和 .playcraftignore 文件,合并并去重。
|
|
27
107
|
* .gitignore 提供基础忽略规则,.playcraftignore 提供额外补充规则。
|
|
28
108
|
* @returns {{ patterns: string[], sources: { gitignore: number, playcraftignore: number } }}
|
|
29
|
-
*/
|
|
30
|
-
|
|
109
|
+
*/
|
|
110
|
+
function parseIgnoreFiles() {
|
|
111
|
+
const gitignorePath = path.join(projectRoot, '.gitignore');
|
|
112
|
+
const playcraftignorePath = path.join(projectRoot, '.playcraftignore');
|
|
113
|
+
|
|
114
|
+
const gitignorePatterns = parseSingleIgnoreFile(gitignorePath);
|
|
115
|
+
const playcraftPatterns = parseSingleIgnoreFile(playcraftignorePath);
|
|
116
|
+
|
|
117
|
+
if (gitignorePatterns.length === 0 && playcraftPatterns.length === 0) {
|
|
118
|
+
console.log('\x1b[33m⚠️ 未找到 .gitignore 或 .playcraftignore 文件,将打包所有文件。\x1b[0m');
|
|
119
|
+
return { patterns: [], sources: { gitignore: 0, playcraftignore: 0 } };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 合并并去重(保持顺序,.gitignore 优先)
|
|
123
|
+
const seen = new Set();
|
|
124
|
+
const merged = [];
|
|
125
|
+
|
|
126
|
+
for (const p of [...gitignorePatterns, ...playcraftPatterns]) {
|
|
127
|
+
if (!seen.has(p)) {
|
|
128
|
+
seen.add(p);
|
|
129
|
+
merged.push(p);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
patterns: merged,
|
|
135
|
+
sources: {
|
|
136
|
+
gitignore: gitignorePatterns.length,
|
|
137
|
+
playcraftignore: playcraftPatterns.length,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
31
143
|
* 将 gitignore 风格的模式转换为正则表达式。
|
|
32
144
|
*
|
|
33
145
|
* gitignore 语义:
|
|
@@ -38,44 +150,201 @@ const seen=new Set;const merged=[];for(const p of[...gitignorePatterns,...playcr
|
|
|
38
150
|
*
|
|
39
151
|
* @param {string} pattern
|
|
40
152
|
* @returns {RegExp}
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
153
|
+
*/
|
|
154
|
+
function patternToRegex(pattern) {
|
|
155
|
+
let p = pattern;
|
|
156
|
+
let anchored = false;
|
|
157
|
+
|
|
158
|
+
// 前导 / 表示锚定到根目录;构建正则前剥离
|
|
159
|
+
if (p.startsWith('/')) {
|
|
160
|
+
p = p.slice(1);
|
|
161
|
+
anchored = true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 如果模式中包含 /,同样视为锚定到根目录
|
|
165
|
+
if (p.includes('/')) {
|
|
166
|
+
anchored = true;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 转义正则特殊字符(* 和 ? 除外)
|
|
170
|
+
let regexStr = p.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
171
|
+
|
|
172
|
+
// 处理 **(匹配任意路径层级,包括嵌套目录)
|
|
173
|
+
regexStr = regexStr.replace(/\*\*/g, '{{GLOBSTAR}}');
|
|
174
|
+
// 处理 *(匹配除路径分隔符外的任意字符)
|
|
175
|
+
regexStr = regexStr.replace(/\*/g, '[^/]*');
|
|
176
|
+
// 处理 ?(匹配除路径分隔符外的单个字符)
|
|
177
|
+
regexStr = regexStr.replace(/\?/g, '[^/]');
|
|
178
|
+
// 还原 globstar 占位符
|
|
179
|
+
regexStr = regexStr.replace(/\{\{GLOBSTAR\}\}/g, '.*');
|
|
180
|
+
|
|
181
|
+
if (anchored) {
|
|
182
|
+
// 锚定模式:从相对路径的起始位置匹配
|
|
183
|
+
return new RegExp(`^${regexStr}(/|$)`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 非锚定模式:在目录树中任意位置匹配路径段
|
|
187
|
+
return new RegExp(`(^|/)${regexStr}(/|$)`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
51
191
|
* 检查相对路径是否应被忽略。
|
|
52
192
|
* @param {string} relativePath - 使用正斜杠规范化后的相对路径
|
|
53
193
|
* @param {RegExp[]} regexPatterns
|
|
54
194
|
* @returns {boolean}
|
|
55
|
-
*/
|
|
195
|
+
*/
|
|
196
|
+
function shouldIgnore(relativePath, regexPatterns) {
|
|
197
|
+
for (const regex of regexPatterns) {
|
|
198
|
+
if (regex.test(relativePath)) return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ==================== 文件收集 ====================
|
|
204
|
+
|
|
56
205
|
/**
|
|
57
206
|
* 递归收集目录下的所有文件,遵循忽略规则。
|
|
58
207
|
* @param {string} dir - 目录的绝对路径
|
|
59
208
|
* @param {string} baseDir - 项目根目录,用于计算相对路径
|
|
60
209
|
* @param {RegExp[]} ignoreRegexes
|
|
61
210
|
* @returns {string[]} 文件绝对路径数组
|
|
62
|
-
*/
|
|
63
|
-
|
|
211
|
+
*/
|
|
212
|
+
function collectFiles(dir, baseDir, ignoreRegexes) {
|
|
213
|
+
const results = [];
|
|
214
|
+
let entries;
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
218
|
+
} catch (e) {
|
|
219
|
+
console.warn(`\x1b[33m⚠️ 无法读取目录: ${dir}\x1b[0m`);
|
|
220
|
+
return results;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
for (const entry of entries) {
|
|
224
|
+
const fullPath = path.join(dir, entry.name);
|
|
225
|
+
// 使用正斜杠以保持匹配一致性
|
|
226
|
+
const relativePath = path.relative(baseDir, fullPath).replace(/\\/g, '/');
|
|
227
|
+
|
|
228
|
+
if (shouldIgnore(relativePath, ignoreRegexes)) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (entry.isDirectory()) {
|
|
233
|
+
results.push(...collectFiles(fullPath, baseDir, ignoreRegexes));
|
|
234
|
+
} else if (entry.isFile() || entry.isSymbolicLink()) {
|
|
235
|
+
results.push(fullPath);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return results;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ==================== Zip 创建 ====================
|
|
243
|
+
|
|
64
244
|
/**
|
|
65
245
|
* 根据收集到的文件创建 zip 压缩包。
|
|
66
246
|
* @param {string[]} files - 文件绝对路径数组
|
|
67
247
|
* @param {string} rootFolderName - zip 内的根文件夹名称
|
|
68
248
|
* @param {string} outputPath - 输出 zip 文件的绝对路径
|
|
69
249
|
* @returns {Promise<{fileCount: number, zipSize: number}>}
|
|
70
|
-
*/
|
|
71
|
-
|
|
250
|
+
*/
|
|
251
|
+
function createZip(files, rootFolderName, outputPath) {
|
|
252
|
+
return new Promise((resolve, reject) => {
|
|
253
|
+
const zipFile = new yazl.ZipFile();
|
|
254
|
+
let fileCount = 0;
|
|
255
|
+
|
|
256
|
+
for (const filePath of files) {
|
|
257
|
+
const relativePath = path.relative(projectRoot, filePath).replace(/\\/g, '/');
|
|
258
|
+
const zipEntryPath = `${rootFolderName}/${relativePath}`;
|
|
259
|
+
|
|
260
|
+
zipFile.addFile(filePath, zipEntryPath);
|
|
261
|
+
fileCount++;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
zipFile.end();
|
|
265
|
+
|
|
266
|
+
// 确保输出目录存在
|
|
267
|
+
const outputDir = path.dirname(outputPath);
|
|
268
|
+
if (!fs.existsSync(outputDir)) {
|
|
269
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const writeStream = fs.createWriteStream(outputPath);
|
|
273
|
+
|
|
274
|
+
writeStream.on('error', (err) => {
|
|
275
|
+
reject(err);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
writeStream.on('close', () => {
|
|
279
|
+
const stats = fs.statSync(outputPath);
|
|
280
|
+
resolve({ fileCount, zipSize: stats.size });
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
zipFile.outputStream.pipe(writeStream);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ==================== 格式化工具 ====================
|
|
288
|
+
|
|
72
289
|
/**
|
|
73
290
|
* 将字节数格式化为可读字符串。
|
|
74
291
|
* @param {number} bytes
|
|
75
292
|
* @returns {string}
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
293
|
+
*/
|
|
294
|
+
function formatSize(bytes) {
|
|
295
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
296
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
297
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// ==================== 主流程 ====================
|
|
301
|
+
|
|
302
|
+
async function main() {
|
|
303
|
+
console.log('\x1b[36m📦 playable-scripts 打包\x1b[0m\n');
|
|
304
|
+
|
|
305
|
+
// 1. 解析 appName
|
|
306
|
+
const appName = resolveAppName();
|
|
307
|
+
console.log(` 应用名称: \x1b[1m${appName}\x1b[0m`);
|
|
308
|
+
|
|
309
|
+
// 2. 解析忽略规则(合并 .gitignore + .playcraftignore)
|
|
310
|
+
const { patterns, sources } = parseIgnoreFiles();
|
|
311
|
+
const ignoreRegexes = patterns.map(patternToRegex);
|
|
312
|
+
|
|
313
|
+
if (patterns.length > 0) {
|
|
314
|
+
const parts = [];
|
|
315
|
+
if (sources.gitignore > 0) parts.push(`${sources.gitignore} 条来自 .gitignore`);
|
|
316
|
+
if (sources.playcraftignore > 0) parts.push(`${sources.playcraftignore} 条来自 .playcraftignore`);
|
|
317
|
+
console.log(` 忽略规则: \x1b[33m${patterns.length}\x1b[0m 条模式 (${parts.join(', ')})`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// 3. 收集文件
|
|
321
|
+
console.log(` 正在扫描项目文件...`);
|
|
322
|
+
const files = collectFiles(projectRoot, projectRoot, ignoreRegexes);
|
|
323
|
+
|
|
324
|
+
if (files.length === 0) {
|
|
325
|
+
console.error('\x1b[31m❌ 没有可打包的文件!请检查 .playcraftignore 规则。\x1b[0m');
|
|
326
|
+
process.exit(1);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
console.log(` 文件数量: \x1b[32m${files.length}\x1b[0m 个待打包文件`);
|
|
330
|
+
|
|
331
|
+
// 4. 创建 zip 压缩包
|
|
332
|
+
const outDir = resolveOutputDir();
|
|
333
|
+
const outputPath = path.resolve(projectRoot, outDir, `${appName}.zip`);
|
|
334
|
+
|
|
335
|
+
console.log(` 输出路径: ${outputPath}\n`);
|
|
336
|
+
console.log(' 正在打包...');
|
|
337
|
+
|
|
338
|
+
try {
|
|
339
|
+
const { fileCount, zipSize } = await createZip(files, appName, outputPath);
|
|
340
|
+
console.log(`\n\x1b[32m✅ 打包完成!\x1b[0m`);
|
|
341
|
+
console.log(` 文件数: ${fileCount}`);
|
|
342
|
+
console.log(` 大小: ${formatSize(zipSize)}`);
|
|
343
|
+
console.log(` 输出: ${outputPath}`);
|
|
344
|
+
} catch (err) {
|
|
345
|
+
console.error(`\n\x1b[31m❌ 打包失败: ${err.message}\x1b[0m`);
|
|
346
|
+
process.exit(1);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
main();
|
package/cli/commands/vite-dev.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
process.env.BABEL_ENV = 'development';
|
|
4
|
+
process.env.NODE_ENV = 'development';
|
|
5
|
+
|
|
6
|
+
const { runViteDev } = require('../../core/vite.dev.js');
|
|
7
|
+
runViteDev();
|