From 183af777b1ec6cdc6ced29bb3a90b64c950ffe7b Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Tue, 17 May 2011 01:14:56 +0200 Subject: [PATCH] automatically include 'nib' if installed --- lib/brunch.js | 13 +++++++++++-- src/brunch.coffee | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/brunch.js b/lib/brunch.js index 1c653dbcf..1aaa81192 100644 --- a/lib/brunch.js +++ b/lib/brunch.js @@ -1,5 +1,5 @@ (function() { - var colors, expressProcess, fileUtil, fs, helpers, package, path, root, spawn, stitch, stylus, timeouts, _; + var colors, expressProcess, fileUtil, fs, helpers, nibAvailable, package, path, root, spawn, stitch, stylus, timeouts, _; root = __dirname + "/../"; fs = require('fs'); path = require('path'); @@ -14,6 +14,15 @@ expressProcess = {}; package = {}; timeouts = {}; + nibAvailable = (function() { + try { + if (require('nib')) { + return true; + } + } catch (error) { + return false; + } + })(); exports["new"] = function(options, callback) { var projectTemplatePath; exports.options = options; @@ -141,7 +150,7 @@ if (err != null) { return helpers.log(colors.lred('stylus err: ' + err)); } else { - return stylus(data).set('filename', main_file_path).set('compress', true).include(path.join(exports.options.brunchPath, 'src')).render(function(err, css) { + return stylus(data).set('filename', main_file_path).set('compress', true).include(path.join(exports.options.brunchPath, 'src')).include(nibAvailable ? require('nib').path : '').render(function(err, css) { if (err != null) { return helpers.log(colors.lred('stylus err: ' + err)); } else { diff --git a/src/brunch.coffee b/src/brunch.coffee index 35011c96a..3168e5744 100644 --- a/src/brunch.coffee +++ b/src/brunch.coffee @@ -25,6 +25,12 @@ package = {} # TODO in future this issues should be handled by a clean dir/file watcher timeouts = {} +# cache if nib is available +nibAvailable = try + true if require('nib') +catch error + false + # project skeleton generator exports.new = (options, callback) -> exports.options = options @@ -166,6 +172,7 @@ exports.compileStylus = -> .set('filename', main_file_path) .set('compress', true) .include(path.join(exports.options.brunchPath, 'src')) + .include(if nibAvailable then require('nib').path else '') .render (err, css) -> if err? helpers.log colors.lred('stylus err: ' + err)