@playcraft/devkit 1.0.25-beta.1.0 → 1.0.26
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
CHANGED
|
@@ -7,7 +7,15 @@
|
|
|
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;let isExiting=false;// ============================================================
|
|
11
|
+
// 📌 中断信号处理(Ctrl+C / kill)
|
|
12
|
+
// ============================================================
|
|
13
|
+
// 单主题构建过程中,theme.schema.json5 可能已被 runThemeValidation()
|
|
14
|
+
// 覆写为合并后的数据。若此时进程被中断,需要在退出前恢复原始 schema,
|
|
15
|
+
// 避免文件被强制中断而遗留在“已覆写”状态。
|
|
16
|
+
// 注意:SIGKILL(kill -9)无法被捕获,属于无法规避的极端情况,
|
|
17
|
+
// 此时依赖 validateThemeData.js 中的兜底检测(下次构建自动识别并降级处理)。
|
|
18
|
+
function handleInterrupt(){if(isExiting)return;isExiting=true;console.log("\n\x1B[33m\u6536\u5230\u4E2D\u65AD\u4FE1\u53F7\uFF0C\u6B63\u5728\u6E05\u7406...\x1B[0m");if(schemaPathToRestore){try{restoreSchema(schemaPathToRestore);console.log("\x1B[36m\u5DF2\u6062\u590D theme.schema.json5\x1B[0m")}catch(e){console.error(`\x1b[31m恢复 theme.schema.json5 失败: ${e.message}\x1b[0m`)}schemaPathToRestore=null}process.exit(1)}process.on("SIGINT",handleInterrupt);process.on("SIGTERM",handleInterrupt);// ============================================================
|
|
11
19
|
// 📌 编译前检查(埋点验证等)
|
|
12
20
|
// ============================================================
|
|
13
21
|
// 支持通过环境变量控制是否跳过检查
|
|
@@ -56,8 +56,8 @@ const headMatch=html.match(/<head[^>]*>([\s\S]*?)<\/head>/i);if(!headMatch)retur
|
|
|
56
56
|
const metaRegex=/<meta\s+[^>]*?\/?>/gi;let match;while((match=metaRegex.exec(headHtml))!==null){const tag=match[0];// 排除 charset 和 viewport(自解压模板已包含)
|
|
57
57
|
if(/charset\s*=/i.test(tag))continue;if(/name\s*=\s*["']viewport["']/i.test(tag))continue;elements.push(tag)}// 提取 title 标签
|
|
58
58
|
const titleMatch=headHtml.match(/<title[^>]*>[\s\S]*?<\/title>/i);if(titleMatch){elements.push(titleMatch[0])}// 提取外部 script 标签(有 src 属性的)
|
|
59
|
-
const scriptRegex=/<script\s+[^>]*src\s*=\s*["'][^"']+["'][^>]*>[\s\S]*?<\/script>/gi;while((match=scriptRegex.exec(headHtml))!==null){elements.push(match[0])}// 提取 link
|
|
60
|
-
const linkRegex=/<link\s+[^>]*?\/?>/gi;while((match=linkRegex.exec(headHtml))!==null){
|
|
59
|
+
const scriptRegex=/<script\s+[^>]*src\s*=\s*["'][^"']+["'][^>]*>[\s\S]*?<\/script>/gi;while((match=scriptRegex.exec(headHtml))!==null){elements.push(match[0])}// 提取 link 标签(排除 icon,模板已内置空 favicon,避免重复声明)
|
|
60
|
+
const linkRegex=/<link\s+[^>]*?\/?>/gi;while((match=linkRegex.exec(headHtml))!==null){const tag=match[0];if(/rel\s*=\s*["'][^"']*icon[^"']*["']/i.test(tag))continue;elements.push(tag)}return elements.join("\n ")}/**
|
|
61
61
|
* 生成自解压 HTML 模板(极简压缩版本,无需 module)
|
|
62
62
|
* @param {string} compressedBase64 - 压缩后的 Base64 字符串
|
|
63
63
|
* @param {string} fflateLibCode - fflate 库代码(已压缩)
|
|
@@ -152,6 +152,7 @@ const htmlTemplate=`
|
|
|
152
152
|
<head>
|
|
153
153
|
<meta charset="UTF-8">
|
|
154
154
|
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
|
|
155
|
+
<link rel="icon" href="data:,">
|
|
155
156
|
${headContent}
|
|
156
157
|
<style>
|
|
157
158
|
body {
|