Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

extract commands to class.

  • Loading branch information...
commit dad8fc79628fd9623fba0e63fe8edc5a0f74546b 1 parent 8726051
Junya Ogura juno authored
10 lib/alloy.rb
View
@@ -2,12 +2,14 @@
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
-require "alloy/command"
-require "alloy/config"
-require "alloy/task"
-
module Alloy
PERL_COLOR_FILTER = %Q{| perl -pe 's/^\\[DEBUG\\].*$/\\e[35m$&\\e[0m/g;s/^\\[INFO\\].*$/\\e[36m$&\\e[0m/g;s/^\\[WARN\\].*$/\\e[33m$&\\e[0m/g;s/^\\[ERROR\\].*$/\\e[31m$&\\e[0m/g;'}
end
+
+require "alloy/command/build"
+require "alloy/command/clean"
+require "alloy/command/coffee_script"
+require "alloy/config"
+require "alloy/task"
59 lib/alloy/command.rb
View
@@ -1,59 +0,0 @@
-# -*- encoding: utf-8 -*-
-
-require 'colored'
-require 'fileutils'
-
-module Alloy
-
- module Command
- def self.compile_coffee
- puts "Compiling CoffeeScript".blue
-
- failed = false
- paths = `find app -name '*.coffee'`.split("\n")
-
- paths.each do |path|
- out_dir = path.gsub(/^app/, 'Resources').gsub(/\/[\w-]*\.coffee$/,"")
- unless system "coffee -c -b -o #{out_dir} #{path}"
- puts "Compilation failed: #{path}".red
- failed = true
- end
- end
-
- puts "Successfully compiled CoffeeScript".green unless failed
- not failed
- end
-
- def self.build(options = {})
- return unless compile_coffee
- options[:device] ||= 'iphone'
-
- config = Alloy::Config.new
-
- puts "Building with Titanium... (DEVICE_TYPE: #{options[:device]})".blue
- case options[:device]
- when 'android'
- system %Q{bash -c "#{config.titanium_android_builder} run '#{config.project_root}/' #{config.android_sdk_path} #{config.app_id} #{config.app_name} #{options[:device]} " #{Alloy::PERL_COLOR_FILTER}}
- when 'iphone'
- begin
- system %Q{bash -c "#{config.titanium_iphone_builder} run '#{config.project_root}/' #{config.iphone_sdk_version} #{config.app_id} #{config.app_name} #{options[:device]}" #{Alloy::PERL_COLOR_FILTER}}
- rescue => e
- puts e.message.red
- system %Q{killall "iPhone Simulator"}
- end
- end
- end
-
- def self.clean(options = {})
- case options[:device]
- when 'android'
- FileUtils.rm_r Dir.glob('build/android/*'), :force => true
- puts "Cleaned build/android".blue
- when 'iphone'
- FileUtils.rm_r Dir.glob('build/iphone/*'), :force => true
- puts "Cleaned build/iphone".blue
- end
- end
- end
-
-end
47 lib/alloy/command/build.rb
View
@@ -0,0 +1,47 @@
+# -*- encoding: utf-8 -*-
+
+require 'colored'
+
+module Alloy::Command
+
+ class Build
+ def initialize(platform)
+ @platform = platform
+ end
+
+ def execute
+ if @platform == 'iphone'
+ build :device => 'iphone'
+ elsif @platform == 'android'
+ build :device => 'android'
+ else
+ raise ArgumentError, "Platform '#{@platform}' is invalid"
+ end
+
+ true
+ end
+
+ private
+
+ def build(options = {})
+ options[:device] ||= 'iphone'
+
+ config = Alloy::Config.new
+
+ puts "Building with Titanium... (DEVICE_TYPE: #{options[:device]})".blue
+ case options[:device]
+ when 'android'
+ system %Q{bash -c "#{config.titanium_android_builder} run '#{config.project_root}/' #{config.android_sdk_path} #{config.app_id} #{config.app_name} #{options[:device]} " #{Alloy::PERL_COLOR_FILTER}}
+ when 'iphone'
+ begin
+ system %Q{bash -c "#{config.titanium_iphone_builder} run '#{config.project_root}/' #{config.iphone_sdk_version} #{config.app_id} #{config.app_name} #{options[:device]}" #{Alloy::PERL_COLOR_FILTER}}
+ rescue => e
+ puts e.message.red
+ system %Q{killall "iPhone Simulator"}
+ end
+ end
+ end
+
+ end
+
+end
43 lib/alloy/command/clean.rb
View
@@ -0,0 +1,43 @@
+# -*- encoding: utf-8 -*-
+
+require 'colored'
+require 'fileutils'
+
+module Alloy::Command
+
+ class Clean
+ def initialize(platform)
+ @platform = platform
+ end
+
+ def execute
+ case @platform
+ when 'android'
+ clean :device => 'android'
+ when 'iphone'
+ clean :device => 'iphone'
+ when nil
+ clean :device => 'android'
+ clean :device => 'iphone'
+ else
+ raise ArgumentError, "Platform '#{@platform}' is invalid"
+ end
+
+ true
+ end
+
+ private
+
+ def clean(options = {})
+ case options[:device]
+ when 'android'
+ FileUtils.rm_r Dir.glob('build/android/*'), :force => true
+ puts "Cleaned build/android".blue
+ when 'iphone'
+ FileUtils.rm_r Dir.glob('build/iphone/*'), :force => true
+ puts "Cleaned build/iphone".blue
+ end
+ end
+ end
+
+end
33 lib/alloy/command/coffee_script.rb
View
@@ -0,0 +1,33 @@
+# -*- encoding: utf-8 -*-
+
+require 'colored'
+
+module Alloy::Command
+
+ class CoffeeScript
+ def execute
+ compile_coffee
+ end
+
+ private
+
+ def compile_coffee
+ puts "Compiling CoffeeScript".blue
+
+ failed = false
+ paths = `find app -name '*.coffee'`.split("\n")
+
+ paths.each do |path|
+ out_dir = path.gsub(/^app/, 'Resources').gsub(/\/[\w-]*\.coffee$/,"")
+ unless system "coffee -c -b -o #{out_dir} #{path}"
+ puts "Compilation failed: #{path}".red
+ failed = true
+ end
+ end
+
+ puts "Successfully compiled CoffeeScript".green unless failed
+ not failed
+ end
+ end
+
+end
33 lib/alloy/task.rb
View
@@ -7,40 +7,25 @@ module Alloy
class Task < Thor
desc 'coffee', 'Compile CoffeeScript into JavaScript'
def coffee
- Command.compile_coffee
+ Command::CoffeeScript.new.execute
end
desc 'build [PLATFORM]', 'Build the app and run in simulator or emulator'
def build(platform = 'iphone')
- if platform == 'iphone'
- Command.build :device => 'iphone'
- elsif platform == 'android'
- Command.build :device => 'android'
- else
- raise ArgumentError, "Platform '#{platform}' is invalid"
- end
+ return unless coffee
+ Command::Build.new(platform).execute
end
desc 'clean [PLATFORM]', 'Clean build directory for specified platform'
def clean(platform = nil)
- case platform
- when 'android'
- Command.clean :device => 'android'
- when 'iphone'
- Command.clean :device => 'iphone'
- when nil
- Command.clean :device => 'android'
- Command.clean :device => 'iphone'
- else
- raise ArgumentError, "Platform '#{platform}' is invalid"
- end
+ Command::Clean.new(platform).execute
end
- desc 'docco', 'Generate documents by Docco'
- def docco
- system %Q{bash -c "find app -name '*.coffee' | xargs docco"}
- system %Q{bash -c "open docs/app.html"}
- end
+ # desc 'docco', 'Generate documents by Docco'
+ # def docco
+ # system %Q{bash -c "find app -name '*.coffee' | xargs docco"}
+ # system %Q{bash -c "open docs/app.html"}
+ # end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.