diff --git a/build-profile.json5 b/build-profile.json5 index 5de5435..c0df701 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -44,12 +44,12 @@ "arkOptions": { "buildProfileFields": { "CHANNEL": "harmony", - "BUILD_TIME": "2605070954" + "BUILD_TIME": "2605071040" } } }, "output": { - "artifactName": "rabbit_harmony_release_2605070954" + "artifactName": "rabbit_harmony_release_v1.0.1_2605071040" } } ], diff --git a/common/BuildProfile.ets b/common/BuildProfile.ets index a35b214..4711eb6 100644 --- a/common/BuildProfile.ets +++ b/common/BuildProfile.ets @@ -2,11 +2,11 @@ * Use these variables when you tailor your ArkTS code. They must be of the const type. */ export const HAR_VERSION = '0.0.1'; -export const BUILD_MODE_NAME = 'release'; -export const DEBUG = false; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; export const TARGET_NAME = 'default'; export const CHANNEL = 'harmony'; -export const BUILD_TIME = '2605061515'; +export const BUILD_TIME = '2605071039'; /** * BuildProfile Class is used only for compatibility purposes. diff --git a/features/mainLayout/BuildProfile.ets b/features/mainLayout/BuildProfile.ets index bdb642c..dd5e38d 100644 --- a/features/mainLayout/BuildProfile.ets +++ b/features/mainLayout/BuildProfile.ets @@ -2,11 +2,11 @@ * Use these variables when you tailor your ArkTS code. They must be of the const type. */ export const HAR_VERSION = '1.0.0'; -export const BUILD_MODE_NAME = 'release'; -export const DEBUG = false; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; export const TARGET_NAME = 'default'; export const CHANNEL = 'harmony'; -export const BUILD_TIME = '2605061515'; +export const BUILD_TIME = '2605071039'; /** * BuildProfile Class is used only for compatibility purposes. diff --git a/features/mainLayout/oh_modules/@ohos/common/BuildProfile.ets b/features/mainLayout/oh_modules/@ohos/common/BuildProfile.ets index a35b214..4711eb6 100644 --- a/features/mainLayout/oh_modules/@ohos/common/BuildProfile.ets +++ b/features/mainLayout/oh_modules/@ohos/common/BuildProfile.ets @@ -2,11 +2,11 @@ * Use these variables when you tailor your ArkTS code. They must be of the const type. */ export const HAR_VERSION = '0.0.1'; -export const BUILD_MODE_NAME = 'release'; -export const DEBUG = false; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; export const TARGET_NAME = 'default'; export const CHANNEL = 'harmony'; -export const BUILD_TIME = '2605061515'; +export const BUILD_TIME = '2605071039'; /** * BuildProfile Class is used only for compatibility purposes. diff --git a/hvigorfile.ts b/hvigorfile.ts index d1c767c..b261530 100644 --- a/hvigorfile.ts +++ b/hvigorfile.ts @@ -25,10 +25,20 @@ updateJsonTime(); function syncBuildFileNameByJson() { const filePath = path.resolve(__dirname, 'build-profile.json5'); + const appConfigPath = path.resolve(__dirname, 'AppScope/app.json5'); + if (!fs.existsSync(filePath)) return; try { - // 1. 读取并解析 JSON (JSON5 格式通常可以当作普通字符串解析) + // 1. 获取版本号 (从 AppScope/app.json5 读取) + let versionName = '1.0.0'; + if (fs.existsSync(appConfigPath)) { + const appContent = fs.readFileSync(appConfigPath, 'utf8'); + const vMatch = appContent.match(/"versionName"\s*:\s*"([^"]+)"/); + if (vMatch) versionName = vMatch[1]; + } + + // 2. 读取并解析 build-profile.json5 const rawContent = fs.readFileSync(filePath, 'utf8'); // 使用正则提取关键信息,避免因 JSON5 语法导致的 JSON.parse 失败 @@ -49,12 +59,14 @@ function syncBuildFileNameByJson() { buildMode = isDebuggable ? 'debug' : 'release'; } - // 2. 生成动态名称 + // 3. 生成动态名称 const now = new Date(); const timeStr = `${now.getFullYear().toString().slice(-2)}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}`; - const newName = `rabbit_harmony_${buildMode}_${timeStr}`; + // const newName = `rabbit_harmony_${buildMode}_${timeStr}`; + // 格式示例: rabbit_harmony_release_v1.0.0_2605062215 + const newName = `rabbit_harmony_${buildMode}_v${versionName}_${timeStr}`; - // 3. 物理替换并写入 + // 4. 物理替换并写入 const updatedArtifactName = rawContent.replace(/("artifactName"\s*:\s*")[^"]*(")/g, `$1${newName}$2`); const updateBuildTimeContent = updatedArtifactName.replace(/("BUILD_TIME"\s*:\s*")[^"]*(")/g, `$1${timeStr}$2`); diff --git a/products/app/build-profile.json5 b/products/app/build-profile.json5 index bc0010f..95147d2 100644 --- a/products/app/build-profile.json5 +++ b/products/app/build-profile.json5 @@ -26,7 +26,7 @@ { "name": "default", "output": { - "artifactName": "rabbit_harmony_2657954" + "artifactName": "rabbit_harmony_v1.0.1_26571040" } }, { diff --git a/products/app/hvigorfile.ts b/products/app/hvigorfile.ts index 53aeaba..9ee0b7b 100644 --- a/products/app/hvigorfile.ts +++ b/products/app/hvigorfile.ts @@ -4,10 +4,21 @@ import path from 'path'; function updateArtifactName() { const filePath = path.resolve(__dirname, 'build-profile.json5'); + const appConfigPath = path.resolve(__dirname, '..', '..', 'AppScope', 'app.json5'); + if (fs.existsSync(filePath)) { + let versionName = '1.0.0'; + if (fs.existsSync(appConfigPath)) { + const appContent = fs.readFileSync(appConfigPath, 'utf8'); + const vMatch = appContent.match(/"versionName"\s*:\s*"([^"]+)"/); + if (vMatch) versionName = vMatch[1]; + } + const now = new Date(); const timeStr = `${now.getFullYear().toString().slice(-2)}${now.getMonth() + 1}${now.getDate()}${now.getHours()}${now.getMinutes()}`; - const newArtifactName = `rabbit_harmony_${timeStr}`; + // const newArtifactName = `rabbit_harmony_${timeStr}`; + // 格式示例: rabbit_harmony_v1.0.0_2605062215 + const newArtifactName = `rabbit_harmony_v${versionName}_${timeStr}`; let content = fs.readFileSync(filePath, 'utf8'); // 使用正则表达式精准匹配 BUILD_TIME 后的值并替换,匹配模式: "BUILD_TIME": "任意内容"