add --ignore and --extensions flag to 6to5-node to compliment require hook options

This commit is contained in:
Sebastian McKenzie 2014-10-16 10:02:16 +11:00
parent 5b08924c02
commit 45c8c29cdf
4 changed files with 29 additions and 10 deletions

View File

@ -2,7 +2,6 @@
var commander = require("commander");
var Module = require("module");
var path = require("path");
var util = require("../lib/6to5/util");
var path = require("path");
var repl = require("repl");
@ -12,13 +11,29 @@ var _ = require("lodash");
commander.option("-e, --eval [script]", "evaluate script");
commander.option("-p, --print", "evaluate script and print result");
commander.option("-i, --ignore [regex]", "ignore all files that match this regex when using the require hook");
commander.option("-x, --extensions [extensions]", "list of extensions to hook into [.es6,.js]", util.list);
var pkg = require("../package.json");
commander.version(pkg.version);
commander.usage("[options] [ -e script | script.js ] [arguments]");
commander.parse(process.argv);
to5.register();
//
var registerOpts = {};
if (commander.ignore) {
registerOpts.ignoreRegex = new RegExp(commander.ignore);
}
if (commander.extensions && commander.extensions.length) {
registerOpts.extensions = commander.extensions
}
to5.register(registerOpts);
//
var _eval = function (code, filename) {
code = to5.transform(code, { filename: filename }).code;

View File

@ -5,6 +5,8 @@ var sourceMap = require("source-map");
var transform = require("../../lib/6to5/transform");
var chokidar = require("chokidar");
var mkdirp = require("mkdirp");
var util2 = require("../../lib/6to5/util");
var util = require("./util");
var path = require("path");
var fs = require("fs");
var _ = require("lodash");
@ -14,12 +16,8 @@ commander.option("-s, --source-maps", "Save source map alongside the compiled co
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
commander.option("-w, --watch", "Recompile files on changes");
var list = function (val) {
return val ? val.split(",") : [];
};
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", list);
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", list);
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util2.list);
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util2.list);
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");

View File

@ -4,8 +4,10 @@ var _ = require("lodash");
exports.util = require("./util");
exports.register = function () {
return require("./register");
exports.register = function (opts) {
var register = require("./register");
if (opts != null) register(opts);
return register;
};
exports.polyfill = function () {

View File

@ -20,6 +20,10 @@ exports.ensureBlock = function (node) {
node.body = b.blockStatement(block);
};
exports.list = function (val) {
return val ? val.split(",") : [];
};
exports.getUid = function (parent, file) {
var node;