-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobile-export.js
More file actions
35 lines (28 loc) Β· 1.08 KB
/
Copy pathmobile-export.js
File metadata and controls
35 lines (28 loc) Β· 1.08 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
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const appApiDir = path.join(__dirname, 'app', 'api');
const backupApiDir = path.join(__dirname, 'app', '_api');
console.log('π Starting Mobile Export Process...');
try {
// 1. Temporarily hide API routes from Next.js (output: export doesn't support them)
if (fs.existsSync(appApiDir)) {
console.log('π¦ Hiding API routes...');
fs.renameSync(appApiDir, backupApiDir);
}
// 2. Run the build
console.log('ποΈ Building static frontend...');
execSync('npx next build', { stdio: 'inherit' });
// 3. Sync with Capacitor
console.log('π² Syncing with Capacitor...');
execSync('npx cap sync', { stdio: 'inherit' });
console.log('β
Mobile build complete! Your "out" folder is ready and synced to Android/iOS projects.');
} catch (error) {
console.error('β Export failed:', error.message);
} finally {
// 4. Restore API routes
if (fs.existsSync(backupApiDir)) {
console.log('βͺ Restoring API routes...');
fs.renameSync(backupApiDir, appApiDir);
}
}