Created
May 23, 2012 17:29
-
-
Save elfsternberg/2776520 to your computer and use it in GitHub Desktop.
Cakefile to find the Coffee/HAML/Less files in a Require.JS layout and pre-compile them into their JS/HTML/CSS forms .
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
fs = require 'fs' | |
{spawn, exec} = require 'child_process' | |
path = require 'path' | |
# Requires that you 'npm install findit' | |
findit = require 'findit' | |
SRCDIR="./src" | |
TGTDIR="./build" | |
find_all = (srcdir, src_prefix) -> | |
mkr = (r) -> new RegExp r.replace /\./, '\\.' | |
build = (src_extension, targ_extension, command, options) -> | |
findit.find(SRCDIR).on 'file', (source, stats) -> | |
if path.extname(source) == src_extension | |
source_path = path.dirname(source) | |
source_file = path.basename(source) | |
target_path = source_path.replace(mkr('^' + SRCDIR), TGTDIR) | |
target = path.join(target_path, source_file) | |
target_file = path.basename(target) | |
fs.mkdir target_path, 0755, (err) -> | |
if err and err.code != 'EEXIST' | |
throw err | |
cmd = command.replace(/\$source/, source) | |
.replace(/\$target_path/, target_path) | |
.replace(/\$source_path/, source_path) | |
.replace(/\$target_file/, target_file) | |
.replace(/\$source_file/, source_file) | |
.replace(/\$target/, target) | |
exec cmd, (error, stderr, stdout) -> | |
if error | |
throw source + ' ' + error | |
if options.verbose | |
console.log(stdout) | |
if stderr | |
console.log(stderr) | |
task 'compile', 'build the proprocessed components', (options) -> | |
build '.coffee', '.js', 'coffee --compile --lint -o $target_path $source', options | |
build '.haml', '.html', 'haml --unix-newlines --no-escape-attrs --double-quote-attributes $source > $target', options | |
build '.less', '.css', 'lessc $source $target', options |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment