1- const fs = require ( "fs" ) ;
2- const path = require ( "path" ) ;
1+ import fs from "fs" ;
2+ import path from "path" ;
3+ import { fileURLToPath } from "url" ;
4+
5+ // Resolve __dirname in ES module
6+ const __filename = fileURLToPath ( import . meta. url ) ;
7+ const __dirname = path . dirname ( __filename ) ;
38
49const appConfigPath = path . join ( __dirname , "../app.config.js" ) ;
5- const appConfig = require ( appConfigPath ) ;
10+
11+ // Import `app.config.js` dynamically
12+ const { default : appConfig } = await import ( appConfigPath ) ;
613
714// Split version into major.minor.patch
815const [ major , minor , patch ] = appConfig . expo . version . split ( "." ) . map ( Number ) ;
@@ -11,6 +18,7 @@ const newVersion = `${major}.${minor}.${patch + 1}`;
1118// Update build number (Android versionCode)
1219const newBuildNumber = ( appConfig . expo . android . versionCode || 1 ) + 1 ;
1320
21+ // Generate updated configuration
1422const updatedConfig = `export default ${ JSON . stringify (
1523 {
1624 ...appConfig ,
@@ -31,5 +39,6 @@ const updatedConfig = `export default ${JSON.stringify(
3139 2
3240) . replace ( / " ( [ ^ " ] + ) " : / g, "$1:" ) } ;`;
3341
42+ // Write updated configuration back to file
3443fs . writeFileSync ( appConfigPath , updatedConfig ) ;
3544console . log ( `Updated to v${ newVersion } (build ${ newBuildNumber } )` ) ;
0 commit comments