Skip to content

Commit b79dbf1

Browse files
fix: acode free build (Acode-Foundation#1908)
* fixed: acode free build * fix: set default import pkg name * Apply suggestion from @greptile-apps[bot] Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * refactor * refactor --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 8473a88 commit b79dbf1

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed
Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,58 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const fs = require("fs");
2+
const path = require("path");
33

44
const 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+
/(import\s+com\.foxdebug\.)(acode|acodefree)(\.R;)/,
26+
`$1${appName}$3`
27+
);
28+
29+
fs.writeFileSync(filePath, updated);
30+
}
1131

1232
try {
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 = /widget id="([0-9a-zA-Z\.\-_]*)"/.exec(config)[1].split(".").pop();
16-
const newFileData = fileData.replace(/(import com\.foxdebug\.)(acode|acodefree)(.R;)/, `$1${appName}$3`);
17-
fs.writeFileSync(menuJava, newFileData);
38+
const match = /widget\s+id="([0-9a-zA-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

Comments
 (0)