Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 14, 2024
1 parent 2a7f281 commit 958b835
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 231 deletions.
6 changes: 3 additions & 3 deletions solara/lib/core/brands/brand_switcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def switch

def update_xcode_project
Solara.logger.start_step("Update Xcode project")
project_path = IOSFilePathManager.instance.xcode_project
project_path = FilePath.xcode_project
XcodeProjectSwitcher.new(project_path, @brand_key).switch
Solara.logger.end_step("Update Xcode project")
end
Expand Down Expand Up @@ -134,9 +134,9 @@ def create_dirs
Solara.logger.start_step("Create artifacts directories")
directories = case @platform
when Platform::Flutter
[FilePath::flutter_artifacts, FilePath::android_artifacts, IOSFilePathManager.instance.artifacts]
[FilePath::flutter_artifacts, FilePath::android_artifacts, FilePath.ios_artifacts]
when Platform::IOS
[IOSFilePathManager.instance.artifacts]
[FilePath.ios_artifacts]
when Platform::Android
[FilePath::android_artifacts]
else
Expand Down
55 changes: 27 additions & 28 deletions solara/lib/core/doctor/brand_doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,6 @@
Dir.glob("#{__dir__}/../../.solara/core/brands/*.rb").each { |file| require file }
Dir.glob("#{__dir__}/validator/template/*.rb").each { |file| require file }

class Issue < StandardError
ERROR = 'ERROR'
WARNING = 'WARNING'

attr_reader :type, :error

def initialize(type, error)
@type = type
@error = error
end

def to_s
"#{@type}: #{@error}"
end

def <=>(other)
[type, error] <=> [other.type, other.error]
end

def self.error(error)
Issue.new(ERROR, error)
end

def self.warning(error)
Issue.new(WARNING, error)
end
end

class BrandDoctor
def initialize
end
Expand Down Expand Up @@ -92,3 +64,30 @@ def validate_brand(brand_key, strategies = [])
end
end

class Issue < StandardError
ERROR = 'ERROR'
WARNING = 'WARNING'

attr_reader :type, :error

def initialize(type, error)
@type = type
@error = error
end

def to_s
"#{@type}: #{@error}"
end

def <=>(other)
[type, error] <=> [other.type, other.error]
end

def self.error(error)
Issue.new(ERROR, error)
end

def self.warning(error)
Issue.new(WARNING, error)
end
end
38 changes: 0 additions & 38 deletions solara/lib/core/doctor/validator/directory_structure_validator.rb

This file was deleted.

37 changes: 0 additions & 37 deletions solara/lib/core/doctor/validator/file_structure_validator.rb

This file was deleted.

8 changes: 4 additions & 4 deletions solara/lib/core/scripts/brand_resources_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def initialize(brand_key)

def update_ios
Solara.logger.start_step("Update iOS resources")
source = IOSFilePathManager.instance.brand_assets(@brand_key)
destination = IOSFilePathManager.instance.assets_artifacts
source = FilePath.ios_brand_assets(@brand_key)
destination = FilePath.ios_assets_artifacts
FileManager.delete_if_exists(destination)

# Copy images and set the Content.json for each one
Expand All @@ -29,8 +29,8 @@ def update_ios
end

def add_to_asset_catalog
source = IOSFilePathManager.instance.brand_assets(@brand_key)
destination = IOSFilePathManager.instance.assets_artifacts
source = FilePath.ios_brand_assets(@brand_key)
destination = FilePath.ios_assets_artifacts
asset_manager = XcodeAssetManager.new(destination)
asset_manager.add(source)
end
Expand Down
93 changes: 91 additions & 2 deletions solara/lib/core/scripts/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def self.generated_config(name, platform)
when Platform::Android
File.join(android_main_artifacts, name)
when Platform::IOS
File.join(IOSFilePathManager.instance.artifacts, name)
File.join(ios_artifacts, name)
else
raise ArgumentError, "Invalid platform: #{SolaraSettingsManager.instance.platform}"
end
Expand Down Expand Up @@ -297,13 +297,102 @@ def self.launcher_icon(brand_key)
when Platform::Android
return android_launcher_icon(brand_key)
when Platform::IOS
path = IOSFilePathManager.instance.brand_app_icon_image(brand_key)
path = ios_brand_app_icon_image(brand_key)
return path
else
raise ArgumentError, "Invalid platform: #{SolaraSettingsManager.instance.platform}"
end
end

def self.ios_brand_app_icon(brand_key)
File.join(brands, brand_key, ios, 'assets', 'AppIcon.appiconset')
end

def self.ios_brand_app_icon_image(brand_key)
appicon_set_path = ios_brand_app_icon(brand_key)

if appicon_set_path.nil?
raise "Error: AppIcon.appiconset not found for brand #{brand_key}"
end

contents_json_path = File.join(appicon_set_path, 'Contents.json')

unless File.exist?(contents_json_path)
raise "Error: Contents.json not found in AppIcon.appiconset for brand #{brand_key}"
end

contents = JSON.parse(File.read(contents_json_path))

largest_image = contents['images'].max_by do |img|
size = img['size'].scan(/(\d+)x(\d+)/).first&.map(&:to_i)
size ? size[0] * size[1] : 0
end

if largest_image
File.join(appicon_set_path, largest_image['filename'])
else
raise "No images found in Contents.json for brand #{brand_key}"
end
end

def self.app_xcconfig(name)
case SolaraSettingsManager.instance.platform
when Platform::Flutter
return File.join(project_root, ios, 'Flutter', name)
when Platform::IOS
return File.join(xcode_project_directory, 'XCConfig', name)
else
raise ArgumentError, "Invalid platform: #{SolaraSettingsManager.instance.platform}"
end
end

def self.xcode_project_directory
Pathname.new(xcode_project).parent.to_s
end

def self.xcode_project
path = ProjectSettingsManager.instance.value('xcodeproj', Platform::IOS)
File.join(project_root, path)
end

def self.ios_brand_assets(brand_key)
File.join(brands, brand_key, ios, 'assets')
end

def self.brand_xcconfig
File.join(ios_artifacts, 'Brand.xcconfig')
end

def self.ios_artifacts
case SolaraSettingsManager.instance.platform
when Platform::Flutter
return File.join(project_root, ios, 'Flutter', 'Artifacts')
when Platform::IOS
return File.join(xcode_project_directory, 'Artifacts')
else
raise ArgumentError, "Invalid platform: #{SolaraSettingsManager.instance.platform}"
end
end


def self.info_plist
path = ProjectSettingsManager.instance.value('Info.plist', Platform::IOS)
File.join(project_root, path)
end

def self.ios_assets_artifacts
File.join(File.dirname(ios_assets), 'Assets.xcassets', 'Artifacts')
end

def self.ios_assets
path = ProjectSettingsManager.instance.value('Assets.xcassets', Platform::IOS)
File.join(project_root, path)
end

def self.app_xcconfig_directory
Pathname.new(app_xcconfig('Debug.xcconfig')).parent.to_s
end

def self.schema
File.join(root, 'core', 'doctor', 'schema')
end
Expand Down
Loading

0 comments on commit 958b835

Please sign in to comment.