@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.
- package/README.md +262 -0
- package/cli/bin/playable-scripts.js +44 -1
- package/cli/commands/build.js +221 -22
- 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 +1290 -127
- package/core/constants.js +16 -2
- package/core/cos-uploader.js +286 -23
- package/core/index.d.ts +8 -4
- package/core/index.js +76 -7
- package/core/loaders/gltf-loader.js +74 -28
- package/core/options.js +326 -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 -4
- package/core/plugins/FflateCompressionPlugin.js +231 -40
- 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/PlaycraftOrientationInjectorPlugin.js +33 -0
- package/core/plugins/SnapchatInjectorPlugin.js +26 -4
- package/core/plugins/SocialMediaInjectorPlugin.js +119 -7
- package/core/plugins/TikTokInjectorPlugin.js +24 -2
- package/core/plugins/UnityInjectorPlugin.js +37 -8
- package/core/plugins/ZipPlugin.js +138 -19
- package/core/plugins/socialMediaVitePlugin.js +108 -2
- package/core/utils/buildDefines.js +31 -2
- package/core/utils/buildTemplateString.js +39 -5
- package/core/utils/date.js +16 -1
- package/core/utils/fontRegistry.js +81 -13
- package/core/utils/fontResolver.js +335 -37
- package/core/utils/generateAdikteevHtmlWebpackPluginConfig.js +42 -7
- package/core/utils/generateBigabidHtmlWebpackPluginConfig.js +30 -3
- package/core/utils/generateInMobiHtmlWebpackPluginConfig.js +43 -7
- package/core/utils/getPlaycraftOrientationSuffix.js +13 -0
- package/core/utils/injectSDKPlugins.js +69 -14
- package/core/utils/logOptions.js +46 -4
- package/core/utils/mergeOptions.js +19 -2
- package/core/utils/parseArgvOptions.js +111 -5
- package/core/utils/resolveChannelFold2Zip.js +15 -3
- package/core/utils/validateThemeData.js +227 -26
- package/core/validators/index.d.ts +4 -0
- package/core/validators/pre-build-checker.js +297 -21
- package/core/validators/tracking-validator.js +358 -40
- package/core/vite.dev.js +322 -17
- package/core/webpack.build.js +520 -56
- package/core/webpack.common.js +177 -11
- package/core/webpack.dev.js +88 -5
- package/defines.d.ts +1 -1
- package/package.json +3 -2
package/core/webpack.common.js
CHANGED
|
@@ -1,11 +1,177 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
package/core/webpack.dev.js
CHANGED
|
@@ -1,15 +1,98 @@
|
|
|
1
|
-
|
|
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
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
*/
|
|
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
|
|
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.
|
|
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
|
+
}
|