Skip to content

Commit 22d8089

Browse files
authored
update hvigorfile.ts file (#463)
1 parent 0df8261 commit 22d8089

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Example/harmony_use_pushy/harmony/entry/hvigorfile.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
22
import fs from 'fs';
33
import path from 'path';
4+
45
export function generatePushyBuildTime(str?: string) {
56
return {
67
pluginId: 'PushyBuildTimePlugin',
@@ -13,11 +14,22 @@ export function generatePushyBuildTime(str?: string) {
1314
if (!fs.existsSync(dirPath)) {
1415
fs.mkdirSync(dirPath, { recursive: true });
1516
}
17+
const moduleJsonPath = path.resolve(__dirname, './oh-package.json5');
18+
let versionName = '';
19+
if (fs.existsSync(moduleJsonPath)) {
20+
const moduleContent = fs.readFileSync(moduleJsonPath, 'utf-8');
21+
const versionMatch = moduleContent.match(/"version":\s*"([^"]+)"/);
22+
if (versionMatch && versionMatch[1]) {
23+
versionName = versionMatch[1];
24+
}
25+
}
1626
const buildTime = new Date().toISOString();
17-
const metaContent = { pushy_build_time : buildTime };
27+
const metaContent = {
28+
pushy_build_time: buildTime,
29+
versionName: versionName
30+
};
1831
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4));
1932
console.log(`Build time written to ${metaFilePath}`);
20-
2133
},
2234
dependencies: [],
2335
postDependencies: ['default@BuildJS']

0 commit comments

Comments
 (0)