@vulkano/core 1.17.4 → 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 +7 -1
- package/bin/vulkano.js +21 -0
- package/bootstrap/views.js +7 -1
- package/libs/Vite.js +71 -0
- package/package.json +5 -2
- package/views/helpers/vite.js +75 -0
- /package/bin/{postinstall.js → setup.js} +0 -0
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
|
+
}
|
package/bootstrap/views.js
CHANGED
|
@@ -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.
|
|
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
|
-
"
|
|
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
|