Skip to content

Instantly share code, notes, and snippets.

@m4tm4t
Created October 29, 2014 18:15
Show Gist options
  • Save m4tm4t/2a65ac6caf7e31aa5069 to your computer and use it in GitHub Desktop.
Save m4tm4t/2a65ac6caf7e31aa5069 to your computer and use it in GitHub Desktop.
Gruntfile for Titanium ( jade, coffee, stss, tishadow )
module.exports = ( grunt ) ->
grunt.initConfig
# Compile coffeescript
coffee:
options:
bare: true
sourceMap: false
compile:
files: [
expand: true
src: ['**/*.coffee']
dest: 'app'
cwd: 'src'
ext: '.js'
]
# Compile STSS
stss:
compile:
files: [
expand: true
src: ['**/*.stss', '!**/_*.stss']
dest: 'app'
cwd: 'src'
ext: '.tss'
]
# Compile Jade
jade:
compile:
options:
pretty: true
files: [
expand: true
src: ['**/*.jade', '!**/includes/**', '!**/templates/**']
dest: 'app'
cwd: 'src'
ext: '.xml'
]
# Cleanup compiled files
clean:
project:
src: [
"build"
"Resources"
"{app,src}/**/*.{js,tss,xml}*"
"hs_err_*"
]
# Tishadow commands
tishadow:
options:
# update: true
# tail: true
withAlloy: true
loglLevel: 1
run:
command: 'run'
# Android options
android:
options:
platform: 'android'
server:
command: 'server'
# Watch changes
watch:
options:
nospawn: true
android:
files: [
"src/**/*.{coffee,stss,jade}"
"!src/**/includes/**"
]
tasks: ['build', 'tishadow:run:android']
# Handle changes
grunt.event.on 'watch', ( action, filepath ) ->
# Only compile changed file
extensions = [
'coffee' : '.js'
'stss' : '.tss'
'jade' : '.xml'
]
extensions.forEach ( ext ) ->
ext_key = Object.keys ext
re = new RegExp ext_key[0]
if filepath.match re
o = new Object
new_filepath = filepath.replace('src', 'app')
new_filepath = new_filepath.replace('.'+ext_key.toString(), ext[ ext_key.toString() ])
o[ new_filepath ] = [ filepath ]
grunt.config.set([ ext_key.toString(), 'compile', 'files' ], o)
require( 'matchdep' ).filterDev('grunt-*').forEach( grunt.loadNpmTasks )
grunt.registerTask 'default', ['clean', 'build']
grunt.registerTask 'build', ['coffee', 'stss', 'jade']
grunt.registerTask 'dev_android', ['default', 'tishadow:run:android', 'tishadow:server:android', 'watch:android']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment