-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
44 lines (34 loc) · 1.2 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
#! /usr/bin/env node
/**
* Created by Josh on 2/7/17.
*/
var cmp = require('./src/Main');
var fs = require('fs');
var pkg = require('./package.json');
var repl = require('./repl');
var userArgs = process.argv.slice(2);
var help = "Commands:" +
"\n--version : gives the current version" +
"\n--help : opens help menu" +
"\n ||filename|.obl| runs your Oblivion file, and prints out the StdOut.";
var cmds = {"--help":function(){console.log(help);}, "--version":function(){console.log(pkg.version)}};
if(userArgs.length === 0) repl.OblRepl();
else if(userArgs.length ===1){
if(userArgs[0] in cmds) {
cmds[userArgs[0]]();
} else {
//reads string from file
fs.readFile(userArgs[0], 'utf-8', function (err, data) {
if (err) throw err;
var output = cmp.Compile(data, 2);
console.log(output[0]);
fs.writeFile(convertFileName(userArgs[0]), output[1], function (err) {
if (err) throw err;
});
});
}
}
function convertFileName(string){
if(!/(.+)\.obl/.test(string)) throw new Error("Only Oblivion files with a .obl extension can be compiled");
return string.match(/(.+)\.obl/)[1] + ".svg";
}