forked from almero-digital-marketing/mikser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (78 loc) · 2.23 KB
/
index.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
'use strict'
var cluster = require('cluster');
var Promise = require('bluebird');
var application = require('./lib/application');
var config = require('./lib/config');
var runtime = require('./lib/runtime');
var database = require('./lib/database');
var loader = require('./lib/loader');
var generator = require('./lib/generator');
var scheduler = require('./lib/scheduler');
var utils = require('./lib/utils');
var manager = require('./lib/manager');
var watcher = require('./lib/watcher');
var diagnostics = require('./lib/diagnostics');
var server = require('./lib/server');
var tools = require('./lib/tools');
var debug = require('./lib/debug');
var broker = require('./lib/broker');
var parser = require('./lib/parser');
var queue = require('./lib/queue');
var observer = require('./lib/observer');
var engine = require('./lib/engine');
var backports = require('./lib/backports');
var _ = require('lodash');
module.exports = function(options) {
let mikser = application(options);
mikser.run = function() {
return Promise.resolve(mikser)
.then(debug)
.then(broker)
.then(config)
.then(runtime)
.then(database)
.then(parser)
.then(queue)
.then(observer)
.then(loader)
.then(generator)
.then(scheduler)
.then(utils)
.then(manager)
.then(tools)
.then(watcher)
.then(diagnostics)
.then(server)
.then(engine)
.then(backports)
.then(() => mikser.emit('mikser.init', cluster.isMaster).return(mikser))
.then((mikser) => {
if (cluster.isMaster) {
console.log('Mikser: Loaded');
return mikser.loadPlugins().then(() => {
mikser.cli.init(true);
mikser.debug.resetWatch()
.then(mikser.manager.glob)
.then(mikser.manager.clean)
.then(mikser.tools.startup)
.then(mikser.tools.compile)
.then(mikser.manager.sync)
.then(mikser.server.listen)
.then(mikser.scheduler.process)
.then(mikser.tools.build)
.then(mikser.watcher.start)
.then(() => {
if (!mikser.options.server && !mikser.options.watch) {
return mikser.tools.shutdown().then(() => {
mikser.exit();
})
}
});
});
} else {
return mikser.loadPlugins().then(mikser.joinMaster);
}
}).return(mikser);
}
return mikser;
}