lib/droiuby/scripts/project.rb in droiuby-0.3.4 vs lib/droiuby/scripts/project.rb in droiuby-0.3.5
- old
+ new
@@ -138,19 +138,28 @@
Net::HTTP.get_print(uri)
end
desc "standalone NAME [PACKAGE_NAME]", "create an android project for this app with the specified java package name"
- def standalone(name, package_name, title = nil, output_dir = 'projects')
+ def standalone(name, package_name, title = nil, output_dir = 'projects', repository = nil, branch = nil)
if output_dir.blank?
output_dir = Dir.pwd
end
- dest_folder = File.join(output_dir,"#{name}")
+ if package_name == :prompt
+ say("Please enter the Java Package Name to be used for your app (e.g. com.awesome.sample ):")
+ package_name = ask("Package Name: ")
+ end
- Dir.chdir dest_folder
+ dest_folder = nil
+ unless name.nil?
+ dest_folder = File.join(output_dir,"#{name}")
+ Dir.chdir dest_folder
+ else
+ dest_folder = Dir.pwd
+ end
if title.nil?
doc = Nokogiri.XML(File.read('config.droiuby'))
@@ -158,16 +167,23 @@
title = element.content
end
end
- template_repository = ENV['droiuby_template'] || 'https://github.com/jedld/droiuby-template.git'
- template_directory = File.expand_path('~/.droiuby/android_project_templates')
+ template_repository = ENV['droiuby_template'] || repository || 'https://github.com/jedld/droiuby-template.git'
+ template_directory = File.expand_path("~/.droiuby/android_project_templates.#{branch.nil? ? 'master' : branch}")
unless File.exists?(template_directory)
say "no cached copy yet. obtaining template project from repository"
- `git clone --depth 1 #{template_repository} #{template_directory}`
+
+ branch = unless branch.nil?
+ "-b #{branch}"
+ else
+ ""
+ end
+
+ `git clone #{branch} --depth 1 #{template_repository} #{template_directory}`
else
say "checking for template updates..."
Dir.chdir template_directory
`git pull`
end
@@ -176,12 +192,19 @@
directory template_directory, File.join(dest_folder,'project')
remove_dir "#{File.join(dest_folder,'project')}/.git"
Dir.chdir File.join(dest_folder,'project')
+ say "creating android porject in #{dest_folder}"
require "#{File.join(dest_folder,'project','init.rb')}"
+ dest_folder = if dest_folder.end_with? '/'
+ dest_folder
+ else
+ "#{dest_folder}/"
+ end
+
archive_name = File.basename(dest_folder.sub!(%r[/$],'')) if archive_name.nil?
init = Init.new
init.init(package_name, "#{archive_name}.zip", title)
Dir.chdir dest_folder
@@ -191,11 +214,11 @@
end
desc "create PROJECT_NAME [APP_NAME] [WORKSPACE_DIR]","create a new droiuby project with NAME"
- def create(name, app_name = :prompt, output_dir = 'projects')
+ def create(name, app_name = :prompt, output_dir = 'projects', type = 'droiuby')
@name = name
if app_name.nil?
@app_name = app_name
elsif app_name == :prompt
say("Please enter the display name for your app (Used for app launcher and Title):")
@@ -203,30 +226,51 @@
end
@description = name
@launcher_icon = ''
@base_url = ''
- @main_xml = File.join("app","views","index.xml")
+ if type == 'droiuby'
+ @main_xml = File.join("app","views","index.xml")
+ elsif type == 'hybrid'
+ @main_xml = File.join("app","activities","index.rb")
+ else
+ say_error "Invalid project type specified"
+ exit(1);
+ end
if output_dir.blank?
output_dir = Dir.pwd
end
dest_folder = File.join(output_dir,"#{name}")
template File.join('ruby','Gemfile.erb'), File.join(dest_folder,"Gemfile")
template File.join('ruby','config.droiuby.erb'), File.join(dest_folder,"config.droiuby")
template File.join('ruby','gitignore.erb'), File.join(dest_folder,".gitignore")
- template File.join('ruby','index.xml.erb'), File.join(dest_folder,"app","views","index.xml")
+
+ if type == 'droiuby'
+ template File.join('ruby','index.xml.erb'), File.join(dest_folder,"app","views","index.xml")
+ end
+
template File.join('ruby','application.css.erb'), File.join(dest_folder,"app","views","styles","application.css")
- template File.join('ruby','index.rb.erb'), File.join(dest_folder,"app","activities","index.rb")
+ if type == 'droiuby'
+ template File.join('ruby','index.rb.erb'), File.join(dest_folder,"app","activities","index.rb")
+ elsif type == 'hybrid'
+ template File.join('ruby','index-hybrid.rb.erb'), File.join(dest_folder,"app","activities","index.rb")
+ end
template File.join('ruby','index_spec.rb.erb'), File.join(dest_folder,"spec","activities","index_spec.rb")
template File.join('ruby','spec_helper.rb.erb'), File.join(dest_folder,"spec","spec_helper.rb")
empty_directory File.join(dest_folder,"lib")
- say "running bundle install"
+
Dir.chdir dest_folder
+ if type == 'hybrid'
+ standalone(nil, :prompt, nil, nil, nil, 'hybrid-mode')
+ end
+
+ say "running bundle install"
`bundle install`
- bundle
+
+
end
desc "package NAME [WORKSPACE_DIR] [true|false]","package a project"
def package(name, source_dir = 'projects', force = "false")