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 docProvider = path . resolve ( __dirname , "../../../platforms/android/app/src/main/java/com/foxdebug/acode/rk/exec/terminal/AlpineDocumentProvider.java" ) ;
7- const repeatChar = ( char , times ) => {
8- let res = "" ;
9- while ( -- times >= 0 ) res += char ;
10- return res ;
11- } ;
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+ ) ;
1213
13- try {
14- const config = fs . readFileSync ( configXML , "utf8" ) ;
15- const appName = / w i d g e t i d = " ( [ 0 - 9 a - z A - Z \. \- _ ] * ) " / . exec ( config ) [ 1 ] . split ( "." ) . pop ( ) ;
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+ }
1621
22+ const data = fs . readFileSync ( filePath , "utf8" ) ;
1723
18-
19- const docProviderData = fs . readFileSync ( docProvider , "utf8" ) ;
20- const newFileData = docProviderData . 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` ) ;
21- fs . writeFileSync ( docProvider , newFileData ) ;
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+ ) ;
2228
29+ fs . writeFileSync ( filePath , updated ) ;
30+ }
2331
24-
32+ try {
33+ if ( ! fs . existsSync ( configXML ) ) {
34+ throw new Error ( "config.xml not found" ) ;
35+ }
36+
37+ const config = fs . readFileSync ( configXML , "utf8" ) ;
38+ const match = / w i d g e t \s + i d = " ( [ 0 - 9 a - z A - Z . \- _ ] + ) " / . exec ( config ) ;
2539
26- const fileData = fs . readFileSync ( menuJava , "utf8" ) ;
27- 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` ) ;
28- fs . writeFileSync ( menuJava , newFileData ) ;
40+ if ( ! match ) {
41+ throw new Error ( "Could not extract widget id from config.xml" ) ;
42+ }
2943
44+ const appName = match [ 1 ] . split ( "." ) . pop ( ) ;
3045
46+ replaceImport ( docProvider , appName ) ;
47+ replaceImport ( menuJava , appName ) ;
3148
3249 const msg = `==== Changed package to com.foxdebug.${ appName } ====` ;
3350
34- console . log ( "" ) ;
35- console . log ( repeatChar ( "=" , msg . length ) ) ;
51+ console . log ( "\n" + repeatChar ( "=" , msg . length ) ) ;
3652 console . log ( msg ) ;
37- console . log ( repeatChar ( "=" , msg . length ) ) ;
38- console . log ( "" ) ;
53+ console . log ( repeatChar ( "=" , msg . length ) + "\n" ) ;
3954
4055} catch ( error ) {
41- console . error ( error ) ;
56+ console . error ( "❌ Error:" , error . message ) ;
4257 process . exit ( 1 ) ;
4358}
0 commit comments