Skip to content

Instantly share code, notes, and snippets.

@kmr
Created January 8, 2012 09:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmr/1577879 to your computer and use it in GitHub Desktop.
Save kmr/1577879 to your computer and use it in GitHub Desktop.
Cakefile for Titanium mobile development
sys = require 'util'
fs = require 'fs'
exec = require('child_process').exec
# アプリ関連設定
APP_NAME = 'appname' # アプリ名
APP_ID = 'net.necomimi.appid' # アプリID
ANDROID_SDK = '/path/to/android-sdk' # AndroidSDKのインストール先
TI_HOME = '/Library/Application\\ Support/Titanium/mobilesdk/osx/1.8.0.1' # 利用するTitaniumのホーム
# 以下は基本的にいじらなくていいはず
TI_ANDROID_BUILDER = "#{TI_HOME}/android/builder.py"
TI_IOS_BUILDER = "#{TI_HOME}/iphone/builder.py"
COFFEE = 'coffee'
COFFEE_OPTIONS = '-cb'
COFFEE_SRCDIR = 'coffee' # *.coffeeファイルがあるディレクトリへのパス
JS_DIR = 'Resources' # *.jsファイルの保存先
consoleOut = (err, stdout, stderr) ->
throw err if err
console.log stdout+stderr
targetList = []
for f in fs.readdirSync COFFEE_SRCDIR
targetList.push RegExp.$1 if f.match /^(\w+)\.coffee$/
task 'coffee', 'compile outdated coffee files', ->
for target in targetList
sys.puts "found #{COFFEE_SRCDIR}/#{target}.coffee"
try
cs = fs.statSync "#{COFFEE_SRCDIR}/#{target}.coffee"
catch error
sys.puts "file not found: #{error.path}"
continue
try
js = fs.statSync "#{JS_DIR}/#{target}.js"
continue if cs.mtime < js.mtime
catch error
null
sys.puts "#{COFFEE_SRCDIR}/#{target}.coffee is outdated."
sys.puts "#{COFFEE} #{COFFEE_OPTIONS} -o #{JS_DIR} #{COFFEE_SRCDIR}/#{target}.coffee"
exec "#{COFFEE} #{COFFEE_OPTIONS} -o #{JS_DIR} #{COFFEE_SRCDIR}/#{target}.coffee", consoleOut
task 'ainstall', 'install package to android device', ->
invoke 'coffee'
sys.puts "#{TI_ANDROID_BUILDER} #{APP_NAME} #{ANDROID_SDK} ./ #{APP_ID} 1"
exec "#{TI_ANDROID_BUILDER} install #{APP_NAME} #{ANDROID_SDK} ./ #{APP_ID} 1", consoleOut
task 'clean', 'delete js files', ->
for target in targetList
exec "rm #{JS_DIR}/#{target}.js"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment