Skip to content

Commit

Permalink
directly calling stylus instead of spawning a new process
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNexploder committed May 16, 2011
1 parent a542f2f commit 5f1e47f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 28 deletions.
37 changes: 25 additions & 12 deletions lib/brunch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function() {
var colors, expressProcess, fileUtil, fs, helpers, package, path, root, spawn, stitch, timeouts, _;
var colors, expressProcess, fileUtil, fs, helpers, package, path, root, spawn, stitch, stylus, timeouts, _;
root = __dirname + "/../";
fs = require('fs');
path = require('path');
Expand All @@ -8,6 +8,7 @@
fileUtil = require('file');
colors = require('../vendor/termcolors').colors;
stitch = require('stitch');
stylus = require('stylus');
_ = require('underscore');
exports.VERSION = '0.7.1';
expressProcess = {};
Expand Down Expand Up @@ -57,7 +58,7 @@
exports.createBuildDirectories(exports.options.buildPath);
exports.initializePackage(exports.options.brunchPath);
exports.compilePackage();
return exports.spawnStylus();
return exports.compileStylus();
};
exports.stop = function() {
if (expressProcess !== {}) {
Expand Down Expand Up @@ -113,7 +114,7 @@
exports.compilePackage();
}
if (file.match(/\.styl$/)) {
return exports.spawnStylus();
return exports.compileStylus();
}
};
exports.compilePackage = function() {
Expand All @@ -133,15 +134,27 @@
}
});
};
exports.spawnStylus = function() {
var executeStylus;
path.join(exports.options.brunchPath, 'src');
executeStylus = spawn('stylus', ['--compress', '--out', path.join(exports.options.buildPath, 'web/css'), path.join(exports.options.brunchPath, 'src/app/styles/main.styl')]);
executeStylus.stdout.on('data', function(data) {
return helpers.log('stylus: ' + data);
});
return executeStylus.stderr.on('data', function(data) {
return helpers.log(colors.lred('stylus err: ' + data));
exports.compileStylus = function() {
var main_file_path;
main_file_path = path.join(exports.options.brunchPath, 'src/app/styles/main.styl');
return fs.readFile(main_file_path, 'utf8', function(err, data) {
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) {
if (err != null) {
return helpers.log(colors.lred('stylus err: ' + err));
} else {
return fs.writeFile(path.join(exports.options.buildPath, 'web/css/main.css'), css, 'utf8', function(err) {
if (err != null) {
return helpers.log(colors.lred('stylus err: ' + err));
} else {
return helpers.log("stylus: " + (colors.green('compiled', true)) + " main.css\n");
}
});
}
});
}
});
};
}).call(this);
41 changes: 25 additions & 16 deletions src/brunch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ helpers = require './helpers'
fileUtil = require 'file'
colors = require('../vendor/termcolors').colors
stitch = require 'stitch'
stylus = require 'stylus'
_ = require 'underscore'

# the current brunch version number
Expand Down Expand Up @@ -73,7 +74,7 @@ exports.build = (options) ->
exports.initializePackage(exports.options.brunchPath)

exports.compilePackage()
exports.spawnStylus()
exports.compileStylus()

exports.stop = ->
expressProcess.kill 'SIGHUP' unless expressProcess is {}
Expand Down Expand Up @@ -132,7 +133,7 @@ exports.dispatch = (file, options) ->
exports.compilePackage()

if file.match(/\.styl$/)
exports.spawnStylus()
exports.compileStylus()

# compile app files
#
Expand All @@ -154,17 +155,25 @@ exports.compilePackage = ->
)
)

# spawn a new stylus process which compiles main.styl
exports.spawnStylus = ->

path.join(exports.options.brunchPath, 'src')
executeStylus = spawn('stylus', [
'--compress',
'--out',
path.join(exports.options.buildPath, 'web/css'),
path.join(exports.options.brunchPath, 'src/app/styles/main.styl')
])
executeStylus.stdout.on 'data', (data) ->
helpers.log 'stylus: ' + data
executeStylus.stderr.on 'data', (data) ->
helpers.log colors.lred('stylus err: ' + data)
# compiles main.styl using stylus
exports.compileStylus = ->
main_file_path = path.join(exports.options.brunchPath, 'src/app/styles/main.styl')
fs.readFile(main_file_path, 'utf8', (err, data) ->
if err?
helpers.log colors.lred('stylus err: ' + err)
else
stylus(data)
.set('filename', main_file_path)
.set('compress', true)
.include(path.join(exports.options.brunchPath, 'src'))
.render (err, css) ->
if err?
helpers.log colors.lred('stylus err: ' + err)
else
fs.writeFile(path.join(exports.options.buildPath, 'web/css/main.css'), css, 'utf8', (err) ->
if err?
helpers.log colors.lred('stylus err: ' + err)
else
helpers.log "stylus: #{colors.green('compiled', true)} main.css\n"
)
)

0 comments on commit 5f1e47f

Please sign in to comment.