Created
November 22, 2014 20:36
-
-
Save willhlaw/48ecfa741b8896beb515 to your computer and use it in GitHub Desktop.
NPM Workflow to Preprocess a Javascript File
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 escodegen = require('escodegen') | |
var through = require('through') | |
var esprima = require('esprima') | |
var modify = require('./modify') // Custom code that you write to preprocess the file | |
module.exports = function(file, opts) { | |
var buffer = [] | |
return through(function(data) { | |
buffer.push(data) | |
}, function() { | |
buffer = buffer.join('\n') | |
var ast = esprima.parse(buffer) | |
// Whatever functionality goes here... | |
modify(ast) | |
buffer = escodegen.generate(ast) | |
this.queue(buffer) | |
this.queue(null) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment