Skip to content

Commit

Permalink
Added build and run tasks for iphone and android
Browse files Browse the repository at this point in the history
  • Loading branch information
vic committed Mar 19, 2012
1 parent 6585f01 commit df70681
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 28 deletions.
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -42,7 +42,7 @@
Normally Tintan will try to guess your current environment setup, you can
however force a particular setting by exporting one of the following variables:

TI_PLATFORM - The platform for mobile development: 'android' or 'iphone'
TI_PLATFORM - The platform for mobile development: 'android', 'iphone', 'mobileweb', 'module'

By default if your OS is Linux, android will be used,
on Mac iphone will be selected by default.
Expand All @@ -63,10 +63,14 @@

By default the python found in PATH

IOS_VERSION - The version of iOS to target, eg. 4.0, 5.0

Default: max value of ~/Library/Application Support/iPhone Simulator/


ANDROID_SDK - The location of the Android development kit.

Default: none.
Default: on Mac the max value of /usr/local/Cellar/android-sdk/* if any.


AVD - The Android virtual device to use for development.
Expand Down
4 changes: 2 additions & 2 deletions etc/Jakefile.coffee
Expand Up @@ -7,5 +7,5 @@ tintan = require('tintan')
# Compile coffee-script sources from src/coffee
tintan.compile 'coffee'

# Make the default task depend on tintan:build.
task 'default', ['tintan:build']
# Make the default task depend on build.
task 'default', ['build']
8 changes: 5 additions & 3 deletions etc/plugins/tintan/plugin.py
Expand Up @@ -21,15 +21,17 @@

def compile(config):
c = config.copy()
c.pop('tiapp')
c.pop('tiapp', '')
c.pop('android_builder', '')
c.pop('logger', '')
project_dir = c.get('project_dir')

tintan = os.path.join(project_dir, 'node_modules/tintan/bin/tintan')

print "[INFO] Executing Tintan"
print " node", tintan, "-C", project_dir, 'tintan:build'
print " node", tintan, "-C", project_dir, 'tintan'

proc = subprocess.Popen(['node', tintan, '-C', project_dir, 'tintan:build'],
proc = subprocess.Popen(['node', tintan, '-C', project_dir, 'tintan'],
env={'TINTAN': to_json(c)}, stderr = sys.stderr, stdout = sys.stdout)
proc.communicate();
ret = proc.wait()
Expand Down
40 changes: 35 additions & 5 deletions lib/tintan.coffee
Expand Up @@ -46,6 +46,21 @@ class $
'win32': 'win'
}[require('os').platform()]

@ios_version: @mem ->
iphone_dir = path.join(process.env.HOME, 'Library', 'Application Support', 'iPhone Simulator')
if path.existsSync iphone_dir
return process.env.IOS_VERSION if process.env.IOS_VERSION &&
path.existsSync(path.join(iphone_dir, process.env.IOS_VERSION))
fs.readdirSync(iphone_dir).sort()[-1..][0]

@android_home: @mem ->
brew_location = '/usr/local/Cellar/android-sdk'
if process.env.ANDROID_SDK && path.existsSync process.env.ANDROID_SDK
process.env.ANDROID_SDK
else if path.existsSync brew_location
path.join brew_location, fs.readdirSync(brew_location).sort()[-1..][0]


@platform: process.env.TI_PLATFORM || {osx: 'iphone'}[@os] || 'android'

@sdk: @mem ->
Expand All @@ -54,23 +69,26 @@ class $
else
fs.readdirSync(path.join(@home(), 'mobilesdk', @os)).sort()[-1..][0]

@tipy: @mem -> path.join(@home(), 'mobilesdk', @os, @sdk(), 'titanium.py')

@py: @mem ->
return py for py in [process.env.PYTHON, process.env.TI_PYTHON,
process.env.PYTHON_EXECUTABLE] when path.existsSync py
@pathSearch 'python'

@titan: (args ..., cb)->
@titan: (args ...)->
@tipy.apply(this, [['titanium.py'], args])

@fastdev: (args ...)-> @titan.apply this, ['fastdev'].concat(args)

@tipy: (ary, args ..., cb)->
unless cb instanceof Function
args.push cb
cb = ->
p = spawn @py(), [@tipy()].concat(args)
tool = path.join.apply(path, [@home(), 'mobilesdk', @os, @sdk()].concat(ary))
p = spawn @py(), [tool].concat(args)
p.stdout.on 'data', (data)-> process.stdout.write data
p.stderr.on 'data', (data)-> process.stderr.write data
p.on 'exit', cb

@fastdev: (args ...)-> @titan.apply this, ['fastdev'].concat(args)

class AppXML

Expand All @@ -83,6 +101,10 @@ class AppXML

plugin: -> @doc.get "./plugins/plugin[contains(text(),'tintan')]"

id: -> @doc.get('./id').text()

guid: -> @doc.get('./guid').text()

name: -> @doc.get('./name').text()

version: ->
Expand All @@ -92,6 +114,14 @@ class AppXML
v = v.concat('0' for i in [0 .. (2 - v.length)])
v.join '.'

targets: (devices ...)->
if devices.length > 0
enabled = (device for device in devices when !!@doc.
get('./deployment-targets/target[@device="'+device+'" and contains(text(), "true")]'))
enabled.length == devices.length
else
@doc.find('./deployment-targets/target[contains(text(), "true")]/@device').map (i)-> i.text()

class Tintan

@$ = $
Expand Down
23 changes: 23 additions & 0 deletions lib/tintan/build.coffee
@@ -0,0 +1,23 @@
module.exports = (tintan)->
Tintan = tintan.constructor

build_deps = []

namespace 'build', ->

if Tintan.appXML().targets 'iphone'
build_deps.push 'build:iphone'
desc 'Build for iPhone'
task 'iphone', ->
Tintan.$.tipy ['iphone', 'builder.py'], 'build',
Tintan.$.ios_version(), process.cwd(), Tintan.appXML().id(), Tintan.appXML().name()

if Tintan.appXML().targets 'android'
build_deps.push 'build:android'
desc 'Build for Android'
task 'android', ->
Tintan.$.tipy ['android', 'builder.py'], 'build',
Tintan.appXML().name(), Tintan.$.android_home(), process.cwd(), Tintan.appXML().id()

desc 'Build sources'
task 'build', build_deps
28 changes: 16 additions & 12 deletions lib/tintan/fastdev.coffee
@@ -1,20 +1,24 @@
module.exports = (tintan)->

fastdev = tintan.constructor.$.fastdev
Tintan = tintan.constructor

namespace 'fastdev', ->
fastdev = Tintan.$.fastdev

desc 'Start fastdev server'
task 'start', -> fastdev 'start'
if Tintan.appXML().targets 'android'

desc 'Stop fastdev server'
task 'stop', -> fastdev 'stop'
namespace 'fastdev', ->

desc 'Get the status of the fastdev server'
task 'status', -> fastdev 'status'
desc 'Start fastdev server'
task 'start', -> fastdev 'start'

desc 'Restart the app connected to this fastdev server'
task 'restart', -> fastdev 'restart-app'
desc 'Stop fastdev server'
task 'stop', -> fastdev 'stop'

desc 'Kill the app connected to this fastdev server'
task 'kill', -> fastdev 'kill-app'
desc 'Get the status of the fastdev server'
task 'status', -> fastdev 'status'

desc 'Restart the app connected to this fastdev server'
task 'restart', -> fastdev 'restart-app'

desc 'Kill the app connected to this fastdev server'
task 'kill', -> fastdev 'kill-app'
18 changes: 18 additions & 0 deletions lib/tintan/run.coffee
@@ -0,0 +1,18 @@
module.exports = (tintan)->
Tintan = tintan.constructor

namespace 'run', ->

if Tintan.appXML().targets 'ipad'
desc 'Run the application on iPad emulator'
task 'ipad', ->
Tintan.$.tipy ['iphone', 'builder.py'], 'simulator',
Tintan.$.ios_version(), process.cwd(), Tintan.appXML().id(), Tintan.appXML().name(),
'ipad', 'retina'

if Tintan.appXML().targets 'iphone'
desc 'Run the application on iPhone emulator'
task 'iphone', ->
Tintan.$.tipy ['iphone', 'builder.py'], 'simulator',
Tintan.$.ios_version(), process.cwd(), Tintan.appXML().id(), Tintan.appXML().name(),
'iphone', 'retina'
9 changes: 5 additions & 4 deletions lib/tintan/tasks.coffee
Expand Up @@ -2,14 +2,15 @@ files = '
fastdev
compile
build
run
'.trim().split(/[^a-zA-Z\/\.]+/).map (s)-> './'+s

module.exports = (tintan)->

require(file) tintan for file in files

namespace 'tintan', ->

task 'build', ['^compile'], ->
console.log 'done'.green + ' building ' + tintan.constructor.appXML().name()
task 'tintan', ->
console.log tintan.constructor.env
console.log 'done'.green + ' building ' + tintan.constructor.appXML().name()

0 comments on commit df70681

Please sign in to comment.