generate_project.rb 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. require 'xcodeproj'
  2. require 'fileutils'
  3. project_path = 'CelestiaTrace.xcodeproj'
  4. # Remove existing project if any
  5. FileUtils.rm_rf(project_path)
  6. # Create a new Xcode project
  7. project = Xcodeproj::Project.new(project_path)
  8. # Create groups
  9. main_group = project.main_group
  10. app_group = main_group.new_group('CelestiaTrace', 'CelestiaTrace')
  11. tests_group = main_group.new_group('CelestiaTraceTests', 'Tests/CelestiaTraceTests')
  12. # Helper to add files recursively
  13. def add_files_recursively(dir, group, target, project)
  14. return unless File.directory?(dir)
  15. Dir.foreach(dir) do |entry|
  16. next if entry == '.' || entry == '..' || entry == '.DS_Store'
  17. path = File.join(dir, entry)
  18. if File.directory?(path)
  19. # Create subgroup with path relative to the parent group
  20. subgroup = group.new_group(entry, entry)
  21. add_files_recursively(path, subgroup, target, project)
  22. elsif entry.end_with?('.swift')
  23. # Add file reference
  24. file_ref = group.new_file(entry)
  25. # Add to build phases
  26. target.add_file_references([file_ref])
  27. end
  28. end
  29. end
  30. # Create iOS App target
  31. app_target = project.new_target(:application, 'CelestiaTrace', :ios, '17.0')
  32. app_target.build_configurations.each do |config|
  33. config.build_settings['SWIFT_VERSION'] = '5.9'
  34. config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '17.0'
  35. config.build_settings['TARGETED_DEVICE_FAMILY'] = '1' # 1 for iPhone, 2 for iPad, 1,2 for both
  36. config.build_settings['SDKROOT'] = 'iphoneos'
  37. config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'com.celestia.trace'
  38. config.build_settings['GENERATE_INFOPLIST_FILE'] = 'NO'
  39. config.build_settings['INFOPLIST_FILE'] = 'CelestiaTrace/Resources/Info.plist'
  40. config.build_settings['INFOPLIST_KEY_UILaunchStoryboardName'] = 'LaunchScreen'
  41. config.build_settings['INFOPLIST_KEY_CFBundleDisplayName'] = '星痕'
  42. config.build_settings['INFOPLIST_KEY_UISupportedInterfaceOrientations'] = 'UIInterfaceOrientationPortrait'
  43. config.build_settings['INFOPLIST_KEY_NSMicrophoneUsageDescription'] = '需要麦克风权限以进行会议现场的音轨录音'
  44. config.build_settings['INFOPLIST_KEY_NSCameraUsageDescription'] = '需要相机权限以在现场录制中拍摄照片记录'
  45. config.build_settings['INFOPLIST_KEY_NSPhotoLibraryUsageDescription'] = '需要相册权限以选择照片记录'
  46. config.build_settings['INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription'] = '需要蓝牙权限以扫描和绑定 BLE 录音设备'
  47. config.build_settings['INFOPLIST_KEY_NSBluetoothPeripheralUsageDescription'] = '需要蓝牙权限以与录音设备传输数据'
  48. config.build_settings['MARKETING_VERSION'] = '1.0.0'
  49. config.build_settings['CURRENT_PROJECT_VERSION'] = '1'
  50. config.build_settings['ASSETCATALOG_COMPILER_APPICON_NAME'] = 'AppIcon'
  51. config.build_settings['CODE_SIGN_STYLE'] = 'Automatic'
  52. # Enable SwiftData & SwiftUI previews support
  53. config.build_settings['DEVELOPMENT_ASSET_PATHS'] = '""'
  54. end
  55. # Create iOS Test target
  56. test_target = project.new_target(:unit_test_bundle, 'CelestiaTraceTests', :ios, '17.0')
  57. test_target.build_configurations.each do |config|
  58. config.build_settings['SWIFT_VERSION'] = '5.9'
  59. config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '17.0'
  60. config.build_settings['SDKROOT'] = 'iphoneos'
  61. config.build_settings['GENERATE_INFOPLIST_FILE'] = 'YES'
  62. config.build_settings['TEST_TARGET_NAME'] = 'CelestiaTrace'
  63. config.build_settings['BUNDLE_LOADER'] = '$(TEST_HOST)'
  64. config.build_settings['TEST_HOST'] = '$(BUILT_PRODUCTS_DIR)/CelestiaTrace.app/CelestiaTrace'
  65. end
  66. # Set up target dependency: Test target depends on App target
  67. test_target.add_dependency(app_target)
  68. # Add files to targets
  69. add_files_recursively('CelestiaTrace', app_group, app_target, project)
  70. add_files_recursively('Tests/CelestiaTraceTests', tests_group, test_target, project)
  71. # Add the asset catalog (AppIcon and launch-screen color) to the app target.
  72. assets_ref = app_group.new_file('Resources/Assets.xcassets')
  73. app_target.resources_build_phase.add_file_reference(assets_ref)
  74. launch_screen_ref = app_group.new_file('Resources/LaunchScreen.storyboard')
  75. app_target.resources_build_phase.add_file_reference(launch_screen_ref)
  76. app_group.new_file('Resources/Info.plist')
  77. # Save project
  78. project.save
  79. puts "Successfully created CelestiaTrace.xcodeproj"