UNPKG

1.4 kBJavaScriptView Raw
1var isCLI = (process.title == "node");
2if (isCLI) {
3 var pkg = require(__dirname + "/package.json");
4
5 require("check-update")({
6 packageName: pkg.name,
7 packageVersion: pkg.version,
8 isCLI: isCLI
9 }, function (err, latestVersion, defaultMessage) {
10 if (!err && pkg.version < latestVersion) {
11 console.log(defaultMessage);
12 }
13 });
14}
15
16module.exports = function (param, dir, cb) {
17 var FlexHosts = require("./api");
18 var readLine = require("readline");
19
20 param = param || {};
21
22 if (typeof dir == "function") {
23 cb = dir;
24 dir = null;
25 }
26 else if (typeof cb != "function") {
27 cb = function (err, host2ip) {
28 if (err) {
29 console.log(err);
30 }
31 else {
32 console.log(host2ip);
33 }
34 };
35 }
36
37 var flexHosts = new FlexHosts(param, dir, cb);
38
39 var rl = readLine.createInterface({
40 input: process.stdin,
41 output: process.stdout
42 });
43 rl.on("SIGINT", function () {
44 process.emit("SIGINT");
45 });
46
47 process.on("SIGINT", (function (i) {
48 return function() {
49 switch (i) {
50 case 0:
51 console.log("\n\x1b[35m%s\x1b[0m", "Press Control-C again to exit.");
52 i++;
53 break;
54 case 1:
55 console.log("Exiting...");
56 flexHosts.restore();
57 i++;
58 break;
59 default:
60 console.log("Waiting...");
61 }
62 }
63 })(0));
64
65 return flexHosts;
66};