@vulkano/core 1.17.0 → 1.17.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.
@@ -0,0 +1,449 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Vulkano scaffold — runs after `npm install @vulkano/core`.
5
+ *
6
+ * If the project does not already have an `app/` or `vulkano/` directory,
7
+ * creates the minimal folder structure and config files needed to start.
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ // npm sets INIT_CWD to the directory where `npm install` was invoked.
14
+ // npm_config_local_prefix is the project root (directory containing node_modules).
15
+ // Fall back to __dirname-based resolution for non-npm invocations.
16
+ const coreRoot = path.resolve(__dirname, '..');
17
+ const projectRoot = process.env.INIT_CWD
18
+ || process.env.npm_config_local_prefix
19
+ || path.resolve(__dirname, '..', '..', '..', '..');
20
+
21
+ if (projectRoot === coreRoot) {
22
+ // Running `npm install` inside the core repo itself — nothing to scaffold
23
+ process.exit(0);
24
+ }
25
+
26
+ const appDir = path.join(projectRoot, 'app');
27
+ const vulkanoDir = path.join(projectRoot, 'vulkano');
28
+
29
+ if (fs.existsSync(appDir) || fs.existsSync(vulkanoDir)) {
30
+ // Project already has a structure — do not touch it
31
+ process.exit(0);
32
+ }
33
+
34
+ // ─────────────────────────────────────────────
35
+ // Prompt
36
+ // ─────────────────────────────────────────────
37
+
38
+ const readline = require('readline');
39
+
40
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
41
+
42
+ rl.question('\n 🌋 Vulkano: Would you like to scaffold a new project? (Y/n) ', (answer) => {
43
+
44
+ rl.close();
45
+
46
+ if (answer.trim().toLowerCase() === 'n') {
47
+ console.log('\n Skipped. You can scaffold manually at any time.\n');
48
+ process.exit(0);
49
+ }
50
+
51
+ scaffold();
52
+
53
+ });
54
+
55
+ // ─────────────────────────────────────────────
56
+ // Scaffold
57
+ // ─────────────────────────────────────────────
58
+
59
+ function scaffold() {
60
+
61
+ function write(relPath, content) {
62
+ const abs = path.join(appDir, relPath);
63
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
64
+ if (!fs.existsSync(abs)) {
65
+ fs.writeFileSync(abs, content, 'utf8');
66
+ }
67
+ }
68
+
69
+ function dir(relPath) {
70
+ const abs = path.join(appDir, relPath);
71
+ fs.mkdirSync(abs, { recursive: true });
72
+ const keep = path.join(abs, '.gitkeep');
73
+ if (!fs.existsSync(keep)) fs.writeFileSync(keep, '', 'utf8');
74
+ }
75
+
76
+ // ─────────────────────────────────────────────
77
+ // app/config/bootstrap.js (required by Vulkano)
78
+ // ─────────────────────────────────────────────
79
+ write('config/bootstrap.js', `/**
80
+ * Bootstrap — called once the server is ready to start.
81
+ * @param {Function} cb Call cb() to finish startup
82
+ */
83
+ module.exports = (cb) => {
84
+
85
+ // Start app
86
+ cb(() => {
87
+
88
+ });
89
+ };
90
+ `);
91
+
92
+ // ─────────────────────────────────────────────
93
+ // app/config/settings.js
94
+ // ─────────────────────────────────────────────
95
+ write('config/settings.js', `/**
96
+ * Application settings
97
+ */
98
+ module.exports = {
99
+
100
+ // Server port (overridden by NODE_PORT / PORT env vars)
101
+ port: parseInt(process.env.PORT, 10) || 8000,
102
+
103
+ // Database connection — key must exist in app/config/connections.js
104
+ database: {
105
+ connection: 'default',
106
+ settings: {
107
+ strictQuery: false,
108
+ debug: false
109
+ }
110
+ }
111
+
112
+ };
113
+ `);
114
+
115
+ // ─────────────────────────────────────────────
116
+ // app/config/connections.js
117
+ // ─────────────────────────────────────────────
118
+ write('config/connections.js', `/**
119
+ * Database connections
120
+ * The key here is referenced from settings.js → database.connection
121
+ */
122
+ module.exports = {
123
+
124
+ default: process.env.MONGO_URI || 'mongodb://localhost:27017/vulkano'
125
+
126
+ };
127
+ `);
128
+
129
+ // ─────────────────────────────────────────────
130
+ // app/config/routes.js
131
+ // ─────────────────────────────────────────────
132
+ write('config/routes.js', `/**
133
+ * Explicit routes (optional)
134
+ * Format: 'METHOD /path': 'ControllerName.action'
135
+ *
136
+ * Convention-based routes are auto-generated from controllers — no need
137
+ * to list them here.
138
+ *
139
+ * Example:
140
+ * - GET /users/ -> File: UsersController, Method: 'get': (req, res) => {}
141
+ * - GET /users/123 -> File: UsersController, Method: 'get :id': (req, res) => {}
142
+ * - POST /users/ -> File: UsersController, Method: 'post': (req, res) => {}
143
+ * - PUT /users/123 -> File: UsersController, Method: 'put :id': (req, res) => {}
144
+ * - DELETE /users/123 -> File: UsersController, Method: 'delete :id': (req, res) => {}
145
+ *
146
+ * But you can write your own routes manually
147
+ *
148
+ */
149
+ module.exports = {
150
+
151
+ // 'GET /': 'HomeController.get'
152
+
153
+ };
154
+ `);
155
+
156
+ // ─────────────────────────────────────────────
157
+ // app/config/express/settings.js
158
+ // ─────────────────────────────────────────────
159
+ write('config/express/settings.js', `/**
160
+ * Express server settings
161
+ */
162
+ module.exports = {
163
+
164
+ // Show "X-Powered-By" header
165
+ poweredBy: false,
166
+
167
+ // Request timeout in milliseconds
168
+ timeout: 120000,
169
+
170
+ // Folder to upload files
171
+ uploadPath: 'public/files',
172
+
173
+ // Number of proxy hops to trust for X-Forwarded-* headers.
174
+ // Use 1 when behind a single load balancer, true to trust all (less secure).
175
+ trustProxy: 1
176
+
177
+ };
178
+ `);
179
+
180
+ // ─────────────────────────────────────────────
181
+ // app/config/express/cors.js
182
+ // ─────────────────────────────────────────────
183
+ write('config/express/cors.js', `/**
184
+ * CORS configuration
185
+ */
186
+ module.exports = {
187
+
188
+ // Enable CORS
189
+ enabled: false,
190
+
191
+ // Path where CORS headers are applied
192
+ path: '/',
193
+
194
+ // Allowed origin — use specific domains in production
195
+ origin: '*',
196
+
197
+ // Additional allowed request headers
198
+ headers: ['x-token-auth']
199
+
200
+ };
201
+ `);
202
+
203
+ // ─────────────────────────────────────────────
204
+ // app/config/express/jwt.js
205
+ // ─────────────────────────────────────────────
206
+ write('config/express/jwt.js', `/**
207
+ * JWT authentication middleware
208
+ */
209
+ module.exports = {
210
+
211
+ //
212
+ // Enable JWT
213
+ // @type Boolean
214
+ //
215
+ enabled: false,
216
+
217
+ //
218
+ // Custom KEY
219
+ // You can use this https://api.wordpress.org/secret-key/1.1/salt/ to change key
220
+ // @type String
221
+ //
222
+ key: process.env.JWT_SECRET_KEY || '',
223
+
224
+ //
225
+ // header name via Request
226
+ // @type String
227
+ //
228
+ header: 'x-token-auth',
229
+
230
+ //
231
+ // Get token via url
232
+ // value: string
233
+ // @type String
234
+ //
235
+ queryParameter: 'token',
236
+
237
+ //
238
+ // Get token via cookie
239
+ // value: string
240
+ // @type String
241
+ //
242
+ cookieName: 'token',
243
+
244
+ //
245
+ // Path to make mandatory the token
246
+ // Example /api/
247
+ // @type String
248
+ //
249
+ path: '/api/',
250
+
251
+ //
252
+ // Path to ignore token request
253
+ // Example: ['/api/auth', '/api/auth/forgot', /^\\/api\\/events/i]
254
+ // you can see https://github.com/jfromaniello/express-unless to more examples
255
+ //
256
+ // To allow the enpoint to verify token replace the api path for /^\\/api\\/auth(?!\\/current)/i
257
+ //
258
+ // @type Array
259
+ //
260
+ ignore: [
261
+ '/api/',
262
+ /^\\/api\\/auth(?!\\/current)/i
263
+ ]
264
+
265
+ };
266
+ `);
267
+
268
+ // ─────────────────────────────────────────────
269
+ // app/config/express/cookies.js
270
+ // ─────────────────────────────────────────────
271
+ write('config/express/cookies.js', `/**
272
+ * Cookie parser
273
+ */
274
+ module.exports = {
275
+
276
+ //
277
+ // Enable Cookies
278
+ // @type Boolean
279
+ //
280
+ enabled: false,
281
+
282
+ // SECRET KEY to sign the cookie
283
+ // You can use this https://api.wordpress.org/secret-key/1.1/salt/ to change key
284
+ // @type String
285
+ secret: process.env.COOKIES_SECRET_KEY || ''
286
+
287
+ };
288
+ `);
289
+
290
+ // ─────────────────────────────────────────────
291
+ // app/config/encryption.js
292
+ // ─────────────────────────────────────────────
293
+ write('config/encryption.js', `/**
294
+ * Encryption settings (used by Encrypter)
295
+ */
296
+ module.exports = {
297
+
298
+ // Secret encryption key — always set via environment variable
299
+ key: process.env.ENCRYPTION_KEY || '',
300
+
301
+ // Salt for key derivation (scrypt)
302
+ salt: process.env.ENCRYPTION_SALT || 'vulkano-salt-v1',
303
+
304
+ // Cipher algorithm
305
+ algorithm: process.env.ENCRYPTION_ALGORITHM || 'aes-256-cbc'
306
+
307
+ };
308
+ `);
309
+
310
+ // ─────────────────────────────────────────────
311
+ // app/controllers/HomeController.js
312
+ // ─────────────────────────────────────────────
313
+ write('controllers/HomeController.js', `/**
314
+ * HomeController
315
+ * Convention-based routes → GET /home/, GET /home/:id, POST /home/save, etc.
316
+ *
317
+ * To map GET / to this controller add to app/config/routes.js:
318
+ * 'GET /': 'HomeController.index'
319
+ */
320
+ module.exports = {
321
+
322
+ // GET /home/
323
+ get(req, res) {
324
+ res.render('home/index.html');
325
+ }
326
+
327
+ };
328
+ `);
329
+
330
+ // ─────────────────────────────────────────────
331
+ // Empty placeholder directories
332
+ // ─────────────────────────────────────────────
333
+ dir('models');
334
+ dir('services');
335
+ dir('responses');
336
+
337
+ // ─────────────────────────────────────────────
338
+ // app/views structure
339
+ // ─────────────────────────────────────────────
340
+ dir('views/home');
341
+ dir('views/_shared/errors');
342
+ dir('views/_shared/templates');
343
+
344
+ write('views/_shared/templates/default.html', `<!DOCTYPE html>
345
+ <html lang="en">
346
+ <head>
347
+ <meta charset="UTF-8">
348
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
349
+ <title>{% block title %}Vulkano{% endblock %}</title>
350
+ <link rel="stylesheet" href="/css/app.css">
351
+ </head>
352
+ <body>
353
+
354
+ {% block content %}{% endblock %}
355
+
356
+ <script src="/js/app.js"></script>
357
+ </body>
358
+ </html>
359
+ `);
360
+
361
+ write('views/home/index.html', `{% extends "_shared/templates/default.html" %}
362
+
363
+ {% block title %}Home — Vulkano{% endblock %}
364
+
365
+ {% block content %}
366
+ <h1>Vulkano is running!</h1>
367
+ {% endblock %}
368
+ `);
369
+
370
+ write('views/_shared/errors/404.html', `<!DOCTYPE html>
371
+ <html lang="en">
372
+ <head>
373
+ <meta charset="UTF-8">
374
+ <title>404 Not Found</title>
375
+ </head>
376
+ <body>
377
+ <h1>404 — Page Not Found</h1>
378
+ </body>
379
+ </html>
380
+ `);
381
+
382
+ write('views/_shared/errors/500.html', `<!DOCTYPE html>
383
+ <html lang="en">
384
+ <head>
385
+ <meta charset="UTF-8">
386
+ <title>500 Server Error</title>
387
+ </head>
388
+ <body>
389
+ <h1>500 — Server Error</h1>
390
+ </body>
391
+ </html>
392
+ `);
393
+
394
+ // public/files for multer uploads
395
+ const publicFiles = path.join(projectRoot, 'public', 'files');
396
+ fs.mkdirSync(publicFiles, { recursive: true });
397
+
398
+ // public/css for css files
399
+ const publicCss = path.join(projectRoot, 'public', 'css');
400
+ fs.mkdirSync(publicCss, { recursive: true });
401
+
402
+ // public/js for js files
403
+ const publicJs = path.join(projectRoot, 'public', 'js');
404
+ fs.mkdirSync(publicJs, { recursive: true });
405
+
406
+ // public/img for image files
407
+ const publicImg = path.join(projectRoot, 'public', 'img');
408
+ fs.mkdirSync(publicImg, { recursive: true });
409
+
410
+ // public/fonts for font files
411
+ const publicFonts = path.join(projectRoot, 'public', 'fonts');
412
+ fs.mkdirSync(publicFonts, { recursive: true });
413
+
414
+ // .env example
415
+ const envExample = path.join(projectRoot, '.env');
416
+ if (!fs.existsSync(envExample)) {
417
+ fs.writeFileSync(envExample, [
418
+ '# Copy to .env and fill in your values',
419
+ 'PORT=8000',
420
+ 'MONGO_URI=',
421
+ 'JWT_SECRET=',
422
+ 'COOKIE_SECRET=',
423
+ 'ENCRYPTION_KEY=',
424
+ 'ENCRYPTION_SALT=salt',
425
+ 'ENCRYPTION_ALGORITHM=aes-256-cbc',
426
+ ''
427
+ ].join('\n'), 'utf8');
428
+ }
429
+
430
+ console.log([
431
+ '',
432
+ ' ✔ Vulkano scaffold created:',
433
+ ' app/config/ ← settings, connections, routes, express, jwt…',
434
+ ' app/controllers/ ← HomeController.js',
435
+ ' app/models/ ← (empty — add your models here)',
436
+ ' app/services/ ← (empty — add your services here)',
437
+ ' app/views/ ← home/index.html, _shared/templates/default.html, errors/404, 500',
438
+ ' public/css/ ← css files',
439
+ ' public/js/ ← js files',
440
+ ' public/img/ ← image files',
441
+ ' public/fonts/ ← font files',
442
+ ' .env ← fill in values',
443
+ '',
444
+ ' Next steps:',
445
+ ' 1. Set MONGO_URI, JWT_SECRET, etc.',
446
+ '',
447
+ ].join('\n'));
448
+
449
+ } // end scaffold()
@@ -36,7 +36,7 @@ module.exports = async function loadDatabaseApplication() {
36
36
  return;
37
37
  }
38
38
 
39
- const toConnect = connection in connections
39
+ const toConnect = (connections && connection in connections)
40
40
  ? connections[connection]
41
41
  : (connection || null);
42
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulkano/core",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "A MVC framework using Express 4",
5
5
  "license": "MIT",
6
6
  "author": "Vulkano Team",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "test": "jest",
13
13
  "test:watch": "jest --watch",
14
- "test:coverage": "jest --coverage"
14
+ "test:coverage": "jest --coverage",
15
+ "postinstall": "node bin/postinstall.js"
15
16
  },
16
17
  "preferGlobal": true,
17
18
  "homepage": "https://github.com/vulkanojs/vulkano-core",