@vulkano/core 1.17.3 → 1.18.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 CHANGED
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable import/no-dynamic-require */
2
+ /* global Vite */
2
3
 
3
4
  /**
4
5
  * Bootstrap.js
@@ -196,7 +197,8 @@ async function startVulkano() {
196
197
 
197
198
  const {
198
199
  sockets,
199
- settings: configSettings
200
+ settings: configSettings,
201
+ vite
200
202
  } = app.config || {};
201
203
 
202
204
  const {
@@ -245,6 +247,10 @@ async function startVulkano() {
245
247
 
246
248
  console.log(`${colors.fg.magenta}${cutLine}`, colors.reset);
247
249
 
250
+ if (vite && vite.enabled) {
251
+ app.vite = Vite.init(vite.buildPath || 'public/.vite');
252
+ }
253
+
248
254
  // Run custom callback after init vulkano
249
255
  if (callbackAfterInitVulkano && typeof callbackAfterInitVulkano === 'function') {
250
256
  callbackAfterInitVulkano();
package/bin/vulkano.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable global-require */
3
+ /* eslint-disable import/extensions */
4
+
5
+ const [,, command] = process.argv;
6
+
7
+ switch (command) {
8
+ case 'init':
9
+ require('./setup.js');
10
+ break;
11
+ default:
12
+ console.log([
13
+ '',
14
+ ' Usage: vulkano <command>',
15
+ '',
16
+ ' Commands:',
17
+ ' init Scaffold a new Vulkano project in the current directory',
18
+ '',
19
+ ].join('\n'));
20
+ process.exit(0);
21
+ }
@@ -1,3 +1,5 @@
1
+ const path = require('path');
2
+
1
3
  const merge = require('../libs/Merge');
2
4
 
3
5
  module.exports = function getExpressConfiguration() {
@@ -49,7 +51,7 @@ module.exports = function getExpressConfiguration() {
49
51
  sockets: {},
50
52
  redis: {},
51
53
  multer: {
52
- dest: 'public/files'
54
+ dest: global.PUBLIC_PATH ? path.join(global.PUBLIC_PATH, 'files') : 'public/files'
53
55
  },
54
56
  morgan: {
55
57
  format: 'dev',
@@ -191,7 +191,8 @@ module.exports = function loadServer() {
191
191
 
192
192
  vulkano.use( (req, res, next) => {
193
193
  if (req.timedout) {
194
- return res.status(503).json({ success: false, statusCode: 503, error: { detail: 'Request timeout' } });
194
+ res.status(503).json({ success: false, statusCode: 503, error: { detail: 'Request timeout' } });
195
+ return;
195
196
  }
196
197
  next();
197
198
  });
@@ -663,7 +664,8 @@ module.exports = function loadServer() {
663
664
 
664
665
  // Timeout — always respond with JSON regardless of request type
665
666
  if (req.timedout || (err && err.timeout)) {
666
- return res.status(503).json({ success: false, statusCode: 503, error: { detail: 'Request timeout' } });
667
+ res.status(503).json({ success: false, statusCode: 503, error: { detail: 'Request timeout' } });
668
+ return;
667
669
  }
668
670
 
669
671
  const status = err ? (err.status || 500) : (res.statusCode || 500);
@@ -15,6 +15,12 @@ const appFilters = require('include-all')({
15
15
  });
16
16
 
17
17
  // Include all helpers
18
+ const coreHelpers = require('include-all')({
19
+ dirname: path.join(CORE_PATH, 'views/helpers'),
20
+ filter: /(.+)\.js$/,
21
+ optional: true
22
+ });
23
+
18
24
  const appHelpers = require('include-all')({
19
25
  dirname: path.join(APP_PATH, 'config/views/helpers'),
20
26
  filter: /(.+)\.js$/,
@@ -32,6 +38,6 @@ module.exports = {
32
38
  appFilters || {}
33
39
  ],
34
40
 
35
- helpers: [appHelpers || {}]
41
+ helpers: [coreHelpers || {}, appHelpers || {}]
36
42
 
37
43
  };
package/libs/Vite.js ADDED
@@ -0,0 +1,71 @@
1
+ const fs = require('fs');
2
+
3
+ module.exports = {
4
+
5
+ init(buildPath) {
6
+
7
+ // we must have a manifest file...
8
+ let manifestPath = null;
9
+
10
+ const viteFolder = [
11
+ ABS_PATH,
12
+ (buildPath || 'public/.vite')
13
+ ].join('/');
14
+
15
+ const env = String(process.env.NODE_ENV || 'development').toLowerCase();
16
+
17
+ const isProd = env === 'production' ? true : false;
18
+
19
+ // Get the main manifest file
20
+ if (fs.existsSync(`${viteFolder}/manifest.json`)) {
21
+ manifestPath = fs.readFileSync(`${viteFolder}/manifest.json`, 'utf8');
22
+ }
23
+
24
+ // if in dev, try to get the env specific manifest file
25
+ if (!isProd) {
26
+ if (fs.existsSync(`${viteFolder}/manifest.${env}.json`)) {
27
+ manifestPath = fs.readFileSync(`${viteFolder}/manifest.${env}.json`, 'utf8');
28
+ } else if (manifestPath) {
29
+ console.log(`No Vite Manifest for env: ${env} exists. Fallback: manifest.json.`);
30
+ }
31
+ }
32
+
33
+ // Show warning if no manifest found
34
+ if (!manifestPath) {
35
+ if (isProd) {
36
+ console.log(`No Vite Manifest exists. Path: ${viteFolder}/manifest.json. Should hot server be running?`);
37
+ } else {
38
+ console.log(`No Vite Manifest exists. Path: ${viteFolder}/manifest.${env}.json. Should hot server be running?`);
39
+ }
40
+ }
41
+
42
+ const manifest = JSON.parse(manifestPath || '{}');
43
+
44
+ const {
45
+ url
46
+ } = manifest || {};
47
+
48
+ if (!url) {
49
+
50
+ return {
51
+ env,
52
+ url: '',
53
+ inputs: manifest || {}
54
+ };
55
+
56
+ }
57
+
58
+ return {
59
+ env,
60
+ ...manifest
61
+ };
62
+
63
+ },
64
+
65
+ buildFolder() {
66
+
67
+ return [ABS_PATH, this.buildPath].join('/');
68
+
69
+ }
70
+
71
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulkano/core",
3
- "version": "1.17.3",
3
+ "version": "1.18.0",
4
4
  "description": "A MVC framework using Express 4",
5
5
  "license": "MIT",
6
6
  "author": "Vulkano Team",
@@ -8,11 +8,14 @@
8
8
  "node": ">=20"
9
9
  },
10
10
  "main": "app.js",
11
+ "bin": {
12
+ "vulkano": "./bin/vulkano.js"
13
+ },
11
14
  "scripts": {
12
15
  "test": "jest",
13
16
  "test:watch": "jest --watch",
14
17
  "test:coverage": "jest --coverage",
15
- "postinstall": "node bin/postinstall.js"
18
+ "init": "node bin/setup.js"
16
19
  },
17
20
  "preferGlobal": true,
18
21
  "homepage": "https://github.com/vulkanojs/vulkano-core",
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Custom backend integration for Vite asset injection.
3
+ * Reads the Vite manifest (dev or production) from `app.vite` to dynamically
4
+ * inject the correct <script> or <link> tags into Nunjucks templates.
5
+ * Supports two asset types via the `type` param: "script" and "style(s)".
6
+ * In development, it emits the Vite HMR client + module entry; in production
7
+ * it resolves the hashed filenames from the manifest and appends a cache-bust
8
+ * query string using the app version.
9
+ *
10
+ * In your template, you can define the CSS and JS entries like this:
11
+ *
12
+ * CSS: {{ vite({ entry: 'app', type: 'style' }) | safe }}
13
+ * JS: {{ vite({ entry: 'app', type: 'script' }) | safe }}
14
+ *
15
+ */
16
+ module.exports = (props) => {
17
+
18
+ const {
19
+ vite
20
+ } = app.config || {};
21
+
22
+ if (!vite || (vite && !vite.enabled) ) {
23
+ return '<!-- Vite support not enabled. Enable it in your config/vite.js -->';
24
+ }
25
+
26
+ const {
27
+ entry,
28
+ type
29
+ } = props || {};
30
+
31
+ const {
32
+ url,
33
+ inputs
34
+ } = app.vite || {};
35
+
36
+ const {
37
+ version
38
+ } = app.pkg || {};
39
+
40
+ const validEntry = Object.keys(inputs).find( (k) => k.indexOf(entry) >= 0 );
41
+
42
+ if (!validEntry) {
43
+ return `<!-- Invalid Entry ${entry} -->`;
44
+ }
45
+
46
+ const currentEntry = inputs[validEntry];
47
+
48
+ const {
49
+ file,
50
+ css
51
+ } = currentEntry || {};
52
+
53
+ if (type === 'styles' || type === 'style') {
54
+ return (css || []).map( (s) => `<link rel="stylesheet" href="${url || '/'}${s}?v=${version}">`).join('\n');
55
+ }
56
+
57
+ if (type === 'script') {
58
+
59
+ // Development
60
+ if (typeof currentEntry === 'string') {
61
+ return [
62
+ '<!-- development -->',
63
+ `<script type="module" src="${url}@vite/client"></script>`,
64
+ `<script type="module" src="${url || '/'}${currentEntry}"></script>`
65
+ ].join('\n');
66
+ }
67
+
68
+ // Production
69
+ return `<script type="module" src="${url || '/'}${file}?v=${version}"></script>`;
70
+
71
+ }
72
+
73
+ return '';
74
+
75
+ };
File without changes