This repository was archived by the owner on Dec 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
46 lines (43 loc) · 1.81 KB
/
cli.js
File metadata and controls
46 lines (43 loc) · 1.81 KB
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
#!/usr/bin/env node
const Server = require("./server.js");
const fs = require("fs");
const path = require("path");
const args = process.argv.splice(process.execArgv.length + 2);
if(args[0]) {
let subArgs = args.slice(1);
let server;
switch(args[0].toLowerCase()) {
case "start":
if(server) console.error("Server instance already running.");
if(subArgs.length === 0) {
server = new Server(process.cwd());
server.start(3000);
} else if(subArgs.length === 1) {
server = new Server(path.isAbsolute(subArgs[0]) ? subArgs[0] : path.join(process.cwd(), subArgs[0]));
server.start(3000);
} else if(subArgs.length === 2) {
server = new Server(path.isAbsolute(subArgs[0]) ? subArgs[0] : path.join(process.cwd(), subArgs[0]));
server.start(subArgs[1]);
} else if(subArgs.length > 2) console.error("Usage: harponica start [directory] [port]");
break;
case "compile":
if(subArgs.length === 0) {
if(!server) server = new Server(process.cwd());
server.compile(path.join(process.cwd(), "compiled"));
} else if(subArgs.length === 1) {
if(!server) server = new Server(path.isAbsolute(subArgs[0]) ? subArgs[0] : path.join(process.cwd(), subArgs[0]));
server.compile(path.join(process.cwd(), "compiled"));
} else if(subArgs.length === 2) {
if(!server) server = new Server(path.isAbsolute(subArgs[0]) ? subArgs[0] : path.join(process.cwd(), subArgs[0]));
server.compile(path.isAbsolute(subArgs[1]) ? subArgs[1] : path.join(process.cwd(), subArgs[1]));
} else {
console.error("Usage: harponica compile [sourceDirectory] [outputDirectory]");
}
break;
}
} else {
console.log("Usage:");
console.log("harponica start [directory=\".\"] [port=3000]");
console.log("harponica stop");
console.log("harponica compile [sourceDirectory=\".\"] [outputDirectory=\"./compiled\"]");
}