-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocal-build.js
More file actions
96 lines (77 loc) · 2.64 KB
/
local-build.js
File metadata and controls
96 lines (77 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
console.log('🚀 zkLove Local Build Script');
console.log('============================');
async function localBuild() {
try {
const platform = process.argv[2] || 'android';
const buildType = process.argv[3] || 'debug';
console.log(`📱 Building for ${platform} (${buildType})`);
// Set production environment
process.env.NODE_ENV = 'production';
// Step 1: Clean previous builds
console.log('🧹 Cleaning previous builds...');
if (fs.existsSync('dist')) {
if (process.platform === 'win32') {
execSync('rmdir /s /q dist', { stdio: 'inherit' });
} else {
execSync('rm -rf dist', { stdio: 'inherit' });
}
}
if (fs.existsSync('www')) {
if (process.platform === 'win32') {
execSync('rmdir /s /q www', { stdio: 'inherit' });
} else {
execSync('rm -rf www', { stdio: 'inherit' });
}
}
// Step 2: Build web version
console.log('🌐 Building web version...');
execSync('npx expo export --platform web', { stdio: 'inherit' });
// Step 3: Copy to Capacitor
console.log('📦 Copying to Capacitor...');
execSync('npx cap copy', { stdio: 'inherit' });
if (platform === 'android') {
// Step 4: Build Android APK
console.log('🤖 Building Android APK...');
if (buildType === 'release') {
execSync('npx cap build android --prod', { stdio: 'inherit' });
} else {
execSync('npx cap run android', { stdio: 'inherit' });
}
// Find the APK
const apkPath = findAPK();
if (apkPath) {
console.log(`✅ APK created: ${apkPath}`);
}
} else if (platform === 'ios') {
// Step 4: Build iOS
console.log('🍎 Building iOS...');
execSync('npx cap run ios', { stdio: 'inherit' });
} else if (platform === 'web') {
console.log('✅ Web build completed in dist/ folder');
}
console.log('🎉 Build completed successfully!');
} catch (error) {
console.error('💥 Build failed:', error.message);
process.exit(1);
}
}
function findAPK() {
const possiblePaths = [
'android/app/build/outputs/apk/debug/app-debug.apk',
'android/app/build/outputs/apk/release/app-release.apk',
'android/app/build/outputs/apk/development/app-development.apk'
];
for (const apkPath of possiblePaths) {
if (fs.existsSync(apkPath)) {
return apkPath;
}
}
return null;
}
if (require.main === module) {
localBuild().catch(console.error);
}
module.exports = { localBuild };