@vulkano/core 1.18.1 → 1.20.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/.vite-hooks/pre-commit +1 -0
- package/app.js +10 -8
- package/bin/setup.js +3 -3
- package/bootstrap/engines/handlebars.js +55 -0
- package/bootstrap/engines/index.js +31 -0
- package/bootstrap/engines/nunjucks.js +33 -0
- package/bootstrap/express.js +1 -1
- package/bootstrap/responses.js +1 -1
- package/bootstrap/server.js +163 -289
- package/bootstrap/services.js +1 -1
- package/bootstrap/views.js +4 -7
- package/libs/Download.js +3 -3
- package/libs/Encrypter.js +1 -1
- package/libs/Filter.js +1 -1
- package/libs/VSError.js +1 -1
- package/libs/Vite.js +1 -1
- package/package.json +10 -10
- package/pnpm-workspace.yaml +16 -0
- package/views/errors/handlebars/exception.html +48 -0
- package/views/errors/handlebars/no_action.html +63 -0
- package/views/errors/handlebars/no_controller.html +65 -0
- package/views/errors/handlebars/no_view.html +57 -0
- package/vite.config.ts +71 -0
- package/.oxlintrc.json +0 -42
- package/biome.json +0 -31
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vp staged
|
package/app.js
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
global.START_TIME = Date.now();
|
|
11
11
|
|
|
12
12
|
const dotenv = require('dotenv');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
const v8 = require('v8');
|
|
15
|
-
const fs = require('fs');
|
|
13
|
+
const path = require('node:path');
|
|
14
|
+
const v8 = require('node:v8');
|
|
15
|
+
const fs = require('node:fs');
|
|
16
16
|
|
|
17
17
|
global.app = {};
|
|
18
18
|
|
|
@@ -149,7 +149,9 @@ async function startVulkano() {
|
|
|
149
149
|
console.log('');
|
|
150
150
|
console.log(`${colors.fg.cyan}${showCenteredText('🌋')}${colors.reset}`);
|
|
151
151
|
console.log(`${colors.fg.cyan}${showCenteredText(`${appName} ${appVersion}`)}${colors.reset}`);
|
|
152
|
-
console.log(
|
|
152
|
+
console.log(
|
|
153
|
+
`${colors.fg.cyan}${showCenteredText(`${pkg.name} ${pkg.version}`.toUpperCase())}${colors.reset}`
|
|
154
|
+
);
|
|
153
155
|
console.log('');
|
|
154
156
|
console.log(`${colors.fg.blue}🔗 github.com/vulkanojs/vulkano${colors.reset}`);
|
|
155
157
|
console.log(`${colors.fg.cyan}☕ buymeacoffee.com/argordmel${colors.reset}`);
|
|
@@ -193,9 +195,7 @@ async function startVulkano() {
|
|
|
193
195
|
|
|
194
196
|
const nodeVersion = process.version.match(/^v(\d+\.\d+\.\d+)/)[1];
|
|
195
197
|
const portText = String(app.vulkano.get('port') || 8000);
|
|
196
|
-
const socketText = sockets.enabled
|
|
197
|
-
? String(sockets.adapter || 'memory').toUpperCase()
|
|
198
|
-
: 'NO';
|
|
198
|
+
const socketText = sockets.enabled ? String(sockets.adapter || 'memory').toUpperCase() : 'NO';
|
|
199
199
|
|
|
200
200
|
serverConfig.push(`🚀 PORT: ${colors.fg.green}${showColumn(portText, 7)}${colors.reset}`);
|
|
201
201
|
serverConfig.push(' | ');
|
|
@@ -238,7 +238,9 @@ async function startVulkano() {
|
|
|
238
238
|
|
|
239
239
|
const startupMs = ((Date.now() - global.START_TIME) / 1000).toFixed(3);
|
|
240
240
|
console.log(`${colors.fg.magenta}${cutLine}${colors.reset}`);
|
|
241
|
-
console.log(
|
|
241
|
+
console.log(
|
|
242
|
+
`${colors.bright}${colors.fg.cyan}${showCenteredText(`⚡ Ready in ${startupMs}s`)}${colors.reset}`
|
|
243
|
+
);
|
|
242
244
|
console.log(`${colors.fg.magenta}${cutLine}${colors.reset}`);
|
|
243
245
|
|
|
244
246
|
if (vite?.enabled) {
|
package/bin/setup.js
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* creates the minimal folder structure and config files needed to start.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const readline = require('readline');
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const path = require('node:path');
|
|
12
|
+
const readline = require('node:readline');
|
|
13
13
|
|
|
14
14
|
// npm sets INIT_CWD to the directory where `npm install` was invoked.
|
|
15
15
|
// npm_config_local_prefix is the project root (directory containing node_modules).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const { create: hbsCreate } = require('express-handlebars');
|
|
2
|
+
|
|
3
|
+
// Wraps a Nunjucks-style function so it works as a Handlebars helper:
|
|
4
|
+
// Hash params → {{{helper key=val}}} calls fn({ key: val })
|
|
5
|
+
// Positional → {{helper value}} calls fn(value)
|
|
6
|
+
// String output is wrapped in SafeString to prevent double-escaping
|
|
7
|
+
function wrapHelper(hbs, fn) {
|
|
8
|
+
return function hbsHelper(...args) {
|
|
9
|
+
const hbsOpts = args[args.length - 1];
|
|
10
|
+
const isHbsOptions = hbsOpts && typeof hbsOpts === 'object' && 'hash' in hbsOpts;
|
|
11
|
+
let result;
|
|
12
|
+
if (isHbsOptions) {
|
|
13
|
+
const positional = args.slice(0, -1);
|
|
14
|
+
result = positional.length === 0 ? fn(hbsOpts.hash) : fn(...positional);
|
|
15
|
+
} else {
|
|
16
|
+
result = fn(...args);
|
|
17
|
+
}
|
|
18
|
+
return typeof result === 'string' ? new hbs.handlebars.SafeString(result) : result;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function registerGroup(hbs, groups, method) {
|
|
23
|
+
(groups || []).forEach((group) => {
|
|
24
|
+
Object.keys(group || {}).forEach((key) => {
|
|
25
|
+
hbs.handlebars[method](key, wrapHelper(hbs, group[key]));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = function setupHandlebars(vulkano, views, viewsExt) {
|
|
31
|
+
const hbs = hbsCreate({
|
|
32
|
+
extname: viewsExt,
|
|
33
|
+
defaultLayout: views.defaultLayout !== undefined ? views.defaultLayout : 'default',
|
|
34
|
+
layoutsDir: views.layoutsDir || `${views.path}/_shared/templates`,
|
|
35
|
+
partialsDir: views.partialsDir || `${views.path}/_shared/partials`,
|
|
36
|
+
...(views.settings || {})
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
registerGroup(hbs, views.filters, 'registerHelper');
|
|
40
|
+
registerGroup(hbs, views.helpers, 'registerHelper');
|
|
41
|
+
|
|
42
|
+
vulkano.use((_req, res, next) => {
|
|
43
|
+
(views.globals || []).forEach((group) => {
|
|
44
|
+
Object.assign(res.locals, group || {});
|
|
45
|
+
});
|
|
46
|
+
res.locals.app = app;
|
|
47
|
+
next();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
vulkano.engine(viewsExt, hbs.engine);
|
|
51
|
+
vulkano.set('view engine', viewsExt);
|
|
52
|
+
|
|
53
|
+
app.server.views._engine = hbs;
|
|
54
|
+
app.handlebars = hbs;
|
|
55
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const viewsConfig = require('../views');
|
|
2
|
+
|
|
3
|
+
const SUPPORTED_ENGINES = ['nunjucks', 'handlebars'];
|
|
4
|
+
|
|
5
|
+
module.exports = function setupViewEngine(vulkano) {
|
|
6
|
+
const views = {
|
|
7
|
+
ext: '.html',
|
|
8
|
+
...viewsConfig,
|
|
9
|
+
...(app.server.views || {})
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const engine = views.engine || 'nunjucks';
|
|
13
|
+
const ext = views.ext || '.html';
|
|
14
|
+
|
|
15
|
+
if (!SUPPORTED_ENGINES.includes(engine)) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`Vulkano: unsupported view engine "${engine}". Supported engines: ${SUPPORTED_ENGINES.join(', ')}.`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
vulkano.set('views', views.path);
|
|
22
|
+
|
|
23
|
+
if (engine === 'handlebars') {
|
|
24
|
+
require('./handlebars')(vulkano, views, ext);
|
|
25
|
+
} else {
|
|
26
|
+
require('./nunjucks')(vulkano, views);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Error view subfolder depends on engine (core dev-mode error templates)
|
|
30
|
+
return engine;
|
|
31
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const nunjucks = require('nunjucks');
|
|
2
|
+
|
|
3
|
+
module.exports = function setupNunjucks(vulkano, views) {
|
|
4
|
+
const settings = {
|
|
5
|
+
autoescape: true,
|
|
6
|
+
watch: !app.PRODUCTION,
|
|
7
|
+
...(views.settings || {}),
|
|
8
|
+
express: vulkano
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const env = nunjucks.configure([views.path, CORE_PATH], settings);
|
|
12
|
+
|
|
13
|
+
env.addGlobal('app', app);
|
|
14
|
+
|
|
15
|
+
(views.globals || []).forEach((group) => {
|
|
16
|
+
Object.keys(group || {}).forEach((key) => env.addGlobal(key, group[key]));
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
(views.helpers || []).forEach((group) => {
|
|
20
|
+
Object.keys(group || {}).forEach((key) => env.addGlobal(key, group[key]));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
(views.filters || []).forEach((group) => {
|
|
24
|
+
Object.keys(group || {}).forEach((key) => env.addFilter(key, group[key]));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
(views.extensions || []).forEach((group) => {
|
|
28
|
+
Object.keys(group || {}).forEach((key) => env.addExtension(key, group[key]));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
app.server.views._engine = env;
|
|
32
|
+
app.nunjucks = nunjucks;
|
|
33
|
+
};
|
package/bootstrap/express.js
CHANGED
package/bootstrap/responses.js
CHANGED