Skip to content

Instantly share code, notes, and snippets.

@bengourley
Created November 7, 2012 17:02
Show Gist options
  • Save bengourley/4032975 to your computer and use it in GitHub Desktop.
Save bengourley/4032975 to your computer and use it in GitHub Desktop.
var stylus = require('stylus')
, nib = require('nib')
, uglify = require('uglifyjs')
function processStylus(input, cb) {
fs.readFile(input.src, function (err, data) {
if (err) return cb(err)
stylus
.use(nib())
.set('compress', true)
.set('more options', { foo: 1 })
.define('my function', function () { /* ... */ })
.compile(data, function (err, css) {
if (err) return cb(err)
fs.writeFile(input.dest, function (err) {
if (err) return cb(err)
cb(null, 'yay')
})
})
}
function processJS(input, cb) {
// The string of concated js
var out = ''
function write() {
fs.writeFile(input.dest, out, function (err) {
if (err) return cb(err)
cb(null, 'yay')
})
}
// Determine whether to bundle or provide loader
if (someFlag) {
// This makes the assumption that the paths in srcs are the
// the same as the public available web path. (but they are not)
out += buildLoader(input.srcs)
} else {
var done = 0
input.srcs.forEach(function (src) {
fs.readFile(src, function (err, data) {
out += uglify(data)
if (++done === input.srcs.length) write()
})
})
}
}
module.exports =
[ { items:
[ { src: 'public/css/screen.styl'
, dest: 'public/css/screen.css'
}
]
, process: processStylus
}
, { items:
[ { dest: 'public/js/app.js'
, srcs: [ 'public/js/a.js', 'public/js/b.js' ]
}
]
, process: processJS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment