Permalink
Browse files

¡Ya llegó su pachucote!

  • Loading branch information...
vic committed Mar 14, 2012
0 parents commit 74bb334876fade48328dac22fabecbc2ced1dace
Showing with 258 additions and 0 deletions.
  1. +1 −0 README.md
  2. +7 −0 bin/tintan
  3. +7 −0 etc/Jakefile.coffee
  4. +8 −0 etc/package.json.eco
  5. +39 −0 etc/plugins/tintan/plugin.py
  6. +44 −0 lib/tintan.coffee
  7. +78 −0 lib/tintan/boot.coffee
  8. +53 −0 lib/tintan/main.coffee
  9. +21 −0 package.json
  10. BIN pub/pachuco.png
@@ -0,0 +1 @@
+Tintan
@@ -0,0 +1,7 @@
+#!/usr/bin/env node
+var path = require('path')
+ , local = path.join( process.cwd(), 'node_modules/tintan/lib/tintan' )
+ , globl = path.join( __dirname, '../lib/tintan' )
+ , exist = path.existsSync( local )
+require('coffee-script')
+require( exist ? local : globl ).$.main()
@@ -0,0 +1,7 @@
+#!/usr/bin/env coffee
+
+require('Tintan').global()
+
+
+compile 'coffee', from: _('src/coffee'), ext: '.coffee'
+compile 'clojure', from: _('src/clojure'), ext: '.clojure'
@@ -0,0 +1,8 @@
+<% devDeps = (tintan: @Tintan.version) ; devDeps[n] = v for own n, v of @Tintan.$.pkg.dependencies %>
+{
+ "name": "<%= @Tintan.appXML.name() %>",
+ "version": "<%= @Tintan.appXML.version() %>",
+ "dependencies": {
+ },
+ "devDependencies": <%- JSON.stringify devDeps %>
+}
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Tintan compiler plugin.
+#
+
+import os, sys, subprocess
+
+try:
+ import json
+except:
+ import simplejson as json
+
+# The Titanium build scripts contain their own json library (Patrick Logan's),
+# so we have to figure out which json functions to use.
+to_json = None
+if hasattr(json, 'dumps'):
+ to_json = json.dumps
+else:
+ to_json = json.write
+
+
+def compile(config):
+ c = config.copy()
+ c.pop('tiapp')
+ project_dir = c.get('project_dir')
+
+ print "[INFO] Tintan plugin loaded. Executing `tintan` on ", project_dir
+
+ tintan = os.path.join(project_dir, 'node_modules/tintan/bin/tintan')
+
+ proc = subprocess.Popen([tintan, '-C', project_dir, 'tintan:build'],
+ env={'CONFIG': to_json(c)})
+ proc.communicate();
+ ret = proc.wait()
+
+ if ret <> 0:
+ raise Exception('Tintan terminated with exitcode: '+str(ret))
+
@@ -0,0 +1,44 @@
+require 'colors'
+path = require 'path'
+fs = require 'fs'
+libxml = require 'libxmljs'
+
+class $
+
+ @_: (pth) -> path.join(process.cwd(), pth)
+
+ @E: (pth) -> path.join(__dirname, '../etc', pth)
+
+ @pkg: JSON.parse fs.readFileSync path.join(__dirname, '../package.json'), 'utf-8'
+
+ @main: -> require('./tintan/main') Tintan
+
+
+class AppXML
+
+ file: $._('tiapp.xml')
+ exist: -> path.existsSync @file
+
+ constructor: ->
+ throw "Missing Titanium file #{@file}".red unless @exist()
+ @doc = libxml.parseXmlString fs.readFileSync @file, 'utf-8'
+
+ plugin: -> @doc.get "./plugins/plugin[contains(text(),'tintan')]"
+
+ name: -> @doc.get('./name').text()
+
+ version: ->
+ v = @doc.get('./version').text()
+ v = v.split '.'
+ if v.length < 3
+ v = v.concat('0' for i in [0 .. (2 - v.length)])
+ v.join '.'
+
+class Tintan
+
+ @$ = $
+ @version: $.pkg.version
+ @appXML = new AppXML
+
+
+module.exports = Tintan
@@ -0,0 +1,78 @@
+require 'colors'
+path = require 'path'
+fs = require 'fs'
+eco = require 'eco'
+info = console.info
+
+{Tintan, $, _, E, appXML} = {}
+
+T = (pth) ->
+ T.deps.push _ pth
+
+ file _(pth), ->
+ info 'create'.green + ' ' + pth
+ jake.mkdirP path.dirname @name
+ temp = E pth + '.eco'
+ if path.existsSync temp
+ temp = fs.readFileSync temp, 'utf-8'
+ value = eco.render temp, Tintan: Tintan
+ fs.writeFileSync @name, value, 'utf-8'
+ else
+ jake.cpR E(pth), @name
+
+T.deps = []
+
+npm_install = ->
+ info 'updating'.green + ' node modules'
+ npm = require('child_process').spawn 'npm', ['install', '-l']
+ npm.stdout.on 'data', (data)-> process.stdout.write(data)
+ npm.stderr.on 'data', (data)-> process.stderr.write(data)
+ npm.on 'exit', (code)=>
+ fail('npm install -l: failed with code '+code) if code != 0
+ complete()
+
+class Boot
+
+ ready: ->
+ false
+
+ constructor: (Ti)->
+
+ Tintan = Ti
+ {$, appXML} = Tintan
+ {E, _} = $
+
+ namespace 'tintan', ->
+
+ desc 'Install the Tintan plugin for Titanium Studio'
+ T 'plugins/tintan/plugin.py'
+
+ desc 'Register plugin on tiapp.xml'
+ task 'plugin', ->
+ unless appXML.plugin()
+ info 'register'.green + ' tintan plugin on tiapp.xml'
+ xml = appXML.doc
+ plugins = xml.get './plugins'
+ unless plugins
+ plugins = xml.root().node 'plugins', ''
+ plugin = plugins.node 'plugin', 'tintan'
+ plugin.attr version: Tintan.version
+ xml.encoding 'utf-8'
+ fs.writeFileSync appXML.file, xml.toString(), 'utf-8'
+ T.deps.push 'plugin'
+
+ desc 'Create a generic package.json'
+ T 'package.json'
+
+ desc 'Create a basic Jakefile'
+ T 'Jakefile.coffee'
+
+ desc 'Install node modules with npm'
+ task 'npm', [_('package.json')], npm_install, async: true
+ T.deps.push 'npm'
+
+ desc 'Iniitalize this project to use Tintan'
+ task 'init', T.deps, ->
+ info 'Tintan initialized'
+
+module.exports = (Tintan)-> new Boot Tintan
@@ -0,0 +1,53 @@
+path = require 'path'
+fs = require 'fs'
+jakeLib = path.dirname require.resolve 'jake'
+jake = require "#{jakeLib}/jake"
+api = require "#{jakeLib}/api"
+utils = require "#{jakeLib}/utils"
+Program = require("#{jakeLib}/program").Program
+Loader = require("#{jakeLib}/loader").Loader
+jakePkg = JSON.parse fs.readFileSync "#{jakeLib}/../package.json", 'utf-8'
+
+jake.version = jakePkg.version
+
+process.addListener 'uncaugthException', (err)-> program.handleErr err
+
+global.jake = jake
+
+args = process.argv.slice(2)
+program = new Program()
+program.parseArgs(args)
+
+main = (Tintan)->
+
+ jake.opts = program.opts
+
+ jake[n] = v for own n, v of utils
+
+ jake.FileList = require("#{jakeLib}/file_list").FileList
+ jake.PackageTask = require("#{jakeLib}/file_list").PackageTask
+ jake.NpmPublishTask = require("#{jakeLib}/file_list").NpmPublishTask
+
+ process.env[n] = v for own n, v of jake.env
+ process.chdir(jake.opts.directory) if jake.opts.directory
+
+ global[n] = v for own n, v of api
+
+ taskNames = program.taskNames
+
+ # require('./build') Tintan
+ boot = require('./boot') Tintan
+ if boot.ready()
+ loader.load(jake.opts.jakefile)
+ else unless taskNames.length
+ taskNames = ['tintan:init']
+
+ taskNames = taskNames.length and taskNames or ['default']
+ api.task '__root__', taskNames, ->
+
+ if jake.opts.tasks
+ jake.showAllTaskDescriptions jake.opts.tasks
+ else
+ jake.Task['__root__'].invoke()
+
+module.exports = program.preemptiveOption() and (->) or main
@@ -0,0 +1,21 @@
+{
+ "name": "tintan"
+, "description": "Titanium development with style."
+, "version": "0.0.1"
+, "keywords": [
+ "titanium", "mobile", "coffee", "clojure", "jasmine"
+ , "bdd", "tdd"
+ ]
+, "bin": {
+ "tintan": "./bin/tintan"
+ }
+, "dependencies": {
+ "colors": ">= 0.0.0"
+ , "jake": ">= 0.0.0"
+ , "libxmljs": ">= 0.0.0"
+ , "eco": ">= 0.0.0"
+ }
+, "devDependencies": {
+ "coffee-script": ">= 0.0.0"
+ }
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 74bb334

Please sign in to comment.