211 lines
5.2 KiB
JavaScript
211 lines
5.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* iOS Build Script
|
|
* Automated build process for iOS using EAS Build or local Xcode
|
|
*
|
|
* Usage:
|
|
* bun run scripts/build-ios.ts --testflight # Build and submit to TestFlight
|
|
* bun run scripts/build-ios.ts --development # Development build
|
|
* bun run scripts/build-ios.ts --preview # Preview build
|
|
*/
|
|
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { exec } from 'child_process';
|
|
import { promisify } from 'util';
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
interface BuildOptions {
|
|
buildType: 'testflight' | 'development' | 'preview' | 'production';
|
|
autoSubmit: boolean;
|
|
skipCleanBuild: boolean;
|
|
}
|
|
|
|
async function checkEASCLI() {
|
|
try {
|
|
await execAsync('eas --version');
|
|
console.log('✅ EAS CLI found\n');
|
|
return true;
|
|
} catch {
|
|
console.error('❌ EAS CLI not found');
|
|
console.error('Install with: npm install -g eas-cli');
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
async function checkEnvironment() {
|
|
console.log('🔍 Checking environment...\n');
|
|
|
|
// Check .env files
|
|
const envFiles = ['apps/mobile/.env', 'apps/mobile/.env.production'];
|
|
|
|
for (const file of envFiles) {
|
|
if (fs.existsSync(file)) {
|
|
console.log(`✅ Found ${file}`);
|
|
}
|
|
}
|
|
|
|
console.log('\n');
|
|
}
|
|
|
|
async function incrementVersion() {
|
|
console.log('📦 Updating version...\n');
|
|
|
|
const appJsonPath = path.join(process.cwd(), 'apps/mobile/app.json');
|
|
const appJson = JSON.parse(fs.readFileSync(appJsonPath, 'utf-8'));
|
|
|
|
const currentVersion = appJson.expo.version;
|
|
const [major, minor, patch] = currentVersion.split('.').map(Number);
|
|
|
|
// Increment patch version
|
|
const newVersion = `${major}.${minor}.${patch + 1}`;
|
|
|
|
appJson.expo.version = newVersion;
|
|
appJson.expo.ios.buildNumber = (parseInt(appJson.expo.ios.buildNumber || '1') + 1).toString();
|
|
|
|
fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 2));
|
|
|
|
console.log(`✅ Version updated: ${currentVersion} → ${newVersion}\n`);
|
|
|
|
return newVersion;
|
|
}
|
|
|
|
async function buildIOS(options: BuildOptions, version: string) {
|
|
console.log(`🚀 Building iOS (${options.buildType})...\n`);
|
|
|
|
const buildArgs = [
|
|
'eas build',
|
|
'--platform ios',
|
|
`--${options.buildType}`,
|
|
!options.skipCleanBuild ? '--clean' : '',
|
|
options.autoSubmit && options.buildType === 'testflight' ? '--auto-submit' : '',
|
|
]
|
|
.filter(Boolean)
|
|
.join(' ');
|
|
|
|
try {
|
|
console.log(`Running: ${buildArgs}\n`);
|
|
|
|
const { stdout, stderr } = await execAsync(buildArgs, {
|
|
cwd: path.join(process.cwd(), 'apps/mobile'),
|
|
stdio: 'inherit',
|
|
timeout: 1200000, // 20 minutes
|
|
});
|
|
|
|
console.log(stdout);
|
|
|
|
if (stderr) {
|
|
console.warn('Warnings:', stderr);
|
|
}
|
|
|
|
console.log(`\n✅ iOS build completed successfully!\n`);
|
|
|
|
return true;
|
|
} catch (err) {
|
|
console.error('❌ iOS build failed:', err);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function publishTestFlight(version: string) {
|
|
console.log('🚀 Publishing to TestFlight...\n');
|
|
|
|
console.log(`
|
|
📱 TestFlight Publication Instructions:
|
|
|
|
1. Go to appstoreconnect.apple.com
|
|
2. Select ShopList app
|
|
3. Click "TestFlight"
|
|
4. Select the build (version ${version})
|
|
5. Fill in test information:
|
|
- What to Test: Describe changes
|
|
- Beta App Description: User-friendly description
|
|
- Beta App Review Information: Contact info
|
|
6. Click "Send for Review"
|
|
7. Wait for Apple review (~24-48 hours)
|
|
8. Add external testers:
|
|
- Create group or use default
|
|
- Add family member emails
|
|
- They receive invite link
|
|
|
|
9. Family members:
|
|
- Click link from email
|
|
- Tap "Open in TestFlight"
|
|
- Tap "Install"
|
|
- Done!
|
|
`);
|
|
|
|
console.log('✅ Build ready for TestFlight\n');
|
|
}
|
|
|
|
async function saveDeploymentInfo(version: string, buildType: string) {
|
|
const info = {
|
|
version,
|
|
buildType,
|
|
timestamp: new Date().toISOString(),
|
|
platform: 'ios',
|
|
};
|
|
|
|
if (!fs.existsSync('.deployment')) {
|
|
fs.mkdirSync('.deployment', { recursive: true });
|
|
}
|
|
|
|
fs.appendFileSync(path.join('.deployment', 'builds.log'), JSON.stringify(info) + '\n');
|
|
|
|
console.log(`📝 Build info saved to .deployment/builds.log\n`);
|
|
}
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
|
|
let buildType: BuildOptions['buildType'] = 'testflight';
|
|
let autoSubmit = false;
|
|
let skipCleanBuild = false;
|
|
|
|
for (const arg of args) {
|
|
if (arg === '--testflight') buildType = 'testflight';
|
|
if (arg === '--development') buildType = 'development';
|
|
if (arg === '--preview') buildType = 'preview';
|
|
if (arg === '--production') buildType = 'production';
|
|
if (arg === '--auto-submit') autoSubmit = true;
|
|
if (arg === '--skip-clean') skipCleanBuild = true;
|
|
}
|
|
|
|
console.log('🍎 ShopList iOS Build Script\n');
|
|
|
|
// Check EAS CLI
|
|
await checkEASCLI();
|
|
|
|
// Check environment
|
|
await checkEnvironment();
|
|
|
|
// Increment version
|
|
const version = await incrementVersion();
|
|
|
|
// Build iOS
|
|
const buildOptions: BuildOptions = {
|
|
buildType,
|
|
autoSubmit,
|
|
skipCleanBuild,
|
|
};
|
|
|
|
const success = await buildIOS(buildOptions, version);
|
|
|
|
if (success) {
|
|
// Save deployment info
|
|
await saveDeploymentInfo(version, buildType);
|
|
|
|
// Show next steps
|
|
if (buildType === 'testflight') {
|
|
await publishTestFlight(version);
|
|
}
|
|
|
|
console.log('🎉 iOS build process complete!\n');
|
|
} else {
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|