@playcraft/devkit 1.0.15-beta.1 → 1.0.17
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 +259 -0
- package/cli/bin/playable-scripts.js +44 -1
- package/cli/commands/build.js +122 -17
- 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 +1091 -124
- package/core/cos-uploader.js +264 -20
- package/core/index.js +58 -4
- package/core/loaders/gltf-loader.js +74 -28
- package/core/options.js +310 -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 -3
- package/core/plugins/FflateCompressionPlugin.js +225 -37
- 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/SnapchatInjectorPlugin.js +26 -4
- package/core/plugins/TikTokInjectorPlugin.js +24 -2
- package/core/plugins/UnityInjectorPlugin.js +37 -8
- package/core/plugins/ZipPlugin.js +138 -19
- package/core/utils/buildDefines.js +29 -2
- package/core/utils/buildTemplateString.js +40 -5
- package/core/utils/date.js +16 -1
- package/core/utils/generateAdikteevHtmlWebpackPluginConfig.js +42 -7
- package/core/utils/generateBigabidHtmlWebpackPluginConfig.js +30 -3
- package/core/utils/generateInMobiHtmlWebpackPluginConfig.js +43 -7
- package/core/utils/injectSDKPlugins.js +58 -11
- package/core/utils/logOptions.js +37 -4
- package/core/utils/mergeOptions.js +19 -2
- package/core/utils/parseArgvOptions.js +110 -5
- package/core/utils/resolveChannelFold2Zip.js +15 -3
- package/core/utils/validateThemeData.js +220 -25
- package/core/validators/pre-build-checker.js +201 -21
- package/core/validators/tracking-validator.js +358 -40
- package/core/vite.dev.js +181 -15
- package/core/webpack.build.js +446 -52
- package/core/webpack.common.js +177 -10
- package/core/webpack.dev.js +82 -5
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# @tencent/playable-scripts
|
|
2
|
+
|
|
3
|
+
HTML5 Playable Ads 构建工具,支持多广告渠道打包。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🚀 **一键构建** - 轻松为不同广告渠道生成构建包
|
|
8
|
+
- ⚡ **自动优化** - 包含压缩、Tree-shaking 和死代码消除
|
|
9
|
+
- 🗜️ **fflate 压缩** - 编译时压缩,运行时解压,体积减少 40-60%
|
|
10
|
+
- 🎯 **多渠道支持** - 支持 Google Ads、Meta、AppLovin、Unity、IronSource、BigoAds 等
|
|
11
|
+
- 🎨 **主题系统** - 支持多主题批量构建
|
|
12
|
+
- 🔄 **并发构建** - 智能并发,大幅提升构建效率
|
|
13
|
+
|
|
14
|
+
## 快速开始
|
|
15
|
+
|
|
16
|
+
### 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
tnpm install --save-dev @tencent/playable-scripts
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 配置 package.json
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "playable-scripts dev",
|
|
28
|
+
"build": "playable-scripts build",
|
|
29
|
+
"builds": "playable-scripts builds"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 启动开发服务器
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm run dev # 默认预览模式
|
|
38
|
+
npm run dev bigoads # 指定渠道调试
|
|
39
|
+
npm run dev -- --port 8080 # 指定端口
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 构建指定渠道
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm run build google # Google Ads
|
|
46
|
+
npm run build facebook # Meta
|
|
47
|
+
npm run build unity # Unity Ads
|
|
48
|
+
npm run build bigoads # BigoAds
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 批量构建
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm run builds # 构建所有渠道
|
|
55
|
+
npm run builds -- -t "theme1,theme2" # 指定主题
|
|
56
|
+
npm run builds -- -c "google,facebook" # 指定渠道
|
|
57
|
+
npm run builds -- --parallel 4 # 指定并发数
|
|
58
|
+
|
|
59
|
+
# Windows PowerShell 兼容格式(推荐)
|
|
60
|
+
npm run builds -- "theme1" "google" # 位置参数:主题 渠道
|
|
61
|
+
npm run builds -- --themes="theme1,theme2" --channels="google,facebook"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 支持的广告渠道
|
|
65
|
+
|
|
66
|
+
| 渠道 | 命令 | 协议 |
|
|
67
|
+
|------|------|------|
|
|
68
|
+
| Preview (预览) | `preview` | none |
|
|
69
|
+
| Google Ads | `google` | none |
|
|
70
|
+
| Meta (Facebook) | `facebook` | none |
|
|
71
|
+
| AppLovin | `applovin` | mraid |
|
|
72
|
+
| Unity Ads | `unity` | mraid |
|
|
73
|
+
| IronSource | `ironsource` | mraid/dapi |
|
|
74
|
+
| TikTok / Pangle | `tiktok` | none |
|
|
75
|
+
| BigoAds | `bigoads` | bigo-mraid |
|
|
76
|
+
| Adikteev | `adikteev` | mraid |
|
|
77
|
+
| Moloco | `moloco` | none |
|
|
78
|
+
| Liftoff | `liftoff` | mraid (ZIP) |
|
|
79
|
+
| InMobi | `inmobi` | mraid |
|
|
80
|
+
| Snapchat | `snapchat` | snapchat |
|
|
81
|
+
|
|
82
|
+
## CLI 参数
|
|
83
|
+
|
|
84
|
+
| 参数 | 描述 | 默认值 |
|
|
85
|
+
|------|----------------|-----------|
|
|
86
|
+
| **广告渠道** | 目标广告渠道 | `preview` |
|
|
87
|
+
| `--out-dir` | 输出目录 | `dist` |
|
|
88
|
+
| `--obfuscate-level` | 代码混淆等级 (1-4) | `4` |
|
|
89
|
+
| `--fflate-compression` | 启用 fflate 压缩 | `true` |
|
|
90
|
+
| `--protocol` | 广告协议 | 渠道自动决定 |
|
|
91
|
+
| `--zip` | ZIP 输出结果 | `false` |
|
|
92
|
+
| `--port` | 开发服务器端口 | `3000` |
|
|
93
|
+
| `--open` | 自动打开浏览器 | `false` |
|
|
94
|
+
| `--language` | 语言代码 | `en` |
|
|
95
|
+
| `--is-channel-fold2zip ` | 所有渠道输出为 ZIP 结果 | `false` |
|
|
96
|
+
|
|
97
|
+
## 配置文件
|
|
98
|
+
|
|
99
|
+
支持两种配置文件(推荐使用 `builds.config.js`):
|
|
100
|
+
|
|
101
|
+
### builds.config.js(推荐)
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
module.exports = {
|
|
105
|
+
// 项目基本信息
|
|
106
|
+
projectName: 'My-Game', // 可选,默认 'Phaser Game'
|
|
107
|
+
googlePlayUrl: 'https://play.google.com/...', // 可选
|
|
108
|
+
appStoreUrl: 'https://apps.apple.com/...', // 可选
|
|
109
|
+
|
|
110
|
+
// 渠道配置
|
|
111
|
+
channels: ['google', 'facebook', 'unity'], // 可选,有默认值
|
|
112
|
+
|
|
113
|
+
// 主题配置(可选)
|
|
114
|
+
themes: {
|
|
115
|
+
enabled: true, // 默认 false
|
|
116
|
+
sourceDir: 'src/theme', // 默认 'src/theme'
|
|
117
|
+
entryFile: 'src/theme/index.ts', // 默认 'src/theme/index.ts'
|
|
118
|
+
whitelist: null, // 可选,过滤函数
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
// 文件命名配置(可选)
|
|
122
|
+
naming: {
|
|
123
|
+
language: 'EN', // 默认 'EN'
|
|
124
|
+
format: '无', // 默认 '无'
|
|
125
|
+
supplier: 'AIX', // 默认 'AIX'
|
|
126
|
+
follower: 'ZQL', // 默认 'ZQL'
|
|
127
|
+
generator: null, // 可选,自定义生成函数
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
// 构建配置(可选)
|
|
131
|
+
build: {
|
|
132
|
+
outputDir: 'dist-all', // 默认 'dist-all'
|
|
133
|
+
tempDirPrefix: 'dist-temp', // 默认 'dist-temp'
|
|
134
|
+
continueOnError: true, // 默认 true
|
|
135
|
+
cleanTemp: true, // 默认 true
|
|
136
|
+
parallel: undefined, // 默认自动计算(CPU核心数-1,最小2最大8)
|
|
137
|
+
},
|
|
138
|
+
cosConfig: {
|
|
139
|
+
enabled: true, // 是否启用 COS 上传
|
|
140
|
+
SecretId: 'YOUR_SECRET_ID', // 腾讯云 SecretId
|
|
141
|
+
SecretKey: 'YOUR_SECRET_KEY', // 腾讯云 SecretKey
|
|
142
|
+
Bucket: 'your-bucket-1234567890', // COS 存储桶名称
|
|
143
|
+
Region: 'ap-guangzhou', // COS 区域
|
|
144
|
+
CdnDomain: 'your-cdn-domain.com', // CDN 域名(用于生成访问链接)
|
|
145
|
+
PathPrefix: 'playable/preview', // COS 路径前缀(可选)
|
|
146
|
+
},
|
|
147
|
+
// 打包参数(可选)
|
|
148
|
+
obfuscateLevel: 4, // 默认 4
|
|
149
|
+
fflateCompression: false, // 默认 true
|
|
150
|
+
};
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### build.json(向后兼容)
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"app": "AppName",
|
|
158
|
+
"name": "ConceptName",
|
|
159
|
+
"google_play_url": "https://play.google.com/...",
|
|
160
|
+
"app_store_url": "https://apps.apple.com/..."
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 配置优先级
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
命令行参数 > build.json > builds.config.js > 默认值
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 代码混淆等级
|
|
171
|
+
|
|
172
|
+
| 等级 | 名称 | 说明 | 体积影响 |
|
|
173
|
+
|------|------|------|----------|
|
|
174
|
+
| **1** | terser-only | 仅 Terser 压缩 | 基准 |
|
|
175
|
+
| **2** | basic | 控制流平坦化 + 字符串编码 | +5~10% |
|
|
176
|
+
| **3** | dead-code | 等级 2 + 死代码注入 | +15~25% |
|
|
177
|
+
| **4** | maximum | 全部拉满(默认) | +30~50% |
|
|
178
|
+
|
|
179
|
+
## fflate 压缩
|
|
180
|
+
|
|
181
|
+
| 指标 | 效果 |
|
|
182
|
+
|------|------|
|
|
183
|
+
| **压缩率** | 66-68% |
|
|
184
|
+
| **体积减少** | 40-60% |
|
|
185
|
+
| **解压速度** | 3-5ms |
|
|
186
|
+
| **兼容性** | 99%+ 浏览器 |
|
|
187
|
+
|
|
188
|
+
## 批量构建
|
|
189
|
+
|
|
190
|
+
### 特性
|
|
191
|
+
|
|
192
|
+
1. **智能并发** - 自动根据 CPU 核心数优化(默认:核心数-1,最小2最大8)
|
|
193
|
+
2. **独立临时目录** - 每个任务使用独立目录,避免冲突
|
|
194
|
+
3. **主题切换** - 自动切换主题入口文件
|
|
195
|
+
4. **错误容忍** - 单个失败不影响其他构建
|
|
196
|
+
|
|
197
|
+
### 命令行参数
|
|
198
|
+
|
|
199
|
+
| 参数 | 缩写 | 描述 | 示例 |
|
|
200
|
+
|------|------|------|------|
|
|
201
|
+
| `--themes` | `-t` | 指定主题列表(逗号分隔) | `-t "theme1,theme2"` |
|
|
202
|
+
| `--channels` | `-c` | 指定渠道列表(逗号分隔) | `-c "google,facebook"` |
|
|
203
|
+
| `--parallel` | `-p` | 指定并发数 | `-p 4` |
|
|
204
|
+
| 位置参数 | - | 第一个参数=主题,第二个=渠道 | `"theme1" "google"` |
|
|
205
|
+
| `=` 格式 | - | Windows PowerShell 兼容 | `--themes="theme1"` |
|
|
206
|
+
|
|
207
|
+
**注意**:
|
|
208
|
+
- **Mac/Linux**:所有格式均可使用
|
|
209
|
+
- **Windows PowerShell**:推荐使用位置参数或 `--themes=value` 格式
|
|
210
|
+
- **Windows CMD**:所有格式均可使用
|
|
211
|
+
|
|
212
|
+
### 输出结构
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
dist-all/
|
|
216
|
+
├── theme1/
|
|
217
|
+
│ ├── google/
|
|
218
|
+
│ │ └── theme1-EN-无-3月-20260304-AIX-ZQL-google.html
|
|
219
|
+
│ └── facebook/
|
|
220
|
+
│ └── theme1-EN-无-3月-20260304-AIX-ZQL-facebook.html
|
|
221
|
+
└── theme2/
|
|
222
|
+
└── ...
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## 全局变量
|
|
226
|
+
|
|
227
|
+
构建时自动注入:
|
|
228
|
+
|
|
229
|
+
| 变量 | 描述 | 示例 |
|
|
230
|
+
|------|------|------|
|
|
231
|
+
| `__DEV__` | 开发模式标志 | `true` / `false` |
|
|
232
|
+
| `AD_NETWORK` | 当前广告渠道 | `"google"`, `"bigoads"` |
|
|
233
|
+
| `AD_PROTOCOL` | 当前广告协议 | `"none"`, `"mraid"` |
|
|
234
|
+
| `GOOGLE_PLAY_URL` | Google Play 链接 | `"https://..."` |
|
|
235
|
+
| `APP_STORE_URL` | App Store 链接 | `"https://..."` |
|
|
236
|
+
|
|
237
|
+
## 配套 SDK
|
|
238
|
+
|
|
239
|
+
配合 `@tencent/playable-sdk` 使用:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
tnpm install @tencent/playable-sdk
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
import { sdk } from '@tencent/playable-sdk';
|
|
247
|
+
|
|
248
|
+
sdk.init((width, height) => {
|
|
249
|
+
new Game(width, height);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
sdk.start(); // 游戏开始
|
|
253
|
+
sdk.finish(); // 游戏结束
|
|
254
|
+
sdk.install(); // 跳转商店
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## 许可证
|
|
258
|
+
|
|
259
|
+
MIT License
|
|
@@ -1,2 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
process.on('unhandledRejection', (err) => {
|
|
6
|
+
throw err;
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const spawn = require('cross-spawn');
|
|
10
|
+
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
|
|
13
|
+
const scriptIndex = args.findIndex((x) => x === 'build' || x === 'dev' || x === 'vite-dev' || x === 'builds' || x === 'pack');
|
|
14
|
+
|
|
15
|
+
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
16
|
+
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
17
|
+
|
|
18
|
+
if (['build', 'dev', 'vite-dev', 'builds', 'pack'].includes(script)) {
|
|
19
|
+
const result = spawn.sync(
|
|
20
|
+
process.execPath,
|
|
21
|
+
nodeArgs.concat(require.resolve('../commands/' + script)).concat(args.slice(scriptIndex + 1)),
|
|
22
|
+
{
|
|
23
|
+
stdio: 'inherit'
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
if (result.signal) {
|
|
27
|
+
if (result.signal === 'SIGKILL') {
|
|
28
|
+
console.log(
|
|
29
|
+
'The build failed because the process exited too early. ' +
|
|
30
|
+
'This probably means the system ran out of memory or someone called ' +
|
|
31
|
+
'`kill -9` on the process.'
|
|
32
|
+
);
|
|
33
|
+
} else if (result.signal === 'SIGTERM') {
|
|
34
|
+
console.log(
|
|
35
|
+
'The build failed because the process exited too early. ' +
|
|
36
|
+
'Someone might have called `kill` or `killall`, or the system could ' +
|
|
37
|
+
'be shutting down.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
process.exit(result.status);
|
|
43
|
+
} else {
|
|
44
|
+
console.log('Unknown script "' + script + '".');
|
|
45
|
+
}
|
package/cli/commands/build.js
CHANGED
|
@@ -1,26 +1,131 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
process.env.BABEL_ENV = 'production';
|
|
4
|
+
process.env.NODE_ENV = 'production';
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { runBuild } = require('../../core/webpack.build.js');
|
|
9
|
+
const { runThemeValidation, restoreSchema } = require('../../core/utils/validateThemeData');
|
|
10
|
+
const { runPreBuildChecks } = require('../../core/validators/pre-build-checker.js');
|
|
11
|
+
|
|
12
|
+
/**
|
|
2
13
|
* 从主题入口文件中检测当前主题名称。
|
|
3
14
|
* 支持以下模式:
|
|
4
15
|
* export { default } from './themeName';
|
|
5
16
|
* import Theme from './themeName';
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
17
|
+
*/
|
|
18
|
+
function detectCurrentTheme(projectRoot) {
|
|
19
|
+
// 尝试加载 builds.config.js 获取主题配置
|
|
20
|
+
const buildsConfigPath = path.join(projectRoot, 'builds.config.js');
|
|
21
|
+
let themeConfig = { sourceDir: 'src/theme', entryFile: 'src/theme/index.ts' };
|
|
22
|
+
|
|
23
|
+
if (fs.existsSync(buildsConfigPath)) {
|
|
24
|
+
try {
|
|
25
|
+
delete require.cache[buildsConfigPath];
|
|
26
|
+
const config = require(buildsConfigPath);
|
|
27
|
+
if (config.themes) {
|
|
28
|
+
themeConfig = { ...themeConfig, ...config.themes };
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {
|
|
31
|
+
// 忽略错误
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const entryPath = path.join(projectRoot, themeConfig.entryFile);
|
|
36
|
+
if (!fs.existsSync(entryPath)) {
|
|
37
|
+
return { themeName: null, themeConfig };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const content = fs.readFileSync(entryPath, 'utf8');
|
|
41
|
+
|
|
42
|
+
// 匹配: export { default } from './themeName' 或 import ... from './themeName'
|
|
43
|
+
const match = content.match(/from\s+['"]\.\/([^'"]+)['"]/);
|
|
44
|
+
if (match) {
|
|
45
|
+
return { themeName: match[1], themeConfig };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return { themeName: null, themeConfig };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// --- 主流程 ---
|
|
52
|
+
const projectRoot = process.cwd();
|
|
53
|
+
const { themeName, themeConfig } = detectCurrentTheme(projectRoot);
|
|
54
|
+
|
|
55
|
+
let schemaPathToRestore = null;
|
|
56
|
+
|
|
57
|
+
// ============================================================
|
|
11
58
|
// 📌 编译前检查(埋点验证等)
|
|
12
59
|
// ============================================================
|
|
13
60
|
// 支持通过环境变量控制是否跳过检查
|
|
14
61
|
// - SKIP_PRE_BUILD_CHECKS=1: 强制跳过检查
|
|
15
62
|
// - PLAYABLE_BATCH_MODE=1: 批量构建模式,子进程自动跳过检查(主进程已执行)
|
|
16
|
-
const isBatchMode=process.env.PLAYABLE_BATCH_MODE
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
63
|
+
const isBatchMode = process.env.PLAYABLE_BATCH_MODE === '1';
|
|
64
|
+
const shouldSkipChecks = process.env.SKIP_PRE_BUILD_CHECKS === '1' || isBatchMode;
|
|
65
|
+
|
|
66
|
+
async function runPreChecks() {
|
|
67
|
+
if (shouldSkipChecks) {
|
|
68
|
+
console.log('\n⚠️ 跳过编译前检查(SKIP_PRE_BUILD_CHECKS=1)\n');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const checkResult = await runPreBuildChecks(projectRoot, {
|
|
73
|
+
verbose: false,
|
|
74
|
+
showDetails: true,
|
|
75
|
+
failFast: false
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (!checkResult.success) {
|
|
79
|
+
console.error('\n❌ 编译前检查失败,终止构建。');
|
|
80
|
+
console.error('提示:如需跳过检查,可设置环境变量: SKIP_PRE_BUILD_CHECKS=1\n');
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 执行编译前检查(异步)
|
|
86
|
+
runPreChecks().then(() => {
|
|
87
|
+
// 检查通过后继续原有流程
|
|
88
|
+
continueWithBuild();
|
|
89
|
+
}).catch((err) => {
|
|
90
|
+
console.error('\n❌ 编译前检查出错:', err);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
function continueWithBuild() {
|
|
95
|
+
// In batch mode (PLAYABLE_BATCH_MODE=1), the parent process has already
|
|
96
|
+
// executed runThemeValidation and overwritten theme.schema.json5 with merged data.
|
|
97
|
+
// Running it again in child processes would cause a race condition:
|
|
98
|
+
// 1. Child reads the already-overwritten schema (pure data, no "properties"/"default")
|
|
99
|
+
// 2. extractDefaultsFromSchema returns {} (empty)
|
|
100
|
+
// 3. Child overwrites schema with {} → file becomes empty object
|
|
101
|
+
const isBatchMode = process.env.PLAYABLE_BATCH_MODE === '1';
|
|
102
|
+
|
|
103
|
+
if (themeName && !isBatchMode) {
|
|
104
|
+
const buildLog = (msg, level) => {
|
|
105
|
+
const colors = { info: '\x1b[36m', success: '\x1b[32m', error: '\x1b[31m' };
|
|
106
|
+
const reset = '\x1b[0m';
|
|
107
|
+
const color = colors[level] || '';
|
|
108
|
+
console.log(`${color}[build] ${msg}${reset}`);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const { valid, schemaPath } = runThemeValidation(themeName, projectRoot, themeConfig, { log: buildLog });
|
|
112
|
+
schemaPathToRestore = schemaPath;
|
|
113
|
+
|
|
114
|
+
if (!valid) {
|
|
115
|
+
// 校验失败时恢复 schema(备份可能已创建)
|
|
116
|
+
if (schemaPathToRestore) restoreSchema(schemaPathToRestore);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 执行构建,无论成功或失败都恢复 schema
|
|
122
|
+
runBuild()
|
|
123
|
+
.then(() => {
|
|
124
|
+
if (schemaPathToRestore) restoreSchema(schemaPathToRestore);
|
|
125
|
+
})
|
|
126
|
+
.catch((err) => {
|
|
127
|
+
if (schemaPathToRestore) restoreSchema(schemaPathToRestore);
|
|
128
|
+
console.error(err);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
});
|
|
131
|
+
}
|
package/cli/commands/builds.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
/**
|
|
3
6
|
* Batch Builds Command for playable-scripts
|
|
4
7
|
*
|
|
5
8
|
* 支持:
|
|
@@ -13,4 +16,12 @@
|
|
|
13
16
|
* playable-scripts builds -c "google,facebook" # 指定渠道
|
|
14
17
|
* playable-scripts builds -t "theme1" -c "google" # 指定主题和渠道
|
|
15
18
|
* playable-scripts builds --parallel 3 # 设置并发数
|
|
16
|
-
*/
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
process.on('unhandledRejection', (err) => {
|
|
22
|
+
throw err;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const { buildBatch } = require('../../core/batch-build');
|
|
26
|
+
|
|
27
|
+
buildBatch();
|
package/cli/commands/dev.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
process.env.BABEL_ENV = 'development';
|
|
4
|
+
process.env.NODE_ENV = 'development';
|
|
5
|
+
|
|
6
|
+
const { runDev } = require('../../core/webpack.dev.js');
|
|
7
|
+
runDev();
|