Created
June 27, 2013 08:42
-
-
Save lis186/5874957 to your computer and use it in GitHub Desktop.
Grunt script that generate view (app/views/*.xml) and style(app/styles/*.tss) from jade(app/views/.jade) in Titanium Alloy project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
function getJadeFiles(srcdir, destdir, wildcard) { | |
var path = require('path'); | |
var files = {}; | |
grunt.file.expand({cwd: srcdir}, wildcard).forEach(function(relpath) { | |
files[path.join(destdir, relpath.replace('.jade','.xml'))] = path.join(srcdir, relpath); | |
}); | |
return files; | |
} | |
function generateXml2tssCommand(srcdir, destdir, wildcard) { | |
var path = require('path'); | |
var commands = []; | |
grunt.file.expand({cwd: srcdir}, wildcard).forEach(function(relpath) { | |
var xmlFile = path.join(srcdir, relpath); | |
var tssFile = path.join(destdir, relpath.replace('.xml','.tss')); | |
if(grunt.file.exists(tssFile)){ | |
grunt.log.writeln(tssFile + ' exists, ignored.'); | |
}else{ | |
grunt.log.writeln(tssFile + ' generated.'); | |
commands.push('xml2tss '+ xmlFile + ' > ' + tssFile); | |
} | |
}); | |
commands = commands.toString().replace(/,/gi, ' && '); | |
return commands; | |
} | |
// Project configuration. | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
watch: { | |
jade2xml: { | |
files: ["app/views/*.jade"], | |
tasks: ["jade", 'shell'] | |
} | |
}, | |
jade: { | |
compile: { | |
options: { | |
data: { | |
debug: false | |
} | |
}, | |
files: getJadeFiles('app/views', 'app/views', '**/*.jade') | |
} | |
}, | |
shell: { | |
xml2tss: { | |
command: generateXml2tssCommand('app/views', 'app/styles', '**/*.xml'), | |
options: { | |
stdout: true | |
} | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-jade'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.loadNpmTasks('grunt-shell'); | |
grunt.registerTask('default', ['jade', 'shell']); | |
grunt.registerTask('xml2tss', ['shell']); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "alloy-jade2tss", | |
"version": "0.1.0", | |
"devDependencies": { | |
"grunt": "~0.4.1", | |
"grunt-contrib-jade": "~0.7.0", | |
"grunt-contrib-watch": "*", | |
"grunt-shell": "*", | |
"xml2tss": "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment