1 |
|
2 | var AppRunner, ref$, bold, cyan, dim, green, red, yaml, Logger, fs, version, appConfig, logger, x$, appRunner;
|
3 | AppRunner = require('./app-runner');
|
4 | ref$ = require('chalk'), bold = ref$.bold, cyan = ref$.cyan, dim = ref$.dim, green = ref$.green, red = ref$.red;
|
5 | yaml = require('js-yaml');
|
6 | Logger = require('../../logger');
|
7 | fs = require('fs');
|
8 | version = require('../../../package.json').version;
|
9 | console.log(dim("Exosphere SDK " + version + "\n"));
|
10 | appConfig = yaml.safeLoad(fs.readFileSync('application.yml', 'utf8'));
|
11 | console.log("Running " + green(appConfig.name) + " " + cyan(appConfig.version) + "\n");
|
12 | logger = new Logger(Object.keys(appConfig.services));
|
13 | x$ = appRunner = new AppRunner(appConfig);
|
14 | x$.on('error', function(err){
|
15 | return console.log(red(error));
|
16 | });
|
17 | x$.on('output', function(data){
|
18 | return logger.log(data);
|
19 | });
|
20 | x$.on('exocomm-online', function(port){
|
21 | return logger.log({
|
22 | name: 'exocomm',
|
23 | text: "online at port " + port
|
24 | });
|
25 | });
|
26 | x$.on('service-online', function(name){
|
27 | return logger.log({
|
28 | name: 'exorun',
|
29 | text: "'" + name + "' is running using exorelay port " + appRunner.portFor(name)
|
30 | });
|
31 | });
|
32 | x$.on('routing-setup', function(){
|
33 | var command, ref$, routing, text, receivers, res$, i$, ref1$, len$, receiver, results$ = [];
|
34 | logger.log({
|
35 | name: 'exocomm',
|
36 | text: 'received routing setup'
|
37 | });
|
38 | for (command in ref$ = appRunner.exocomm.clientRegistry.routes) {
|
39 | routing = ref$[command];
|
40 | text = " [ " + bold(command) + " ] --> ";
|
41 | res$ = [];
|
42 | for (i$ = 0, len$ = (ref1$ = routing.receivers).length; i$ < len$; ++i$) {
|
43 | receiver = ref1$[i$];
|
44 | res$.push(bold(receiver.name) + " (" + receiver.host + ":" + receiver.port + ")");
|
45 | }
|
46 | receivers = res$;
|
47 | text += receivers.join(' & ');
|
48 | results$.push(logger.log({
|
49 | name: 'exocomm',
|
50 | text: text
|
51 | }));
|
52 | }
|
53 | return results$;
|
54 | });
|
55 | x$.on('message', function(arg$){
|
56 | var sender, message, receivers;
|
57 | sender = arg$.sender, message = arg$.message, receivers = arg$.receivers;
|
58 | return logger.log({
|
59 | name: 'exocomm',
|
60 | text: sender + " --[ " + message + " ]-> " + receivers.join(' and ')
|
61 | });
|
62 | });
|
63 | x$.startExocomm();
|
64 | x$.startServices();
|
65 | x$.on('all-services-online', function(){
|
66 | var x$;
|
67 | logger.log({
|
68 | name: 'exorun',
|
69 | text: 'all services online'
|
70 | });
|
71 | x$ = appRunner;
|
72 | x$.on('routing-done', function(){
|
73 | return logger.log({
|
74 | name: 'exorun',
|
75 | text: "application ready"
|
76 | });
|
77 | });
|
78 | x$.sendServiceConfiguration();
|
79 | return x$;
|
80 | }); |
\ | No newline at end of file |