Class: Joyce::Tasks::AppBuilder
- Inherits:
-
Object
- Object
- Joyce::Tasks::AppBuilder
- Includes:
- FileUtils
- Defined in:
- lib/joyce/tasks/build.rb
Instance Method Summary collapse
-
#copy_gems(gems, destination:) ⇒ Object
the gem approach from releasy: https://github.com/Spooner/releasy/blob/master/lib/releasy/mixins/has_gemspecs.rb.
- #make(app_name:, app_class_name:, template_location:, target_directory:) ⇒ Object
- #vendored_gem_names(ignoring:) ⇒ Object
- #write_main_rb(root:, app_name:, app_class_name:) ⇒ Object
Instance Method Details
#copy_gems(gems, destination:) ⇒ Object
the gem approach from releasy: https://github.com/Spooner/releasy/blob/master/lib/releasy/mixins/has_gemspecs.rb
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/joyce/tasks/build.rb', line 60 def copy_gems(gems, destination:) gems_dir = "#{destination}/gems" mkdir_p gems_dir gems.each do |gem| spec = gemspecs.find { |g| g.name == gem } gem_dir = spec.full_gem_path puts "Copying gem: #{spec.name} #{spec.version}" cp_r gem_dir, gems_dir end end |
#make(app_name:, app_class_name:, template_location:, target_directory:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/joyce/tasks/build.rb', line 8 def make(app_name:, app_class_name:, template_location:, target_directory:) target_app_bundle_root = File.join(target_directory, "#{app_name}.app") cp_r template_location, target_app_bundle_root puts "--- Ruby.app copied!" puts "--- copying your source code..." cp_r "lib/.", "#{target_app_bundle_root}/Contents/Resources/lib" puts "--- source code copied in!" puts "--- let's copy gems in..." gem_destination = "#{target_app_bundle_root}/Contents/Resources/vendor" gems_to_ignore = %w[ gosu minitest ] gems_to_ignore << app_name # since we just copied over source? gem_list = vendored_gem_names(ignoring: gems_to_ignore) copy_gems(gem_list, destination: File.join(gem_destination)) puts "--- gems copied" # TODO copy assets...? puts "--- copying your media..." cp_r "media/.", "#{target_app_bundle_root}/Contents/Resources/media" puts "--- media copied in!" puts "--- writing main.rb..." write_main_rb(app_class_name: app_class_name, root: target_app_bundle_root, app_name: app_name) puts "--- main.rb written!" end |
#vendored_gem_names(ignoring:) ⇒ Object
71 72 73 |
# File 'lib/joyce/tasks/build.rb', line 71 def vendored_gem_names(ignoring:) (gemspecs.map(&:name) - ignoring).sort end |
#write_main_rb(root:, app_name:, app_class_name:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/joyce/tasks/build.rb', line 37 def write_main_rb(root:,app_name:,app_class_name:) File.open("#{root}/Contents/Resources/main.rb", "w") do |file| require_paths = gemspecs.map do |spec| spec.require_paths.map {|path| "#{spec.name}-#{spec.version}/#{path}" } end file.puts <<-ruby require 'fileutils' FileUtils.mkdir_p("#{Dir.home}/#{app_name}/") $stdout.reopen("#{Dir.home}/#{app_name}/app.log", "w") $stderr.reopen("#{Dir.home}/#{app_name}/err.log", "w") GEM_REQUIRE_PATHS = #{require_paths.flatten.inspect} GEM_REQUIRE_PATHS.each do |path| $LOAD_PATH.unshift File.expand_path(File.join("../vendor/gems", path), __FILE__) end require 'joyce' require '#{app_name}' #{app_class_name}.kickstart! ruby end end |