Section 8/131 menit

8. Migrasi Bertahap ke Project Generator

8. Migrasi Bertahap ke Project Generator

Fase 1 — XcodeGen: Eliminasi Merge Conflict

swift
# Langkah 1: Install XcodeGen
brew install xcodegen

# Langkah 2: Ekstrak konfigurasi dari project.pbxproj yang ada
# XcodeGen tidak punya tool otomatis — proses ini manual
# Gunakan xcode-project-to-yaml (tool komunitas) sebagai starting point
gem install xcode-proj-to-yaml
xcode-proj-to-yaml MyApp.xcodeproj

# Langkah 3: Edit project.yml hasil generate — hapus hal yang tidak perlu,
# pindahkan build settings ke xcconfig untuk kerapian lebih baik

# Langkah 4: Tambahkan ke .gitignore
echo "*.xcodeproj" >> .gitignore
echo "*.xcworkspace" >> .gitignore

# Langkah 5: Tambahkan ke git hook agar auto-regenerate
cat > .git/hooks/post-checkout << 'EOF'
#!/bin/bash
if command -v xcodegen &> /dev/null; then
    xcodegen generate --quiet
fi
EOF
chmod +x .git/hooks/post-checkout

Fase 2 — Modularisasi + Tuist

swift
# Langkah 1: Konversi project.yml ke Tuist Project.swift
# Tuist menyediakan panduan migrasi dari XcodeGen
# https://docs.tuist.io/tutorials/tuist/migrate-from-xcodegen

# Langkah 2: Buat struktur folder Tuist/
mkdir Tuist
cat > Tuist/Config.swift << 'EOF'
import ProjectDescription
let config = Config()
EOF

# Langkah 3: Pindah satu module sekaligus ke Tuist project definition
# Mulai dari leaf modules (tidak ada dependency ke first-party modules)

# Langkah 4: Aktifkan binary caching setelah semua modules di-migrasi
tuist cache

Fase 3 — Bazel (untuk tim yang butuh)

Migrasi ke Bazel adalah investasi besar. Strategi yang direkomendasikan:

swift
1. Pilot dengan satu module leaf (tidak ada first-party deps)
2. Validasi bahwa output artifact identik dengan Xcode build
3. Setup remote cache (BuildBuddy/EngFlow/self-hosted)
4. Ukur waktu build sebelum/sesudah
5. Expand ke module lain secara bertahap
6. Pertahankan Xcode project gen (rules_xcodeproj) agar developer tetap bisa pakai Xcode