@playcraft/devkit 1.0.16 → 1.0.18

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 (57) hide show
  1. package/README.md +259 -0
  2. package/cli/bin/playable-scripts.js +44 -1
  3. package/cli/commands/build.js +130 -17
  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 +1091 -124
  9. package/core/cos-uploader.js +264 -20
  10. package/core/index.js +71 -4
  11. package/core/loaders/gltf-loader.js +74 -28
  12. package/core/options.js +310 -15
  13. package/core/plugins/AdikteevInjectorPlugin.js +26 -4
  14. package/core/plugins/BigoAdsInjectorPlugin.js +21 -4
  15. package/core/plugins/DAPIInjectorPlugin.js +25 -2
  16. package/core/plugins/DebuggerInjectionPlugin.js +31 -3
  17. package/core/plugins/ExitAPIInjectorPlugin.js +57 -3
  18. package/core/plugins/FflateCompressionPlugin.js +225 -37
  19. package/core/plugins/FontInjectionWebpackPlugin.js +59 -0
  20. package/core/plugins/LiftoffInjectorPlugin.js +26 -4
  21. package/core/plugins/MRAIDInjectorPlugin.js +24 -2
  22. package/core/plugins/MintegralInjectorPlugin.js +25 -2
  23. package/core/plugins/PangleInjectorPlugin.js +24 -2
  24. package/core/plugins/SnapchatInjectorPlugin.js +26 -4
  25. package/core/plugins/TikTokInjectorPlugin.js +24 -2
  26. package/core/plugins/UnityInjectorPlugin.js +37 -8
  27. package/core/plugins/ZipPlugin.js +138 -19
  28. package/core/resources/fonts/README.md +31 -0
  29. package/core/resources/fonts/maoken-regular.woff2 +0 -0
  30. package/core/resources/fonts/maoken-regular.woff2.chars +1 -0
  31. package/core/resources/fonts/maoken-zhuyuan.ttf +0 -0
  32. package/core/resources/fonts/noto-sans-sc-regular.woff2 +0 -0
  33. package/core/resources/fonts/pangmen-biaoti.ttf +0 -0
  34. package/core/resources/fonts/pangmen-regular.woff2 +0 -0
  35. package/core/resources/fonts/pangmen-regular.woff2.chars +1 -0
  36. package/core/resources/fonts/poppins-regular.woff2 +0 -0
  37. package/core/utils/buildDefines.js +29 -2
  38. package/core/utils/buildTemplateString.js +40 -5
  39. package/core/utils/date.js +16 -1
  40. package/core/utils/fontRegistry.js +97 -0
  41. package/core/utils/fontResolver.js +398 -0
  42. package/core/utils/generateAdikteevHtmlWebpackPluginConfig.js +42 -7
  43. package/core/utils/generateBigabidHtmlWebpackPluginConfig.js +30 -3
  44. package/core/utils/generateInMobiHtmlWebpackPluginConfig.js +43 -7
  45. package/core/utils/injectSDKPlugins.js +58 -11
  46. package/core/utils/logOptions.js +37 -4
  47. package/core/utils/mergeOptions.js +19 -2
  48. package/core/utils/parseArgvOptions.js +110 -5
  49. package/core/utils/resolveChannelFold2Zip.js +15 -3
  50. package/core/utils/validateThemeData.js +220 -25
  51. package/core/validators/pre-build-checker.js +201 -21
  52. package/core/validators/tracking-validator.js +358 -40
  53. package/core/vite.dev.js +332 -16
  54. package/core/webpack.build.js +494 -52
  55. package/core/webpack.common.js +177 -11
  56. package/core/webpack.dev.js +82 -5
  57. 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,92 @@
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
+
14
+ /**
2
15
  * Creates webpack configuration for development
3
16
  * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
4
17
  * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
5
18
  * @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
6
19
  * @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}/**
20
+ */
21
+ function makeWebpackDevConfig(customOptions, customDefines, webpackCustomConfig) {
22
+ const devOptions = mergeOptions(options, customOptions);
23
+ logOptions(devOptions)
24
+ customDefines = customDefines || {};
25
+ webpackCustomConfig = webpackCustomConfig || {};
26
+
27
+ const webpackConfig = merge(
28
+ webpackCommonConfig,
29
+ {
30
+ mode: 'development',
31
+ devtool: 'inline-source-map',
32
+ devServer: {
33
+ static: {
34
+ directory: path.resolve('dist')
35
+ },
36
+ hot: true,
37
+ // compress: true,
38
+ port: devOptions['port'],
39
+ allowedHosts: 'all',
40
+ open: devOptions['open']
41
+ },
42
+ plugins: [
43
+ new HtmlWebpackPlugin({
44
+ template: path.resolve('src/index.html'),
45
+ inlineSource: '.(js|css|png|jpg|webp|svg|xml|atlas|mp3|gif|glb|fbx|obj)$',
46
+ meta: {
47
+ viewport: 'width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,user-scalable=no'
48
+ }
49
+ }),
50
+
51
+ new webpack.DefinePlugin({
52
+ ...buildDefines(),
53
+ ...devOptions.defines,
54
+ __DEV__: JSON.stringify(devOptions['dev'] === undefined ? true : devOptions['dev']),
55
+ ...customDefines
56
+ })
57
+ ]
58
+ },
59
+ webpackCustomConfig
60
+ );
61
+
62
+ if (devOptions['debugger']) {
63
+ webpackConfig.plugins.push(new DebuggerInjectionPlugin(devOptions['debugger']));
64
+ }
65
+
66
+ // 注入渠道 SDK 插件(与 build 保持一致)
67
+ injectSDKPlugins(webpackConfig, {
68
+ network: devOptions['network'],
69
+ protocol: devOptions['protocol'],
70
+ orientation: devOptions['orientation']
71
+ });
72
+
73
+ return webpackConfig;
74
+ }
75
+
76
+ /**
10
77
  * Starts webpack development server
11
78
  * @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
12
79
  * @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
13
80
  * @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
14
81
  * @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;
82
+ */
83
+ function runDev(webpackConfig, customOptions, customDefines, webpackCustomConfig) {
84
+ if (!webpackConfig) webpackConfig = makeWebpackDevConfig(customOptions, customDefines, webpackCustomConfig);
85
+
86
+ const compiler = webpack(webpackConfig);
87
+ const server = new WebpackDevServer(webpackConfig.devServer, compiler);
88
+ server.start();
89
+ }
90
+
91
+ exports.makeWebpackDevConfig = makeWebpackDevConfig;
92
+ exports.runDev = runDev;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/devkit",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
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
+ }