| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- require 'xcodeproj'
- require 'fileutils'
- project_path = 'CelestiaTrace.xcodeproj'
- # Remove existing project if any
- FileUtils.rm_rf(project_path)
- # Create a new Xcode project
- project = Xcodeproj::Project.new(project_path)
- # Create groups
- main_group = project.main_group
- app_group = main_group.new_group('CelestiaTrace', 'CelestiaTrace')
- tests_group = main_group.new_group('CelestiaTraceTests', 'Tests/CelestiaTraceTests')
- # Helper to add files recursively
- def add_files_recursively(dir, group, target, project)
- return unless File.directory?(dir)
- Dir.foreach(dir) do |entry|
- next if entry == '.' || entry == '..' || entry == '.DS_Store'
- path = File.join(dir, entry)
-
- if File.directory?(path)
- # Create subgroup with path relative to the parent group
- subgroup = group.new_group(entry, entry)
- add_files_recursively(path, subgroup, target, project)
- elsif entry.end_with?('.swift')
- # Add file reference
- file_ref = group.new_file(entry)
- # Add to build phases
- target.add_file_references([file_ref])
- end
- end
- end
- # Create iOS App target
- app_target = project.new_target(:application, 'CelestiaTrace', :ios, '17.0')
- app_target.build_configurations.each do |config|
- config.build_settings['SWIFT_VERSION'] = '5.9'
- config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '17.0'
- config.build_settings['TARGETED_DEVICE_FAMILY'] = '1' # 1 for iPhone, 2 for iPad, 1,2 for both
- config.build_settings['SDKROOT'] = 'iphoneos'
- config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'com.celestia.trace'
- config.build_settings['GENERATE_INFOPLIST_FILE'] = 'NO'
- config.build_settings['INFOPLIST_FILE'] = 'CelestiaTrace/Resources/Info.plist'
- config.build_settings['INFOPLIST_KEY_UILaunchStoryboardName'] = 'LaunchScreen'
- config.build_settings['INFOPLIST_KEY_CFBundleDisplayName'] = '星痕 CelestiaTrace'
- config.build_settings['INFOPLIST_KEY_UISupportedInterfaceOrientations'] = 'UIInterfaceOrientationPortrait'
- config.build_settings['INFOPLIST_KEY_NSMicrophoneUsageDescription'] = '需要麦克风权限以进行会议现场的音轨录音'
- config.build_settings['INFOPLIST_KEY_NSLocationWhenInUseUsageDescription'] = '需要定位权限以在笔记和照片记录中插入所在位置'
- config.build_settings['INFOPLIST_KEY_NSCameraUsageDescription'] = '需要相机权限以在现场录制中拍摄照片记录'
- config.build_settings['INFOPLIST_KEY_NSPhotoLibraryUsageDescription'] = '需要相册权限以选择照片记录'
- config.build_settings['INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription'] = '需要蓝牙权限以扫描和绑定 BLE 录音设备'
- config.build_settings['INFOPLIST_KEY_NSBluetoothPeripheralUsageDescription'] = '需要蓝牙权限以与录音设备传输数据'
- # Keep active microphone recordings running while the app is backgrounded or the device is locked.
- config.build_settings['INFOPLIST_KEY_UIBackgroundModes'] = 'audio bluetooth-central'
- config.build_settings['MARKETING_VERSION'] = '1.0.0'
- config.build_settings['CURRENT_PROJECT_VERSION'] = '1'
- config.build_settings['ASSETCATALOG_COMPILER_APPICON_NAME'] = 'AppIcon'
- config.build_settings['CODE_SIGN_STYLE'] = 'Automatic'
- # Enable SwiftData & SwiftUI previews support
- config.build_settings['DEVELOPMENT_ASSET_PATHS'] = '""'
- end
- # Create the Live Activity widget extension used on the Lock Screen and Dynamic Island.
- live_activity_target = project.new_target(
- :app_extension,
- 'CelestiaTraceLiveActivity',
- :ios,
- '17.0'
- )
- live_activity_target.build_configurations.each do |config|
- config.build_settings['SWIFT_VERSION'] = '5.9'
- config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '17.0'
- config.build_settings['TARGETED_DEVICE_FAMILY'] = '1'
- config.build_settings['SDKROOT'] = 'iphoneos'
- config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'com.celestia.trace.live-activity'
- config.build_settings['GENERATE_INFOPLIST_FILE'] = 'NO'
- config.build_settings['INFOPLIST_FILE'] = 'CelestiaTraceLiveActivity/Info.plist'
- config.build_settings['MARKETING_VERSION'] = '1.0.0'
- config.build_settings['CURRENT_PROJECT_VERSION'] = '1'
- config.build_settings['CODE_SIGN_STYLE'] = 'Automatic'
- config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'YES'
- config.build_settings['SKIP_INSTALL'] = 'YES'
- config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = '$(inherited) @executable_path/../../Frameworks'
- end
- live_activity_group = main_group.new_group(
- 'CelestiaTraceLiveActivity',
- 'CelestiaTraceLiveActivity'
- )
- live_activity_sources = %w[
- CelestiaTraceLiveActivityBundle.swift
- RecordingLiveActivityWidget.swift
- ].map { |filename| live_activity_group.new_file(filename) }
- live_activity_target.add_file_references(live_activity_sources)
- live_activity_group.new_file('Info.plist')
- app_target.add_dependency(live_activity_target)
- embed_extensions_phase = app_target.new_copy_files_build_phase('Embed Foundation Extensions')
- embed_extensions_phase.dst_subfolder_spec = '13'
- embed_extensions_phase.add_file_reference(live_activity_target.product_reference, true)
- # Create iOS Test target
- test_target = project.new_target(:unit_test_bundle, 'CelestiaTraceTests', :ios, '17.0')
- test_target.build_configurations.each do |config|
- config.build_settings['SWIFT_VERSION'] = '5.9'
- config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '17.0'
- config.build_settings['SDKROOT'] = 'iphoneos'
- config.build_settings['GENERATE_INFOPLIST_FILE'] = 'YES'
- config.build_settings['TEST_TARGET_NAME'] = 'CelestiaTrace'
- config.build_settings['BUNDLE_LOADER'] = '$(TEST_HOST)'
- config.build_settings['TEST_HOST'] = '$(BUILT_PRODUCTS_DIR)/CelestiaTrace.app/CelestiaTrace'
- end
- # Set up target dependency: Test target depends on App target
- test_target.add_dependency(app_target)
- # Add files to targets
- add_files_recursively('CelestiaTrace', app_group, app_target, project)
- add_files_recursively('Tests/CelestiaTraceTests', tests_group, test_target, project)
- shared_activity_ref = project.files.find do |file|
- file.path == 'RecordingActivityAttributes.swift'
- end
- live_activity_target.add_file_references([shared_activity_ref]) if shared_activity_ref
- # Add the asset catalog (AppIcon and launch-screen color) to the app target.
- assets_ref = app_group.new_file('Resources/Assets.xcassets')
- app_target.resources_build_phase.add_file_reference(assets_ref)
- launch_screen_ref = app_group.new_file('Resources/LaunchScreen.storyboard')
- app_target.resources_build_phase.add_file_reference(launch_screen_ref)
- app_group.new_file('Resources/Info.plist')
- # Save project
- project.save
- puts "Successfully created CelestiaTrace.xcodeproj"
|