grunt-titanium

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-titanium --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt-titanium sits on top of your Titanium SDK installation. It won't install the SDK for you. It won't install Android, iOS, etc... for you. Be sure your Titanium environment is setup before trying to use this plugin as part of your development workflow.

If set to true, grunt-titanium will use your globally installed version of titanium to execute the commands. If false (default), it will use the version of titanium included with grunt-titanium's dependencies.

The rest of the options and flags are the same as the those available to the Titanium CLI. You can see this list like this by typing titanium help COMMAND_NAME. The options should be named as camel case as opposed to the dashed format used by the CLI, making them easier to use as keys in your options. For example, --build-only becomes buildOnly. More details in the examples below.

Based on the output of the Titanium app, determine if it has failed. This is necessary if you want a run or ti_run task to finish, since Titanium runs indefinitely if there's no intervention or error. Useful for chaining commands together.

Here's the details on each possible usage, where data represents each line of output from Titanium. If the condition is true, the task is considered to have failed.

type

condition

example

String

data.indexOf(String) !== -1

{ failure: 'I failed' }

RegExp

RegExp.test(data)

{ faillure: /(?:failed|errored)/i }

Function

Function(data)

{ failure: function(data) { return data.charAt(0) === '!' } }

Check the Gruntfile.js for more examples of success and failure conditions.

Based on the output of the Titanium app, determine if it has succeeded. This is necessary if you want a run or ti_run task to finish, since Titanium runs indefinitely if there's no intervention or error. Useful for chaining commands together.

Here's the details on each possible usage, where data represents each line of output from Titanium. If the condition is true, the task is considered to have succeeded.

type

condition

example

String

data.indexOf(String) !== -1

{ success: 'SUCCESS' }

RegExp

RegExp.test(data)

{ success: /(?:success|done)/i }

Function

Function(data)

{ success: function(data) { return data.charAt(0) === '!' } }

Check the Gruntfile.js for more examples of success and failure conditions.

There's a few practical usage examples in this repo's Gruntfile.js. Also, ti-mocha's Gruntfile.js uses grunt-titanium to automate the launching of runtime testing. Aside from that, here's a few more examples. Note that grunt-titanium will use sensible defaults for many required CLI parameters.

Before getting into the individual command you can run with the titanium task, let's look at the most common use case with titanium_run. Here we will create a new titanium app, add files to it using grunt's file capabilities, then build the app.

grunt.initConfig({

ti_run:{

options:{

build:{

platform:'ios'

}

},

myapp:{

files:{

'tmp/myapp':['test/fixtures/myapp/**/*']

}

}

}

});

But the ti-run task tries to make a lot of smart decisions for you, so the above could also be defined as tersely as this:

grunt.initConfig({

ti_run:{

myapp:{}

}

});

or even more tersely:

grunt.initConfig({

ti_run:['myapp']

});

For details on the multiple default locations that ti_run will check for files, please read issue #12. Using these locations will make your Gruntfile.js much cleaner.

grunt-titanium makes it trivial to add creating a Titanium project to your workflow. Extremely useful for testing. The following would create an app named MyTestApp in the same directory as your Gruntfile.js.

Try out some of the Titanium CLI's other commands. grunt-titanium can do anything the CLI can do, so feel free to be inventive. Let's say we have some automated testing and we need to change the current selected Titanium SDK as part of that testing. No problem: