@playcraft/devkit 1.0.26 → 1.0.28

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 (56) hide show
  1. package/README.md +262 -0
  2. package/cli/bin/playable-scripts.js +44 -1
  3. package/cli/commands/build.js +221 -22
  4. package/cli/commands/builds.js +13 -2
  5. package/cli/commands/dev.js +7 -1
  6. package/cli/commands/pack.js +308 -39
  7. package/cli/commands/vite-dev.js +7 -1
  8. package/core/batch-build.js +1290 -127
  9. package/core/constants.js +16 -2
  10. package/core/cos-uploader.js +286 -23
  11. package/core/index.d.ts +8 -4
  12. package/core/index.js +76 -7
  13. package/core/loaders/gltf-loader.js +74 -28
  14. package/core/options.js +326 -15
  15. package/core/plugins/AdikteevInjectorPlugin.js +26 -4
  16. package/core/plugins/BigoAdsInjectorPlugin.js +21 -4
  17. package/core/plugins/DAPIInjectorPlugin.js +25 -2
  18. package/core/plugins/DebuggerInjectionPlugin.js +31 -3
  19. package/core/plugins/ExitAPIInjectorPlugin.js +57 -4
  20. package/core/plugins/FflateCompressionPlugin.js +231 -40
  21. package/core/plugins/FontInjectionWebpackPlugin.js +46 -4
  22. package/core/plugins/LiftoffInjectorPlugin.js +26 -4
  23. package/core/plugins/MRAIDInjectorPlugin.js +24 -2
  24. package/core/plugins/MintegralInjectorPlugin.js +25 -2
  25. package/core/plugins/PangleInjectorPlugin.js +24 -2
  26. package/core/plugins/PlaycraftOrientationInjectorPlugin.js +33 -0
  27. package/core/plugins/SnapchatInjectorPlugin.js +26 -4
  28. package/core/plugins/SocialMediaInjectorPlugin.js +119 -7
  29. package/core/plugins/TikTokInjectorPlugin.js +24 -2
  30. package/core/plugins/UnityInjectorPlugin.js +37 -8
  31. package/core/plugins/ZipPlugin.js +138 -19
  32. package/core/plugins/socialMediaVitePlugin.js +108 -2
  33. package/core/utils/buildDefines.js +31 -2
  34. package/core/utils/buildTemplateString.js +39 -5
  35. package/core/utils/date.js +16 -1
  36. package/core/utils/fontRegistry.js +81 -13
  37. package/core/utils/fontResolver.js +335 -37
  38. package/core/utils/generateAdikteevHtmlWebpackPluginConfig.js +42 -7
  39. package/core/utils/generateBigabidHtmlWebpackPluginConfig.js +30 -3
  40. package/core/utils/generateInMobiHtmlWebpackPluginConfig.js +43 -7
  41. package/core/utils/getPlaycraftOrientationSuffix.js +13 -0
  42. package/core/utils/injectSDKPlugins.js +69 -14
  43. package/core/utils/logOptions.js +46 -4
  44. package/core/utils/mergeOptions.js +19 -2
  45. package/core/utils/parseArgvOptions.js +111 -5
  46. package/core/utils/resolveChannelFold2Zip.js +15 -3
  47. package/core/utils/validateThemeData.js +227 -26
  48. package/core/validators/index.d.ts +4 -0
  49. package/core/validators/pre-build-checker.js +297 -21
  50. package/core/validators/tracking-validator.js +358 -40
  51. package/core/vite.dev.js +322 -17
  52. package/core/webpack.build.js +520 -56
  53. package/core/webpack.common.js +177 -11
  54. package/core/webpack.dev.js +88 -5
  55. package/defines.d.ts +1 -1
  56. package/package.json +3 -2
