@vulkano/core 1.1.0 → 1.2.0
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 +47 -24
- package/bootstrap/server.js +27 -6
- package/bootstrap/views.js +27 -0
- package/controllers/ScaffoldController.js +29 -2
- package/controllers/controllers.js +4 -2
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -164,18 +164,41 @@ const colors = {
|
|
|
164
164
|
|
|
165
165
|
function startVulkano() {
|
|
166
166
|
|
|
167
|
+
const appName = appPkg.name.toUpperCase().split('-').join(' ');
|
|
168
|
+
const appVersion = appPkg.version;
|
|
169
|
+
const author = appPkg.author || pkg.author;
|
|
170
|
+
|
|
171
|
+
const lineWidth = 38;
|
|
172
|
+
|
|
173
|
+
const showCenteredText = (text) => {
|
|
174
|
+
|
|
175
|
+
const colSize = (lineWidth / 2) - 3;
|
|
176
|
+
const textLength = (text || '').length;
|
|
177
|
+
const textLeftSize = Math.trunc(textLength / 2);
|
|
178
|
+
const textRightSize = textLength - textLeftSize;
|
|
179
|
+
|
|
180
|
+
const textPaddingLeft = ''.padStart( colSize - textLeftSize, ' ');
|
|
181
|
+
const textPaddingRight = ''.padEnd( colSize - textRightSize, ' ');
|
|
182
|
+
const textCentered = `${textPaddingLeft}${text}${textPaddingRight}`;
|
|
183
|
+
|
|
184
|
+
return textCentered;
|
|
185
|
+
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const cutLine = '-'.padEnd(lineWidth, '-');
|
|
189
|
+
|
|
167
190
|
console.log('');
|
|
191
|
+
console.log(`${colors.fg.magenta}${cutLine}`, colors.reset);
|
|
168
192
|
console.log('');
|
|
169
|
-
console.log(
|
|
170
|
-
console.log(
|
|
171
|
-
console.log(colors.fg.cyan,
|
|
172
|
-
console.log(colors.fg.cyan, ` APP VERSION ${appPkg.version}`, colors.reset);
|
|
173
|
-
console.log(colors.fg.cyan, ` @VULKANO/CORE ${pkg.version}`, colors.reset);
|
|
193
|
+
console.log(colors.fg.cyan, showCenteredText('🌋'), colors.reset);
|
|
194
|
+
console.log(colors.fg.cyan, showCenteredText(`${appName} ${appVersion}`), colors.reset);
|
|
195
|
+
console.log(colors.fg.cyan, showCenteredText(`${pkg.name} ${pkg.version}`.toUpperCase()), colors.reset);
|
|
174
196
|
console.log('');
|
|
175
|
-
console.log(colors.fg.blue, '🔗
|
|
176
|
-
console.log(colors.fg.cyan, '☕
|
|
197
|
+
console.log(colors.fg.blue, '🔗 github.com/vulkanojs/vulkano', colors.reset);
|
|
198
|
+
console.log(colors.fg.cyan, '☕ buymeacoffee.com/argordmel', colors.reset);
|
|
177
199
|
console.log('');
|
|
178
|
-
console.log(
|
|
200
|
+
console.log(` Author: ${colors.fg.green}${author}${colors.reset}`);
|
|
201
|
+
console.log(`${colors.fg.magenta}${cutLine}`, colors.reset);
|
|
179
202
|
|
|
180
203
|
// Routes
|
|
181
204
|
app.routes = controllers;
|
|
@@ -219,18 +242,23 @@ function startVulkano() {
|
|
|
219
242
|
connection
|
|
220
243
|
} = database || {};
|
|
221
244
|
|
|
245
|
+
const showColumn = (text, titleLength) => {
|
|
246
|
+
const txt = `${text.padEnd( 16 - titleLength, ' ')}`;
|
|
247
|
+
return txt;
|
|
248
|
+
};
|
|
249
|
+
|
|
222
250
|
const connectionToShow = connection && process.env.MONGO_URI ? 'MONGO_URI' : connection;
|
|
223
251
|
|
|
224
252
|
const serverConfig = [];
|
|
225
253
|
|
|
226
254
|
const nodeVersion = process.version.match(/^v(\d+\.\d+\.\d+)/)[1];
|
|
227
|
-
const portText = String(app.server.get('port') || 8000)
|
|
228
|
-
const socketText =
|
|
229
|
-
const redisText =
|
|
255
|
+
const portText = String(app.server.get('port') || 8000);
|
|
256
|
+
const socketText = sockets.enabled ? 'YES' : 'NO';
|
|
257
|
+
const redisText = redis && redis.enabled ? 'YES' : 'NO';
|
|
230
258
|
|
|
231
|
-
serverConfig.push(` PORT: ${colors.fg.green}${portText}${colors.reset}`);
|
|
259
|
+
serverConfig.push(` PORT: ${colors.fg.green}${showColumn(portText, 7)}${colors.reset}`);
|
|
232
260
|
serverConfig.push(' | ');
|
|
233
|
-
serverConfig.push(` ENV: ${app.PRODUCTION ? colors.fg.red : colors.fg.green}${NODE_ENV}${colors.reset}`);
|
|
261
|
+
serverConfig.push(` ENV: ${app.PRODUCTION ? colors.fg.red : colors.fg.green}${showColumn(NODE_ENV, 0)}${colors.reset}`);
|
|
234
262
|
|
|
235
263
|
console.log(serverConfig.join(''));
|
|
236
264
|
|
|
@@ -238,29 +266,24 @@ function startVulkano() {
|
|
|
238
266
|
const totalHeapSizeGb = (totalHeapSize / 1024 / 1024 / 1024).toFixed(2);
|
|
239
267
|
|
|
240
268
|
const nodeConfig = [];
|
|
241
|
-
nodeConfig.push(` NODE: ${colors.fg.green}${nodeVersion}${colors.reset}`);
|
|
269
|
+
nodeConfig.push(` NODE: ${colors.fg.green}${showColumn(nodeVersion, 7)}${colors.reset}`);
|
|
242
270
|
nodeConfig.push(' | ');
|
|
243
271
|
nodeConfig.push(' MAX MEM: ', `${colors.fg.green}${totalHeapSizeGb} GB${colors.reset}`);
|
|
244
272
|
console.log(nodeConfig.join(''));
|
|
245
273
|
|
|
246
274
|
const startUpConfig = [];
|
|
247
|
-
startUpConfig.push(' SOCKETS: ', `${colors.fg.green}${socketText}${colors.reset}`);
|
|
275
|
+
startUpConfig.push(' SOCKETS: ', `${colors.fg.green}${showColumn(socketText, 10)}${colors.reset}`);
|
|
248
276
|
startUpConfig.push(' | ');
|
|
249
|
-
startUpConfig.push(` STARTUP: ${colors.fg.green}${moment(moment().diff(global.START_TIME)).format('
|
|
277
|
+
startUpConfig.push(` STARTUP: ${colors.fg.green}${moment(moment().diff(global.START_TIME)).format('s.SSS')}s${colors.reset}`);
|
|
250
278
|
console.log(startUpConfig.join(''));
|
|
251
279
|
|
|
252
280
|
const dbConfig = [];
|
|
253
|
-
|
|
254
|
-
dbConfig.push(' REDIS: ', `${colors.fg.green}${redisText}${colors.reset}`);
|
|
255
|
-
} else {
|
|
256
|
-
dbConfig.push(' REDIS: ', `${colors.fg.green}${redisText}${colors.reset}`);
|
|
257
|
-
}
|
|
258
|
-
|
|
281
|
+
dbConfig.push(' REDIS: ', `${colors.fg.green}${showColumn(redisText, 8)}${colors.reset}`);
|
|
259
282
|
dbConfig.push(' | ');
|
|
260
|
-
dbConfig.push(' DB: ', connection ? `${colors.fg.green}${connectionToShow}${colors.reset}` : `${colors.fg.blue}
|
|
283
|
+
dbConfig.push(' DB: ', connection ? `${colors.fg.green}${connectionToShow}${colors.reset}` : `${colors.fg.blue}NO DATABASE${colors.reset}`);
|
|
261
284
|
console.log(dbConfig.join(''));
|
|
262
285
|
|
|
263
|
-
console.log(`${colors.fg.magenta}
|
|
286
|
+
console.log(`${colors.fg.magenta}${cutLine}`, colors.reset);
|
|
264
287
|
|
|
265
288
|
// Run custom callback after init vulkano
|
|
266
289
|
if (callbackAfterInitVulkano && typeof callbackAfterInitVulkano === 'function') {
|
package/bootstrap/server.js
CHANGED
|
@@ -24,6 +24,8 @@ const AllControllers = require('include-all')({
|
|
|
24
24
|
optional: true
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
const viewsConfig = require('./views');
|
|
28
|
+
|
|
27
29
|
const responses = require('./responses');
|
|
28
30
|
|
|
29
31
|
const JWT = require('../libs/Jwt');
|
|
@@ -113,8 +115,6 @@ module.exports = {
|
|
|
113
115
|
delete expressConfig.settings;
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
const views = app.server.views || {};
|
|
117
|
-
|
|
118
118
|
// Middleware
|
|
119
119
|
const middleware = app.config.middleware || ((req, res, next) => {
|
|
120
120
|
next();
|
|
@@ -306,13 +306,26 @@ module.exports = {
|
|
|
306
306
|
// ---------------
|
|
307
307
|
// VIEWS
|
|
308
308
|
// ---------------
|
|
309
|
+
|
|
310
|
+
const views = {
|
|
311
|
+
...viewsConfig,
|
|
312
|
+
...(app.server.views || {})
|
|
313
|
+
};
|
|
314
|
+
|
|
309
315
|
server.set('views', views.path);
|
|
310
316
|
|
|
311
|
-
const
|
|
312
|
-
|
|
317
|
+
const {
|
|
318
|
+
settings: nunjucksSettingsUser
|
|
319
|
+
} = views || {};
|
|
320
|
+
|
|
321
|
+
const nunjucksSettings = {
|
|
313
322
|
autoescape: true,
|
|
314
|
-
watch: !app.PRODUCTION
|
|
315
|
-
|
|
323
|
+
watch: !app.PRODUCTION,
|
|
324
|
+
...(nunjucksSettingsUser || {}),
|
|
325
|
+
express: server
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const envNunjucks = nunjucks.configure(views.path, nunjucksSettings);
|
|
316
329
|
|
|
317
330
|
app.server.views._engine = envNunjucks;
|
|
318
331
|
|
|
@@ -326,6 +339,14 @@ module.exports = {
|
|
|
326
339
|
});
|
|
327
340
|
}
|
|
328
341
|
|
|
342
|
+
if (views.helpers && Array.isArray(views.helpers)) {
|
|
343
|
+
views.helpers.forEach((helper) => {
|
|
344
|
+
Object.keys(helper || []).forEach((i) => {
|
|
345
|
+
envNunjucks.addGlobal(i, helper[i]);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
329
350
|
if (views.filters && Array.isArray(views.filters)) {
|
|
330
351
|
views.filters.forEach((filter) => {
|
|
331
352
|
Object.keys(filter || []).forEach((i) => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
// Include all filters
|
|
4
|
+
const appFilters = require('include-all')({
|
|
5
|
+
dirname: path.join(APP_PATH, 'config/views/filters'),
|
|
6
|
+
filter: /(.+)\.js$/,
|
|
7
|
+
optional: true
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// Include all helpers
|
|
11
|
+
const appHelpers = require('include-all')({
|
|
12
|
+
dirname: path.join(APP_PATH, 'config/views/helpers'),
|
|
13
|
+
filter: /(.+)\.js$/,
|
|
14
|
+
optional: true
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
|
|
19
|
+
path: path.join(APP_PATH, 'views'),
|
|
20
|
+
|
|
21
|
+
engine: 'nunjucks',
|
|
22
|
+
|
|
23
|
+
filters: [appFilters || {}],
|
|
24
|
+
|
|
25
|
+
helpers: [appHelpers || {}]
|
|
26
|
+
|
|
27
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports = (modelName) => {
|
|
1
|
+
module.exports = (modelName, allowedMethods) => {
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
config
|
|
@@ -51,7 +51,7 @@ module.exports = (modelName) => {
|
|
|
51
51
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const allMethods = {
|
|
55
55
|
|
|
56
56
|
get(req, res) {
|
|
57
57
|
|
|
@@ -105,4 +105,31 @@ module.exports = (modelName) => {
|
|
|
105
105
|
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
+
if (allowedMethods) {
|
|
109
|
+
|
|
110
|
+
const tempAllowedMethods = Array.isArray(allowedMethods)
|
|
111
|
+
? allowedMethods.map( (m) => m.toLowerCase() )
|
|
112
|
+
: allowedMethods.split(',').map( (m) => m.trim().toLowerCase() );
|
|
113
|
+
|
|
114
|
+
if (!tempAllowedMethods.includes('post')) {
|
|
115
|
+
delete allMethods.post;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (!tempAllowedMethods.includes('get')) {
|
|
119
|
+
delete allMethods.get;
|
|
120
|
+
delete allMethods['get :id'];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!tempAllowedMethods.includes('put')) {
|
|
124
|
+
delete allMethods['put :id'];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!tempAllowedMethods.includes('delete')) {
|
|
128
|
+
delete allMethods['delete :id'];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return allMethods;
|
|
134
|
+
|
|
108
135
|
};
|
|
@@ -22,12 +22,13 @@ module.exports = function loadControllersApplication() {
|
|
|
22
22
|
|
|
23
23
|
const {
|
|
24
24
|
scaffold,
|
|
25
|
+
allowedMethods,
|
|
25
26
|
model
|
|
26
27
|
} = current;
|
|
27
28
|
|
|
28
29
|
if (scaffold && model) {
|
|
29
30
|
|
|
30
|
-
const scaffoldingCurrent = scaffoldController(model);
|
|
31
|
+
const scaffoldingCurrent = scaffoldController(model, allowedMethods);
|
|
31
32
|
|
|
32
33
|
Object.keys(scaffoldingCurrent).forEach( (m) => {
|
|
33
34
|
|
|
@@ -61,12 +62,13 @@ module.exports = function loadControllersApplication() {
|
|
|
61
62
|
|
|
62
63
|
const {
|
|
63
64
|
scaffold: subcurrentScaffold,
|
|
65
|
+
allowedMethods: subAllowedMethods,
|
|
64
66
|
model: subcurrentModel
|
|
65
67
|
} = subcurrent || {};
|
|
66
68
|
|
|
67
69
|
if (subcurrentScaffold && subcurrentModel) {
|
|
68
70
|
|
|
69
|
-
const scaffoldingSubcurrent = scaffoldController(subcurrentModel);
|
|
71
|
+
const scaffoldingSubcurrent = scaffoldController(subcurrentModel, subAllowedMethods);
|
|
70
72
|
|
|
71
73
|
Object.keys(scaffoldingSubcurrent).forEach( (m) => {
|
|
72
74
|
|