mirror of https://github.com/tildeio/helix
Add helix CLI tool for generating projects
Also introduces the concept of parent projects which have child crates
This commit is contained in:
parent
93f0a2ee31
commit
d0a3a9e37a
|
@ -2,7 +2,8 @@ PATH
|
|||
remote: ../../ruby
|
||||
specs:
|
||||
helix_runtime (0.5.0.alpha.1)
|
||||
rake (~> 10.0)
|
||||
rake (>= 10.0)
|
||||
thor (~> 0.19.4)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
|
@ -23,6 +24,7 @@ GEM
|
|||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-support (3.5.0)
|
||||
thor (0.19.4)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
|
|
@ -3,6 +3,7 @@ PATH
|
|||
specs:
|
||||
helix_runtime (0.5.0.alpha.1)
|
||||
rake (>= 10.0)
|
||||
thor (~> 0.19.4)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
|
@ -23,6 +24,7 @@ GEM
|
|||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-support (3.5.0)
|
||||
thor (0.19.4)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
|
|
@ -2,7 +2,8 @@ PATH
|
|||
remote: ../../ruby
|
||||
specs:
|
||||
helix_runtime (0.5.0.alpha.1)
|
||||
rake (~> 10.0)
|
||||
rake (>= 10.0)
|
||||
thor (~> 0.19.4)
|
||||
|
||||
PATH
|
||||
remote: .
|
||||
|
@ -22,6 +23,7 @@ GEM
|
|||
i18n (0.8.1)
|
||||
minitest (5.8.3)
|
||||
rake (10.5.0)
|
||||
thor (0.19.4)
|
||||
thread_safe (0.3.6)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
|
|
|
@ -2,7 +2,8 @@ PATH
|
|||
remote: ../../ruby
|
||||
specs:
|
||||
helix_runtime (0.5.0.alpha.1)
|
||||
rake (~> 10.0)
|
||||
rake (>= 10.0)
|
||||
thor (~> 0.19.4)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
|
@ -22,6 +23,7 @@ GEM
|
|||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.4.0)
|
||||
rspec-support (3.4.1)
|
||||
thor (0.19.4)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
|
|
@ -2,7 +2,8 @@ PATH
|
|||
remote: ../../ruby
|
||||
specs:
|
||||
helix_runtime (0.5.0.alpha.1)
|
||||
rake (~> 10.0)
|
||||
rake (>= 10.0)
|
||||
thor (~> 0.19.4)
|
||||
|
||||
PATH
|
||||
remote: .
|
||||
|
@ -15,6 +16,7 @@ GEM
|
|||
specs:
|
||||
minitest (5.8.3)
|
||||
rake (10.5.0)
|
||||
thor (0.19.4)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'helix_runtime'
|
||||
require 'helix_runtime/cli'
|
||||
|
||||
HelixRuntime::CLI::Base.start(ARGV)
|
|
@ -13,12 +13,13 @@ Gem::Specification.new do |spec|
|
|||
spec.homepage = "https://github.com/tildeio/helix"
|
||||
|
||||
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
||||
spec.bindir = "exe"
|
||||
spec.bindir = "bin"
|
||||
spec.extensions = ["ext/helix_runtime/native/extconf.rb"]
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ["lib"]
|
||||
|
||||
spec.add_dependency "rake", ">= 10.0"
|
||||
spec.add_dependency "thor", "~> 0.19.4"
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.10"
|
||||
spec.add_development_dependency "rspec", "~> 3.4"
|
||||
|
|
|
@ -2,6 +2,7 @@ require "helix_runtime/version"
|
|||
require "helix_runtime/native"
|
||||
require "helix_runtime/platform"
|
||||
require 'helix_runtime/project'
|
||||
require 'helix_runtime/parent_project'
|
||||
|
||||
module HelixRuntime
|
||||
IS_WINDOWS = RUBY_PLATFORM =~ /mingw/
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
require 'helix_runtime/cli/bootstrap'
|
||||
|
||||
module HelixRuntime
|
||||
module CLI
|
||||
class Base < Thor
|
||||
include Thor::Actions
|
||||
|
||||
register CLI::Bootstrap, "bootstrap", "bootstrap PATH [NAME]", "Bootstrap Helix"
|
||||
|
||||
desc "add_crate NAME", "Add child project"
|
||||
def add_crate(name)
|
||||
bootstrap("crates/#{name}", name)
|
||||
append_to_file "Gemfile", "gem '#{name}', path: 'crates/#{name}'\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,73 @@
|
|||
require 'thor'
|
||||
|
||||
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
|
||||
|
||||
desc "Bootstrap Helix"
|
||||
source_root File.expand_path("../templates", __FILE__)
|
||||
|
||||
# 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 create_cargo_toml
|
||||
template "Cargo.toml", "#{base_path}/Cargo.toml"
|
||||
end
|
||||
|
||||
def add_rust_lib_file
|
||||
copy_file "lib.rs", "#{base_path}/src/lib.rs"
|
||||
end
|
||||
|
||||
def create_gemspec
|
||||
template "gem.gemspec", "#{base_path}/#{app_name}.gemspec"
|
||||
end
|
||||
|
||||
def create_gemfile
|
||||
template "Gemfile", "#{base_path}/Gemfile"
|
||||
end
|
||||
|
||||
def add_rake_task
|
||||
template "helix_runtime.rake", "#{base_path}/lib/tasks/helix_runtime.rake"
|
||||
end
|
||||
|
||||
def add_ruby_lib_file
|
||||
template "lib.rb", "#{base_path}/lib/#{app_name}.rb"
|
||||
end
|
||||
|
||||
def add_gitignore
|
||||
template "gitignore", "#{base_path}/.gitignore"
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def base_path
|
||||
File.expand_path(path)
|
||||
end
|
||||
|
||||
def app_name
|
||||
name || File.basename(base_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "<%= app_name %>"
|
||||
version = "0.1.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
helix_runtime = "<%= HelixRuntime::VERSION %>"
|
|
@ -0,0 +1,3 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gemspec
|
|
@ -0,0 +1,14 @@
|
|||
# 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
|
|
@ -0,0 +1,4 @@
|
|||
target
|
||||
tmp
|
||||
*.bundle
|
||||
*.so
|
|
@ -0,0 +1,5 @@
|
|||
require 'helix_runtime/build_task'
|
||||
|
||||
HelixRuntime::BuildTask.new("<%= app_name %>")
|
||||
|
||||
task :default => :build
|
|
@ -0,0 +1,7 @@
|
|||
require "helix_runtime"
|
||||
|
||||
begin
|
||||
require "<%= app_name %>/native"
|
||||
rescue LoadError
|
||||
warn "Unable to load <%= app_name %>/native. Please run `rake build`"
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
#[macro_use]
|
||||
extern crate helix_runtime as helix;
|
||||
|
||||
// declare_types! {
|
||||
// class MyClass {
|
||||
// def hello(&self) {
|
||||
// println!("Hello!");
|
||||
// }
|
||||
// }
|
||||
// }
|
|
@ -0,0 +1,35 @@
|
|||
require 'rake/tasklib'
|
||||
require 'helix_runtime'
|
||||
|
||||
module HelixRuntime
|
||||
# FIXME: I don't like this name
|
||||
class ParentBuildTask < Rake::TaskLib
|
||||
|
||||
def initialize
|
||||
define
|
||||
end
|
||||
|
||||
def define
|
||||
task :build do
|
||||
project.projects.each do |p|
|
||||
puts "Building #{p.name}"
|
||||
p.build
|
||||
end
|
||||
end
|
||||
|
||||
task :clobber do
|
||||
project.projects.each do |p|
|
||||
puts "Clobbering #{p.name}"
|
||||
p.clobber
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def project
|
||||
@project ||= ParentProject.new(Dir.pwd)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,40 @@
|
|||
module HelixRuntime
|
||||
class ParentProject
|
||||
|
||||
attr_accessor :root
|
||||
|
||||
def initialize(root)
|
||||
@root = find_root(root)
|
||||
end
|
||||
|
||||
def projects
|
||||
@projects ||= Dir["#{root}/crates/*"]
|
||||
.select{|f| File.directory?(f) }
|
||||
.map{|d| Project.new(d) }
|
||||
end
|
||||
|
||||
def ensure_built!
|
||||
projects.each(&:ensure_built!)
|
||||
end
|
||||
|
||||
def outdated_build?
|
||||
projects.any?(&:outdated_build?)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_root(root)
|
||||
root = File.expand_path(root)
|
||||
dir = root
|
||||
loop do
|
||||
return dir if !Dir["#{dir}/{Gemfile,*.gemspec}"].empty?
|
||||
|
||||
new_dir = File.dirname(dir)
|
||||
raise "Unable to find root for #{root}" if new_dir == dir
|
||||
|
||||
dir = new_dir
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue