@vulkano/core 1.4.1 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app.js CHANGED
@@ -124,66 +124,36 @@ app.config = allConfig;
124
124
  app.pkg = appPkg;
125
125
 
126
126
  // Include all components
127
- require('./bootstrap/services')();
128
- require('./database/mongodb')();
129
-
130
- const controllers = require('./controllers/controllers')();
131
- const server = require('./bootstrap/server');
132
-
133
- const colors = {
134
- reset: '\x1b[0m',
135
- bright: '\x1b[1m',
136
- dim: '\x1b[2m',
137
- underscore: '\x1b[4m',
138
- blink: '\x1b[5m',
139
- reverse: '\x1b[7m',
140
- hidden: '\x1b[8m',
141
- fg: {
142
- black: '\x1b[30m',
143
- red: '\x1b[31m',
144
- green: '\x1b[32m',
145
- yellow: '\x1b[33m',
146
- blue: '\x1b[34m',
147
- magenta: '\x1b[35m',
148
- cyan: '\x1b[36m',
149
- white: '\x1b[37m',
150
- crimson: '\x1b[38m' // Scarlet
151
- },
152
- bg: {
153
- black: '\x1b[40m',
154
- red: '\x1b[41m',
155
- green: '\x1b[42m',
156
- yellow: '\x1b[43m',
157
- blue: '\x1b[44m',
158
- magenta: '\x1b[45m',
159
- cyan: '\x1b[46m',
160
- white: '\x1b[47m',
161
- crimson: '\x1b[48m'
162
- }
163
- };
164
-
165
- function startVulkano() {
127
+ const {
128
+ lineWidth,
129
+ colors,
130
+ showCenteredText,
131
+ showColumn
132
+ } = require('./bootstrap/logger');
166
133
 
167
- const appName = appPkg.name.toUpperCase().split('-').join(' ');
168
- const appVersion = appPkg.version;
169
- const author = appPkg.author || pkg.author;
134
+ // Include all components
135
+ const loadDatabase = require('./database/mongodb');
136
+ const loadServices = require('./bootstrap/services');
137
+ const loadControllers = require('./controllers/controllers');
138
+ const loadServer = require('./bootstrap/server');
170
139
 
171
- const lineWidth = 38;
140
+ async function startVulkano() {
172
141
 
173
- const showCenteredText = (text) => {
142
+ // Load Services
143
+ loadServices();
174
144
 
175
- const colSize = (lineWidth / 2) - 3;
176
- const textLength = (text || '').length;
177
- const textLeftSize = Math.trunc(textLength / 2);
178
- const textRightSize = textLength - textLeftSize;
145
+ // Load Database
146
+ await loadDatabase();
179
147
 
180
- const textPaddingLeft = ''.padStart( colSize - textLeftSize, ' ');
181
- const textPaddingRight = ''.padEnd( colSize - textRightSize, ' ');
182
- const textCentered = `${textPaddingLeft}${text}${textPaddingRight}`;
148
+ // Load Controllers
149
+ const controllers = loadControllers();
183
150
 
184
- return textCentered;
151
+ // Server
152
+ const server = loadServer();
185
153
 
186
- };
154
+ const appName = appPkg.name.toUpperCase().split('-').join(' ');
155
+ const appVersion = appPkg.version;
156
+ const author = appPkg.author || pkg.author;
187
157
 
188
158
  const cutLine = '-'.padEnd(lineWidth, '-');
189
159
 
@@ -230,8 +200,7 @@ function startVulkano() {
230
200
 
231
201
  const {
232
202
  sockets,
233
- settings: configSettings,
234
- redis
203
+ settings: configSettings
235
204
  } = app.config || {};
236
205
 
237
206
  const {
@@ -242,11 +211,6 @@ function startVulkano() {
242
211
  connection
243
212
  } = database || {};
244
213
 
245
- const showColumn = (text, titleLength) => {
246
- const txt = `${text.padEnd( 16 - titleLength, ' ')}`;
247
- return txt;
248
- };
249
-
250
214
  const connectionToShow = connection && process.env.MONGO_URI ? 'MONGO_URI' : connection;
251
215
 
252
216
  const serverConfig = [];
@@ -254,7 +218,7 @@ function startVulkano() {
254
218
  const nodeVersion = process.version.match(/^v(\d+\.\d+\.\d+)/)[1];
255
219
  const portText = String(app.vulkano.get('port') || 8000);
256
220
  const socketText = sockets.enabled ? 'YES' : 'NO';
257
- const redisText = redis && redis.enabled ? 'YES' : 'NO';
221
+ const adapterText = sockets.enabled ? String(sockets.adapter || 'memory').toUpperCase() : 'NO';
258
222
 
259
223
  serverConfig.push(` PORT: ${colors.fg.green}${showColumn(portText, 7)}${colors.reset}`);
260
224
  serverConfig.push(' | ');
@@ -278,7 +242,7 @@ function startVulkano() {
278
242
  console.log(startUpConfig.join(''));
279
243
 
280
244
  const dbConfig = [];
281
- dbConfig.push(' REDIS: ', `${colors.fg.green}${showColumn(redisText, 8)}${colors.reset}`);
245
+ dbConfig.push(' ADAPTER: ', `${colors.fg.green}${showColumn(adapterText, 10)}${colors.reset}`);
282
246
  dbConfig.push(' | ');
283
247
  dbConfig.push(' DB: ', connection ? `${colors.fg.green}${connectionToShow}${colors.reset}` : `${colors.fg.blue}NO DATABASE${colors.reset}`);
284
248
  console.log(dbConfig.join(''));
@@ -7,8 +7,7 @@ module.exports = function getExpressConfiguration() {
7
7
  cors,
8
8
  jwt,
9
9
  settings,
10
- sockets,
11
- redis,
10
+ sockets: rawSockets,
12
11
  cookies,
13
12
  // Folder express config files
14
13
  express: expressServerConfig
@@ -64,14 +63,49 @@ module.exports = function getExpressConfiguration() {
64
63
  frameguard: null
65
64
  };
66
65
 
66
+ // --------
67
+ // Sockets
68
+ // --------
69
+
70
+ // Default config
71
+ const defaultConfig = {
72
+ enabled: false,
73
+ adapter: 'memory',
74
+ adapters: {
75
+ mongodb: {
76
+ enabled: false
77
+ },
78
+ redis: {
79
+ enabled: false
80
+ }
81
+ }
82
+ };
83
+
84
+ // Check Sockets configuration config/sockets/config.js
85
+ const {
86
+ config: socketsConfig
87
+ } = rawSockets || {};
88
+
89
+ // Merge config
90
+ const sockets = {
91
+ ...(defaultConfig || {}),
92
+ ...(socketsConfig || {}),
93
+ ...(rawSockets || {}),
94
+ config: {
95
+ ...(socketsConfig.config || {})
96
+ }
97
+ };
98
+
99
+ // Set the new values
100
+ app.config.sockets = { ...sockets };
101
+
67
102
  // Merge all express configuration: config/file.js, config/express/file.js, config/settings.js
68
103
  const expressConfig = merge.all([
69
104
  {
70
105
  cookies,
71
106
  jwt,
72
107
  cors,
73
- sockets,
74
- redis
108
+ sockets
75
109
  },
76
110
  expressDefaultConfig || {},
77
111
  expressServerConfig || {},
@@ -0,0 +1,59 @@
1
+ const logger = {
2
+
3
+ lineWidth: 39,
4
+
5
+ colors: {
6
+ reset: '\x1b[0m',
7
+ bright: '\x1b[1m',
8
+ dim: '\x1b[2m',
9
+ underscore: '\x1b[4m',
10
+ blink: '\x1b[5m',
11
+ reverse: '\x1b[7m',
12
+ hidden: '\x1b[8m',
13
+ fg: {
14
+ black: '\x1b[30m',
15
+ red: '\x1b[31m',
16
+ green: '\x1b[32m',
17
+ yellow: '\x1b[33m',
18
+ blue: '\x1b[34m',
19
+ magenta: '\x1b[35m',
20
+ cyan: '\x1b[36m',
21
+ white: '\x1b[37m',
22
+ crimson: '\x1b[38m' // Scarlet
23
+ },
24
+ bg: {
25
+ black: '\x1b[40m',
26
+ red: '\x1b[41m',
27
+ green: '\x1b[42m',
28
+ yellow: '\x1b[43m',
29
+ blue: '\x1b[44m',
30
+ magenta: '\x1b[45m',
31
+ cyan: '\x1b[46m',
32
+ white: '\x1b[47m',
33
+ crimson: '\x1b[48m'
34
+ }
35
+ },
36
+
37
+ showCenteredText(text) {
38
+
39
+ const colSize = (logger.lineWidth / 2) - 3;
40
+ const textLength = (text || '').length;
41
+ const textLeftSize = Math.trunc(textLength / 2);
42
+ const textRightSize = textLength - textLeftSize;
43
+
44
+ const textPaddingLeft = ''.padStart( colSize - textLeftSize, ' ');
45
+ const textPaddingRight = ''.padEnd( colSize - textRightSize, ' ');
46
+ const textCentered = `${textPaddingLeft}${text}${textPaddingRight}`;
47
+
48
+ return textCentered;
49
+
50
+ },
51
+
52
+ showColumn(text, titleLength) {
53
+ const txt = `${text.padEnd( 17 - titleLength, ' ')}`;
54
+ return txt;
55
+ }
56
+
57
+ };
58
+
59
+ module.exports = logger;