Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 15, 2024
1 parent 4d76f14 commit 929c5ba
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 25 deletions.
4 changes: 2 additions & 2 deletions solara/lib/core/scripts/brand_resources_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def update_android
FilePath.android_brand_res(@brand_key),
FilePath.android_res_artifacts)

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

FileManager.new.copy_files_recursively(
Expand All @@ -60,7 +60,7 @@ def update_flutter
YamlManager.new(FilePath.pub_spec_yaml).add_to_nested_array(
'flutter',
'assets',
'assets/artifacts/')
"assets/#{FilePath.artifacts_dir_name}/")

destination = FilePath.flutter_assets_artifacts
FileManager.delete_if_exists(destination)
Expand Down
24 changes: 16 additions & 8 deletions solara/lib/core/scripts/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ def self.project_root
SolaraSettingsManager.instance.project_root
end

def self.artifacts_dir_name
'solara_artifacts'
end

def self.artifacts_dir_name_ios
'SolaraArtifacts'
end

def self.root
SolaraSettingsManager.instance.root
end
Expand Down Expand Up @@ -134,15 +142,15 @@ def self.generated_config(name, platform)
end

def self.flutter_artifacts
File.join(project_root, 'lib', 'artifacts')
File.join(project_root, 'lib', artifacts_dir_name)
end

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

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

def self.android_brand_config(brand_key)
Expand Down Expand Up @@ -186,7 +194,7 @@ def self.android_res
end

def self.android_res_artifacts
File.join(android_project_root, 'app', 'src', 'main', 'artifacts')
File.join(android_project_root, 'app', 'src', 'main', artifacts_dir_name)
end

def self.android_artifacts_strings
Expand All @@ -206,7 +214,7 @@ def self.brand_flutter_assets(brand_key)
end

def self.flutter_assets_artifacts
File.join(project_root, 'assets', 'artifacts')
File.join(project_root, 'assets', artifacts_dir_name)
end

def self.pub_spec_yaml
Expand Down Expand Up @@ -366,9 +374,9 @@ def self.brand_xcconfig
def self.ios_artifacts
case SolaraSettingsManager.instance.platform
when Platform::Flutter
return File.join(project_root, ios, 'Flutter', 'Artifacts')
return File.join(project_root, ios, 'Flutter', artifacts_dir_name_ios)
when Platform::IOS
return File.join(xcode_project_directory, 'Artifacts')
return File.join(xcode_project_directory, artifacts_dir_name_ios)
else
raise ArgumentError, "Invalid platform: #{SolaraSettingsManager.instance.platform}"
end
Expand All @@ -381,7 +389,7 @@ def self.info_plist
end

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

