-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·54 lines (47 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env node
var compiler = require('./dist/index');
var fs = require('fs');
var compile = compiler.compile;
var compileCode = compiler.compileCode;
var args = parseArgs();
function parseArgs() {
var out = {};
var flagOn = false;
typeof process !== 'undefined' &&
Array.isArray(process.argv) &&
process.argv.forEach(function (arg) {
if (arg[0] === '-') {
flagOn = arg.slice(1);
} else {
if (flagOn) {
out[flagOn] = arg;
flagOn = false;
}
}
});
return out;
}
// If the file name to compile came in through the command line,
// compile it and write it out.
if (args.i) {
compile(args.i, function (err, result) {
if (err) {
throw err;
} else {
if (args.o) {
fs.writeFile(args.o, result, function (err) {
if (err) throw err;
console.log('Finished.');
});
} else {
console.log(result);
}
}
}, {finalize: true}); // Adds in library code and such
}
// Otherwise, export our compile functions so this can be required
// by other modules.
module.exports = {
compile: compile,
compileCode: compileCode
};