#!/usr/bin/env ruby require 'optparse' require 'methadone' require_relative '../motion-prime/version' class App include Methadone::Main include Methadone::CLILogging include Methadone::SH main do |command, *opts| case command.to_sym when :new then create_base(*opts) when :bootstrap then create_bootstrap(*opts) when :generate then generate(*opts) when :g then generate(*opts) else help end 0 end def self.help info "Command line tools for MotionPrime" info "Commands:" info " new " info " Creates a new MotionPrime app from a template." info " generate scaffold " info " Creates a new MotionPrime scaffold from a template." info " generate screen|model|table " info " Creates a new MotionPrime resource from a template." end def self.create_base(name) create(name, "motion-prime", "git://github.com/droidlabs/motion-prime.git") end def self.create_bootstrap(name) create(name, "prime_bootstrap", "git://github.com/motionprime/prime_bootstrap.git") end def self.create(name, template_name, repo) return puts "Usage: prime new " unless name.to_s.length > 0 info "Creating new MotionPrime iOS app: #{name}" if false sh "motion create #{name} --template=#{repo}" else clone_template(template_name, repo) sh "motion create #{name} --template=#{template_name}" end info "Command: bundle instal" sh "cd ./#{name}; bundle install" info "Command: pod setup" sh "cd ./#{name}; pod setup" info "Command: rake pod:install" sh "cd ./#{name}; rake pod:install" end def self.generate(resource, name) require_relative '../generators/generator' MotionPrime::Generator.factory(resource).generate(name) end def self.home_path ENV['HOME'].split('/')[0..2].join('/') end def self.clone_template(name, repo) path = File.expand_path(File.join(home_path, 'Library/RubyMotion/template', name)) git_clone(path, repo) end def self.git_clone(path, repo) if File.exist?(path) system("git --work-tree=#{path} --git-dir=#{path}/.git pull origin master") else system("git clone #{repo} #{path}") end end description "Command line tools for MotionPrime" arg :command arg :opt, :optional version MotionPrime::VERSION go! end