@@ -1,11 +1,177 @@
1
- "use strict";const path=require("path");const fs=require("fs");const TsconfigPathsPlugin=require("tsconfig-paths-webpack-plugin");const{VueLoaderPlugin}=require("vue-loader");const{options}=require("./options");const tsConfigPath=path.resolve(options.tsConfig);const jsConfigPath=path.resolve(options.jsConfig);let jsTsConfigPath=null;if(fs.existsSync(tsConfigPath)){jsTsConfigPath=tsConfigPath}else if(fs.existsSync(jsConfigPath)){jsTsConfigPath=jsConfigPath}/** @type {string[]} List of file extensions that webpack will resolve */const allowedExtensions=[".vue",".ts",".tsx",".js",".json",".json5",".png",".glb",".fbx",".obj",".jpg",".webp",".mp3",".svg",".xml",".atlas",".fnt",".css",".gif",".mp4",".woff",".woff2",".ttf",".otf"];/** @type {import('webpack').Configuration} Base webpack configuration used by both development and build configs */const webpackConfig={entry:path.resolve("src/index"),resolve:{extensions:allowedExtensions,alias:{assets:path.resolve("assets"),vue:"vue/dist/vue.esm-bundler.js","@":path.resolve("src")},plugins:jsTsConfigPath?[new TsconfigPathsPlugin({configFile:jsTsConfigPath,extensions:allowedExtensions})]:[]},output:{filename:"build.js",path:path.resolve("dist")},module:{rules:[// Vue 单文件组件
2
- {test:/\.vue$/,loader:"vue-loader"},// {
3
- // test: /\.tsx?$/,
4
- // use: 'ts-loader',
5
- // exclude: /node_modules/,
6
- // },
7
- {test:/\.ts?$/,exclude:/node_modules/,use:[{loader:"babel-loader",options:{// presets: ['@babel/preset-env'],
8
- plugins:options.compilation.allowTemplateLiterals===false?["@babel/plugin-transform-template-literals"]:[]}},{loader:"esbuild-loader",options:{loader:"ts",target:"es2015"}}]},{test:/\.css$/,use:["style-loader","css-loader"]},{test:/\.(js|mjs)$/,// exclude: /node_modules/,
9
- use:{loader:"babel-loader",options:{// presets: ['@babel/preset-env'],
10
- plugins:options.compilation.allowTemplateLiterals===false?["@babel/plugin-transform-template-literals"]:[]}}},{test:/\.(gltf)$/,loader:path.join(__dirname,"loaders/gltf-loader.js")},{test:/\.(gif|png|jpe?g|webp|mp3|mp4|m4a|ogg|wav|glb|fbx|obj)$/i,type:"asset/inline"},{test:/\.json5$/i,type:"javascript/auto",use:{loader:"json5-loader",options:{esModule:false}}},// 处理 json?url → base64
11
- {test:/\.json$/i,resourceQuery:/url/,type:"asset/inline",generator:{dataUrl:content=>`data:application/json;base64,${content.toString("base64")}`}},{test:/\.(svg|xml)$/i,type:"asset/source"},{test:/\.atlas$/,type:"asset/inline",generator:{dataUrl:content=>{return`data:text/atlas;base64,${content.toString("base64")}`}}},{test:/\.fnt$/i,type:"asset/inline",generator:{dataUrl:content=>{return`data:text/plain;base64,${content.toString("base64")}`}}},{test:/\.(woff|woff2|eot|ttf|otf)$/i,type:"asset/inline"}]},plugins:[new VueLoaderPlugin]};exports.allowedExtensions=allowedExtensions;exports.webpackCommonConfig=webpackConfig;
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
4
+ const { VueLoaderPlugin } = require('vue-loader');
5
+ const { options } = require('./options');
6
+
7
+ const tsConfigPath = path.resolve(options.tsConfig);
8
+ const jsConfigPath = path.resolve(options.jsConfig);
9
+ let jsTsConfigPath = null;
10
+ if (fs.existsSync(tsConfigPath)) {
11
+ jsTsConfigPath = tsConfigPath;
12
+ } else if (fs.existsSync(jsConfigPath)) {
13
+ jsTsConfigPath = jsConfigPath;
14
+ }
15
+
16
+ /** @type {string[]} List of file extensions that webpack will resolve */
17
+ const allowedExtensions = [
18
+ '.vue',
19
+ '.ts',
20
+ '.tsx',
21
+ '.js',
22
+ '.json',
23
+ '.json5',
24
+ '.png',
25
+ '.glb',
26
+ '.fbx',
27
+ '.obj',
28
+ '.jpg',
29
+ '.webp',
30
+ '.mp3',
31
+ '.svg',
32
+ '.xml',
33
+ '.atlas',
34
+ '.fnt',
35
+ '.css',
36
+ '.gif',
37
+ '.mp4',
38
+ '.woff',
39
+ '.woff2',
40
+ '.ttf',
41
+ '.otf'
42
+ ];
43
+
44
+ /** @type {import('webpack').Configuration} Base webpack configuration used by both development and build configs */
45
+ const webpackConfig = {
46
+ entry: path.resolve('src/index'),
47
+ resolve: {
48
+ extensions: allowedExtensions,
49
+ alias: {
50
+ assets: path.resolve('assets'),
51
+ vue: 'vue/dist/vue.esm-bundler.js',
52
+ '@': path.resolve('src'),
53
+ },
54
+ plugins: jsTsConfigPath
55
+ ? [
56
+ new TsconfigPathsPlugin({
57
+ configFile: jsTsConfigPath,
58
+ extensions: allowedExtensions
59
+ })
60
+ ]
61
+ : []
62
+ },
63
+ output: {
64
+ filename: 'build.js',
65
+ path: path.resolve('dist')
66
+ },
67
+ module: {
68
+ rules: [
69
+ // Vue 单文件组件
70
+ {
71
+ test: /\.vue$/,
72
+ loader: 'vue-loader'
73
+ },
74
+ // {
75
+ // test: /\.tsx?$/,
76
+ // use: 'ts-loader',
77
+ // exclude: /node_modules/,
78
+ // },
79
+ {
80
+ test: /\.ts?$/,
81
+ exclude: /node_modules/,
82
+ use: [
83
+ {
84
+ loader: 'babel-loader',
85
+ options: {
86
+ // presets: ['@babel/preset-env'],
87
+ plugins:
88
+ options.compilation.allowTemplateLiterals === false ? ['@babel/plugin-transform-template-literals'] : []
89
+ }
90
+ },
91
+
92
+ {
93
+ loader: 'esbuild-loader',
94
+ options: {
95
+ loader: 'ts',
96
+ target: 'es2015'
97
+ }
98
+ }
99
+ ]
100
+ },
101
+ {
102
+ test: /\.css$/,
103
+ use: ['style-loader', 'css-loader']
104
+ },
105
+ {
106
+ test: /\.(js|mjs)$/,
107
+ // exclude: /node_modules/,
108
+ use: {
109
+ loader: 'babel-loader',
110
+ options: {
111
+ // presets: ['@babel/preset-env'],
112
+ plugins: options.compilation.allowTemplateLiterals === false ? ['@babel/plugin-transform-template-literals'] : []
113
+ }
114
+ }
115
+ },
116
+ {
117
+ test: /\.(gltf)$/,
118
+ loader: path.join(__dirname, 'loaders/gltf-loader.js')
119
+ },
120
+ {
121
+ test: /\.(gif|png|jpe?g|webp|mp3|mp4|m4a|ogg|wav|glb|fbx|obj)$/i,
122
+ type: 'asset/inline'
123
+ },
124
+ {
125
+ test: /\.json5$/i,
126
+ type: 'javascript/auto',
127
+ use: {
128
+ loader: 'json5-loader',
129
+ options: {
130
+ esModule: false
131
+ }
132
+ }
133
+ },
134
+ // 处理 json?url → base64
135
+ {
136
+ test: /\.json$/i,
137
+ resourceQuery: /url/,
138
+ type: 'asset/inline',
139
+ generator: {
140
+ dataUrl: (content) => `data:application/json;base64,${content.toString('base64')}`
141
+ }
142
+ },
143
+ {
144
+ test: /\.(svg|xml)$/i,
145
+ type: 'asset/source'
146
+ },
147
+ {
148
+ test: /\.atlas$/,
149
+ type: 'asset/inline',
150
+ generator: {
151
+ dataUrl: (content) => {
152
+ return `data:text/atlas;base64,${content.toString('base64')}`;
153
+ }
154
+ }
155
+ },
156
+ {
157
+ test: /\.fnt$/i,
158
+ type: 'asset/inline',
159
+ generator: {
160
+ dataUrl: (content) => {
161
+ return `data:text/plain;base64,${content.toString('base64')}`;
162
+ }
163
+ }
164
+ },
165
+ {
166
+ test: /\.(woff|woff2|eot|ttf|otf)$/i,
167
+ type: 'asset/inline'
168
+ }
169
+ ]
170
+ },
171
+ plugins: [
172
+ new VueLoaderPlugin()
173
+ ]
174
+ };
175
+
176
+ exports.allowedExtensions = allowedExtensions;
177
+ exports.webpackCommonConfig = webpackConfig;
@@ -1,15 +1,98 @@
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");/**
1
+ const { merge } = require('webpack-merge');
2
+ const webpack = require('webpack');
3
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
4
+ const WebpackDevServer = require('webpack-dev-server');
5
+ const { webpackCommonConfig } = require('./webpack.common.js');
6
+ const path = require('path');
7
+ const { DebuggerInjectionPlugin } = require('./plugins/DebuggerInjectionPlugin.js');
8
+ const { options } = require('./options.js');
9
+ const { mergeOptions } = require('./utils/mergeOptions.js');
10
+ const { buildDefines } = require('./utils/buildDefines.js');
11
+ const { logOptions } = require('./utils/logOptions.js');
12
+ const { injectSDKPlugins } = require('./utils/injectSDKPlugins.js');
13
+ const { PlaycraftOrientationInjectorPlugin } = require('./plugins/PlaycraftOrientationInjectorPlugin.js');
14
+
15
+ /**
2
16
  * Creates webpack configuration for development
3
17
  * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
4
18
  * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
5
19
  * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
6
20
  * @returns {import('webpack').Configuration} Final webpack development configuration
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
- 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}/**
21
+ */
22
+ function makeWebpackDevConfig(customOptions, customDefines, webpackCustomConfig) {
23
+ const devOptions = mergeOptions(options, customOptions);
24
+ logOptions(devOptions)
25
+ customDefines = customDefines || {};
26
+ webpackCustomConfig = webpackCustomConfig || {};
27
+
28
+ /** @type {'both'|'landscape'|'portrait'} */
29
+ const playcraftOrientationValue = devOptions.playcraftOrientationValue || 'both';
30
+
31
+ const webpackConfig = merge(
32
+ webpackCommonConfig,
33
+ {
34
+ mode: 'development',
35
+ devtool: 'inline-source-map',
36
+ devServer: {
37
+ static: {
38
+ directory: path.resolve('dist')
39
+ },
40
+ hot: true,
41
+ // compress: true,
42
+ port: devOptions['port'],
43
+ allowedHosts: 'all',
44
+ open: devOptions['open']
45
+ },
46
+ plugins: [
47
+ new HtmlWebpackPlugin({
48
+ template: path.resolve('src/index.html'),
49
+ inlineSource: '.(js|css|png|jpg|webp|svg|xml|atlas|mp3|gif|glb|fbx|obj)$',
50
+ meta: {
51
+ viewport: 'width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,user-scalable=no'
52
+ }
53
+ }),
54
+ // 注入 window.playcraftOrientation 全局变量,标识当前构建产物对应的横竖屏方向版本
55
+ new PlaycraftOrientationInjectorPlugin(playcraftOrientationValue),
56
+
57
+ new webpack.DefinePlugin({
58
+ ...buildDefines(devOptions),
59
+ ...devOptions.defines,
60
+ __DEV__: JSON.stringify(devOptions['dev'] === undefined ? true : devOptions['dev']),
61
+ ...customDefines
62
+ })
63
+ ]
64
+ },
65
+ webpackCustomConfig
66
+ );
67
+
68
+ if (devOptions['debugger']) {
69
+ webpackConfig.plugins.push(new DebuggerInjectionPlugin(devOptions['debugger']));
70
+ }
71
+
72
+ // 注入渠道 SDK 插件(与 build 保持一致)
73
+ injectSDKPlugins(webpackConfig, {
74
+ network: devOptions['network'],
75
+ protocol: devOptions['protocol'],
76
+ playcraftOrientationValue
77
+ });
78
+
79
+ return webpackConfig;
80
+ }
81
+
82
+ /**
10
83
  * Starts webpack development server
11
84
  * @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
12
85
  * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
13
86
  * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
14
87
  * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
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;
88
+ */
89
+ function runDev(webpackConfig, customOptions, customDefines, webpackCustomConfig) {
90
+ if (!webpackConfig) webpackConfig = makeWebpackDevConfig(customOptions, customDefines, webpackCustomConfig);
91
+
92
+ const compiler = webpack(webpackConfig);
93
+ const server = new WebpackDevServer(webpackConfig.devServer, compiler);
94
+ server.start();
95
+ }
96
+
97
+ exports.makeWebpackDevConfig = makeWebpackDevConfig;
98
+ exports.runDev = runDev;
package/defines.d.ts CHANGED
@@ -49,7 +49,7 @@ declare const APP: string;
49
49
  declare const NAME: string;
