From 22d80890e2dbe232864f13bf1ad61ba4f08d4968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=A2=E4=BB=94=E7=B3=95?= Date: Tue, 7 Jan 2025 14:20:13 +0800 Subject: [PATCH] update hvigorfile.ts file (#463) --- .../harmony/entry/hvigorfile.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Example/harmony_use_pushy/harmony/entry/hvigorfile.ts b/Example/harmony_use_pushy/harmony/entry/hvigorfile.ts index d3d3aa0..054a94b 100644 --- a/Example/harmony_use_pushy/harmony/entry/hvigorfile.ts +++ b/Example/harmony_use_pushy/harmony/entry/hvigorfile.ts @@ -1,6 +1,7 @@ import { hapTasks } from '@ohos/hvigor-ohos-plugin'; import fs from 'fs'; import path from 'path'; + export function generatePushyBuildTime(str?: string) { return { pluginId: 'PushyBuildTimePlugin', @@ -13,11 +14,22 @@ export function generatePushyBuildTime(str?: string) { if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath, { recursive: true }); } + const moduleJsonPath = path.resolve(__dirname, './oh-package.json5'); + let versionName = ''; + if (fs.existsSync(moduleJsonPath)) { + const moduleContent = fs.readFileSync(moduleJsonPath, 'utf-8'); + const versionMatch = moduleContent.match(/"version":\s*"([^"]+)"/); + if (versionMatch && versionMatch[1]) { + versionName = versionMatch[1]; + } + } const buildTime = new Date().toISOString(); - const metaContent = { pushy_build_time : buildTime }; + const metaContent = { + pushy_build_time: buildTime, + versionName: versionName + }; fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4)); console.log(`Build time written to ${metaFilePath}`); - }, dependencies: [], postDependencies: ['default@BuildJS']