@@ -278,6 +278,54 @@ target_link_libraries(rnoh_app PUBLIC rnoh_pushy)
278278 }
279279` ` `
280280
281+ 在 ` harmony / entry / hvigorfile .ts ` 中增加如下配置:
282+ ` ` ` ts
283+ import { hapTasks } from ' @ohos/hvigor-ohos-plugin' ;
284+ import fs from ' fs' ;
285+ import path from ' path' ;
286+
287+ export function generatePushyBuildTime(str ? : string ) {
288+ return {
289+ pluginId: ' PushyBuildTimePlugin' ,
290+ apply(pluginContext ) {
291+ pluginContext .registerTask ({
292+ name: ' pushy_build_time' ,
293+ run : (taskContext ) => {
294+ const metaFilePath = path .resolve (__dirname , ' src/main/resources/rawfile/meta.json' );
295+ const dirPath = path .dirname (metaFilePath );
296+ if (! fs .existsSync (dirPath )) {
297+ fs .mkdirSync (dirPath , { recursive: true });
298+ }
299+ const moduleJsonPath = path .resolve (__dirname , ' ../AppScope/app.json5' );
300+ let versionName = ' ' ;
301+ if (fs .existsSync (moduleJsonPath )) {
302+ const moduleContent = fs .readFileSync (moduleJsonPath , ' utf-8' );
303+ const versionMatch = moduleContent .match (/ "versionName":\s * "([^ "] + )"/ );
304+ if (versionMatch && versionMatch [1 ]) {
305+ versionName = versionMatch [1 ];
306+ }
307+ }
308+ const buildTime = new Date ().toISOString ();
309+ const metaContent = {
310+ pushy_build_time: buildTime ,
311+ versionName: versionName
312+ };
313+ fs .writeFileSync (metaFilePath , JSON .stringify (metaContent , null , 4 ));
314+ console .log (` Build time written to ${metaFilePath } ` );
315+ },
316+ dependencies: [],
317+ postDependencies: [' default@BuildJS' ]
318+ })
319+ }
320+ }
321+ }
322+
323+ export default {
324+ system: hapTasks , /* Built-in plugin of Hvigor. It cannot be modified. */
325+ plugins:[generatePushyBuildTime ()] /* Custom plugin to extend the functionality of Hvigor. */
326+ }
327+ ` ` `
328+
281329在 ` harmony / entry / src / main / ets / RNPackagesFactory .ts ` 代码如下:
282330` ` ` ts
283331import type {RNPackageContext , RNPackage } from ' @rnoh/react-native-openharmony/ts' ;
0 commit comments