-
-
Save grncdr/612586b5d808ba826ea4 to your computer and use it in GitHub Desktop.
sketch of how to do the useful part of gulp as a module
This file contains 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
/** | |
* This is an example of what a build script would look like | |
*/ | |
var globStream = require('glob-stream').create | |
var globWatch = require('glob-watcher') | |
// I have no idea if this exists, probably not | |
var createSassTransform = require('sass-transform') | |
// these two are defined below, haven't published them yet | |
var st = require('spit-take') | |
var replacer = require('replacer') | |
var unsassify = st( | |
replacer([/\.sass$/, '.css'], [/\/sassy\//, 'css']), | |
createSassTransform | |
) | |
var globs = "./sassy/*.sass" | |
globStream(globs).pipe(unsassify) | |
globWatch(globs, unsassify.write.bind(unsassify)) |
This file contains 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
// Might publish this if I can't find something like it. | |
module.exports = function replacer () { | |
var replaceArgs = [].slice.call(arguments) | |
return function (string) { | |
replaceArgs.reduce(function (string, args) { | |
return string.replace.apply(string, args) | |
}, string) | |
} | |
} |
This file contains 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
var fs = require('fs') | |
var once = require('once') | |
var through = require('through2') | |
module.exports = function spitTake (transformPath, makeTransformStream) { | |
var inProgress = {} | |
return through2({objectMode: true}, transformFile) | |
function transformFileObject (file, _, cb) { | |
var self = this | |
var srcPath = file.path | |
var destPath = transformPath(srcPath) | |
if (!inProgress[destPath]) { | |
run(srcPath, destPath, makeTransformStream(), onEnd) | |
} else { | |
inProgress[destPath].on('end', function () { | |
run(srcPath, destPath, makeTransformStream(), onEnd) | |
}) | |
} | |
function onEnd (err) { | |
delete inProgress[destPath] | |
this.push(destPath) | |
cb(err) | |
} | |
} | |
} | |
function run (src, dest, transform, callback) { | |
callback = once(callback) | |
var input = fs.createReadStream(src) | |
var output = fs.createWriteStream(dest) | |
var transform = makeTransformStream() | |
input.on('error', callback) | |
output.on('error', callback) | |
input.pipe(transform).pipe(output).on('end', callback.bind(null, null)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment