-
Notifications
You must be signed in to change notification settings - Fork 0
/
xpl-push.js
84 lines (63 loc) · 1.84 KB
/
xpl-push.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*jslint node: true, vars: true, nomen: true */
'use strict';
const Xpl = require("xpl-api");
const commander = require('commander');
const os = require('os');
const debug = require('debug')('xpl-push');
const API = require('./lib/API');
const HttpServer = API.httpServer;
const NeDB_Store = API.nedb_store;
const PushEngine = API.pushEngine;
var Store= NeDB_Store;
commander.version(require("./package.json").version);
commander.option("-a, --deviceAliases <aliases>", "Devices aliases");
Xpl.fillCommander(commander);
HttpServer.fillCommander(commander);
NeDB_Store.fillCommander(commander);
PushEngine.fillCommander(commander);
commander.command("create").action(() => {
var store = new Store(commander);
store.create((error) => {
if (error) {
console.error(error);
return;
}
});
});
commander.command("run").action(() => {
var deviceAliases = Xpl.loadDeviceAliases(commander.deviceAliases);
var store = new Store(commander);
store.connect((error) => {
if (error) {
console.error(error);
return;
}
var xpl = new Xpl(commander);
xpl.on("error", (error) => {
console.error("XPL error", error);
});
xpl.bind((error) => {
if (error) {
console.error("Can not open xpl bridge ", error);
process.exit(2);
return;
}
var pushEngine=new PushEngine(commander, xpl, store, deviceAliases);
pushEngine.start((error, rules) => {
if (error) {
console.error("Can not start engine", error, error.stack);
process.exit(3);
return;
}
var server=new HttpServer(commander, store, rules);
server.listen((error) => {
if (error) {
console.error(error);
return;
}
});
});
});
});
});
commander.parse(process.argv);