Skip to content

Instantly share code, notes, and snippets.

@jessehattabaugh
Created May 2, 2014 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessehattabaugh/5f6a275a160b339e35a7 to your computer and use it in GitHub Desktop.
Save jessehattabaugh/5f6a275a160b339e35a7 to your computer and use it in GitHub Desktop.
build script
#!/usr/bin/env node
"use strict";
var fs = require('fs'),
gw = require('globwatcher').globwatcher;
var cssw = gw('./source/*.styl', {persistent: true});
cssw.on('added', function (filename) {
console.log(filename + ' added');
buildStylus(filename);
});
cssw.on('changed', function (filename) {
console.log(filename + ' changed');
buildStylus(filename);
});
cssw.ready.then(function() {
console.log('watching for changes to stylus');
});
var stylus = require('stylus'),
nib = require('nib');
function buildStylus(filename) {
fs.readFile(filename, 'utf8', function (err, data) {
if (err) console.error(err);
stylus(data)
.use(nib())
.render(function (err, css) {
if (err) return console.error(err);
fs.writeFile('./build/www/index.css', css, function (err) {
if (err) return console.error(err);
console.log('CSS compiled');
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment