1- const fs = require ( 'fs' ) ;
2- const path = require ( ' path' ) ;
1+ const fs = require ( "fs" ) ;
2+ const path = require ( " path" ) ;
33
44const configXML = path . resolve ( __dirname , "../../../config.xml" ) ;
5- const menuJava = path . resolve ( __dirname , "../../../platforms/android/app/src/main/java/com/foxdebug/browser/Menu.java" ) ;
6- const repeatChar = ( char , times ) => {
7- let res = "" ;
8- while ( -- times >= 0 ) res += char ;
9- return res ;
10- } ;
5+ const menuJava = path . resolve (
6+ __dirname ,
7+ "../../../platforms/android/app/src/main/java/com/foxdebug/browser/Menu.java"
8+ ) ;
9+ const docProvider = path . resolve (
10+ __dirname ,
11+ "../../../platforms/android/app/src/main/java/com/foxdebug/acode/rk/exec/terminal/AlpineDocumentProvider.java"
12+ ) ;
13+
14+ const repeatChar = ( char , times ) => char . repeat ( times ) ;
15+
16+ function replaceImport ( filePath , appName ) {
17+ if ( ! fs . existsSync ( filePath ) ) {
18+ console . warn ( `⚠ File not found: ${ filePath } ` ) ;
19+ return ;
20+ }
21+
22+ const data = fs . readFileSync ( filePath , "utf8" ) ;
23+
24+ const updated = data . replace (
25+ / ( i m p o r t \s + c o m \. f o x d e b u g \. ) ( a c o d e | a c o d e f r e e ) ( \. R ; ) / ,
26+ `$1${ appName } $3`
27+ ) ;
28+
29+ fs . writeFileSync ( filePath , updated ) ;
30+ }
1131
1232try {
33+ if ( ! fs . existsSync ( configXML ) ) {
34+ throw new Error ( "config.xml not found" ) ;
35+ }
36+
1337 const config = fs . readFileSync ( configXML , "utf8" ) ;
14- const fileData = fs . readFileSync ( menuJava , "utf8" ) ;
15- const appName = / w i d g e t i d = " ( [ 0 - 9 a - z A - Z \. \- _ ] * ) " / . exec ( config ) [ 1 ] . split ( "." ) . pop ( ) ;
16- const newFileData = fileData . replace ( / ( i m p o r t c o m \. f o x d e b u g \. ) ( a c o d e | a c o d e f r e e ) ( .R ; ) / , `$1${ appName } $3` ) ;
17- fs . writeFileSync ( menuJava , newFileData ) ;
38+ const match = / w i d g e t \s + i d = " ( [ 0 - 9 a - z A - Z . \- _ ] + ) " / . exec ( config ) ;
39+
40+ if ( ! match ) {
41+ throw new Error ( "Could not extract widget id from config.xml" ) ;
42+ }
43+
44+ const appName = match [ 1 ] . split ( "." ) . pop ( ) ;
45+
46+ replaceImport ( docProvider , appName ) ;
47+ replaceImport ( menuJava , appName ) ;
1848
1949 const msg = `==== Changed package to com.foxdebug.${ appName } ====` ;
2050
21- console . log ( "" ) ;
22- console . log ( repeatChar ( "=" , msg . length ) ) ;
51+ console . log ( "\n" + repeatChar ( "=" , msg . length ) ) ;
2352 console . log ( msg ) ;
24- console . log ( repeatChar ( "=" , msg . length ) ) ;
25- console . log ( "" ) ;
53+ console . log ( repeatChar ( "=" , msg . length ) + "\n" ) ;
2654
2755} catch ( error ) {
28- console . error ( error ) ;
56+ console . error ( "❌ Error:" , error . message ) ;
2957 process . exit ( 1 ) ;
3058}
0 commit comments