Skip to content

Commit 97df703

Browse files
authored
feat: add Windows support in build script (#6)
1 parent bf459cc commit 97df703

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

scripts/build.js

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
const os = require('os');
1+
const os = require("os");
22
const { execSync } = require("child_process");
33
const path = require("path");
4-
5-
6-
const platform = os.platform(); // e.g., 'linux', 'darwin', 'win32',"*bsd"
7-
8-
if (platform !== "linux" && !platform.includes("bsd") && platform !== "darwin") {
9-
log.error(`Unsupported platform: ${platform}. A Unix-like system is required.`);
4+
const fs = require("fs");
5+
6+
const platform = os.platform();
7+
const isWindows = platform === "win32";
8+
9+
// Check for supported platforms
10+
if (
11+
!["linux", "darwin", "win32"].includes(platform) &&
12+
!platform.includes("bsd")
13+
) {
14+
console.error(`Unsupported platform: ${platform}`);
15+
process.exit(1);
1016
}
1117

1218

13-
1419
// CLI args: appType (free/paid), buildMode (d/p or debug/prod)
1520
const appType = (process.argv[2] || "paid").toLowerCase();
1621
const buildMode = (process.argv[3] || "d").toLowerCase();
@@ -68,11 +73,10 @@ try {
6873
const match = versionOutput.match(/version\s+"(\d+)(?:\.(\d+))?/);
6974
const majorVersion = match ? parseInt(match[1]) : null;
7075

71-
const major = match?.[1];
72-
const minor = match?.[2];
73-
const versionString = major ? `${major}${minor ? '.' + minor : ''}` : 'unknown';
76+
const versionString = match?.[1]
77+
? `${match[1]}${match[2] ? "." + match[2] : ""}`
78+
: "unknown";
7479
log.info(`Current Java version is ${versionString}.`);
75-
7680

7781
if (!majorVersion || majorVersion < 21) {
7882
log.error(`Java 21 is required.`);
@@ -91,6 +95,7 @@ log.info(`Build Mode: ${normalizedMode}`);
9195
//edit the android/app/src/free/AndroidManifest.xml file
9296
const AD_APP_ID = "ca-app-pub-5911839694379275~4255791238";
9397
const PROJECT_ROOT = execSync("npm prefix").toString().trim();
98+
const androidDir = path.join(PROJECT_ROOT, "android");
9499

95100
try {
96101
// Plugin logic based on app type
@@ -123,21 +128,38 @@ try {
123128
);
124129
}
125130

126-
execSync(`mkdir -p ${PROJECT_ROOT}/www/css/build && mkdir -p ${PROJECT_ROOT}/www/js/build`)
131+
// Create build folders
132+
fs.mkdirSync(path.join(PROJECT_ROOT, "www", "css", "build"), {
133+
recursive: true,
134+
});
135+
fs.mkdirSync(path.join(PROJECT_ROOT, "www", "js", "build"), {
136+
recursive: true,
137+
});
127138

128-
// Webpack build
139+
// Webpack
129140
const webpackMode =
130-
normalizedMode.toLowerCase() === "release" ? "production" : "development";
141+
normalizedMode === "Release" ? "production" : "development";
131142
execSync(`webpack --progress --mode ${webpackMode}`, { stdio: "inherit" });
132143

144+
// Preload styles
133145
execSync("node ./utils/loadStyles.js", { stdio: "inherit" });
146+
147+
// Sync
134148
execSync("npm run sync", { stdio: "inherit" });
135149

136-
// Final Gradle command
150+
// Ensure gradlew is executable on Unix systems
151+
const gradlewPath = path.join(
152+
androidDir,
153+
isWindows ? "gradlew.bat" : "gradlew",
154+
);
155+
if (!isWindows) {
156+
fs.chmodSync(gradlewPath, 755);
157+
}
158+
159+
// Run gradle task
137160
const gradleTask = `assemble${normalizedType}${normalizedMode}`;
138-
execSync(`sh "${PROJECT_ROOT}/scripts/gradlew-link" ${gradleTask}`, {
139-
stdio: "inherit",
140-
});
161+
const gradleCmd = `${isWindows ? "gradlew.bat" : "./gradlew"} ${gradleTask}`;
162+
execSync(gradleCmd, { cwd: androidDir, stdio: "inherit" });
141163

142164
log.success("Build completed successfully.");
143165
} catch (e) {

scripts/gradlew-link

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)