forked from karimomaya/OTCL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandline.js
executable file
·48 lines (38 loc) · 1.33 KB
/
commandline.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
#!/usr/bin/env node
let program = require('commander');
let __FileSystem = require('fs');
let __OTCompiler = require("./engine/__OTCompiler.js");
let fs = require('fs');
program
.version('1.0.0')
.option('-s, --server <url>','OT server URL','http://localhost/')
.description('Opentext command-line interface');
program
.command('run <script-file>')
.alias('r')
.description('run script file')
.action((filename) => {
__FileSystem.readFile(filename, (err, data) => {
if (err) throw err;
__OTCompiler().evaluator(data.toString(),program.server);
});
});
program
.command('compile <script-file> <out-js-file>')
.alias('c')
.description('compile script file to js')
.action((filename,jsfilename) => {
__FileSystem.readFile(filename, (err, data) => {
if (err) throw err;
js = "#!/usr/bin/env node \n"+
"var _OTCL = require('otcl');\n"+
"var _OTCommands = _OTCL.commands('"+program.server+"');\n\n";
js += __OTCompiler().translator(data.toString());
fs.writeFile(jsfilename, js,function(err, data){
if (err) console.log(err);
console.log("Successfully Written to File.");
});
fs.chmod(jsfilename, '755');
});
});
program.parse(process.argv);