forked from Strider-CD/strider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
129 lines (110 loc) · 3.7 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var app = require('./lib/app')
, backchannel = require('./lib/backchannel')
, common = require('./lib/common')
, config = require('./lib/config')
, loader = require('strider-extension-loader')
, middleware = require('./lib/middleware')
, auth = require('./lib/auth')
, models = require('./lib/models')
, websockets = require('./lib/websockets')
, pluginTemplates = require('./lib/pluginTemplates')
, utils = require('./lib/utils')
, _ = require('lodash')
common.extensions = {}
require('./defaultExtensions')(common.extensions);
//
// ### Register panel
//
// A panel is simply a snippet of HTML associated with a given key.
// Strider will output panels registered for specific template.
//
function registerPanel(key, value) {
// Nothing yet registered for this panel
key = value.id //
console.log("!! registerPanel", key)
if (common.extensions[key] === undefined) {
common.extensions[key] = {panel : value}
} else {
if (common.extensions[key].panel){
console.log("!!", key, common.extensions[key], value)
throw "Multiple Panels for " + key
}
common.extensions[key].panel = value;
}
}
module.exports = function(extdir, c, callback) {
var appConfig = config;
// override with c
for (var k in c){
appConfig[k] = c[k];
}
// Initialize the (web) app
var appInstance = app.init(appConfig);
var cb = callback || function() {}
//
// ### Strider Context Object
//
// Context object is passed to each extension. It carries various config
// settings, as well as handles to enable functions to register things.
// Context can also be accessed as a singleton within Strider as
// common.context.
var context = {
config: appConfig,
enablePty: config.enablePty,
emitter: common.emitter,
extensionRoutes: [],
extdir: extdir,
loader: loader,
models: models,
logger: console,
middleware: middleware,
auth: auth, //TODO - may want to make this a subset of the auth module
registerPanel: registerPanel,
registerBlock: pluginTemplates.registerBlock,
};
// Make extension context available throughout application.
common.context = context;
loader.initWebAppExtensions(extdir, context, appInstance,
function(err, initialized, templates) {
if (err) {
return cb(err)
}
if (templates){
for (var k in templates){
pluginTemplates.registerTemplate(k, templates[k]);
}
}
initialized.forEach(function(x) {
console.log(x.id , "webapp extension available")
if (common.extensions[x.id] === undefined) {
common.extensions[x.id] = x
} else {
console.log("!!! Multiple webapp extension", x)
}
})
loader.initRunnerExtensions(extdir, context, function(err, loaded){
console.log("Environment Runner's loaded:" , loaded)
if (!loaded || loaded.length < 1) throw "No EnvironmentRunner Loaded!";
// FOR NOW WE JUST USE THE FIRST: TODO - make this selectable.
var runner = loaded[0]
context.loader.listWorkerExtensions(extdir, function(err, workers){
common.availableWorkers = workers;
workers.forEach(function(x){
console.log(x.id , " worker extension available")
if (common.extensions[x.id] === undefined) {
common.extensions[x.id] = x
} else {
common.extensions[x.id].worker = x.worker
}
})
runner.create(context.emitter, {}, function(){
// We're all up and running
common.availableWorkers = workers
app.run(appInstance);
cb(err, initialized, appInstance)
});
})
})
});
return appInstance;
};