miki-template 2.3.1 → 2.3.3

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.
Files changed (167) hide show
  1. package/README.md +1 -1
  2. package/package.json +24 -2
  3. package/src/codegen.js +140 -9
  4. package/src/parser.js +69 -1
  5. package/src/tags/control.js +112 -51
  6. package/src/tags/extra.js +4 -17
  7. package/src/tags/i18n.js +6 -17
  8. package/src/tags/inheritance.js +6 -20
  9. package/src/tags/util.js +5 -20
  10. package/.eslintrc.json +0 -16
  11. package/.github/release-notes/v1.3.1.md +0 -55
  12. package/.github/release-notes/v1.3.3.md +0 -77
  13. package/.github/release-notes/v1.3.7.md +0 -20
  14. package/.github/workflows/ci.yml +0 -42
  15. package/.github/workflows/docs.yml +0 -107
  16. package/.github/workflows/release.yml +0 -107
  17. package/AGENT.md +0 -71
  18. package/API_REFERENCE.md +0 -341
  19. package/CHANGELOG.md +0 -173
  20. package/CODE_OF_CONDUCT.md +0 -14
  21. package/CONTRIBUTING.md +0 -27
  22. package/ROADMAP.md +0 -40
  23. package/assets/banner.png +0 -0
  24. package/assets/logo.png +0 -0
  25. package/benchmarks/ejs-results.json +0 -17
  26. package/benchmarks/ejs.js +0 -38
  27. package/benchmarks/handlebars-results.json +0 -17
  28. package/benchmarks/handlebars.js +0 -45
  29. package/benchmarks/miki-results.json +0 -17
  30. package/benchmarks/miki.js +0 -39
  31. package/benchmarks/pug-results.json +0 -17
  32. package/benchmarks/pug.js +0 -38
  33. package/benchmarks/report.json +0 -17
  34. package/benchmarks/run.js +0 -81
  35. package/benchmarks/stress.mjs +0 -647
  36. package/benchmarks/templates/large.dtpl +0 -7
  37. package/benchmarks/templates/medium.dtpl +0 -3
  38. package/benchmarks/templates/small.dtpl +0 -7
  39. package/context/component.md +0 -109
  40. package/context/prd.md +0 -131
  41. package/context/project-structure.md +0 -33
  42. package/dir/base.html +0 -23
  43. package/dir/cmpnt.html +0 -11
  44. package/dir/footer.html +0 -3
  45. package/dir/home.html +0 -80
  46. package/dir/index.html +0 -80
  47. package/dir/navbar.html +0 -9
  48. package/docs/api/async-render.md +0 -170
  49. package/docs/api/cache.md +0 -174
  50. package/docs/api/compile.md +0 -256
  51. package/docs/api/context-processors.md +0 -154
  52. package/docs/api/filters.md +0 -437
  53. package/docs/api/finder.md +0 -188
  54. package/docs/api/helpers.md +0 -106
  55. package/docs/api/i18n.md +0 -314
  56. package/docs/api/index.md +0 -108
  57. package/docs/api/libraries.md +0 -414
  58. package/docs/api/render-partial.md +0 -162
  59. package/docs/api/render.md +0 -184
  60. package/docs/api/security.md +0 -290
  61. package/docs/api/setup-express.md +0 -152
  62. package/docs/api/tags.md +0 -268
  63. package/docs/assets/banner.png +0 -0
  64. package/docs/assets/logo.png +0 -0
  65. package/docs/filter.md +0 -0
  66. package/docs/guide/advanced-usage.md +0 -794
  67. package/docs/guide/async-rendering.md +0 -616
  68. package/docs/guide/context-processors.md +0 -514
  69. package/docs/guide/custom-filters.md +0 -622
  70. package/docs/guide/custom-tags.md +0 -542
  71. package/docs/guide/filters.md +0 -1314
  72. package/docs/guide/getting-started.md +0 -204
  73. package/docs/guide/installation.md +0 -190
  74. package/docs/guide/partial-templates.md +0 -734
  75. package/docs/guide/quick-start.md +0 -444
  76. package/docs/guide/security.md +0 -690
  77. package/docs/guide/tags.md +0 -1566
  78. package/docs/guide/template-discovery.md +0 -340
  79. package/docs/guide/template-inheritance.md +0 -546
  80. package/docs/guide/what-is-miki-template.md +0 -28
  81. package/docs/guide/why-miki-template.md +0 -75
  82. package/docs/index.md +0 -86
  83. package/docs/integrations/elysia.md +0 -80
  84. package/docs/integrations/express.md +0 -219
  85. package/docs/integrations/fastify.md +0 -79
  86. package/docs/integrations/hono.md +0 -80
  87. package/docs/integrations/index.md +0 -68
  88. package/docs/integrations/koa.md +0 -90
  89. package/docs/integrations/nestjs.md +0 -80
  90. package/docs/integrations/tsed.md +0 -83
  91. package/docs/performance.md +0 -74
  92. package/eslint.config.mjs +0 -42
  93. package/ex.mjs +0 -36
  94. package/live-test/integrations/elysia-example.js +0 -16
  95. package/live-test/integrations/express-example.js +0 -24
  96. package/live-test/integrations/fastify-example.js +0 -20
  97. package/live-test/integrations/hono-example.js +0 -16
  98. package/live-test/integrations/koa-example.js +0 -30
  99. package/live-test/integrations/nestjs-example.js +0 -25
  100. package/live-test/integrations/smoke-test.js +0 -166
  101. package/live-test/integrations/tsed-example.js +0 -23
  102. package/live-test/package-lock.json +0 -1150
  103. package/live-test/package.json +0 -13
  104. package/live-test/packages/product/templates/product/detail.html +0 -7
  105. package/live-test/server.js +0 -38
  106. package/live-test/templates/app_templates/detail.html +0 -6
  107. package/live-test/views/base.html +0 -8
  108. package/live-test/views/child.html +0 -7
  109. package/live-test/views/home.html +0 -17
  110. package/live-test/views/index.html +0 -1
  111. package/miki-template-extension/.github/workflows/ci.yml +0 -116
  112. package/miki-template-extension/.vscodeignore +0 -7
  113. package/miki-template-extension/CHANGELOG.md +0 -99
  114. package/miki-template-extension/LICENSE +0 -21
  115. package/miki-template-extension/README.md +0 -273
  116. package/miki-template-extension/extension.js +0 -1013
  117. package/miki-template-extension/icon.png +0 -0
  118. package/miki-template-extension/icon.svg +0 -10
  119. package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
  120. package/miki-template-extension/package.json +0 -280
  121. package/miki-template-extension/snippets/miki-template.json +0 -717
  122. package/miki-template-extension/syntaxes/language-configuration.json +0 -114
  123. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +0 -355
  124. package/miki-template-extension/tests/grammar-tests.json +0 -162
  125. package/miki-template-extension/tests/run-grammar-tests.js +0 -82
  126. package/mkdocs.yml +0 -195
  127. package/overrides/main.html +0 -26
  128. package/requirements-docs.txt +0 -2
  129. package/sample-app/package-lock.json +0 -901
  130. package/sample-app/package.json +0 -9
  131. package/sample-app/server.js +0 -14
  132. package/sample-app/views/index.html +0 -1
  133. package/scripts/build-vsix.js +0 -129
  134. package/scripts/build-vsix.ps1 +0 -15
  135. package/snippets/miki-template.json +0 -177
  136. package/src/asyncRender.js +0 -21
  137. package/src/types.d.ts +0 -107
  138. package/syntaxes/language-configuration.json +0 -26
  139. package/syntaxes/miki-template.tmLanguage.json +0 -146
  140. package/tests/asyncRender.test.js +0 -17
  141. package/tests/base.html +0 -6
  142. package/tests/child.html +0 -3
  143. package/tests/context_processors.test.js +0 -13
  144. package/tests/esm.test.mjs +0 -61
  145. package/tests/filters.test.js +0 -263
  146. package/tests/finder-appdirs.test.js +0 -19
  147. package/tests/finder.test.js +0 -17
  148. package/tests/fixtures/views/nested/index.html +0 -1
  149. package/tests/fixtures/views/partial.html +0 -1
  150. package/tests/fixtures/views/sub/deepfile.html +0 -1
  151. package/tests/fixtures/views-appdirs/product/site/detail.html +0 -1
  152. package/tests/include_security.test.js +0 -9
  153. package/tests/integration/README.md +0 -32
  154. package/tests/integration/features.test.cjs +0 -1681
  155. package/tests/integration/features.test.mjs +0 -1697
  156. package/tests/integration/finder.esm.test.mjs +0 -13
  157. package/tests/integration/partial-render.test.cjs +0 -13
  158. package/tests/integration/templates/base.miki +0 -6
  159. package/tests/integration/templates/child.miki +0 -6
  160. package/tests/integration/templates/index.html +0 -17
  161. package/tests/lexer.test.js +0 -45
  162. package/tests/parser.test.js +0 -57
  163. package/tests/partial.html +0 -1
  164. package/tests/partialdef.test.js +0 -79
  165. package/tests/production_checks.js +0 -57
  166. package/tests/security.test.js +0 -28
  167. package/tests/tags.test.js +0 -233
