Class: Joyce::Tasks::AppBuilder

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/joyce/tasks/build.rb

Instance Method Summary collapse

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 basically just copy over your own system gems, ignoring binary things then we'll write out a prelude in main.rb that $unshifts the load path for each of these :/ but it should almost certainly work!



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/joyce/tasks/build.rb', line 65

def copy_gems(gems, destination:)
	gems_dir = "#{destination}/gems"
	# specs_dir = "#{destination}/specifications"
	mkdir_p gems_dir #, fileutils_options
	# mkdir_p specs_dir, fileutils_options

	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
	  #,  fileutils_options
	  # spec_file = File.expand_path("../../specifications/#{File.basename gem_dir}.gemspec", gem_dir)
	  # cp_r spec_file, specs_dir, fileutils_options
	end
end

#make(app_name:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/joyce/tasks/build.rb', line 6

def make(app_name:)
  target_app_bundle_root = File.join("..", "dist", "#{app_name}.app")

  puts "--- build os x app here!"
  cp_r "../dist/Ruby.app", target_app_bundle_root
  puts "--- Ruby.app copied!"

  puts "--- copying your source code..."
  cp_r "lib", "#{target_app_bundle_root}/Contents/Resources/lib"

  puts "--- Analyzing your gems..."
  p Bundler.definition.specs_for([:default])

  puts "--- Okay, let's copy gems in..."

  gem_destination = "#{target_app_bundle_root}/Contents/Resources/vendor"

  # info "Copying source gems from system"
  binary_gems_to_ignore = %w[ gosu minitest ]
  gem_list = vendored_gem_names(ignoring: binary_gems_to_ignore)

  copy_gems(gem_list, destination: File.join(gem_destination))

  write_main_rb(root: target_app_bundle_root) #(app_class: "#{app_name}::Application")
end

#vendored_gem_names(ignoring:) ⇒ Object



83
84
85
# File 'lib/joyce/tasks/build.rb', line 83

def vendored_gem_names(ignoring:)
	(gemspecs.map(&:name) - ignoring).sort
end

#write_main_rb(root:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/joyce/tasks/build.rb', line 32

def write_main_rb(root:)
	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
      $stdout.reopen("/Users/joe/joyce/game.log", "w")
      $stderr.reopen("/Users/joe/joyce/err.log", "w")

      puts "--- unshifting gem paths"

	    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

      puts "--- gems shifted"

      require 'forwardable'
      require 'joyce'
      require 'application'
      
      Example::Application.kickstart!
      ruby
	end
end