@playcraft/devkit 1.0.10 → 1.0.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/cli/commands/build.js +7 -1
- package/core/batch-build.js +2 -1
- package/package.json +1 -1
package/cli/commands/build.js
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
const buildsConfigPath=path.join(projectRoot,"builds.config.js");let themeConfig={sourceDir:"src/theme",entryFile:"src/theme/index.ts"};if(fs.existsSync(buildsConfigPath)){try{delete require.cache[buildsConfigPath];const config=require(buildsConfigPath);if(config.themes){themeConfig={...themeConfig,...config.themes}}}catch(e){// 忽略错误
|
|
8
8
|
}}const entryPath=path.join(projectRoot,themeConfig.entryFile);if(!fs.existsSync(entryPath)){return{themeName:null,themeConfig}}const content=fs.readFileSync(entryPath,"utf8");// 匹配: export { default } from './themeName' 或 import ... from './themeName'
|
|
9
9
|
const match=content.match(/from\s+['"]\.\/([^'"]+)['"]/);if(match){return{themeName:match[1],themeConfig}}return{themeName:null,themeConfig}}// --- 主流程 ---
|
|
10
|
-
const projectRoot=process.cwd();const{themeName,themeConfig}=detectCurrentTheme(projectRoot);let schemaPathToRestore=null
|
|
10
|
+
const projectRoot=process.cwd();const{themeName,themeConfig}=detectCurrentTheme(projectRoot);let schemaPathToRestore=null;// In batch mode (PLAYABLE_BATCH_MODE=1), the parent process has already
|
|
11
|
+
// executed runThemeValidation and overwritten theme.schema.json5 with merged data.
|
|
12
|
+
// Running it again in child processes would cause a race condition:
|
|
13
|
+
// 1. Child reads the already-overwritten schema (pure data, no "properties"/"default")
|
|
14
|
+
// 2. extractDefaultsFromSchema returns {} (empty)
|
|
15
|
+
// 3. Child overwrites schema with {} → file becomes empty object
|
|
16
|
+
const isBatchMode=process.env.PLAYABLE_BATCH_MODE==="1";if(themeName&&!isBatchMode){const buildLog=(msg,level)=>{const colors={info:"\x1B[36m",success:"\x1B[32m",error:"\x1B[31m"};const reset="\x1B[0m";const color=colors[level]||"";console.log(`${color}[build] ${msg}${reset}`)};const{valid,schemaPath}=runThemeValidation(themeName,projectRoot,themeConfig,{log:buildLog});schemaPathToRestore=schemaPath;if(!valid){// 校验失败时恢复 schema(备份可能已创建)
|
|
11
17
|
if(schemaPathToRestore)restoreSchema(schemaPathToRestore);process.exit(1)}}// 执行构建,无论成功或失败都恢复 schema
|
|
12
18
|
runBuild().then(()=>{if(schemaPathToRestore)restoreSchema(schemaPathToRestore)}).catch(err=>{if(schemaPathToRestore)restoreSchema(schemaPathToRestore);console.error(err);process.exit(1)});
|
package/core/batch-build.js
CHANGED
|
@@ -59,7 +59,8 @@ const fileName=config.naming.generator?config.naming.generator(themeName,channel
|
|
|
59
59
|
// 构建命令行参数
|
|
60
60
|
const buildArgs=[channel,`--out-dir "${tempDir}"`];// 如果配置中有商店链接,通过命令行参数传递
|
|
61
61
|
if(config.googlePlayUrl){buildArgs.push(`--google-play-url "${config.googlePlayUrl}"`)}if(config.appStoreUrl){buildArgs.push(`--app-store-url "${config.appStoreUrl}"`)}// 如果启用了 isChannelFold2Zip,透传参数给子进程
|
|
62
|
-
if(isChannelFold2Zip){buildArgs.push("--is-channel-fold2zip")}await execAsync(`npm run build -- ${buildArgs.join(" ")}`,{cwd:projectRoot,env:{...process.env,PLAYABLE_BUILD_TASK_ID:taskId,PLAYABLE_FILENAME:fileName
|
|
62
|
+
if(isChannelFold2Zip){buildArgs.push("--is-channel-fold2zip")}await execAsync(`npm run build -- ${buildArgs.join(" ")}`,{cwd:projectRoot,env:{...process.env,PLAYABLE_BUILD_TASK_ID:taskId,PLAYABLE_FILENAME:fileName,// 通过环境变量传递文件名
|
|
63
|
+
PLAYABLE_BATCH_MODE:"1"// 标识批量构建模式,子进程跳过 runThemeValidation(主进程已处理)
|
|
63
64
|
},// 不使用 stdio: 'inherit' 以支持并发,而是捕获输出
|
|
64
65
|
maxBuffer:10*1024*1024// 10MB buffer
|
|
65
66
|
});// 复制 tempDir 所有文件到目标目录
|