-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
executable file
·65 lines (56 loc) · 1.29 KB
/
cli.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
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
const argv = require("yargs").argv;
const Tommy = require(".");
if (argv.webserver) {
const express = require("express");
const app = express();
app.use(express.json());
app.post("/", async (req, res) => {
try {
let tommy = new Tommy(
req.body.src,
req.body.dst,
req.body.config,
req.body.force
);
const files = await tommy.run();
res.json({
status: "OK",
files: files
});
} catch (err) {
res.status(400).send(
err.message
? {
status: "ERR",
error: {
message: err.message
}
}
: {
status: "ERR",
error: err
}
);
}
});
app.listen(argv.port || 80, () => {
console.log("Running Tommy WebServer on port: " + (argv.port || 80));
});
} else {
require("console-ultimate/global").replace();
let config = null;
if (argv.config) {
config = require(require("fs").realpathSync(argv.config));
}
let tommy = new Tommy(argv.src, argv.dst, config, argv.force, argv.watch);
tommy
.run()
.then(_ => {
process.exit(0);
})
.catch(err => {
console.error(err || "Unexpected error");
process.exit(1);
});
}