1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _imaHelpers = require('ima-helpers');
|
8 |
|
9 | var _imaHelpers2 = _interopRequireDefault(_imaHelpers);
|
10 |
|
11 | var _namespace = require('./namespace');
|
12 |
|
13 | var _namespace2 = _interopRequireDefault(_namespace);
|
14 |
|
15 | var _ObjectContainer = require('./ObjectContainer');
|
16 |
|
17 | var _ObjectContainer2 = _interopRequireDefault(_ObjectContainer);
|
18 |
|
19 | var _Router = require('./router/Router');
|
20 |
|
21 | var _Router2 = _interopRequireDefault(_Router);
|
22 |
|
23 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
24 |
|
25 | _namespace2.default.namespace('ima');
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | const PRODUCTION_ENVIRONMENT = 'prod';
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | class Bootstrap {
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | constructor(oc) {
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 | this._oc = oc;
|
53 |
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 | this._config = {};
|
60 | }
|
61 |
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | run(config) {
|
76 | this._config = config;
|
77 |
|
78 | this._initSettings();
|
79 | this._bindDependencies();
|
80 | this._initServices();
|
81 | this._initRoutes();
|
82 | }
|
83 |
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | _initSettings() {
|
92 | let currentApplicationSettings = {};
|
93 |
|
94 | let plugins = this._config.plugins.concat([this._config]);
|
95 |
|
96 | plugins.filter(plugin => typeof plugin.initSettings === 'function').forEach(plugin => {
|
97 | let allPluginSettings = plugin.initSettings(_namespace2.default, this._oc, this._config.settings);
|
98 | let environmentPluginSetting = this._getEnvironmentSetting(allPluginSettings);
|
99 |
|
100 | _imaHelpers2.default.assignRecursively(currentApplicationSettings, environmentPluginSetting);
|
101 | });
|
102 |
|
103 | this._config.bind = Object.assign(this._config.bind || {}, currentApplicationSettings, this._config.settings);
|
104 | }
|
105 |
|
106 | |
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | _getEnvironmentSetting(allSettings) {
|
113 | let environment = this._config.settings.$Env;
|
114 | let environmentSetting = allSettings[environment] || {};
|
115 |
|
116 | if (environment !== PRODUCTION_ENVIRONMENT) {
|
117 | let productionSettings = allSettings[PRODUCTION_ENVIRONMENT];
|
118 | _imaHelpers2.default.assignRecursively(productionSettings, environmentSetting);
|
119 | environmentSetting = productionSettings;
|
120 | }
|
121 |
|
122 | return environmentSetting;
|
123 | }
|
124 |
|
125 | |
126 |
|
127 |
|
128 |
|
129 | _bindDependencies() {
|
130 | this._oc.setBindingState(_ObjectContainer2.default.IMA_BINDING_STATE);
|
131 | this._config.initBindIma(_namespace2.default, this._oc, this._config.bind);
|
132 |
|
133 | this._oc.setBindingState(_ObjectContainer2.default.PLUGIN_BINDING_STATE);
|
134 | this._config.plugins.filter(plugin => typeof plugin.initBind === 'function').forEach(plugin => {
|
135 | plugin.initBind(_namespace2.default, this._oc, this._config.bind);
|
136 | });
|
137 |
|
138 | this._oc.setBindingState(_ObjectContainer2.default.APP_BINDING_STATE);
|
139 | this._config.initBindApp(_namespace2.default, this._oc, this._config.bind);
|
140 | }
|
141 |
|
142 | |
143 |
|
144 |
|
145 | _initRoutes() {
|
146 | let router = this._oc.get(_Router2.default);
|
147 | this._config.initRoutes(_namespace2.default, this._oc, this._config.routes, router);
|
148 | }
|
149 |
|
150 | |
151 |
|
152 |
|
153 | _initServices() {
|
154 | this._config.initServicesIma(_namespace2.default, this._oc, this._config.services);
|
155 |
|
156 | this._config.plugins.filter(plugin => typeof plugin.initServices === 'function').forEach(plugin => {
|
157 | plugin.initServices(_namespace2.default, this._oc, this._config.services);
|
158 | });
|
159 |
|
160 | this._config.initServicesApp(_namespace2.default, this._oc, this._config.services);
|
161 | }
|
162 | }
|
163 |
|
164 | exports.default = Bootstrap;
|
165 | _namespace2.default.ima.Bootstrap = Bootstrap;
|
166 |
|
167 | typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/Bootstrap', [], function (_export, _context) {
|
168 | 'use strict';
|
169 | return {
|
170 | setters: [],
|
171 | execute: function () {
|
172 | _export('default', exports.default);
|
173 | }
|
174 | };
|
175 | });
|