@playcraft/devkit 1.0.11 → 1.0.13

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.
Files changed (39) hide show
  1. package/LICENSE +21 -21
  2. package/cli/bin/playable-scripts.js +0 -0
  3. package/cli/commands/build.js +5 -5
  4. package/cli/commands/builds.js +14 -14
  5. package/cli/commands/pack.js +47 -47
  6. package/core/batch-build.js +81 -77
  7. package/core/cos-uploader.js +37 -34
  8. package/core/index.d.ts +185 -185
  9. package/core/loaders/gltf-loader.js +19 -19
  10. package/core/plugins/AdikteevInjectorPlugin.js +11 -11
  11. package/core/plugins/BigoAdsInjectorPlugin.js +4 -4
  12. package/core/plugins/DAPIInjectorPlugin.js +4 -4
  13. package/core/plugins/DebuggerInjectionPlugin.js +5 -5
  14. package/core/plugins/ExitAPIInjectorPlugin.js +9 -9
  15. package/core/plugins/FflateCompressionPlugin.js +43 -43
  16. package/core/plugins/LiftoffInjectorPlugin.js +11 -11
  17. package/core/plugins/MRAIDInjectorPlugin.js +3 -3
  18. package/core/plugins/MintegralInjectorPlugin.js +4 -4
  19. package/core/plugins/PangleInjectorPlugin.js +3 -3
  20. package/core/plugins/SnapchatInjectorPlugin.js +4 -4
  21. package/core/plugins/TikTokInjectorPlugin.js +3 -3
  22. package/core/plugins/UnityInjectorPlugin.js +13 -13
  23. package/core/resources/snapchat-config.json +1 -1
  24. package/core/resources/tiktok-config.json +1 -1
  25. package/core/utils/buildDefines.js +2 -2
  26. package/core/utils/buildTemplateString.js +2 -2
  27. package/core/utils/generateAdikteevHtmlWebpackPluginConfig.js +26 -26
  28. package/core/utils/generateInMobiHtmlWebpackPluginConfig.js +16 -16
  29. package/core/utils/injectSDKPlugins.js +10 -10
  30. package/core/utils/logOptions.js +2 -2
  31. package/core/utils/mergeOptions.js +5 -5
  32. package/core/utils/parseArgvOptions.js +4 -4
  33. package/core/utils/resolveChannelFold2Zip.js +12 -12
  34. package/core/utils/validateThemeData.js +91 -72
  35. package/core/vite.dev.js +12 -12
  36. package/core/webpack.build.js +12 -12
  37. package/core/webpack.dev.js +12 -12
  38. package/defines.d.ts +54 -54
  39. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
