-
Notifications
You must be signed in to change notification settings - Fork 1
/
bin.js
84 lines (65 loc) · 2.43 KB
/
bin.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
#!/usr/bin/env node
'use strict';
require('./external/hubu');
var _ = require('lodash');
var path = require('path');
var configurable = require('./api/configurable');
//TODO dynamicly load and register components
var httpServer = require('./lib/components/http-server');
var router = require('./lib/components/router');
var fileManager = require('./lib/components/file-manager');
var proxyRequestHandler = require('./lib/components/proxy-request-handler');
var assetRequestHandler = require('./lib/components/asset-request-handler');
var translationsResponseHandler = require('./lib/components/translations-response-handler');
var uiFilesResponseHandler = require('./lib/components/uifiles-response-handler');
var Project = require('./lib/components/project');
var cli = require('cli');
var parseOptions = {};
var configurableServiceListener = {
contract: configurable,
listener: function (event) {
if (event.getType() === SOC.ServiceEvent.REGISTERED) {
getService(event.getReference(), addParseOptions);
}
}
};
function getService(serviceReference, fn) {
fn.call(null, hub.getService(this, serviceReference));
hub.ungetService(serviceReference);
}
function addParseOptions(configurable) {
return _.assign(parseOptions, configurable.getConfigurationOptions());
}
hub.registerServiceListener(configurableServiceListener);
loadComponents();
cli.parse(parseOptions);
cli.main(exec);
function exec(args, options) {
this.debug('args ' + JSON.stringify(args));
this.debug('options ' + JSON.stringify(options));
if (_.isEmpty(args)) {
args.push('.');
}
_.forEach(args, registerProjectForDir);
var serviceReferences = hub.getServiceReferences(configurable);
_.forEach(serviceReferences, function (serviceReference) {
getService(serviceReference, function (service) {
service.updateConfiguration(_.pick(options, _.keys(service.getConfigurationOptions())));
});
});
hub.publish(this, '/framework/started', {});
}
function registerProjectForDir(projectDir) {
hub.registerComponent(hub.createInstance(Project, {projectDir: path.resolve(projectDir)}));
}
function loadComponents() {
hub
.registerComponent(httpServer.component)
.registerComponent(router.component)
.registerComponent(proxyRequestHandler.component)
.registerComponent(assetRequestHandler.component)
.registerComponent(translationsResponseHandler.component)
.registerComponent(uiFilesResponseHandler.component)
.registerComponent(fileManager.component)
.start();
}