Skip to content
yuchi edited this page Dec 14, 2014 · 12 revisions

Welcome to the titaniumifier, the build tool to author high quality Titanium SDK modules with all the power of npm.

Introduction

Titaniumifier is a tool which converts a CommonJS package into a Titanium SDK CommonJS module.

It does this by using a static analysis tool (browserify) to identify the dependency graph of your package and bundling it into a single zipfile, ready to be installed through Titanium Studio or gitTio.

  • A CommonJS package is a standard way of defining a distributable package. Its most known user is Node.js and its powerful repository, npm. The definition of the package resides in the package.json file in the root of the project.

    It can have multiple files and depend on other packages.

  • A Titanium SDK CommonJS module instead is just a zipfile with a manifest file which contains the metadata of the module and a <module id>.js file which is the actual module.

    It’s a single file architecture, with no dependency management.

Getting Started

You need to have Node.js and npm installed to follow this mini-guide, but you already have if you have the Titanium SDK environment set up.

If you never used it, you need to install the Command Line Interface for Grunt, the JavaScript Task Runner:

$ [sudo] npm install --global grunt-cli

Create your project directory:

$ mkdir my-awesome-thing
$ cd my-awesome-thing

Initialize a package.json

$ npm init

…and by following the wizard you’ll end up with something like this:

$ cat ./package.json
{
  "name": "my-awesome-thing",
  "version": "1.0.0",
  "description": "Does awesome things!",
  "main": "./index.js"
}

Setup the Grunt tasks by creating a Gruntfile.js in the root of your project and by installing the required dependencies:

$ npm install --save-dev grunt grunt-titaniumifier
// Gruntfile.js
module.exports = function (grunt) {
  grunt.initConfig({
    // Our task will be executed with `titaniumifier:module`
    "titaniumifier": {
      "module": {
        files: {
          // The package is in "." and the zipfile will be written in "."
          ".": "."
        }
      }
    }
  });

  // Load dependencies
  grunt.loadNpmTasks('grunt-titaniumifier');
};

Create an index.js:

// index.js

module.exports.shout = function (s) {
 return s + '!!';
};

And finally launch titaniumifier:

$ grunt titaniumifier:module

But we get an error!

Fatal error: No `guid` found. Here’s one for you: 946f6eea-6afd-0508-0854-518c1150dc3b

Modify the package.json file to include the missing guid (the error has built a random one for you):

{
  "name": "my-awesome-thing",
  "version": "1.0.0",
  "description": "Does awesome things!",
  "titaniumManifest": {
    "guid": "946f6eea-6afd-0508-0854-518c1150dc3b"
  },
  "main": "./index.js"
}

Run grunt again:

$ grunt titaniumifier:module

Running "titaniumifier:module" (titaniumifier) task
>> Module zip written in /path/to/my-awesome-thing

🎉 Awesome! You now have a titaniumified package as my-awesome-thing-commonjs-1.0.0.zip in your project root directory!

Clone this wiki locally