Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
ideyaa committed Sep 16, 2024
1 parent 08dc187 commit 422a17f
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 94 deletions.
1 change: 1 addition & 0 deletions solara/lib/core/brands/brand_onboarder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def clone_brand
Solara.logger.debug("Cloning #{@clone_brand_key} to #{@brand_key}")
source = FilePath.brand(@clone_brand_key)
destination = FilePath.brand(@brand_key)
FileUtils.rm_rf(destination) if File.exist?(destination)
FolderCopier.new(source, destination).copy
end

Expand Down
12 changes: 10 additions & 2 deletions solara/lib/core/brands/brand_switcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,21 @@ def switch
BrandConfigManager.new(@brand_key).generate_ios_xcconfig
@theme_switcher.switch(Language::Swift)
@brand_config_switcher.switch(Language::Swift)
update_xcode_project
switch_infoplist
switch_xcode_project
@resource_manager.update_ios
end

private

def update_xcode_project
def switch_infoplist
Solara.logger.start_step("Switch Info.plist")
project_path = FilePath.xcode_project
InfoPlistSwitcher.new(project_path, @brand_key).switch
Solara.logger.end_step("Switch Info.plist")
end

def switch_xcode_project
Solara.logger.start_step("Switch Xcode project")
project_path = FilePath.xcode_project
XcodeProjectSwitcher.new(project_path, @brand_key).switch
Expand Down
2 changes: 0 additions & 2 deletions solara/lib/core/dashboard/brand/source/BrandRemoteSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class BrandRemoteSource {
"name": "Android Platform Configuration",
"inputType": "text",
"content": {
"brandName": "",
"applicationId": "",
"versionName": "1.0.0",
"versionCode": 1,
Expand All @@ -90,7 +89,6 @@ class BrandRemoteSource {
"name": "iOS Platform Configuration",
"inputType": "text",
"content": {
"PRODUCT_NAME": "",
"PRODUCT_BUNDLE_IDENTIFIER": "",
"MARKETING_VERSION": "1.0.0",
"BUNDLE_VERSION": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"type": "object",
"required": [
"brandName",
"applicationId",
"versionName",
"versionCode"
],
"properties": {
"brandName": {
"type": "string"
},
"applicationId": {
"type": "string"
},
Expand Down
5 changes: 0 additions & 5 deletions solara/lib/core/doctor/schema/platform/ios/ios_config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"type": "object",
"properties": {
"PRODUCT_NAME": {
"type": "string",
"description": "The name of the product."
},
"PRODUCT_BUNDLE_IDENTIFIER": {
"type": "string",
"description": "The bundle identifier of the product."
Expand All @@ -19,7 +15,6 @@
}
},
"required": [
"PRODUCT_NAME",
"PRODUCT_BUNDLE_IDENTIFIER",
"MARKETING_VERSION",
"BUNDLE_VERSION"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ def ios_config
:ios_config,
issue_type: Issue::ERROR)

issues += @validator.validate_single_property(
'PRODUCT_NAME',
:ios_config,
issue_type: Issue::ERROR)

issues += @validator.validate_property_duplicates(
'PRODUCT_NAME',
:ios_config,
issue_type: Issue::WARNING)

issues += @validator.validate_single_property(
'PRODUCT_BUNDLE_IDENTIFIER',
:ios_config,
Expand Down Expand Up @@ -58,16 +48,6 @@ def android_config
:android_config,
issue_type: Issue::ERROR)

issues += @validator.validate_single_property(
'brandName',
:android_config,
issue_type: Issue::ERROR)

issues += @validator.validate_property_duplicates(
'brandName',
:android_config,
issue_type: Issue::WARNING)

issues += @validator.validate_single_property(
'applicationId',
:android_config,
Expand Down
2 changes: 0 additions & 2 deletions solara/lib/core/scripts/brand_config_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def add_basic_brand_info(config, platform)
def add_android_info(config, prefix: '')
android_config = load_config(FilePath.android_config(@brand_key))
config_mappings = {
'brandName' => 'BrandName',
'applicationId' => 'ApplicationId',
'versionName' => 'VersionName',
'versionCode' => 'VersionCode'
Expand All @@ -64,7 +63,6 @@ def add_android_info(config, prefix: '')
def add_ios_info(config, prefix: '')
ios_config = load_config(FilePath.ios_config(@brand_key))
config_mappings = {
'PRODUCT_NAME' => 'ProductName',
'PRODUCT_BUNDLE_IDENTIFIER' => 'BundleIdentifier',
'MARKETING_VERSION' => 'MarketingVersion',
'BUNDLE_VERSION' => 'BundleVersion'
Expand Down
11 changes: 11 additions & 0 deletions solara/lib/core/scripts/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def self.ios_config(brand_key)
File.join(ios_brand_root(brand_key), 'ios_config.json')
end

def self.project_infoplist_string_catalog
File.join(project_info_plist_directory, 'InfoPlist.xcstrings')
end

def self.brand_infoplist_string_catalog(brand_key)
File.join(ios_brand_root(brand_key), 'InfoPlist.xcstrings')
end

def self.brand_config(brand_key)
File.join(brands, brand_key, 'shared', 'brand_config.json')
end
Expand Down Expand Up @@ -382,6 +390,9 @@ def self.ios_artifacts
end
end

def self.project_info_plist_directory
Pathname.new(info_plist).parent.to_s
end

def self.info_plist
path = ProjectSettingsManager.instance.value('Info.plist', Platform::IOS)
Expand Down
8 changes: 2 additions & 6 deletions solara/lib/core/scripts/folder_copier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ def initialize(source_path, destination_path)
@destination_path = destination_path
end

def copy(delete_if_exists: true)
if File.exist?(@destination_path)
if delete_if_exists
FileUtils.rm_rf(@destination_path)
end
end
def copy
FileUtils.mkdir_p(@destination_path)
copy_files_and_folders(@source_path, @destination_path)
Solara.logger.debug("Copied #{@source_path} to #{@destination_path} successfully.")
end

private
Expand Down
26 changes: 17 additions & 9 deletions solara/lib/core/scripts/gitignore_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ def initialize(gitignore_path = '.gitignore')

def self.ignore
Solara.logger.start_step("Exclude Brand-Generated Files and Folders from Git")
GitignoreManager.new(FilePath.project_root)
.add_items([
"# Generated by Solara. Ignore redundant brand specific changes.",
"**/#{FilePath.artifacts_dir_name}/",
"**/#{FilePath.artifacts_dir_name_ios}/",
"solara/brands/current_app.json",
"solara/.solara/aliases/",
"solara/.solara/solara_settings.json",
])

items = [
"# Generated by Solara. Ignore redundant brand specific changes.",
"**/#{FilePath.artifacts_dir_name}/",
"**/#{FilePath.artifacts_dir_name_ios}/",
"solara/brands/current_app.json",
"solara/.solara/aliases/",
"solara/.solara/solara_settings.json",
]

if Platform.is_flutter || Platform.is_ios
items << FileManager.get_relative_path_to_root(FilePath.project_infoplist_string_catalog)
# The excluded InfoPlist.xcstrings maybe at the root. In this case we have to avoid ignoring the brands files.
items << '!solara/brands/**/InfoPlist.xcstrings'
end

GitignoreManager.new(FilePath.project_root).add_items(items)
Solara.logger.end_step("Exclude Brand-Generated Files and Folders from Git")
end

Expand Down
51 changes: 51 additions & 0 deletions solara/lib/core/scripts/platform/ios/infoplist_switcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$LOAD_PATH.unshift(File.expand_path(__dir__))

class InfoPlistSwitcher
def initialize(project_path, brand_key)
@project_path = project_path
@brand_key = brand_key
@project = Xcodeproj::Project.open(@project_path)
end

def switch
copy_string_catalog
update_info_plist
@project.save
Solara.logger.debug("Switched #{FilePath.info_plist} successfully.")
end

private

def copy_string_catalog
# Remove from project before copying
project_infoplist_string_catalog = FilePath.project_infoplist_string_catalog
if File.exist?(project_infoplist_string_catalog)
FileUtils.rm_rf(project_infoplist_string_catalog)
Solara.logger.debug("Deleted #{project_infoplist_string_catalog} successfully.")
end

source = FilePath.brand_infoplist_string_catalog(@brand_key)
destination = FilePath.project_info_plist_directory
FolderCopier.new(source, destination).copy
end

def update_info_plist
info_plist_path = FilePath.info_plist
manager = IOSPlistManager.new(@project, info_plist_path)
manager.set_info_plist_in_build_settings

xcconfig_values = {
'PRODUCT_BUNDLE_IDENTIFIER' => "$(PRODUCT_BUNDLE_IDENTIFIER)",
'MARKETING_VERSION' => "$(MARKETING_VERSION)",
'BUNDLE_VERSION' => "$(BUNDLE_VERSION)"
}

info_plist = Xcodeproj::Plist.read_from_path(info_plist_path)
info_plist['CFBundleIdentifier'] = xcconfig_values['PRODUCT_BUNDLE_IDENTIFIER']
info_plist['CFBundleShortVersionString'] = xcconfig_values['MARKETING_VERSION']
info_plist['CFBundleVersion'] = xcconfig_values['BUNDLE_VERSION']

Xcodeproj::Plist.write_to_path(info_plist, info_plist_path)
end

end
20 changes: 2 additions & 18 deletions solara/lib/core/scripts/platform/ios/ios_plist_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,15 @@ def initialize(project, info_plist_path)
@info_plist_path = info_plist_path
end

def create_and_add_info_plist
# add_info_plist_to_project
set_info_plist_in_build_settings
save_project
end

private

def add_info_plist_to_project
file_ref = @project.files.select { |f| f.path == @info_plist_path }.first
if file_ref
Solara.logger.debug("Info.plist file reference already exists in the project. Skipping this step.")
else
file_ref = XcodeProjectManager.new.add_single_file_to_group(@project, @project.main_group, @info_plist_path)
Solara.logger.debug("Info.plist file created. file_ref = #{file_ref}")
end
end

def set_info_plist_in_build_settings
path = FileManager.get_relative_path(FilePath.xcode_project_directory, @info_plist_path)
main_target.build_configurations.each do |config|
config.build_settings['INFOPLIST_FILE'] = path
end
end

private

def save_project
@project.save
end
Expand Down
25 changes: 1 addition & 24 deletions solara/lib/core/scripts/platform/ios/xcode_project_switcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ def initialize(project_path, brand_key)

def switch
update_xcode_target_settings
update_info_plist
add_artifacts_group
update_debug_and_release_xcconfig
@project.save
Solara.logger.debug("Updated #{@project_path} to use the values of #{FilePath.brand_xcconfig}")
Solara.logger.debug("Switched #{@project_path} Successfully.")
end

private

def update_xcode_target_settings
@target.build_configurations.each do |config|
config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = '$(PRODUCT_BUNDLE_IDENTIFIER)'
config.build_settings['PRODUCT_NAME'] = '$(PRODUCT_NAME)'
config.build_settings['MARKETING_VERSION'] = '$(MARKETING_VERSION)'

# We need to apply code signing only if the user has provided its config
Expand All @@ -47,27 +45,6 @@ def update_xcode_target_settings
end
end

def update_info_plist
info_plist_path = FilePath.info_plist
manager = IOSPlistManager.new(@project, info_plist_path)
manager.create_and_add_info_plist

xcconfig_values = {
'PRODUCT_NAME' => "$(PRODUCT_NAME)",
'PRODUCT_BUNDLE_IDENTIFIER' => "$(PRODUCT_BUNDLE_IDENTIFIER)",
'MARKETING_VERSION' => "$(MARKETING_VERSION)",
'BUNDLE_VERSION' => "$(BUNDLE_VERSION)"
}

info_plist = Xcodeproj::Plist.read_from_path(info_plist_path)
info_plist['CFBundleDisplayName'] = xcconfig_values['PRODUCT_NAME']
info_plist['CFBundleIdentifier'] = xcconfig_values['PRODUCT_BUNDLE_IDENTIFIER']
info_plist['CFBundleShortVersionString'] = xcconfig_values['MARKETING_VERSION']
info_plist['CFBundleVersion'] = xcconfig_values['BUNDLE_VERSION']

Xcodeproj::Plist.write_to_path(info_plist, info_plist_path)
end

def update_debug_and_release_xcconfig
debug_xcconfig_path = FilePath.app_xcconfig('Debug.xcconfig')
release_xcconfig_path = FilePath.app_xcconfig('Release.xcconfig')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"brandName": "",
"applicationId": "",
"versionName": "1.0.0",
"versionCode": 1,
Expand Down
30 changes: 30 additions & 0 deletions solara/lib/core/template/brands/ios/InfoPlist.xcstrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"sourceLanguage": "en",
"strings": {
"CFBundleDisplayName": {
"comment": "Bundle display name",
"extractionState": "extracted_with_value",
"localizations": {
"en": {
"stringUnit": {
"state": "new",
"value": ""
}
}
}
},
"CFBundleName": {
"comment": "Bundle name",
"extractionState": "extracted_with_value",
"localizations": {
"en": {
"stringUnit": {
"state": "new",
"value": ""
}
}
}
}
},
"version": "1.0"
}
1 change: 0 additions & 1 deletion solara/lib/core/template/brands/ios/ios_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"PRODUCT_NAME": "",
"PRODUCT_BUNDLE_IDENTIFIER": "",
"MARKETING_VERSION": "1.0.0",
"BUNDLE_VERSION": 1,
Expand Down

0 comments on commit 422a17f

Please sign in to comment.