sukima / ti_coffee_plugin

A build-time CoffeeScript compiler plugin for Titanium build scripts - Reborn
http://sukima.github.io/ti_coffee_plugin
Other
1 stars 0 forks source link

DEPRECATED

This code has been deprecated and is no longer maintained. The newest Titanium CLI tools make asynchronous compile hooks near impossible. Since a complete rewrite would be needed to become compatible with new versions of Titanium I opted to deprecate this in favor for pre-compile build tools such as gulp or grunt. I assume most coders who are using CoffeeScript have leveled up and can manage a build environment outside of Titanium Studio and no longer require the crutch of a compile hook such as this.

Anyone interested in rewriting this for the newer versions of Titanium can easily take over this project and remove the deprecation.

For an example of a gulp build using Titanium and CoffeeScript please check out this example project.

CoffeeScript -> Javascript compiler plugin for Titanium Projects.

Build Status

The ti_coffee_plugin simply scans your Titanium project's src folder at build time and looks for files with the .coffee extension. When it finds such files, it runs the CoffeeScript compiler (coffee -c) to produce a Javascript file of the same name and places it into the Resources directory with the same tree structure. E.g., src/ui/win.coffee would become Resources/ui/win.js.

This plugin has been updated for the Titanium SDK 3.X build system. However, The following documentation maybe outdated. The main webpage might have more updated information. Also please feel free to contribute changes to keep this README current.

Setup

(In addition to these instructions, see also videos concerning using this with Titanium Mobile and Titanium Desktop.)

Python

Requires Python 2.5, because the hashlib module is used.

CoffeeScript

First, of course, you'll need the coffee command available on your system. If you can't go out to a command-line/terminal and successfully execute coffee, then be sure to setup CoffeeScript correctly.

Also, if you're on OS X and you used Homebrew to install CoffeeScript and Node.js, GUI applications such as Titanium Developer and Titanium Studio -- which are precisely the apps that launch your Titanium project's build process and thus this plugin -- might not be able to successfully execute coffee because /usr/local/bin is not in the PATH by default for GUI apps, and changes to ~/.profile, /etc/paths, etc., are not useful for GUI apps. The easiest solution is to simply symlink coffee and node in /usr/bin, which is in the PATH:

$ sudo ln -s /usr/local/bin/node /usr/bin/node
$ sudo ln -s /usr/local/bin/coffee /usr/bin/coffee

If you'd rather not do that, you can muck around with ~/.MacOSX/environment.plist following Apple's instructions.

This Plugin

In the folder which houses your Titanium SDKs -- on OS X this would be /Library/Application Support/Titanium, create a plugins/ti_coffee_plugin/1.0 folder. Put the plugin.py from this repository into that folder. So on OS X you would have this file:

/Library/Application Support/Titanium/plugins/ti_coffee_plugin/1.0/plugin.py

On Ubuntu this would be ~/.titanium

Next, you need to tell your Titanium project to run this plugin when the Titanium build scripts build your project.

Build-time plugins for Titanium projects are invoked if the plugin is registered in the project's tiapp.xml file. For the ti_coffee_plugin, you could do it like this:

<!-- This is a child element of <ti:app> in tiapp.xml -->
<plugins>
  <plugin version="1.0">ti_coffee_plugin</plugin>
</plugins>

Sample Application

The sample/ folder contains a very simple app.coffee as a proof-of-concept. You can copy that file into a new project, then run the project to see how it works. To do that successfully, you'll also need to update your tiapp.xml following the example inside tiapp.xml.example.

Disadvantages of Using This Plugin

License

The code is Copyright 2011 by William Dawson, and made available under the Apache 2.0 license. Please see the LICENSE file that accompanies the source, and the licensing declarations at the top of each source file.

Disclaimers

This is a private project of mine and currently not supported by Appcelerator! If you have issues, please file them in the GitHub Issues section of the repository and I will try to get to them in a timely fashion. Better yet, fork and improve!