1
  "use strict";const{merge}=require("webpack-merge");const{webpackCommonConfig}=require("./webpack.common.js");const webpack=require("webpack");const TerserPlugin=require("terser-webpack-plugin");const CopyWebpackPlugin=require("copy-webpack-plugin");const HtmlInlineScriptPlugin=require("html-inline-script-webpack-plugin");const HtmlWebpackPlugin=require("html-webpack-plugin");const MiniCssExtractPlugin=require("mini-css-extract-plugin");const{ZipPlugin}=require("./plugins/ZipPlugin.js");const{FflateCompressionPlugin}=require("./plugins/FflateCompressionPlugin.js");const{generateAdikteevHtmlWebpackPluginConfig}=require("./utils/generateAdikteevHtmlWebpackPluginConfig.js");const{generateBigabidHtmlWebpackPluginConfig}=require("./utils/generateBigabidHtmlWebpackPluginConfig.js");const{generateInMobiHtmlWebpackPluginConfig}=require("./utils/generateInMobiHtmlWebpackPluginConfig.js");const path=require("path");const{mergeOptions}=require("./utils/mergeOptions.js");const{options}=require("./options.js");const{buildDefines}=require("./utils/buildDefines.js");const{buildTemplateString}=require("./utils/buildTemplateString.js");const{logOptions}=require("./utils/logOptions.js");const{injectSDKPlugins}=require("./utils/injectSDKPlugins.js");const{resolveChannelFold2Zip}=require("./utils/resolveChannelFold2Zip.js");/** @type {AD_NETWORK[]} *//** @type {AD_NETWORK[]} */const zipOutputNetworks=["google","pangle","tiktok","vungle","mytarget","mintegral","adikteev","bigabid","inmobi",// InMobi 支持 ZIP 格式(包含 index.html + 资源文件)
2
- "snapchat","bigoads","liftoff"];/** @type {AD_NETWORK[]} */const zipOutputAllowedNetworks=["facebook","moloco"];/**
3
- * Creates webpack configuration for production build
4
- * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
5
- * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
6
- * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
7
- * @returns {import('webpack').Configuration} Final webpack production configuration
2
+ "snapchat","bigoads","liftoff"];/** @type {AD_NETWORK[]} */const zipOutputAllowedNetworks=["facebook","moloco"];/**
3
+ * Creates webpack configuration for production build
4
+ * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
5
+ * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
6
+ * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
7
+ * @returns {import('webpack').Configuration} Final webpack production configuration
8
8
  */function makeWebpackBuildConfig(customOptions,customDefines,webpackCustomConfig){const buildOptions=mergeOptions(options,customOptions);logOptions(buildOptions);customDefines=customDefines||{};webpackCustomConfig=webpackCustomConfig||{};/** @type {AD_NETWORK} */const adNetwork=buildOptions["network"];/** @type {AD_PROTOCOL} */const adProtocol=buildOptions["protocol"];let outDir=buildTemplateString(buildOptions.outDir,buildOptions);function getFileName(){let filename=buildTemplateString(buildOptions.filename,buildOptions);if(adNetwork==="mintegral")return filename.replace(/\s+/g,"").replace(/[^a-zA-Z0-9]/g,"_").replace("_fullhash_6_","[fullhash:6]");return filename}const isZipOutput=zipOutputNetworks.includes(adNetwork)||buildOptions.zip&&zipOutputAllowedNetworks.includes(adNetwork);const{isChannelFold2Zip,isZipOutputFinal}=resolveChannelFold2Zip({isChannelFold2ZipOption:buildOptions.isChannelFold2Zip,adNetwork,isZipOutput});let htmlFileName="";if(adNetwork==="mintegral")htmlFileName="index.html";// 修改为 index.html
9
9
  else if(isZipOutputFinal)htmlFileName="index.html";else htmlFileName=`${getFileName()}.html`;const metaTags={viewport:"width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,user-scalable=no"};if(adNetwork==="mintegral"){metaTags["viewport"]="width=device-width,user-scalable=no,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0"}if(!buildOptions.skipRecommendedMeta){metaTags["HandheldFriendly"]="True";metaTags["cleartype"]={"http-equiv":"cleartype",content:"on"};metaTags["apple-mobile-web-app-capable"]="yes";metaTags["mobile-web-app-capable"]="yes";metaTags["X-UA-Compatible"]={"http-equiv":"X-UA-Compatible",content:"IE=10"}}let htmlWebpackPluginConfig={template:path.resolve("src/index.html"),filename:htmlFileName,title:`${buildOptions.name} - ${buildOptions.app}`,inlineSource:".(js|css|png|jpg|webp|svg|xml|atlas|mp3|gif|glb|fbx|obj)$",meta:metaTags};if(adNetwork==="adikteev")htmlWebpackPluginConfig=generateAdikteevHtmlWebpackPluginConfig("src/index.html");else if(adNetwork==="bigabid")htmlWebpackPluginConfig=generateBigabidHtmlWebpackPluginConfig("src/index.html");else if(adNetwork==="inmobi")htmlWebpackPluginConfig=generateInMobiHtmlWebpackPluginConfig("src/index.html",buildOptions);const webpackConfig=merge(webpackCommonConfig,{mode:"production",stats:"errors-only",optimization:{usedExports:true,minimize:(buildOptions.obfuscateLevel!==undefined?buildOptions.obfuscateLevel:2)>=1,minimizer:[new TerserPlugin({extractComments:false,terserOptions:{safari10:true,mangle:{reserved:["$"],// ⚠️ 不要开启 properties: true,会混淆 Phaser 等框架的属性名导致运行时错误
10
10
  // properties: true,
@@ -51,12 +51,12 @@ injectSDKPlugins(webpackConfig,{network:adNetwork,protocol:adProtocol,orientatio
51
51
  webpackConfig.plugins.push(new CopyWebpackPlugin({patterns:[{from:path.join(__dirname,"resources","bigoads-config.json"),to:"config.json"}]}))}webpackConfig.plugins.push(new ZipPlugin({filename:isChannelFold2Zip?adNetwork:getFileName(),path:path.resolve(outDir),cleanTempFolder:true// 🗑️ 生成 zip 后删除临时文件夹
52
52
  }));webpackConfig.output.path=path.resolve(outDir,adNetwork);if(adNetwork==="adikteev"){webpackConfig.output.filename="creative.js";// Adikteev 需要将 CSS 单独提取为 style.css 文件
53
53
  webpackConfig.plugins.push(new MiniCssExtractPlugin({filename:"style.css"}))}else if(adNetwork==="bigabid")webpackConfig.output.filename="main.js";else if(adNetwork==="inmobi")webpackConfig.output.filename="main.js"}// 添加 fflate 压缩插件(仅在打正式包时生效)
54
- if(buildOptions.fflateCompression){console.log("\u2705 fflate compression enabled (production build only)");webpackConfig.plugins.push(new FflateCompressionPlugin({enabled:true,level:9,keepOriginal:false,logStats:true,googlePlayUrl:buildOptions.googlePlayUrl,appStoreUrl:buildOptions.appStoreUrl}))}return webpackConfig}/**
55
- * Runs webpack production build
56
- * @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
57
- * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
58
- * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
59
- * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
54
+ if(buildOptions.fflateCompression){console.log("\u2705 fflate compression enabled (production build only)");webpackConfig.plugins.push(new FflateCompressionPlugin({enabled:true,level:9,keepOriginal:false,logStats:true,googlePlayUrl:buildOptions.googlePlayUrl,appStoreUrl:buildOptions.appStoreUrl}))}return webpackConfig}/**
55
+ * Runs webpack production build
56
+ * @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
57
+ * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
58
+ * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
59
+ * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
60
60
  */function runBuild(webpackConfig,customOptions,customDefines,webpackCustomConfig){return new Promise((resolve,reject)=>{if(!webpackConfig)webpackConfig=makeWebpackBuildConfig(customOptions,customDefines,webpackCustomConfig);const compiler=webpack(webpackConfig);compiler.run((err,stats)=>{if(err){console.error("Build failed:",err.stack||err);if(err.details){console.error("Error details:",err.details)}return reject(err)}if(stats.hasErrors()){const errors=stats.compilation.errors;console.error(`\n❌ Build finished with ${errors.length} error(s):\n`);// 打印每个错误的详细信息
61
61
  errors.forEach((error,index)=>{console.error(`\n[Error ${index+1}/${errors.length}]`);console.error(error.message||error);if(error.stack){console.error(error.stack)}});// 拒绝 Promise 时传递格式化的错误消息
62
62
  const errorMessage=errors.map((e,i)=>`[${i+1}] ${e.message||e}`).join("\n");reject(new Error(`Webpack build failed with ${errors.length} error(s):\n${errorMessage}`))}else{console.log(`Build successful!`);resolve()}})})}exports.makeWebpackBuildConfig=makeWebpackBuildConfig;exports.runBuild=runBuild;
@@ -1,15 +1,15 @@
1
- "use strict";const{merge}=require("webpack-merge");const webpack=require("webpack");const HtmlWebpackPlugin=require("html-webpack-plugin");const WebpackDevServer=require("webpack-dev-server");const{webpackCommonConfig}=require("./webpack.common.js");const path=require("path");const{DebuggerInjectionPlugin}=require("./plugins/DebuggerInjectionPlugin.js");const{options}=require("./options.js");const{mergeOptions}=require("./utils/mergeOptions.js");const{buildDefines}=require("./utils/buildDefines.js");const{logOptions}=require("./utils/logOptions.js");const{injectSDKPlugins}=require("./utils/injectSDKPlugins.js");/**
2
- * Creates webpack configuration for development
3
- * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
4
- * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
5
- * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
6
- * @returns {import('webpack').Configuration} Final webpack development configuration
1
+ "use strict";const{merge}=require("webpack-merge");const webpack=require("webpack");const HtmlWebpackPlugin=require("html-webpack-plugin");const WebpackDevServer=require("webpack-dev-server");const{webpackCommonConfig}=require("./webpack.common.js");const path=require("path");const{DebuggerInjectionPlugin}=require("./plugins/DebuggerInjectionPlugin.js");const{options}=require("./options.js");const{mergeOptions}=require("./utils/mergeOptions.js");const{buildDefines}=require("./utils/buildDefines.js");const{logOptions}=require("./utils/logOptions.js");const{injectSDKPlugins}=require("./utils/injectSDKPlugins.js");/**
2
+ * Creates webpack configuration for development
3
+ * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
4
+ * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
5
+ * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
6
+ * @returns {import('webpack').Configuration} Final webpack development configuration
7
7
  */function makeWebpackDevConfig(customOptions,customDefines,webpackCustomConfig){const devOptions=mergeOptions(options,customOptions);logOptions(devOptions);customDefines=customDefines||{};webpackCustomConfig=webpackCustomConfig||{};const webpackConfig=merge(webpackCommonConfig,{mode:"development",devtool:"inline-source-map",devServer:{static:{directory:path.resolve("dist")},hot:true,// compress: true,
8
8
  port:devOptions["port"],allowedHosts:"all",open:devOptions["open"]},plugins:[new HtmlWebpackPlugin({template:path.resolve("src/index.html"),inlineSource:".(js|css|png|jpg|webp|svg|xml|atlas|mp3|gif|glb|fbx|obj)$",meta:{viewport:"width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,user-scalable=no"}}),new webpack.DefinePlugin({...buildDefines(),...devOptions.defines,__DEV__:JSON.stringify(devOptions["dev"]===undefined?true:devOptions["dev"]),...customDefines})]},webpackCustomConfig);if(devOptions["debugger"]){webpackConfig.plugins.push(new DebuggerInjectionPlugin(devOptions["debugger"]))}// 注入渠道 SDK 插件(与 build 保持一致)
9
- injectSDKPlugins(webpackConfig,{network:devOptions["network"],protocol:devOptions["protocol"],orientation:devOptions["orientation"]});return webpackConfig}/**
10
- * Starts webpack development server
11
- * @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
12
- * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
13
- * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
14
- * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
9
+ injectSDKPlugins(webpackConfig,{network:devOptions["network"],protocol:devOptions["protocol"],orientation:devOptions["orientation"]});return webpackConfig}/**
10
+ * Starts webpack development server
11
+ * @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
12
+ * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
13
+ * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
14
+ * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
15
15
  */function runDev(webpackConfig,customOptions,customDefines,webpackCustomConfig){if(!webpackConfig)webpackConfig=makeWebpackDevConfig(customOptions,customDefines,webpackCustomConfig);const compiler=webpack(webpackConfig);const server=new WebpackDevServer(webpackConfig.devServer,compiler);server.start()}exports.makeWebpackDevConfig=makeWebpackDevConfig;exports.runDev=runDev;
package/defines.d.ts CHANGED
@@ -1,54 +1,54 @@
1
- declare module '*.png';
2
- declare module '*.jpg';
3
- declare module '*.svg';
4
- declare module '*.webp';
5
- declare module '*.xml';
6
- declare module '*.atlas';
7
- declare module '*.glb';
8
- declare module '*.gltf';
9
- declare module '*.fbx';
10
- declare module '*.obj';
11
- declare module '*.mp3';
12
- declare module '*.mp4';
13
- declare module '*.otf';
14
- declare module '*.ttf';
15
- declare module '*.woff';
16
- declare module '*.woff2';
17
-
18
- declare const AD_NETWORK:
19
- | 'preview'
20
- | 'applovin'
21
- | 'unity'
22
- | 'google'
23
- | 'ironsource'
24
- | 'facebook'
25
- | 'moloco'
26
- | 'mintegral'
27
- | 'vungle'
28
- | 'adcolony'
29
- | 'tapjoy'
30
- | 'snapchat'
31
- | 'tiktok'
32
- | 'appreciate'
33
- | 'chartboost'
34
- | 'pangle'
35
- | 'mytarget'
36
- | 'liftoff'
37
- | 'smadex'
38
- | 'adikteev'
39
- | 'bigabid'
40
- | 'inmobi'
41
- | 'bigoads';
42
-
43
- declare const AD_PROTOCOL: 'mraid' | 'dapi' | 'nucleo' | 'none';
44
-
45
- declare const GOOGLE_PLAY_URL: string;
46
- declare const APP_STORE_URL: string;
47
- declare const APP: string;
48
- declare const NAME: string;
49
- declare const VERSION: string;
50
- declare const LANGUAGE: 'auto' | 'en' | 'es' | 'zh' | 'hi' | 'ar' | 'fr' | 'de' | 'ja' | 'pt';
51
- declare const ORIENTATION: 'both' | 'portrait' | 'landscape' | 'square';
52
- declare const BUILD_HASH: string;
53
-
54
- declare const __DEV__: boolean;
1
+ declare module '*.png';
2
+ declare module '*.jpg';
3
+ declare module '*.svg';
4
+ declare module '*.webp';
5
+ declare module '*.xml';
6
+ declare module '*.atlas';
7
+ declare module '*.glb';
8
+ declare module '*.gltf';
9
+ declare module '*.fbx';
10
+ declare module '*.obj';
11
+ declare module '*.mp3';
12
+ declare module '*.mp4';
13
+ declare module '*.otf';
14
+ declare module '*.ttf';
15
+ declare module '*.woff';
16
+ declare module '*.woff2';
17
+
18
+ declare const AD_NETWORK:
19
+ | 'preview'
20
+ | 'applovin'
21
+ | 'unity'
22
+ | 'google'
23
+ | 'ironsource'
24
+ | 'facebook'
25
+ | 'moloco'
26
+ | 'mintegral'
27
+ | 'vungle'
28
+ | 'adcolony'
29
+ | 'tapjoy'
30
+ | 'snapchat'
31
+ | 'tiktok'
32
+ | 'appreciate'
33
+ | 'chartboost'
34
+ | 'pangle'
35
+ | 'mytarget'
36
+ | 'liftoff'
37
+ | 'smadex'
38
+ | 'adikteev'
39
+ | 'bigabid'
40
+ | 'inmobi'
41
+ | 'bigoads';
42
+
43
+ declare const AD_PROTOCOL: 'mraid' | 'dapi' | 'nucleo' | 'none';
44
+
45
+ declare const GOOGLE_PLAY_URL: string;
46
+ declare const APP_STORE_URL: string;
47
+ declare const APP: string;
48
+ declare const NAME: string;
49
+ declare const VERSION: string;
50
+ declare const LANGUAGE: 'auto' | 'en' | 'es' | 'zh' | 'hi' | 'ar' | 'fr' | 'de' | 'ja' | 'pt';
51
+ declare const ORIENTATION: 'both' | 'portrait' | 'landscape' | 'square';
52
+ declare const BUILD_HASH: string;
53
+
54
+ declare const __DEV__: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/devkit",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "HTML5 Playable Ads 构建工具,支持多广告渠道打包",
5
5
  "main": "core/index.js",
6
6
  "module": "core/index.js",