From 1db6e8feb571b82aa2d236a4d313a479f1aef7a5 Mon Sep 17 00:00:00 2001 From: Shaban Kamel Date: Tue, 10 Sep 2024 16:44:18 +0300 Subject: [PATCH] Solara --- solara/lib/core/doctor/doctor_manager.rb | 1 + .../schema/platform/ios/ios_config.json | 2 +- solara/lib/core/scripts/file_path.rb | 4 ++ .../core/scripts/solara_version_manager.rb | 42 +++++++++++++++++++ solara/lib/solara.rb | 16 ++++++- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 solara/lib/core/scripts/solara_version_manager.rb diff --git a/solara/lib/core/doctor/doctor_manager.rb b/solara/lib/core/doctor/doctor_manager.rb index 5fe992f..8d6da39 100644 --- a/solara/lib/core/doctor/doctor_manager.rb +++ b/solara/lib/core/doctor/doctor_manager.rb @@ -27,6 +27,7 @@ def ensure_initialized! brands = FilePath.brands brands_list = FilePath.brands_list platform = SolaraSettingsManager.instance.platform + puts "ensure_initialized! platform: #{platform}" unless File.exist?(brands) && File.exist?(brands_list) && !platform.nil? && !platform.empty? Solara.logger.error("Solara is not initialized here. Please run 'solara init' to initialize.") exit 1 diff --git a/solara/lib/core/doctor/schema/platform/ios/ios_config.json b/solara/lib/core/doctor/schema/platform/ios/ios_config.json index d5b0a1a..61ec1c6 100644 --- a/solara/lib/core/doctor/schema/platform/ios/ios_config.json +++ b/solara/lib/core/doctor/schema/platform/ios/ios_config.json @@ -14,7 +14,7 @@ "description": "The marketing version of the product." }, "BUNDLE_VERSION": { - "type": "string", + "type": "number", "description": "The bundle version of the product." } }, diff --git a/solara/lib/core/scripts/file_path.rb b/solara/lib/core/scripts/file_path.rb index d859ba3..5015793 100644 --- a/solara/lib/core/scripts/file_path.rb +++ b/solara/lib/core/scripts/file_path.rb @@ -271,6 +271,10 @@ def self.solara_settings File.join(dot_solara, 'solara_settings.json') end + def self.solara_version + File.join(dot_solara, 'solara_version.json') + end + def self.solara_aliases_sh File.join(ENV['HOME'], '.solara', 'aliases.sh') end diff --git a/solara/lib/core/scripts/solara_version_manager.rb b/solara/lib/core/scripts/solara_version_manager.rb new file mode 100644 index 0000000..2adee8a --- /dev/null +++ b/solara/lib/core/scripts/solara_version_manager.rb @@ -0,0 +1,42 @@ +require 'singleton' + +require 'singleton' +require 'json' + +class SolaraVersionManager + include Singleton + + def sversion + json['solaraVersion'] + end + + def version=(value) + new_json = json + new_json['solaraVersion'] = value + save(new_json) + end + + def value(key) + json[key] + end + + def add(key, value) + new_json = json + new_json[key] = value + save(new_json) + end + + private + + def json + path = FilePath.solara_version + FileManager.create_file_if_not_exist(path) + JSON.parse(File.read(path)) + rescue JSON::ParserError => e + {} + end + + def save(json) + File.write(FilePath.solara_version, JSON.pretty_generate(json)) + end +end \ No newline at end of file diff --git a/solara/lib/solara.rb b/solara/lib/solara.rb index bada269..ff7b5c8 100644 --- a/solara/lib/solara.rb +++ b/solara/lib/solara.rb @@ -3,6 +3,7 @@ Dir['*.rb'].each { |file| require_relative file } Dir.glob("#{__dir__}/core/scripts/*.rb").each { |file| require file } require 'solara_manager' +require 'rubygems' module Solara ROOT = Pathname.new(File.expand_path('..', __FILE__)) @@ -35,8 +36,7 @@ class CLI < Thor def initialize(*args) super - Solara.logger.verbose = options[:verbose] || false - ensure_platform + setup end def self.exit_on_failure? @@ -224,5 +224,17 @@ def validate_brand_name(brand_name) end brand_name end + + + def setup + Solara.logger.verbose = options[:verbose] || false + + ensure_platform + + # Solara version is mandatory because the structure and logic may change in the future and need to migrate. + SolaraVersionManager.instance.version = Gem.loaded_specs['solara'].version.to_s + end + end + end \ No newline at end of file