File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Example/harmony_use_pushy/harmony/entry Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 11import { hapTasks } from '@ohos/hvigor-ohos-plugin' ;
22import fs from 'fs' ;
33import path from 'path' ;
4+
45export 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 ( / " v e r s i o n " : \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' ]
You can’t perform that action at this time.
0 commit comments