Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 20, 2024
1 parent 6a6ce6f commit ed20b1b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 40 deletions.
71 changes: 50 additions & 21 deletions solara/lib/core/brands/brand_switcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def start

@health_checker.check_health
BrandsManager.instance.save_current_brand(@brand_key)
@artifacts_switcher.create_dirs
@artifacts_switcher.switch
switch
SolaraConfigurator.new.start

Expand Down Expand Up @@ -140,30 +140,59 @@ def initialize(platform)
@platform = platform
end

def create_dirs
def switch
Solara.logger.start_step("Switch artifacts directories")
directories = case @platform
when Platform::Flutter
[
FilePath.ios_assets_artifacts,
FilePath.flutter_project_fonts,
FilePath.flutter_assets_artifacts,
FilePath::flutter_lib_artifacts,
FilePath::android_artifacts,
FilePath.ios_artifacts
]
when Platform::IOS
[
FilePath.ios_assets_artifacts,
FilePath.ios_artifacts]
when Platform::Android
[FilePath::android_artifacts]
else
raise ArgumentError, "Invalid platform: #{@platform}"
end
directories = directories_for_platform
DirectoryCreator.create_directories(directories, delete_if_exists: true)
Solara.logger.end_step("Switch artifacts directories")
end

private

def directories_for_platform
case @platform
when Platform::Flutter
FlutterArtifactSwitcher.new.directories +
IOSArtifactSwitcher.new.directories +
AndroidArtifactSwitcher.new.directories
when Platform::IOS
IOSArtifactSwitcher.new.directories
when Platform::Android
AndroidArtifactSwitcher.new.directories
else
raise ArgumentError, "Invalid platform: #{@platform}"
end
end
end

class FlutterArtifactSwitcher
def directories
[
FilePath.flutter_project_fonts,
FilePath.flutter_assets_artifacts,
FilePath.flutter_lib_artifacts,
]
end
end

class IOSArtifactSwitcher
def directories
[
FilePath.ios_project_root_artifacts,
FilePath.ios_project_assets_artifacts,
]
end
end

class AndroidArtifactSwitcher
def directories
[
FilePath.android_project_root_artifacts,
FilePath.android_project_main_artifacts,
FilePath.android_project_java_artifacts,
FilePath.android_project_assets_artifacts
]
end
end

class ThemeSwitcher
Expand Down
9 changes: 4 additions & 5 deletions solara/lib/core/scripts/brand_resources_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(brand_key)
def update_ios
Solara.logger.start_step("Switch iOS resources")
source = FilePath.ios_brand_assets(@brand_key)
destination = FilePath.ios_assets_artifacts
destination = FilePath.ios_project_assets_artifacts

# Copy images and set the Content.json for each one
add_to_asset_catalog
Expand All @@ -31,7 +31,7 @@ def update_ios

def add_to_asset_catalog
source = FilePath.ios_brand_assets(@brand_key)
destination = FilePath.ios_assets_artifacts
destination = FilePath.ios_project_assets_artifacts
asset_manager = XcodeAssetManager.new(destination)
asset_manager.add(source)
end
Expand All @@ -40,10 +40,9 @@ def update_android
Solara.logger.start_step("Switch Android resources")
FileManager.new.copy_files_recursively(
FilePath.android_brand_res(@brand_key),
FilePath.android_project_res_artifacts)
FilePath.android_project_main_artifacts)

assets_artifacts = File.join(FilePath.android_project_assets, FilePath.artifacts_dir_name)
FileManager.delete_if_exists(assets_artifacts)
assets_artifacts = FilePath.android_project_assets_artifacts

FileManager.new.copy_files_recursively(
FilePath.android_brand_assets(@brand_key),
Expand Down
28 changes: 16 additions & 12 deletions solara/lib/core/scripts/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def self.generated_config(name, platform)
when Platform::Flutter
File.join(flutter_lib_artifacts, name)
when Platform::Android
File.join(android_main_artifacts, name)
File.join(android_project_java_artifacts, name)
when Platform::IOS
File.join(ios_artifacts, name)
File.join(ios_project_root_artifacts, name)
else
raise ArgumentError, "Invalid platform: #{SolaraSettingsManager.instance.platform}"
end
Expand All @@ -161,11 +161,11 @@ def self.flutter_lib_artifacts
File.join(project_root, 'lib', artifacts_dir_name)
end

def self.android_artifacts
def self.android_project_root_artifacts
File.join(android_project_root, artifacts_dir_name)
end

def self.android_main_artifacts
def self.android_project_java_artifacts
File.join(android_project_root, 'app', 'src', 'main', 'java', artifacts_dir_name)
end

Expand Down Expand Up @@ -197,24 +197,28 @@ def self.android_project_assets
File.join(android_project_root, 'app', 'src', 'main', 'assets')
end

def self.android_project_assets_artifacts
File.join(android_project_assets, artifacts_dir_name)
end

def self.android_brand_assets(brand_key)
File.join(android_brand_root(brand_key), 'assets')
end

def self.android_generated_properties
File.join(android_artifacts, 'brand.properties')
File.join(android_project_root_artifacts, 'brand.properties')
end

def self.android_project_res
File.join(android_project_root, 'app', 'src', 'main', 'res')
end

def self.android_project_res_artifacts
def self.android_project_main_artifacts
File.join(android_project_root, 'app', 'src', 'main', artifacts_dir_name)
end

def self.android_artifacts_strings
File.join(android_project_res_artifacts, 'values', 'strings.xml')
File.join(android_project_main_artifacts, 'values', 'strings.xml')
end

def self.android_strings
Expand Down Expand Up @@ -380,22 +384,22 @@ def self.ios_brand_assets(brand_key)
end

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

def self.ios_project_fonts
File.join(ios_artifacts, 'Fonts')
File.join(ios_project_root_artifacts, 'Fonts')
end

def self.android_project_fonts
File.join(android_project_res_artifacts, 'font')
File.join(android_project_main_artifacts, 'font')
end

def self.flutter_project_fonts
File.join(project_root, 'assets', 'solara_fonts')
end

def self.ios_artifacts
def self.ios_project_root_artifacts
case SolaraSettingsManager.instance.platform
when Platform::Flutter
return File.join(project_root, ios, 'Flutter', artifacts_dir_name_ios)
Expand All @@ -415,7 +419,7 @@ def self.info_plist
File.join(project_root, path)
end

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def validate(file_system)
else
ignored = [
'solara/',
"#{FilePath.artifacts_dir_name}/",
"#{FilePath.artifacts_dir_name_ios}/",
'Pods/',
'build/']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def add_artifacts_group
flutter_group = @project.groups.find { |group| group.name == 'Flutter' }
artifacts_group = flutter_group.groups.find { |group| group.name == artifacts_dir_name }
artifacts_group = flutter_group.new_group(artifacts_dir_name) if artifacts_group.nil?
add_files_to_group(artifacts_group, FilePath.ios_artifacts)
add_files_to_group(artifacts_group, FilePath.ios_project_root_artifacts)
when Platform::IOS
artifacts_group = @project.groups.find { |group| group.name == artifacts_dir_name }
artifacts_group = @project.new_group(artifacts_dir_name) if artifacts_group.nil?
add_files_to_group(artifacts_group, FilePath.ios_artifacts)
add_files_to_group(artifacts_group, FilePath.ios_project_root_artifacts)
else
raise ArgumentError, "Invalid platform: #{@platform}"
end
Expand Down

0 comments on commit ed20b1b

Please sign in to comment.