def self.ios_assets
Expand Down
4 changes: 2 additions & 2 deletions solara/lib/core/scripts/gitignore_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def self.ignore
GitignoreManager.new(FilePath.project_root)
.add_items([
"# Generated by Solara. Ignore redundant brand specific changes.",
"**/artifacts/",
"**/Artifacts/",
"**/#{FilePath.artifacts_dir_name}/",
"**/#{FilePath.artifacts_dir_name_ios}/",
"solara/brands/current_app.json",
"solara/.solara/aliases/",
"solara/.solara/solara_settings.json",
Expand Down
6 changes: 5 additions & 1 deletion solara/lib/core/scripts/interactive_file_system_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def validate(file_system)
validate_required_item(item)
end
else
ignored = %w[solara/ Artifacts/ Pods/ build/]
ignored = [
'solara/',
"#{FilePath.artifacts_dir_name_ios}/",
'Pods/',
'build/']

root = File.join(@project_root, item_path)
paths = if recursive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def initialize
end

def switch(config)
Solara.logger.start_step("Generate artifacts/strings.xml")
Solara.logger.start_step("Generate #{FilePath.artifacts_dir_name}/strings.xml")
strings_file = FilePath.android_artifacts_strings

# Create the file if it doesn't exist
Expand All @@ -16,7 +16,7 @@ def switch(config)
Solara.logger.debug("Updated #{strings_file} with name: \"#{config['brandName']}\"")

remove_app_name_from_strings
Solara.logger.end_step("Generate artifacts/strings.xml")
Solara.logger.end_step("Generate #{FilePath.artifacts_dir_name}/strings.xml")
end

# It's important to delete app_name to avoid duplicate resources
Expand Down
7 changes: 4 additions & 3 deletions solara/lib/core/scripts/platform/android/gradle_switcher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Dir[File.expand_path('../../*.rb', __dir__)].each { |file| require_relative file }
require 'fileutils'
require 'json'

Expand All @@ -10,14 +11,14 @@ class GradleSwitcher

KOTLIN_PROPERTIES_LOADER = <<-KOTLIN
val brandProperties = Properties().apply {
load(FileInputStream(file("../artifacts/brand.properties")))
load(FileInputStream(file("../#{FilePath.artifacts_dir_name}/brand.properties")))
}
KOTLIN

GROOVY_PROPERTIES_LOADER = <<-GROOVY
project.ext {
brandProperties = new Properties()
brandProperties.load(new FileInputStream(file("../artifacts/brand.properties")))
brandProperties.load(new FileInputStream(file("../#{FilePath.artifacts_dir_name}/brand.properties")))
}
GROOVY

Expand All @@ -30,7 +31,7 @@ class GradleSwitcher
KOTLIN_VERSION_CODE = 'versionCode = brandProperties.getProperty("versionCode").toInt()'
GROOVY_VERSION_CODE = "versionCode = project.ext.brandProperties.getProperty('versionCode').toInteger()"

DEFAULT_SOURCE_SETS = %w[src/main/res src/main/artifacts]
DEFAULT_SOURCE_SETS = ['src/main/res', "src/main/#{FilePath.artifacts_dir_name}"]

def initialize(brand_key)
@brand_key = brand_key
Expand Down
2 changes: 1 addition & 1 deletion solara/lib/core/scripts/platform/ios/xcconfig_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def generate

def generate_xcconfig_content
content = <<~XCCONFIG
ASSETCATALOG_COMPILER_APPICON_NAME = Artifacts/AppIcon
ASSETCATALOG_COMPILER_APPICON_NAME = #{FilePath.artifacts_dir_name_ios}/AppIcon
#{load_config.map { |key, value| "#{key.upcase} = #{value}" }.join("\n")}
XCCONFIG

Expand Down
12 changes: 7 additions & 5 deletions solara/lib/core/scripts/platform/ios/xcode_project_switcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def update_debug_and_release_xcconfig

def create_xcconfigs_and_add_to_project(debug_xcconfig_path, release_xcconfig_path)
FileManager.create_files_if_not_exist([debug_xcconfig_path, release_xcconfig_path])
base_xcconfig_name = 'Artifacts/Brand.xcconfig'
base_xcconfig_name = "#{FilePath.artifacts_dir_name_ios}/Brand.xcconfig"

case @platform
when Platform::Flutter
Expand Down Expand Up @@ -108,15 +108,17 @@ def set_base_xcconfigs(debug_xcconfig_path, release_xcconfig_path)
end

def add_artifacts_group
artifacts_dir_name = FilePath.artifacts_dir_name_ios

case @platform
when Platform::Flutter
flutter_group = @project.groups.find { |group| group.name == 'Flutter' }
artifacts_group = flutter_group.groups.find { |group| group.name == 'Artifacts' }
artifacts_group = flutter_group.new_group("Artifacts") if artifacts_group.nil?
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)
when Platform::IOS
artifacts_group = @project.groups.find { |group| group.name == 'Artifacts' }
artifacts_group = @project.new_group("Artifacts") if artifacts_group.nil?
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)
else
raise ArgumentError, "Invalid platform: #{@platform}"
Expand Down
2 changes: 1 addition & 1 deletion solara/lib/core/scripts/strings_xml_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def delete_app_name
app_name_element = @doc.elements['resources/string[@name="app_name"]']
app_name_element.remove if app_name_element
save_changes
Solara.logger.debug("Removed app_name from #{@file_path} to avoid duplication with artifacts/strings.xml.")
Solara.logger.debug("Removed app_name from #{@file_path} to avoid duplication with #{FilePath.artifacts_dir_name}/strings.xml.")
end

private
Expand Down

0 comments on commit 929c5ba

Please sign in to comment.