@playcraft/devkit 1.0.31-beta.1 → 1.0.31-beta.11
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 +53 -6
- package/cli/commands/build.js +241 -32
- package/cli/commands/builds.js +13 -2
- package/cli/commands/dev.js +22 -1
- package/cli/commands/pack.js +323 -41
- package/cli/commands/vite-dev.js +7 -1
- package/core/artifacts/emit.js +98 -1
- package/core/artifacts/fflate.js +31 -1
- package/core/artifacts/zip.js +39 -1
- package/core/batch-build.js +1261 -149
- package/core/constants.js +20 -2
- package/core/cos-uploader.js +289 -23
- package/core/engines/cocos/clean-cache.js +188 -0
- package/core/engines/cocos/clean-cache.test.js +75 -0
- package/core/engines/cocos/cli-build.js +116 -2
- package/core/engines/cocos/cli.js +38 -1
- package/core/engines/cocos/constants.js +21 -1
- package/core/engines/cocos/creator-cli.js +108 -1
- package/core/engines/cocos/dev-server.js +412 -2
- package/core/engines/cocos/fs.js +105 -1
- package/core/engines/cocos/injects/3x/init.js +438 -19
- package/core/engines/cocos/injects/3x/main.js +52 -2
- package/core/engines/cocos/injects/libs/pako.js +2 -1
- package/core/engines/cocos/mcp-refresh.js +76 -2
- package/core/engines/cocos/merge.js +147 -2
- package/core/engines/cocos/pack.js +187 -1
- package/core/engines/cocos/preview-cache.js +51 -0
- package/core/engines/cocos/preview-cache.test.js +32 -0
- package/core/engines/cocos/preview-concat.js +192 -0
- package/core/engines/cocos/preview-concat.test.js +73 -0
- package/core/engines/cocos/preview-json-hook.js +200 -0
- package/core/engines/cocos/preview-json-pack.js +379 -0
- package/core/engines/cocos/preview-json-pack.test.js +226 -0
- package/core/engines/cocos/preview-proxy.js +132 -0
- package/core/engines/cocos/rebundle-preview.js +56 -0
- package/core/engines/cocos/strip-social-share.js +115 -3
- package/core/engines/cocos/theme-assets.js +161 -2
- package/core/engines/cocos/writable-cli.js +250 -0
- package/core/engines/cocos/writable-cli.test.js +112 -0
- package/core/engines/web/index.js +20 -1
- package/core/engines/web/vite.dev.js +322 -17
- package/core/engines/web/webpack.build.js +522 -65
- package/core/engines/web/webpack.common.js +177 -11
- package/core/engines/web/webpack.dev.js +88 -6
- package/core/index.d.ts +3 -0
- package/core/index.js +101 -7
- package/core/injectors/apply.js +94 -1
- package/core/injectors/check-channel-matrix.js +130 -2
- package/core/injectors/spec.js +217 -9
- package/core/loaders/gltf-loader.js +74 -28
- package/core/options.js +353 -16
- 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 +56 -3
- 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 +29 -3
- 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 +154 -20
- package/core/plugins/socialMediaVitePlugin.js +108 -2
- package/core/utils/buildDefines.js +30 -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 +9 -2
- package/core/utils/injectSDKPlugins.js +68 -13
- package/core/utils/logOptions.js +46 -5
- package/core/utils/mergeOptions.js +21 -2
- package/core/utils/parseArgvOptions.js +125 -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 +287 -25
- package/core/validators/tracking-validator.js +444 -43
- package/core/validators/tracking-validator.test.js +92 -0
- package/core/vite.dev.js +1 -1
- package/core/webpack.build.js +1 -1
- package/core/webpack.common.js +1 -1
- package/core/webpack.dev.js +1 -1
- package/package.json +3 -2
|
@@ -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|mpeg|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,16 +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
|
-
|
|
10
|
-
|
|
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
|
+
/**
|
|
11
83
|
* Starts webpack development server
|
|
12
84
|
* @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
|
|
13
85
|
* @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
|
|
14
86
|
* @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
|
|
15
87
|
* @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
|
|
16
|
-
*/
|
|
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/core/index.d.ts
CHANGED
|
@@ -135,6 +135,9 @@ export interface CLIOptions {
|
|
|
135
135
|
skipEngineBuild: boolean;
|
|
136
136
|
creatorBin: string;
|
|
137
137
|
generatedThemeFile: string;
|
|
138
|
+
enableSplash: boolean;
|
|
139
|
+
/** Drop library/ + temp/programming before `cocos build`. Batch builds default this on. */
|
|
140
|
+
cleanCache?: boolean;
|
|
138
141
|
};
|
|
139
142
|
}
|
|
140
143
|
|
package/core/index.js
CHANGED
|
@@ -1,7 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
const{
|
|
3
|
-
const{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
const { allowedExtensions, webpackCommonConfig } = require('./webpack.common.js');
|
|
2
|
+
const { parseArgvOptions } = require('./utils/parseArgvOptions.js');
|
|
3
|
+
const { mergeOptions } = require('./utils/mergeOptions.js');
|
|
4
|
+
const { options } = require('./options.js');
|
|
5
|
+
const { DAPIInjectorPlugin } = require('./plugins/DAPIInjectorPlugin.js');
|
|
6
|
+
const { DebuggerInjectionPlugin } = require('./plugins/DebuggerInjectionPlugin.js');
|
|
7
|
+
const { ExitAPIInjectorPlugin } = require('./plugins/ExitAPIInjectorPlugin.js');
|
|
8
|
+
const { runBuild, makeWebpackBuildConfig } = require('./webpack.build.js');
|
|
9
|
+
const { runDev, makeWebpackDevConfig } = require('./webpack.dev.js');
|
|
10
|
+
const { runViteDev, makeViteDevConfig, json5Plugin, assetInlinePlugin, fontFamilyPlugin } = require('./vite.dev.js');
|
|
11
|
+
|
|
12
|
+
// 字体注入
|
|
13
|
+
const { FontInjectionWebpackPlugin } = require('./plugins/FontInjectionWebpackPlugin.js');
|
|
14
|
+
const { FONT_REGISTRY, getRegisteredFontKeys, isBuiltin: isBuiltinFont, getFontEntry } = require('./utils/fontRegistry.js');
|
|
15
|
+
const { getOrGenerateFontCSS } = require('./utils/fontResolver.js');
|
|
16
|
+
|
|
17
|
+
// 验证器
|
|
18
|
+
const {
|
|
19
|
+
runPreBuildChecks,
|
|
20
|
+
runTrackingCheck,
|
|
21
|
+
registerChecker,
|
|
22
|
+
toggleChecker,
|
|
23
|
+
listCheckers
|
|
24
|
+
} = require('./validators/pre-build-checker.js');
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
validateTracking,
|
|
28
|
+
printValidationResult,
|
|
29
|
+
TRACKING_METHODS,
|
|
30
|
+
SDK_TO_TRACKING_MAP
|
|
31
|
+
} = require('./validators/tracking-validator.js');
|
|
32
|
+
|
|
33
|
+
exports.mergeOptions = mergeOptions;
|
|
34
|
+
exports.parseArgvOptions = parseArgvOptions;
|
|
35
|
+
|
|
36
|
+
exports.options = options;
|
|
37
|
+
|
|
38
|
+
exports.allowedExtensions = allowedExtensions;
|
|
39
|
+
exports.webpackCommonConfig = webpackCommonConfig;
|
|
40
|
+
exports.makeWebpackDevConfig = makeWebpackDevConfig;
|
|
41
|
+
exports.makeWebpackBuildConfig = makeWebpackBuildConfig;
|
|
42
|
+
exports.runDev = runDev;
|
|
43
|
+
exports.runBuild = runBuild;
|
|
44
|
+
|
|
45
|
+
exports.DAPIInjectorPlugin = DAPIInjectorPlugin;
|
|
46
|
+
exports.ExitAPIInjectorPlugin = ExitAPIInjectorPlugin;
|
|
47
|
+
exports.DebuggerInjectionPlugin = DebuggerInjectionPlugin;
|
|
48
|
+
|
|
49
|
+
exports.makeViteDevConfig = makeViteDevConfig;
|
|
50
|
+
exports.runViteDev = runViteDev;
|
|
51
|
+
|
|
52
|
+
// 公共 Vite 插件(供项目 vite.config.ts 直接引用)
|
|
53
|
+
exports.json5Plugin = json5Plugin;
|
|
54
|
+
exports.assetInlinePlugin = assetInlinePlugin;
|
|
55
|
+
exports.fontFamilyPlugin = fontFamilyPlugin;
|
|
56
|
+
|
|
57
|
+
// 编译前检查器导出
|
|
58
|
+
exports.runPreBuildChecks = runPreBuildChecks;
|
|
59
|
+
exports.runTrackingCheck = runTrackingCheck;
|
|
60
|
+
exports.registerChecker = registerChecker;
|
|
61
|
+
exports.toggleChecker = toggleChecker;
|
|
62
|
+
exports.listCheckers = listCheckers;
|
|
63
|
+
|
|
64
|
+
// 埋点验证器导出
|
|
65
|
+
exports.validateTracking = validateTracking;
|
|
66
|
+
exports.printValidationResult = printValidationResult;
|
|
67
|
+
exports.TRACKING_METHODS = TRACKING_METHODS;
|
|
68
|
+
exports.SDK_TO_TRACKING_MAP = SDK_TO_TRACKING_MAP;
|
|
69
|
+
|
|
70
|
+
// 字体注入导出
|
|
71
|
+
exports.FontInjectionWebpackPlugin = FontInjectionWebpackPlugin;
|
|
72
|
+
exports.FONT_REGISTRY = FONT_REGISTRY;
|
|
73
|
+
exports.getRegisteredFontKeys = getRegisteredFontKeys;
|
|
74
|
+
exports.isBuiltinFont = isBuiltinFont;
|
|
75
|
+
exports.getFontEntry = getFontEntry;
|
|
76
|
+
exports.getOrGenerateFontCSS = getOrGenerateFontCSS;
|
|
77
|
+
|
|
78
|
+
const { runCocosBuild, syncThemeForPreview } = require('./engines/cocos/pack.js');
|
|
79
|
+
const { runCocosEngineBuild } = require('./engines/cocos/cli-build.js');
|
|
80
|
+
const { prepareWritableCocosCli } = require('./engines/cocos/writable-cli.js');
|
|
81
|
+
const { syncGeneratedTheme } = require('./engines/cocos/theme-assets.js');
|
|
82
|
+
const { refreshAssets } = require('./engines/cocos/mcp-refresh.js');
|
|
83
|
+
const { spawnCocos, needsXvfb } = require('./engines/cocos/cli.js');
|
|
84
|
+
const {
|
|
85
|
+
stripAdsdkCjsImport,
|
|
86
|
+
stripSocialShareFromDir,
|
|
87
|
+
isSocialMediaNetwork,
|
|
88
|
+
} = require('./engines/cocos/strip-social-share.js');
|
|
89
|
+
const { runCocosDev } = require('./engines/cocos/dev-server.js');
|
|
90
|
+
exports.runCocosBuild = runCocosBuild;
|
|
91
|
+
exports.syncThemeForPreview = syncThemeForPreview;
|
|
92
|
+
exports.runCocosEngineBuild = runCocosEngineBuild;
|
|
93
|
+
exports.prepareWritableCocosCli = prepareWritableCocosCli;
|
|
94
|
+
exports.syncGeneratedTheme = syncGeneratedTheme;
|
|
95
|
+
exports.refreshAssets = refreshAssets;
|
|
96
|
+
exports.spawnCocos = spawnCocos;
|
|
97
|
+
exports.needsXvfb = needsXvfb;
|
|
98
|
+
exports.stripAdsdkCjsImport = stripAdsdkCjsImport;
|
|
99
|
+
exports.stripSocialShareFromDir = stripSocialShareFromDir;
|
|
100
|
+
exports.isSocialMediaNetwork = isSocialMediaNetwork;
|
|
101
|
+
exports.runCocosDev = runCocosDev;
|
package/core/injectors/apply.js
CHANGED
|
@@ -1 +1,94 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { load } = require('cheerio');
|
|
4
|
+
const { META, LIFTOFF_FONT } = require('./spec');
|
|
5
|
+
|
|
6
|
+
function renderTag(tag) {
|
|
7
|
+
const attrs = tag.attributes || {};
|
|
8
|
+
const attrStr = Object.entries(attrs)
|
|
9
|
+
.map(([k, v]) => `${k}="${String(v).replace(/"/g, '"')}"`)
|
|
10
|
+
.join(' ');
|
|
11
|
+
if (tag.tagName === 'meta') {
|
|
12
|
+
return `<meta ${attrStr} />`;
|
|
13
|
+
}
|
|
14
|
+
const inner = tag.innerHTML || '';
|
|
15
|
+
return `<script${attrStr ? ' ' + attrStr : ''}>${inner}</script>`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function applyMeta($, spec) {
|
|
19
|
+
const viewport = spec.viewport || META.COMMON_VIEWPORT;
|
|
20
|
+
if ($('meta[charset]').length) {
|
|
21
|
+
$('meta[charset]').first().attr('charset', META.COMMON_CHARSET);
|
|
22
|
+
} else {
|
|
23
|
+
$('head').prepend(`<meta charset="${META.COMMON_CHARSET}" />`);
|
|
24
|
+
}
|
|
25
|
+
if ($('meta[name="viewport"]').length) {
|
|
26
|
+
$('meta[name="viewport"]').attr('content', viewport);
|
|
27
|
+
} else {
|
|
28
|
+
$('head').prepend(`<meta name="viewport" content="${viewport}" />`);
|
|
29
|
+
}
|
|
30
|
+
if (!spec.skipRecommendedMeta) {
|
|
31
|
+
if (!$('meta[name="HandheldFriendly"]').length) {
|
|
32
|
+
$('head').append('<meta name="HandheldFriendly" content="True" />');
|
|
33
|
+
}
|
|
34
|
+
if (!$('meta[http-equiv="cleartype"]').length) {
|
|
35
|
+
$('head').append('<meta http-equiv="cleartype" content="on" />');
|
|
36
|
+
}
|
|
37
|
+
if (!$('meta[name="apple-mobile-web-app-capable"]').length) {
|
|
38
|
+
$('head').append('<meta name="apple-mobile-web-app-capable" content="yes" />');
|
|
39
|
+
}
|
|
40
|
+
if (!$('meta[name="mobile-web-app-capable"]').length) {
|
|
41
|
+
$('head').append('<meta name="mobile-web-app-capable" content="yes" />');
|
|
42
|
+
}
|
|
43
|
+
if (!$('meta[http-equiv="X-UA-Compatible"]').length) {
|
|
44
|
+
$('head').append('<meta http-equiv="X-UA-Compatible" content="IE=10" />');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (spec.liftoffFont) {
|
|
48
|
+
$('head').append(LIFTOFF_FONT);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function applyInjections(html, spec) {
|
|
53
|
+
const $ = load(html);
|
|
54
|
+
applyMeta($, spec);
|
|
55
|
+
const tags = (spec.headTags || []).slice().reverse();
|
|
56
|
+
for (const tag of tags) {
|
|
57
|
+
$('head').prepend(renderTag(tag));
|
|
58
|
+
}
|
|
59
|
+
let out = $.html();
|
|
60
|
+
for (const transform of spec.htmlTransforms || []) {
|
|
61
|
+
out = transform(out);
|
|
62
|
+
}
|
|
63
|
+
if (spec.scanStubHtml) {
|
|
64
|
+
if (/<\/body>/i.test(out)) {
|
|
65
|
+
out = out.replace(/<\/body>/i, `${spec.scanStubHtml}</body>`);
|
|
66
|
+
} else {
|
|
67
|
+
out += spec.scanStubHtml;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function extractInlineScripts(html) {
|
|
74
|
+
const $ = load(html);
|
|
75
|
+
const scripts = [];
|
|
76
|
+
$('script').each((_i, el) => {
|
|
77
|
+
const $el = $(el);
|
|
78
|
+
if ($el.attr('src')) return;
|
|
79
|
+
scripts.push($el.html() || '');
|
|
80
|
+
$el.remove();
|
|
81
|
+
});
|
|
82
|
+
return { html: $.html(), scripts };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function extractBodyScripts(html) {
|
|
86
|
+
return extractInlineScripts(html);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = {
|
|
90
|
+
applyInjections,
|
|
91
|
+
extractBodyScripts,
|
|
92
|
+
extractInlineScripts,
|
|
93
|
+
renderTag,
|
|
94
|
+
};
|