50
50
  declare const VERSION: string;
51
51
  declare const LANGUAGE: 'auto' | 'en' | 'es' | 'zh' | 'hi' | 'ar' | 'fr' | 'de' | 'ja' | 'pt';
52
- declare const ORIENTATION: 'both' | 'portrait' | 'landscape' | 'square';
52
+ declare const PLAYCRAFT_ORIENTATION: 'both' | 'landscape' | 'portrait';
53
53
  declare const BUILD_HASH: string;
54
54
 
55
55
  declare const __DEV__: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/devkit",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "HTML5 Playable Ads 构建工具,支持多广告渠道打包",
5
5
  "main": "core/index.js",
6
6
  "module": "core/index.js",
@@ -15,6 +15,7 @@
15
15
  "defines.d.ts"
16
16
  ],
17
17
  "scripts": {
18
+ "build": "node scripts/build.js",
18
19
  "deploy": "npm run build && cd dist && npm publish --registry https://registry.npmjs.org/ --access public",
19
20
  "deploy:beta": "npm run build && cd dist && npm publish --registry https://registry.npmjs.org/ --access public --tag beta"
20
21
  },
@@ -82,4 +83,4 @@
82
83
  "publishConfig": {
83
84
  "registry": "https://www.npmjs.com/registry"
84
85
  }
85
- }
86
+ }