-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
111 lines (89 loc) · 4.25 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
let { userArgs } = require("./yargs");
let express = require("express");
let exp = express();
// set json handler for json responses
exp.use(express.json());
const path = require('path');
const fs = require('fs-extra');
const { constants } = require('./constants');
const { header } = require("./header");
const { cleanup } = require("./cleanup");
const { Utils } = require("./utils/utils");
const { Database } = require('./db');
const { Builder } = require("./builder/main");
let { Listener } = require("./listener/main");
let { TestData } = require("./utils/testdata");
let { Backup } = require("./utils/backup");
let { ExportData } = require("./utils/exportdata");
let { GUI } = require("./gui/main");
let { VersionCheck } = require("./utils/versioncheck");
let { Patches } = require("./patches/main");
let { RequiredFiles } = require("./utils/requiredfiles");
let { OverlayWebSocket } = require("./websocket/main");
let { OverlayPage } = require("./websocket/overlay");
let { TwitterManager } = require("./twitter/main");
let { TransitionsPage } = require("./websocket/transitions");
let { TransitionManager } = require("./transitions/main");
let { TimerBarManager } = require("./timerbars/main");
let { CustomOverlayManager } = require('./customoverlay/main');
let utils, listener, db, builder, testData, gui, patches, overlayWebsocket, overlayPage, twitter, transitionsPage, transitionManager, timerbarManager, customOverlayManager;
utils = new Utils();
// make sure folders and files exist as early as possible
new RequiredFiles({ fs, utils, userArgs });
userArgs.DEBUG && utils.console(" ");
userArgs.DEBUG && utils.console(" ");
const dataDir = path.join("./", "/data");
const themeDir = path.join(dataDir,"/themes");
const defaultThemeDir = path.join(themeDir,"/default");
const Cryptr = require('cryptr');
const cryptr = new Cryptr('platyscreditsbot');
// create the patches to run after listener is done
patches = new Patches({ fs, path, utils, dataDir, userArgs });
patches.prep().then((s,f)=>{
patches.prePatches().then(()=>{
header(utils, constants).then(()=>{
// Just some output for the cli
builder = new Builder({utils, userArgs});
}).then(()=>{
// handle cleaning up databases etc on startup
cleanup(userArgs, path, fs, utils, dataDir, themeDir, defaultThemeDir).then(() => {
userArgs.DEBUG && utils.console(" ");
userArgs.DEBUG && utils.console("Starting...");
userArgs.DEBUG && utils.console(" ");
db = new Database({ fs, cryptr, dataDir, utils, path, defaultThemeDir, themeDir, userArgs });
db.ready().then(()=>{
let versioncheck = new VersionCheck({ utils, userArgs });
// run checker now, for cli notification. GUI has its own calls
versioncheck.run();
testData = new TestData({ userArgs, utils });
gui = new GUI({ db, utils, dataDir, userArgs, fs });
backup = new Backup({ fs, path, utils, dataDir, userArgs });
exportdata = new ExportData({ db, fs, path, utils, dataDir, userArgs });
overlayWebsocket = new OverlayWebSocket({ utils, userArgs });
overlayPage = new OverlayPage({ utils, userArgs });
twitterManager = new TwitterManager({ db, utils, userArgs, overlayWebsocket });
transitionsPage = new TransitionsPage({ utils, userArgs });
transitionManager = new TransitionManager({ db, utils, userArgs, overlayWebsocket });
timerbarManager = new TimerBarManager({ db, utils, userArgs, overlayWebsocket });
customOverlayManager = new CustomOverlayManager({ db, utils, userArgs, overlayWebsocket });
listener = new Listener({ db, utils, exp, dataDir, userArgs, builder, testData, express, gui, backup, exportdata, versioncheck: versioncheck, fs, overlayPage, twitterManager, transitionsPage: transitionsPage, transitionManager: transitionManager, timerbarManager: timerbarManager, customOverlayManager: customOverlayManager });
// start listening to gets/posts and then run patch check
listener.start().then(()=>{
patches.postPatches(db).then(()=>{
// done patching
db.switchToActiveTheme();
}).then(()=>{
// fire up websocket
overlayWebsocket.init();
}).then(()=>{
// fire up the twitter manager
twitterManager.init();
});
});
});
});
});
});
}).catch((e)=>{
// cant update
});