This commit is contained in:
Peter Wagenet 2017-04-24 12:50:39 -07:00
parent f7b55fa133
commit 1de20cefcb
6 changed files with 46 additions and 47 deletions

View File

@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
spec.add_dependency "rake", ">= 10.0"
spec.add_dependency "thor", "~> 0.19.4"
spec.add_dependency "bundler", "~> 1.14"
spec.add_development_dependency "bundler", "~> 1.10"
spec.add_development_dependency "rspec", "~> 3.4"
spec.add_development_dependency "rake-compiler", "~> 0.9.7"
end

View File

@ -1,11 +1,12 @@
require 'thor'
require 'bundler/cli'
require 'bundler/cli/gem'
module HelixRuntime
module CLI
class Bootstrap < Thor::Group
argument :path, type: :string
argument :name, type: :string, optional: true
class_option :skip_bundle, type: :boolean, default: false
include Thor::Actions
@ -15,6 +16,27 @@ module HelixRuntime
# NOTE: Instead of using destination_root, we include the full path so
# that we see the path relative to the root of where we're running the command.
def build_gem
# Add Bundler templates to path
self.class.source_paths << Bundler::CLI.source_root
# Set shell output
Bundler.ui = Bundler::UI::Shell.new
gem_cli = Bundler::CLI::Gem.new({}, app_name, self)
# Set custom target
gem_cli.instance_variable_set(:@target, Pathname.new(base_path))
# No-op the safe check, so we can re-run the command.
# We may later want to have a separate update command instead of doing this.
def gem_cli.ensure_safe_gem_name(*); end
# Run
gem_cli.run
ensure
# Remove bundler templates from path
self.class.source_paths.delete(Bundler::CLI.source_root)
end
def create_cargo_toml
template "Cargo.toml", "#{base_path}/Cargo.toml"
end
@ -24,11 +46,10 @@ module HelixRuntime
end
def create_gemspec
template "gem.gemspec", "#{base_path}/#{app_name}.gemspec"
end
def create_gemfile
template "Gemfile", "#{base_path}/Gemfile"
# template "gem.gemspec", "#{base_path}/#{app_name}.gemspec"
insert_into_file "#{base_path}/#{app_name}.gemspec",
"\n\n spec.add_dependency 'helix_runtime', '~> #{HelixRuntime::GEM_VERSION}'",
after: 'spec.require_paths = ["lib"]'
end
def add_rake_task
@ -36,26 +57,32 @@ module HelixRuntime
end
def add_ruby_lib_file
template "lib.rb", "#{base_path}/lib/#{app_name}.rb"
append_to_file "#{base_path}/lib/#{app_name}.rb", <<-FILE
require "helix_runtime"
begin
require "#{app_name}>/native"
rescue LoadError
warn "Unable to load #{app_name}/native. Please run `rake build`"
end
FILE
end
def add_gitignore
template "gitignore", "#{base_path}/.gitignore"
def update_gitignore
append_to_file "#{base_path}/.gitignore", <<-FILE
/target/
*.bundle
*.so
FILE
end
def update_rakefile
unless File.exists?("#{base_path}/Rakefile")
create_file "#{base_path}/Rakefile", "require 'bundler/setup'\n"
end
append_to_file "#{base_path}/Rakefile", "import 'lib/tasks/helix_runtime.rake'\n"
end
def bundle
unless options.skip_bundle
inside path do
run "bundle"
end
def update_git
if Bundler.git_present?
`git add .`
end
end

View File

@ -1,3 +0,0 @@
source 'https://rubygems.org'
gemspec

View File

@ -1,14 +0,0 @@
# encoding: utf-8
Gem::Specification.new do |s|
s.name = '<%= app_name %>'
s.version = '1.0.0'
s.authors = ['Ruby Developer']
s.summary = "A Helix project"
s.files = Dir['{lib/**/*,[A-Z]*}']
s.platform = Gem::Platform::RUBY
s.require_path = 'lib'
s.add_dependency 'helix_runtime', '~> <%= HelixRuntime::GEM_VERSION %>'
end

View File

@ -1,4 +0,0 @@
target
tmp
*.bundle
*.so

View File

@ -1,7 +0,0 @@
require "helix_runtime"
begin
require "<%= app_name %>/native"
rescue LoadError
warn "Unable to load <%= app_name %>/native. Please run `rake build`"
end