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 ) ;
3
8
4
9
const 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 ) ;
6
13
7
14
// Split version into major.minor.patch
8
15
const [ major , minor , patch ] = appConfig . expo . version . split ( "." ) . map ( Number ) ;
@@ -11,6 +18,7 @@ const newVersion = `${major}.${minor}.${patch + 1}`;
11
18
// Update build number (Android versionCode)
12
19
const newBuildNumber = ( appConfig . expo . android . versionCode || 1 ) + 1 ;
13
20
21
+ // Generate updated configuration
14
22
const updatedConfig = `export default ${ JSON . stringify (
15
23
{
16
24
...appConfig ,
@@ -31,5 +39,6 @@ const updatedConfig = `export default ${JSON.stringify(
31
39
2
32
40
) . replace ( / " ( [ ^ " ] + ) " : / g, "$1:" ) } ;`;
33
41
42
+ // Write updated configuration back to file
34
43
fs . writeFileSync ( appConfigPath , updatedConfig ) ;
35
44
console . log ( `Updated to v${ newVersion } (build ${ newBuildNumber } )` ) ;
0 commit comments