@@ -1,83 +0,0 @@
1
- # TSDX / TSed (Ts.ED)
2
-
3
- Use miki-template with Ts.ED (TSed) by wiring it into the underlying Express or Koa adapter.
4
-
5
- ## Setup
6
-
7
- Ts.ED can run on Express or Koa. When using the Express adapter, obtain the raw Express app and call `setupExpress()`.
8
-
9
- === "TypeScript"
10
-
11
- ```typescript
12
- // server.ts
13
- import { ServerLoader } from '@tsed/di';
14
- import * as miki from 'miki-template';
15
-
16
- async function bootstrap() {
17
- const server = await ServerLoader.bootstrap();
18
- // server.rawApp is the underlying Express/Koa instance depending on adapter
19
- miki.setupExpress(server.rawApp, {
20
- extension: 'html',
21
- views: './views'
22
- });
23
- await server.listen();
24
- }
25
-
26
- bootstrap();
27
- ```
28
-
29
- === "CommonJS"
30
-
31
- ```javascript
32
- const { ServerLoader } = require('@tsed/di');
33
- const miki = require('miki-template');
34
-
35
- async function bootstrap() {
36
- const server = await ServerLoader.bootstrap();
37
- miki.setupExpress(server.rawApp, {
38
- extension: 'html',
39
- views: './views'
40
- });
41
- await server.listen();
42
- }
43
-
44
- bootstrap();
45
- ```
46
-
47
- ## Using in Controllers
48
-
49
- Once wired, use `res.render()` in your Ts.ED controllers:
50
-
51
- ```typescript
52
- import { Controller, Get, Req, Res } from '@tsed/common';
53
- import { Request, Response } from 'express';
54
-
55
- @Controller('/')
56
- export class AppController {
57
- @Get('/')
58
- renderHome(@Req() req: Request, @Res() res: Response) {
59
- res.render('home', { user: req.user });
60
- }
61
-
62
- @Get('/partials/:name')
63
- renderPartial(@Req() req: Request, @Res() res: Response) {
64
- res.render(`home#${req.params.name}`, { user: req.user });
65
- }
66
- }
67
- ```
68
-
69
- ## Partial Rendering
70
-
71
- ```typescript
72
- @Get('/cards/:id')
73
- renderCard(@Req() req: Request, @Res() res: Response) {
74
- res.render(`home#card`, { user: req.user });
75
- }
76
- ```
77
-
78
- ## Next Steps
79
-
80
- - [Integrations Overview](../index.md)
81
- - [API Reference: setupExpress param($m) $m.Value -replace '([a-z][a-z0-9-]+)\.md
82
- , '../.md' -replace '([a-z][a-z0-9-]+)
83
- , '../.md'
@@ -1,74 +0,0 @@
1
- # Performance
2
-
3
-
4
-
5
- miki-template is built for real-world apps. Its compiled-AST engine is especially fast on templates with loops, conditionals, and filters — where other engines struggle.
6
-
7
-
8
-
9
- ## Benchmark Results
10
-
11
-
12
-
13
- Renders per second (higher is better):
14
-
15
-
16
-
17
- | Template | miki-template | pug | handlebars | ejs |
18
-
19
- |----------|--------------|-----|------------|-----|
20
-
21
- | Small | ~1.1M rps | 1.1M rps | 300k rps | 113k rps |
22
-
23
- | Medium | ~40k rps | 27k rps | 4k rps | 2k rps |
24
-
25
- | Large | **~2530 rps** | 1886 rps | 493 rps | 1881 rps |
26
-
27
-
28
-
29
- ## Key Takeaways
30
-
31
-
32
-
33
- - On **small** templates, miki-template is competitive with pug.
34
-
35
- - On **medium** templates, miki-template beats pug.
36
-
37
- - On **large/realistic** templates (the ones that matter in production), miki-template **dominates by ~150×**.
38
-
39
-
40
-
41
- ## Why miki-template Wins on Real Templates
42
-
43
-
44
-
45
- - **Compiled AST**: Templates are compiled once and reused, avoiding repeated parsing.
46
-
47
- - **No runtime interpretation**: No string concatenation or function reconstruction per render.
48
-
49
- - **Optimized loops and filters**: for-loops and filters are implemented as efficient node traversals.
50
-
51
- - **Cache-friendly**: Compiled templates are cached by default.
52
-
53
-
54
-
55
- ## Running Benchmarks
56
-
57
-
58
-
59
- ```bash
60
-
61
- npm run bench
62
-
63
- ```
64
-
65
-
66
-
67
- ## Next Steps
68
-
69
-
70
-
71
- - [Getting Started](guide/getting-started.md)
72
-
73
- - [API Reference](api/index.md)
74
-
package/eslint.config.mjs DELETED
@@ -1,42 +0,0 @@
1
- export default [
2
- {
3
- files: ['src/**/*.js'],
4
- languageOptions: {
5
- ecmaVersion: 'latest',
6
- sourceType: 'commonjs',
7
- globals: {
8
- Buffer: 'readonly',
9
- console: 'readonly',
10
- exports: 'readonly',
11
- module: 'readonly',
12
- process: 'readonly',
13
- __dirname: 'readonly',
14
- __filename: 'readonly',
15
- require: 'readonly',
16
- setTimeout: 'readonly',
17
- setInterval: 'readonly',
18
- clearTimeout: 'readonly',
19
- clearInterval: 'readonly',
20
- setImmediate: 'readonly',
21
- clearImmediate: 'readonly',
22
- global: 'readonly',
23
- // Node 18+ standard globals
24
- URL: 'readonly',
25
- URLSearchParams: 'readonly',
26
- TextEncoder: 'readonly',
27
- TextDecoder: 'readonly',
28
- fetch: 'readonly',
29
- crypto: 'readonly',
30
- performance: 'readonly'
31
- }
32
- },
33
- rules: {
34
- 'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
35
- 'no-console': 'off',
36
- 'no-undef': 'error',
37
- 'semi': ['error', 'always'],
38
- 'quotes': ['error', 'single'],
39
- 'indent': ['error', 2]
40
- }
41
- }
42
- ];
package/ex.mjs DELETED
@@ -1,36 +0,0 @@
1
- import express from 'express'
2
- import miki, {__express,registerContextProcessor} from "miki-template"
3
- import path from 'node:path';
4
-
5
- const app =express()
6
- const dir=path.join(process.cwd(),"dir")
7
-
8
- // app.engine('html', __express);
9
- // app.set('view engine', 'html');
10
- // app.set('views', dir);
11
- miki.setupExpress(app, { extension: 'html', views: dir });
12
-
13
-
14
-
15
- // registerContextProcessor((cx)=>({
16
- // siteName:"code with miki",
17
- // login:{'name':"miki", 'email':"miki@example.com"}
18
- // }))
19
- app.get("/",(req,res)=>{
20
- const users=[
21
- {'name':"miki", 'email':"miki@example.com"},
22
- {'name':"miki2", 'email':"miki2@example.com"},
23
- {'name':"miki3", 'email':"miki3@example.com"}
24
- ]
25
- let data=[
26
- {name:"miki", email:"jack@miki.com",address:"kumba"},
27
- {name:"luis",email:"luis@miki.com",address:"kumba"}
28
- ]
29
- res.render("index",{name:"miki-template context", users:users, data:data})
30
- // res.send(content)
31
- })
32
-
33
-
34
- app.listen(3000, () => {
35
- console.log('Server is running on port 3000 click: http://localhost:3000')
36
- } )
@@ -1,16 +0,0 @@
1
- import { Elysia } from 'elysia';
2
- import path from 'path';
3
- import miki from '../../src/esm.mjs';
4
-
5
- const app = new Elysia();
6
-
7
- app.get('/', async () => {
8
- const html = await miki.asyncRender('home', {}, { views: path.resolve('./live-test/views') });
9
- return new Response(html, { headers: { 'Content-Type': 'text/html' } });
10
- });
11
-
12
- export async function start(port = 3004) {
13
- return app.listen({ port });
14
- }
15
-
16
- if (import.meta.url === `file://${process.argv[1]}`) start().then(() => console.log('Elysia example listening on 3004'));
@@ -1,24 +0,0 @@
1
- const express = require('express');
2
- const path = require('path');
3
- const miki = require('../../');
4
-
5
- const app = express();
6
- miki.setupExpress(app, { extension: 'html', views: path.resolve(__dirname, '..', 'views') });
7
-
8
- app.get('/', (req, res) => res.render('home', { user: 'ExpressUser', title: 'ExpressCard' }));
9
- app.get('/partial', (req, res) => res.render('home#card', { user: 'ExpressUser', title: 'ExpressCard' }));
10
-
11
- function start(port = 3000, host = '127.0.0.1') {
12
- return new Promise((resolve, reject) => {
13
- try {
14
- const srv = app.listen(port, host, () => {
15
- console.log('Express example listening on', port);
16
- resolve(srv);
17
- });
18
- } catch (err) { reject(err); }
19
- });
20
- }
21
-
22
- if (require.main === module) start().catch(err => { console.error(err); process.exit(1); });
23
-
24
- module.exports = { app, start };
@@ -1,20 +0,0 @@
1
- const Fastify = require('fastify');
2
- const path = require('path');
3
- const miki = require('../../');
4
-
5
- const app = Fastify();
6
-
7
- app.get('/', async (request, reply) => {
8
- const html = await miki.asyncRender('home', { user: 'FastifyUser', title: 'FastifyCard' }, { views: path.resolve(__dirname, '..', 'views') });
9
- reply.type('text/html').send(html);
10
- });
11
-
12
- function start(port = 3002, host = '127.0.0.1') {
13
- return app.listen({ port, host });
14
- }
15
-
16
- if (require.main === module) {
17
- start().then(() => console.log('Fastify example listening on 3002')).catch(err => { console.error('Fastify failed to start', err); process.exit(1); });
18
- }
19
-
20
- module.exports = { app, start };
@@ -1,16 +0,0 @@
1
- import { Hono } from 'hono';
2
- import miki from '../../src/esm.mjs';
3
- import path from 'path';
4
-
5
- const app = new Hono();
6
-
7
- app.get('/', async (c) => {
8
- const html = await miki.asyncRender('home', {}, { views: path.resolve('./live-test/views') });
9
- return c.html(html);
10
- });
11
-
12
- export async function start(port = 3005) {
13
- return app.listen({ port });
14
- }
15
-
16
- if (import.meta.url === `file://${process.argv[1]}`) start().then(() => console.log('Hono example listening on 3005'));
@@ -1,30 +0,0 @@
1
- const Koa = require('koa');
2
- const path = require('path');
3
- const miki = require('../../');
4
-
5
- const app = new Koa();
6
-
7
- app.context.render = async function (view, locals = {}) {
8
- const html = await miki.asyncRender(view, locals, { views: path.resolve(__dirname, '..', 'views') });
9
- this.type = 'text/html';
10
- this.body = html;
11
- };
12
-
13
- app.use(async (ctx) => {
14
- await ctx.render('home', { user: 'KoaUser', title: 'KoaCard' });
15
- });
16
-
17
- function start(port = 3001, host = '127.0.0.1') {
18
- return new Promise((resolve, reject) => {
19
- try {
20
- const srv = app.listen(port, host, () => {
21
- console.log('Koa example listening on', port);
22
- resolve(srv);
23
- });
24
- } catch (err) { reject(err); }
25
- });
26
- }
27
-
28
- if (require.main === module) start().catch(err => { console.error(err); process.exit(1); });
29
-
30
- module.exports = { app, start };
@@ -1,25 +0,0 @@
1
- /*
2
- Minimal NestJS integration example (TypeScript flavor shown).
3
-
4
- This file is an illustrative snippet and is NOT executed by the
5
- smoke-test (NestJS requires heavier deps). Use it as a guide.
6
-
7
- // main.ts
8
- import { NestFactory } from '@nestjs/core';
9
- import { AppModule } from './app.module';
10
- import * as miki from 'miki-template';
11
-
12
- async function bootstrap() {
13
- const app = await NestFactory.create(AppModule);
14
- const expressApp = app.getHttpAdapter().getInstance();
15
- // Wire miki into underlying Express instance
16
- miki.setupExpress(expressApp, { extension: 'html', views: './views' });
17
- await app.listen(3006);
18
- }
19
-
20
- bootstrap();
21
-
22
- */
23
-
24
- // Plain JS note: If you use Nest with JS, the same pattern applies:
25
- // obtain the underlying Express instance and call miki.setupExpress(...)
@@ -1,166 +0,0 @@
1
- const { spawn } = require('child_process');
2
- const path = require('path');
3
- const http = require('http');
4
-
5
- async function start(scriptPath) {
6
- // Skip optional ESM integrations when their deps are missing
7
- const missing = {
8
- 'elysia-example.js': 'elysia',
9
- 'hono-example.js': 'hono'
10
- };
11
- const basename = path.basename(scriptPath);
12
- if (missing[basename]) {
13
- try { require.resolve(missing[basename]); }
14
- catch {
15
- console.warn(`Skipping ${basename}: ${missing[basename]} is not installed`);
16
- return null;
17
- }
18
- }
19
-
20
- // Require the example module and call its exported start() which
21
- // returns a Promise or a server instance.
22
- const mod = require(scriptPath);
23
- if (mod && typeof mod.start === 'function') {
24
- let res;
25
- try {
26
- res = mod.start();
27
- } catch (err) {
28
- console.warn(`Skipping ${basename}: start() failed: ${err.message}`);
29
- return null;
30
- }
31
- // Fastify returns a Promise resolving to server address; Koa/Express
32
- // return a server instance synchronously — normalize both.
33
- if (res && typeof res.then === 'function') {
34
- try {
35
- await res;
36
- return res;
37
- } catch (err) {
38
- console.warn(`Skipping ${basename}: start() promise rejected: ${err.message}`);
39
- return null;
40
- }
41
- }
42
- return res;
43
- }
44
- // Fallback: spawn as a child process
45
- return new Promise((resolve, reject) => {
46
- const child = spawn(process.execPath, [scriptPath], { stdio: 'inherit' });
47
- child.on('error', reject);
48
- setTimeout(() => resolve(child), 800);
49
- });
50
- }
51
-
52
- async function fetch(url) {
53
- return new Promise((resolve, reject) => {
54
- http.get(url, res => {
55
- let data = '';
56
- res.on('data', c => data += c.toString());
57
- res.on('end', () => resolve({ status: res.statusCode, body: data }));
58
- }).on('error', reject);
59
- });
60
- }
61
-
62
- async function main() {
63
- const root = path.resolve(__dirname);
64
- const servers = [
65
- { file: path.join(root, 'express-example.js'), url: 'http://localhost:3000/' },
66
- { file: path.join(root, 'koa-example.js'), url: 'http://localhost:3001/' },
67
- { file: path.join(root, 'fastify-example.js'), url: 'http://localhost:3002/' }
68
- ];
69
- // Add ESM-based examples (elysia, hono). These will be spawned as
70
- // child processes if they cannot be required as modules.
71
- servers.push({ file: path.join(root, 'elysia-example.js'), url: 'http://localhost:3004/' });
72
- servers.push({ file: path.join(root, 'hono-example.js'), url: 'http://localhost:3005/' });
73
-
74
- const procs = [];
75
- for (const s of servers) {
76
- procs.push(await start(s.file));
77
- }
78
-
79
- // Test each server
80
- for (let i = 0; i < servers.length; i++) {
81
- const s = servers[i];
82
- const p = procs[i];
83
- if (!p) {
84
- console.warn(`Skipping smoke-test for ${path.basename(s.file)} (not running)`);
85
- continue;
86
- }
87
- try {
88
- const res = await fetch(s.url);
89
- console.log(`${s.url} -> ${res.status} length=${res.body.length}`);
90
- } catch (e) {
91
- console.error(`Failed to fetch ${s.url}:`, e.message || e);
92
- }
93
- }
94
-
95
- // Test partial route on express
96
- try {
97
- const res = await fetch('http://localhost:3000/partial');
98
- console.log(`/partial -> ${res.status} length=${res.body.length}`);
99
- } catch (e) { console.error('Partial fetch failed', e.message || e); }
100
-
101
- // Programmatic engine tests: render('home#card') via the engine APIs
102
- try {
103
- // Try requiring as if the package were installed; fallback to local
104
- let miki;
105
- try { miki = require('miki-template'); } catch (e) { miki = require('../..'); }
106
-
107
- // For each framework, test programmatic partial rendering and finder behavior
108
- const frameworks = ['express', 'koa', 'fastify', 'elysia', 'hono'];
109
- for (const name of frameworks) {
110
- const viewsDir = path.resolve(__dirname, '..', 'views');
111
- try {
112
- const asyncHtml = await miki.asyncRender('home#card', { user: name + 'Async', title: name + 'Card' }, { views: viewsDir });
113
- console.log(`${name}: asyncRender(home#card) length=${asyncHtml.length}`);
114
- } catch (e) { console.error(`${name}: asyncRender failed`, e && e.message ? e.message : e); }
115
-
116
- try {
117
- const syncHtml = miki.render('home#card', { user: name + 'Sync', title: name + 'Card' }, { views: viewsDir });
118
- console.log(`${name}: render(home#card) length=${syncHtml.length}`);
119
- } catch (e) { console.error(`${name}: render failed`, e && e.message ? e.message : e); }
120
-
121
- // Finder tests: simulate multiple view roots including nested app-template dirs
122
- try {
123
- const found = miki.findTemplateInViews('home', [viewsDir, path.resolve(__dirname, '..')]);
124
- console.log(`${name}: finder resolved -> ${found ? found : 'not found'}`);
125
- } catch (e) { console.error(`${name}: finder error`, e && e.message ? e.message : e); }
126
- }
127
- } catch (e) {
128
- console.error('Engine partial render failed:', e && e.stack ? e.stack : e);
129
- }
130
-
131
- // Cleanup: attempt graceful shutdown for each started server
132
- for (let i = 0; i < procs.length; i++) {
133
- const p = procs[i];
134
- if (!p) continue;
135
- try {
136
- if (typeof p.kill === 'function') {
137
- p.kill();
138
- continue;
139
- }
140
- if (typeof p.close === 'function') {
141
- p.close();
142
- continue;
143
- }
144
- // Fastify may return an address string; try to require module and call exported stop/close
145
- try {
146
- const mod = require(servers[i].file);
147
- if (mod) {
148
- if (typeof mod.stop === 'function') await mod.stop();
149
- else if (typeof mod.close === 'function') await mod.close();
150
- else if (mod.app && typeof mod.app.close === 'function') mod.app.close();
151
- }
152
- } catch (e) {
153
- // ignore
154
- }
155
- } catch (e) {
156
- // ignore errors during cleanup
157
- }
158
- }
159
- }
160
-
161
- if (require.main === module) {
162
- main().catch(err => {
163
- console.error('smoke-test failed', err && err.stack ? err.stack : err);
164
- process.exit(1);
165
- });
166
- }
@@ -1,23 +0,0 @@
1
- /*
2
- Ts.ED integration (Express adapter)
3
-
4
- This is an example snippet for Ts.ED users. Ts.ED can run on Express
5
- or Koa — when using the Express adapter, obtain the raw Express app
6
- and call `miki.setupExpress()` as shown.
7
-
8
- // server.ts (snippet)
9
- import { ServerLoader } from '@tsed/di';
10
- import * as miki from 'miki-template';
11
-
12
- async function bootstrap() {
13
- const server = await ServerLoader.bootstrap();
14
- // server.rawApp is the underlying Express/Koa instance depending on adapter
15
- miki.setupExpress(server.rawApp, { extension: 'html', views: './views' });
16
- await server.listen();
17
- }
18
-
19
- bootstrap();
20
-
21
- */
22
-
23
- // Plain JS: same approach — call setupExpress on the underlying app.