add 6to5-node bin
This commit is contained in:
19
README.md
19
README.md
@@ -71,6 +71,20 @@ Compile the file `script.js` and output it to stdout.
|
||||
|
||||
$ 6to5 script.js
|
||||
|
||||
#### Node
|
||||
|
||||
Launch a repl.
|
||||
|
||||
$ 6to5-node
|
||||
|
||||
Evaluate code.
|
||||
|
||||
$ 6to5-node -e "class Test { }"
|
||||
|
||||
Compile and run `test.js`.
|
||||
|
||||
$ 6to5-node test
|
||||
|
||||
### Browserify
|
||||
|
||||
$ browserify script.js -t 6to5/browserify --outfile bundle.js
|
||||
@@ -166,3 +180,8 @@ Cannot subclass built-ins such as `Date`, `Array`, `DOM` etc.
|
||||
## Comparison to Traceur
|
||||
|
||||
### Performance
|
||||
|
||||
## The future
|
||||
|
||||
Implement own parser and generator that preserves whitespace and automatically
|
||||
works out generation rules based on code input.
|
||||
|
||||
2
bin/6to5
2
bin/6to5
@@ -3,9 +3,9 @@
|
||||
var commander = require("commander");
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var mkdirp = require("mkdirp");
|
||||
var to5 = require("../lib/6to5/node");
|
||||
var path = require("path");
|
||||
var util = require("../lib/6to5/util");
|
||||
var to5 = require("../lib/6to5/node");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
|
||||
61
bin/6to5-node
Executable file
61
bin/6to5-node
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var path = require("path");
|
||||
var to5 = require("../lib/6to5/node");
|
||||
var util = require("../lib/6to5/util");
|
||||
var path = require("path");
|
||||
var repl = require("repl");
|
||||
var vm = require("vm");
|
||||
var _ = require("lodash");
|
||||
|
||||
commander.option("-e, --eval [script]", "evaluate script");
|
||||
commander.option("-p, --print", "evaluate script and print result");
|
||||
|
||||
var pkg = require("../package.json");
|
||||
commander.version(pkg.version);
|
||||
commander.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
commander.parse(process.argv);
|
||||
|
||||
to5.register();
|
||||
|
||||
if (commander.eval) {
|
||||
var code = to5.transform(commander.eval, { filename: "eval" });
|
||||
var result = eval(code);
|
||||
if (commander.print) console.log(result);
|
||||
} else {
|
||||
var filenames = commander.args;
|
||||
|
||||
if (filenames.length) {
|
||||
_.each(filenames, function (filename) {
|
||||
require(require.resolve(path.join(process.cwd(), filename)));
|
||||
});
|
||||
} else {
|
||||
replStart();
|
||||
}
|
||||
}
|
||||
|
||||
function replStart() {
|
||||
repl.start({
|
||||
prompt: "> ",
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
eval: replEval
|
||||
});
|
||||
}
|
||||
|
||||
function replEval(code, context, filename, callback) {
|
||||
var err;
|
||||
var result;
|
||||
|
||||
try {
|
||||
code = code.slice(1, -2); // remove "(" and "\n)"
|
||||
code = to5.transform(code, { filename: filename });
|
||||
|
||||
result = vm.runInContext(code, context, filename, { displayErrors: false });
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
callback(err, result);
|
||||
}
|
||||
@@ -85,10 +85,10 @@ exports.buildUidGenerator = function () {
|
||||
var ids = {};
|
||||
|
||||
return function (name) {
|
||||
var i = ids[name] || 0;
|
||||
var i = ids[name] || 1;
|
||||
|
||||
var id = "_" + name;
|
||||
if (i > 0) id += i;
|
||||
if (i > 1) id += i;
|
||||
ids[name] = i + 1;
|
||||
return id;
|
||||
};
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
"preferGlobal": true,
|
||||
"main": "lib/6to5/node.js",
|
||||
"bin": {
|
||||
"6to5": "./bin/6to5"
|
||||
"6to5": "./bin/6to5",
|
||||
"6to5-node": "./bin/6to5-node"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
|
||||
Reference in New Issue
Block a user