kempo-server 2.1.1 → 3.0.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/CONFIG.md +295 -187
- package/README.md +31 -4
- package/SPA.md +14 -14
- package/UTILS.md +39 -0
- package/dist/defaultConfig.js +1 -1
- package/dist/index.js +1 -1
- package/dist/render.js +2 -0
- package/dist/rescan.js +1 -0
- package/dist/router.js +1 -1
- package/dist/serveFile.js +1 -1
- package/dist/templating/index.js +1 -0
- package/dist/templating/parse.js +1 -0
- package/docs/dist/caching.html +324 -0
- package/docs/dist/cli-utils.html +175 -0
- package/docs/dist/configuration.html +414 -0
- package/docs/dist/examples.html +296 -0
- package/docs/dist/fs-utils.html +206 -0
- package/docs/dist/getting-started.html +167 -0
- package/docs/dist/index.html +183 -0
- package/docs/dist/middleware.html +237 -0
- package/docs/dist/request-response.html +200 -0
- package/docs/dist/routing.html +177 -0
- package/docs/dist/templating.html +292 -0
- package/docs/{theme.css → dist/theme.css} +1 -3
- package/docs/src/.config.js +11 -0
- package/docs/{caching.html → src/caching.page.html} +4 -19
- package/docs/{cli-utils.html → src/cli-utils.page.html} +4 -20
- package/docs/{configuration.html → src/configuration.page.html} +4 -18
- package/docs/src/default.template.html +35 -0
- package/docs/{examples.html → src/examples.page.html} +9 -18
- package/docs/{fs-utils.html → src/fs-utils.page.html} +4 -20
- package/docs/{getting-started.html → src/getting-started.page.html} +4 -18
- package/docs/src/index.page.html +79 -0
- package/docs/{middleware.html → src/middleware.page.html} +4 -18
- package/docs/src/nav.fragment.html +73 -0
- package/docs/{request-response.html → src/request-response.page.html} +4 -18
- package/docs/{routing.html → src/routing.page.html} +4 -18
- package/docs/src/templating.page.html +188 -0
- package/{llm.txt → llms.txt} +100 -30
- package/package.json +7 -3
- package/scripts/build.js +19 -11
- package/scripts/render.js +58 -0
- package/src/defaultConfig.js +14 -2
- package/src/index.js +1 -1
- package/src/rescan.js +14 -0
- package/src/router.js +82 -11
- package/src/serveFile.js +27 -0
- package/src/templating/index.js +132 -0
- package/src/templating/parse.js +285 -0
- package/tests/cacheConfig.node-test.js +2 -2
- package/tests/config-flag.node-test.js +61 -25
- package/tests/customRoute-outside-root.node-test.js +1 -1
- package/tests/rescan.node-test.js +69 -0
- package/tests/router-wildcard.node-test.js +47 -2
- package/tests/templating-parse.node-test.js +243 -0
- package/tests/templating-render.node-test.js +188 -0
- package/tests/utils/test-scenario.js +4 -4
- package/docs/.config.json.example +0 -29
- package/docs/api/_admin/cache/DELETE.js +0 -28
- package/docs/api/_admin/cache/GET.js +0 -53
- package/docs/api/user/[id]/GET.js +0 -15
- package/docs/api/user/[id]/[info]/DELETE.js +0 -12
- package/docs/api/user/[id]/[info]/GET.js +0 -17
- package/docs/api/user/[id]/[info]/POST.js +0 -18
- package/docs/api/user/[id]/[info]/PUT.js +0 -19
- package/docs/index.html +0 -88
- package/docs/init.js +0 -0
- package/docs/kempo.min.css +0 -1
- package/docs/nav.inc.html +0 -41
- package/docs/nav.inc.js +0 -16
- /package/docs/{manifest.json → dist/manifest.json} +0 -0
- /package/docs/{media → dist/media}/hexagon.svg +0 -0
- /package/docs/{media → dist/media}/icon-maskable.png +0 -0
- /package/docs/{media → dist/media}/icon.svg +0 -0
- /package/docs/{media → dist/media}/icon128.png +0 -0
- /package/docs/{media → dist/media}/icon144.png +0 -0
- /package/docs/{media → dist/media}/icon152.png +0 -0
- /package/docs/{media → dist/media}/icon16-48.svg +0 -0
- /package/docs/{media → dist/media}/icon16.png +0 -0
- /package/docs/{media → dist/media}/icon192.png +0 -0
- /package/docs/{media → dist/media}/icon256.png +0 -0
- /package/docs/{media → dist/media}/icon32.png +0 -0
- /package/docs/{media → dist/media}/icon384.png +0 -0
- /package/docs/{media → dist/media}/icon48.png +0 -0
- /package/docs/{media → dist/media}/icon512.png +0 -0
- /package/docs/{media → dist/media}/icon64.png +0 -0
- /package/docs/{media → dist/media}/icon72.png +0 -0
- /package/docs/{media → dist/media}/icon96.png +0 -0
- /package/docs/{media → dist/media}/kempo-fist.svg +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
<page pageName="Templating" title="Templating - Kempo Server">
|
|
2
|
+
<content>
|
|
3
|
+
<p>Kempo Server includes a built-in XML-based templating system for building static sites with shared layouts, reusable fragments, and dynamic content. Pages can be pre-rendered at build time or server-side rendered on each request.</p>
|
|
4
|
+
|
|
5
|
+
<nav class="b r mb p">
|
|
6
|
+
<h4 class="mt0">On This Page</h4>
|
|
7
|
+
<ul>
|
|
8
|
+
<li><a href="#overview">Overview</a></li>
|
|
9
|
+
<li><a href="#file-types">File Types</a></li>
|
|
10
|
+
<li><a href="#templates">Templates</a></li>
|
|
11
|
+
<li><a href="#pages">Pages</a></li>
|
|
12
|
+
<li><a href="#fragments">Fragments</a></li>
|
|
13
|
+
<li><a href="#variables">Variables</a></li>
|
|
14
|
+
<li><a href="#conditionals">Conditionals</a></li>
|
|
15
|
+
<li><a href="#loops">Loops</a></li>
|
|
16
|
+
<li><a href="#rendering">Rendering</a></li>
|
|
17
|
+
<li><a href="#ssr">Server-Side Rendering</a></li>
|
|
18
|
+
<li><a href="#configuration">Configuration</a></li>
|
|
19
|
+
</ul>
|
|
20
|
+
</nav>
|
|
21
|
+
|
|
22
|
+
<h2 id="overview">Overview</h2>
|
|
23
|
+
<p>The templating system uses three file types that work together:</p>
|
|
24
|
+
<ul>
|
|
25
|
+
<li><strong>Templates</strong> (<code>*.template.html</code>) — Shared page layouts with named content slots</li>
|
|
26
|
+
<li><strong>Pages</strong> (<code>*.page.html</code>) — Individual pages that fill template slots with content</li>
|
|
27
|
+
<li><strong>Fragments</strong> (<code>*.fragment.html</code>) — Reusable HTML partials included in templates or other fragments</li>
|
|
28
|
+
</ul>
|
|
29
|
+
<p>All three file types are blocked from being served directly by the default <code>disallowedRegex</code> configuration.</p>
|
|
30
|
+
|
|
31
|
+
<h2 id="file-types">File Types</h2>
|
|
32
|
+
<p>A typical project structure:</p>
|
|
33
|
+
<pre><code class="hljs markdown">my-site/<br />├─ default.template.html # Shared layout<br />├─ nav.fragment.html # Reusable navigation<br />├─ footer.fragment.html # Reusable footer<br />├─ index.page.html # Homepage → renders to index.html<br />├─ about.page.html # About → renders to about.html<br />├─ blog/<br />│ ├─ index.page.html # Blog index → blog/index.html<br />│ ├─ post-1.page.html # Blog post → blog/post-1.html<br /></code></pre>
|
|
34
|
+
<p>Templates and fragments are resolved by walking up the directory tree from the page file to the root, so subdirectories can override them by providing their own versions.</p>
|
|
35
|
+
|
|
36
|
+
<h2 id="templates">Templates</h2>
|
|
37
|
+
<p>A template defines the shared HTML structure for your pages. Use <code><location></code> tags to define named content slots that pages will fill.</p>
|
|
38
|
+
<pre><code class="hljs xml"><span class="hljs-comment"><!-- default.template.html --></span><br /><span class="hljs-meta"><!DOCTYPE html></span><br /><span class="hljs-tag"><<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">head</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span> /></span><br /> <span class="hljs-tag"><<span class="hljs-name">title</span>></span>{{title}}<span class="hljs-tag"></<span class="hljs-name">title</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">head</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">body</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">fragment</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"nav"</span> /></span><br /> <span class="hljs-tag"><<span class="hljs-name">main</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">h1</span>></span>{{pageName}}<span class="hljs-tag"></<span class="hljs-name">h1</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">location</span> /></span><br /> <span class="hljs-tag"></<span class="hljs-name">main</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">location</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"scripts"</span>></span><br /> <span class="hljs-comment"><!-- default scripts if page doesn't provide any --></span><br /> <span class="hljs-tag"></<span class="hljs-name">location</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">body</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">html</span>></span></code></pre>
|
|
39
|
+
|
|
40
|
+
<h3>Location Tags</h3>
|
|
41
|
+
<p>Locations are named slots in a template that pages fill with content. The <code>name</code> attribute is optional — a <code><location></code> without a name defaults to <code>"default"</code>.</p>
|
|
42
|
+
<ul>
|
|
43
|
+
<li><code><location /></code> — Self-closing default slot (equivalent to <code><location name="default" /></code>)</li>
|
|
44
|
+
<li><code><location name="scripts" /></code> — Named slot, renders empty if the page doesn't provide content for it</li>
|
|
45
|
+
<li><code><location name="scripts">...fallback...</location></code> — Includes fallback content used when the page doesn't override it</li>
|
|
46
|
+
</ul>
|
|
47
|
+
|
|
48
|
+
<h2 id="pages">Pages</h2>
|
|
49
|
+
<p>A page file wraps its content in a <code><page></code> root element and uses <code><content></code> blocks to fill the template's locations. The <code>location</code> attribute is optional — a <code><content></code> block without one targets the <code>"default"</code> location. Multiple <code><content></code> blocks targeting the same location are concatenated in order.</p>
|
|
50
|
+
<pre><code class="hljs xml"><span class="hljs-comment"><!-- about.page.html → renders to about.html --></span><br /><span class="hljs-tag"><<span class="hljs-name">page</span> <span class="hljs-attr">pageName</span>=<span class="hljs-string">"About Us"</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"About - My Site"</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">content</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">p</span>></span>Welcome to our about page.<span class="hljs-tag"></<span class="hljs-name">p</span>></span><br /> <span class="hljs-tag"></<span class="hljs-name">content</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">page</span>></span></code></pre>
|
|
51
|
+
|
|
52
|
+
<h3>Page Attributes</h3>
|
|
53
|
+
<p>Attributes on the <code><page></code> tag become template variables. In the example above, <code>{{pageName}}</code> resolves to <code>About Us</code> and <code>{{title}}</code> resolves to <code>About - My Site</code>.</p>
|
|
54
|
+
<p>The special <code>template</code> attribute selects which template to use. It defaults to <code>default</code>, which looks for <code>default.template.html</code>.</p>
|
|
55
|
+
<pre><code class="hljs xml"><span class="hljs-comment"><!-- Uses blog.template.html instead of default.template.html --></span><br /><span class="hljs-tag"><<span class="hljs-name">page</span> <span class="hljs-attr">template</span>=<span class="hljs-string">"blog"</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"My Post"</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">content</span> <span class="hljs-attr">location</span>=<span class="hljs-string">"main"</span>></span>...<span class="hljs-tag"></<span class="hljs-name">content</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">page</span>></span></code></pre>
|
|
56
|
+
|
|
57
|
+
<h2 id="fragments">Fragments</h2>
|
|
58
|
+
<p>Fragments are reusable HTML partials. Include them in templates or other fragments using the <code><fragment></code> tag.</p>
|
|
59
|
+
<pre><code class="hljs xml"><span class="hljs-comment"><!-- nav.fragment.html --></span><br /><span class="hljs-tag"><<span class="hljs-name">fragment</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">nav</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"./"</span>></span>Home<span class="hljs-tag"></<span class="hljs-name">a</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"./about.html"</span>></span>About<span class="hljs-tag"></<span class="hljs-name">a</span>></span><br /> <span class="hljs-tag"></<span class="hljs-name">nav</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">fragment</span>></span></code></pre>
|
|
60
|
+
<p>Include it in a template:</p>
|
|
61
|
+
<pre><code class="hljs xml"><span class="hljs-comment"><!-- Self-closing: renders empty if fragment file not found --></span><br /><span class="hljs-tag"><<span class="hljs-name">fragment</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"nav"</span> /></span><br /><br /><span class="hljs-comment"><!-- With fallback content if fragment file not found --></span><br /><span class="hljs-tag"><<span class="hljs-name">fragment</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"nav"</span>></span><span class="hljs-tag"><<span class="hljs-name">nav</span>></span>Fallback Nav<span class="hljs-tag"></<span class="hljs-name">nav</span>></span><span class="hljs-tag"></<span class="hljs-name">fragment</span>></span></code></pre>
|
|
62
|
+
<p>Fragments can include other fragments. The maximum nesting depth is controlled by <code>maxFragmentDepth</code> (default: 10).</p>
|
|
63
|
+
|
|
64
|
+
<h3>File Resolution</h3>
|
|
65
|
+
<p>When a page references a template or a template includes a fragment, the system searches for the file starting in the page's directory and walking up to the root. This means:</p>
|
|
66
|
+
<ul>
|
|
67
|
+
<li>Templates and fragments placed at the root apply to all pages</li>
|
|
68
|
+
<li>A subdirectory can provide its own version to override the parent</li>
|
|
69
|
+
</ul>
|
|
70
|
+
|
|
71
|
+
<h2 id="variables">Variables</h2>
|
|
72
|
+
<p>Use <code>{{variableName}}</code> syntax to insert dynamic values into templates and fragments.</p>
|
|
73
|
+
|
|
74
|
+
<h3>Built-in Variables</h3>
|
|
75
|
+
<table>
|
|
76
|
+
<thead>
|
|
77
|
+
<tr>
|
|
78
|
+
<th>Variable</th>
|
|
79
|
+
<th>Description</th>
|
|
80
|
+
</tr>
|
|
81
|
+
</thead>
|
|
82
|
+
<tbody>
|
|
83
|
+
<tr><td><code>{{pathToRoot}}</code></td><td>Relative path from the page to the root directory (e.g. <code>./</code>, <code>../</code>, <code>../../</code>)</td></tr>
|
|
84
|
+
<tr><td><code>{{year}}</code></td><td>Current four-digit year</td></tr>
|
|
85
|
+
<tr><td><code>{{date}}</code></td><td>Current date in ISO format (<code>YYYY-MM-DD</code>)</td></tr>
|
|
86
|
+
<tr><td><code>{{datetime}}</code></td><td>Full ISO 8601 datetime string</td></tr>
|
|
87
|
+
<tr><td><code>{{timestamp}}</code></td><td>Unix timestamp in milliseconds</td></tr>
|
|
88
|
+
<tr><td><code>{{version}}</code></td><td>Version from the root <code>package.json</code></td></tr>
|
|
89
|
+
<tr><td><code>{{env}}</code></td><td>Value of <code>NODE_ENV</code></td></tr>
|
|
90
|
+
</tbody>
|
|
91
|
+
</table>
|
|
92
|
+
|
|
93
|
+
<h3>Page Attributes as Variables</h3>
|
|
94
|
+
<p>Any attribute on the <code><page></code> tag is available as a variable in the template:</p>
|
|
95
|
+
<pre><code class="hljs xml"><span class="hljs-comment"><!-- page file --></span><br /><span class="hljs-tag"><<span class="hljs-name">page</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"My Page"</span> <span class="hljs-attr">author</span>=<span class="hljs-string">"Dustin"</span>></span>...<span class="hljs-tag"></<span class="hljs-name">page</span>></span><br /><br /><span class="hljs-comment"><!-- template file --></span><br /><span class="hljs-tag"><<span class="hljs-name">title</span>></span>{{title}}<span class="hljs-tag"></<span class="hljs-name">title</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"author"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"{{author}}"</span> /></span></code></pre>
|
|
96
|
+
|
|
97
|
+
<h3>Globals and State</h3>
|
|
98
|
+
<p>Additional variables can be provided through the <code>globals</code> and <code>state</code> configuration objects. Globals and state are merged with page attributes, with page attributes taking priority.</p>
|
|
99
|
+
<pre><code class="hljs javascript"><span class="hljs-comment">// .config.js</span><br /><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {<br /> <span class="hljs-attr">templating</span>: {<br /> <span class="hljs-attr">globals</span>: {<br /> <span class="hljs-attr">siteName</span>: <span class="hljs-string">'My Site'</span>,<br /> <span class="hljs-attr">copyright</span>: <span class="hljs-string">'© 2026 My Company'</span><br /> },<br /> <span class="hljs-attr">state</span>: {<br /> <span class="hljs-attr">buildId</span>: () => <span class="hljs-built_in">Date</span>.now().toString(<span class="hljs-number">36</span>)<br /> }<br /> }<br />};</code></pre>
|
|
100
|
+
<p>Function values in globals or state are called at render time, allowing dynamic values.</p>
|
|
101
|
+
|
|
102
|
+
<h3>Dot-Path Access</h3>
|
|
103
|
+
<p>Variables support dot notation for nested object access:</p>
|
|
104
|
+
<pre><code class="hljs xml">{{site.name}}<br />{{author.email}}</code></pre>
|
|
105
|
+
|
|
106
|
+
<h2 id="conditionals">Conditionals</h2>
|
|
107
|
+
<p>Use <code><if></code> blocks to conditionally include content based on variable values.</p>
|
|
108
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">if</span> <span class="hljs-attr">condition</span>=<span class="hljs-string">"showBanner"</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"banner"</span>></span>Welcome!<span class="hljs-tag"></<span class="hljs-name">div</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">if</span>></span></code></pre>
|
|
109
|
+
|
|
110
|
+
<h3>Supported Operators</h3>
|
|
111
|
+
<p>Conditions support a full expression syntax:</p>
|
|
112
|
+
<table>
|
|
113
|
+
<thead>
|
|
114
|
+
<tr>
|
|
115
|
+
<th>Operator</th>
|
|
116
|
+
<th>Description</th>
|
|
117
|
+
</tr>
|
|
118
|
+
</thead>
|
|
119
|
+
<tbody>
|
|
120
|
+
<tr><td><code>===</code></td><td>Strict equality</td></tr>
|
|
121
|
+
<tr><td><code>!==</code></td><td>Strict inequality</td></tr>
|
|
122
|
+
<tr><td><code>></code>, <code><</code>, <code>>=</code>, <code><=</code></td><td>Comparison</td></tr>
|
|
123
|
+
<tr><td><code>&&</code></td><td>Logical AND</td></tr>
|
|
124
|
+
<tr><td><code>||</code></td><td>Logical OR</td></tr>
|
|
125
|
+
<tr><td><code>!</code></td><td>Logical NOT</td></tr>
|
|
126
|
+
<tr><td><code>( )</code></td><td>Grouping</td></tr>
|
|
127
|
+
</tbody>
|
|
128
|
+
</table>
|
|
129
|
+
|
|
130
|
+
<h3>Examples</h3>
|
|
131
|
+
<pre><code class="hljs xml"><span class="hljs-comment"><!-- Truthy check --></span><br /><span class="hljs-tag"><<span class="hljs-name">if</span> <span class="hljs-attr">condition</span>=<span class="hljs-string">"isLoggedIn"</span>></span>Welcome back!<span class="hljs-tag"></<span class="hljs-name">if</span>></span><br /><br /><span class="hljs-comment"><!-- Negation --></span><br /><span class="hljs-tag"><<span class="hljs-name">if</span> <span class="hljs-attr">condition</span>=<span class="hljs-string">"!isLoggedIn"</span>></span>Please log in.<span class="hljs-tag"></<span class="hljs-name">if</span>></span><br /><br /><span class="hljs-comment"><!-- String comparison --></span><br /><span class="hljs-tag"><<span class="hljs-name">if</span> <span class="hljs-attr">condition</span>=<span class="hljs-string">"env === 'production'"</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"analytics.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">if</span>></span><br /><br /><span class="hljs-comment"><!-- Compound conditions --></span><br /><span class="hljs-tag"><<span class="hljs-name">if</span> <span class="hljs-attr">condition</span>=<span class="hljs-string">"isAdmin && hasPermission"</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/admin"</span>></span>Admin Panel<span class="hljs-tag"></<span class="hljs-name">a</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">if</span>></span></code></pre>
|
|
132
|
+
|
|
133
|
+
<h2 id="loops">Loops</h2>
|
|
134
|
+
<p>Use <code><foreach></code> blocks to iterate over arrays.</p>
|
|
135
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">foreach</span> <span class="hljs-attr">in</span>=<span class="hljs-string">"navLinks"</span> <span class="hljs-attr">as</span>=<span class="hljs-string">"link"</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"{{link.url}}"</span>></span>{{link.label}}<span class="hljs-tag"></<span class="hljs-name">a</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">foreach</span>></span></code></pre>
|
|
136
|
+
<p>The <code>in</code> attribute references an array variable and <code>as</code> names the loop variable. The loop variable supports dot-path access for object items.</p>
|
|
137
|
+
|
|
138
|
+
<p>Provide the array through globals or state:</p>
|
|
139
|
+
<pre><code class="hljs javascript"><span class="hljs-comment">// .config.js</span><br /><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {<br /> <span class="hljs-attr">templating</span>: {<br /> <span class="hljs-attr">globals</span>: {<br /> <span class="hljs-attr">navLinks</span>: [<br /> { <span class="hljs-attr">url</span>: <span class="hljs-string">'/'</span>, <span class="hljs-attr">label</span>: <span class="hljs-string">'Home'</span> },<br /> { <span class="hljs-attr">url</span>: <span class="hljs-string">'/about.html'</span>, <span class="hljs-attr">label</span>: <span class="hljs-string">'About'</span> }<br /> ]<br /> }<br /> }<br />};</code></pre>
|
|
140
|
+
|
|
141
|
+
<h2 id="rendering">Rendering</h2>
|
|
142
|
+
<p>Pages can be pre-rendered to static HTML files using the CLI tool or the programmatic API.</p>
|
|
143
|
+
|
|
144
|
+
<h3>CLI</h3>
|
|
145
|
+
<pre><code class="hljs bash"><span class="hljs-comment"># Render to a separate output directory</span><br />npx kempo-server-render ./src ./dist<br /><br /><span class="hljs-comment"># Render in-place (output to same directory)</span><br />npx kempo-server-render ./src<br /><br /><span class="hljs-comment"># With a state file</span><br />npx kempo-server-render ./src ./dist state.json</code></pre>
|
|
146
|
+
<p>The CLI automatically loads <code>.config.js</code> or <code>.config.json</code> from the input directory for globals, state, and maxFragmentDepth settings.</p>
|
|
147
|
+
|
|
148
|
+
<h3>Programmatic API</h3>
|
|
149
|
+
<pre><code class="hljs javascript"><span class="hljs-keyword">import</span> { renderDir, renderPage } <span class="hljs-keyword">from</span> <span class="hljs-string">'kempo-server/templating'</span>;<br /><br /><span class="hljs-comment">// Render all pages in a directory</span><br /><span class="hljs-keyword">const</span> count = <span class="hljs-keyword">await</span> renderDir(<span class="hljs-string">'./src'</span>, <span class="hljs-string">'./dist'</span>, globals, state, maxDepth);<br /><br /><span class="hljs-comment">// Render a single page</span><br /><span class="hljs-keyword">const</span> html = <span class="hljs-keyword">await</span> renderPage(<span class="hljs-string">'./src/about.page.html'</span>, <span class="hljs-string">'./src'</span>, globals, state, maxDepth);</code></pre>
|
|
150
|
+
|
|
151
|
+
<h2 id="ssr">Server-Side Rendering</h2>
|
|
152
|
+
<p>Pages can also be rendered on each request instead of pre-built. This is useful during development so you can see changes without rebuilding.</p>
|
|
153
|
+
|
|
154
|
+
<h3>SSR Fallback</h3>
|
|
155
|
+
<p>When <code>ssr</code> is enabled, the server first looks for a static file. If no static file is found, it looks for a matching <code>.page.html</code> file and renders it on the fly.</p>
|
|
156
|
+
<pre><code class="hljs javascript"><span class="hljs-comment">// .config.js</span><br /><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {<br /> <span class="hljs-attr">templating</span>: {<br /> <span class="hljs-attr">ssr</span>: <span class="hljs-literal">true</span><br /> }<br />};</code></pre>
|
|
157
|
+
|
|
158
|
+
<h3>SSR Priority</h3>
|
|
159
|
+
<p>When <code>ssrPriority</code> is also enabled, the server renders the <code>.page.html</code> file <em>before</em> checking for static files. This ensures you always see the latest template changes, even if a pre-rendered <code>.html</code> file exists in the same directory.</p>
|
|
160
|
+
<pre><code class="hljs javascript"><span class="hljs-comment">// dev.config.js</span><br /><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {<br /> <span class="hljs-attr">templating</span>: {<br /> <span class="hljs-attr">ssr</span>: <span class="hljs-literal">true</span>,<br /> <span class="hljs-attr">ssrPriority</span>: <span class="hljs-literal">true</span><br /> }<br />};</code></pre>
|
|
161
|
+
<p>This is ideal for development. For production, pre-render your pages and serve them as static files with SSR disabled.</p>
|
|
162
|
+
|
|
163
|
+
<h2 id="configuration">Configuration</h2>
|
|
164
|
+
<p>All templating options live under the <code>templating</code> key in your configuration file.</p>
|
|
165
|
+
<table>
|
|
166
|
+
<thead>
|
|
167
|
+
<tr>
|
|
168
|
+
<th>Option</th>
|
|
169
|
+
<th>Default</th>
|
|
170
|
+
<th>Description</th>
|
|
171
|
+
</tr>
|
|
172
|
+
</thead>
|
|
173
|
+
<tbody>
|
|
174
|
+
<tr><td><code>preRender</code></td><td><code>false</code></td><td>Pre-render pages on server start</td></tr>
|
|
175
|
+
<tr><td><code>ssr</code></td><td><code>false</code></td><td>Enable server-side rendering as a fallback</td></tr>
|
|
176
|
+
<tr><td><code>ssrPriority</code></td><td><code>false</code></td><td>Render pages before checking for static files (requires <code>ssr: true</code>)</td></tr>
|
|
177
|
+
<tr><td><code>globals</code></td><td><code>{}</code></td><td>Variables available to all pages</td></tr>
|
|
178
|
+
<tr><td><code>state</code></td><td><code>{}</code></td><td>Additional variables (function values are called at render time)</td></tr>
|
|
179
|
+
<tr><td><code>maxFragmentDepth</code></td><td><code>10</code></td><td>Maximum fragment nesting depth</td></tr>
|
|
180
|
+
</tbody>
|
|
181
|
+
</table>
|
|
182
|
+
|
|
183
|
+
<h3>Development vs Production</h3>
|
|
184
|
+
<p>A common pattern is to use separate config files:</p>
|
|
185
|
+
<pre><code class="hljs javascript"><span class="hljs-comment">// dev.config.js — live rendering, no rebuild needed</span><br /><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {<br /> <span class="hljs-attr">templating</span>: { <span class="hljs-attr">ssr</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">ssrPriority</span>: <span class="hljs-literal">true</span> }<br />};<br /><br /><span class="hljs-comment">// prod.config.js — static files only</span><br /><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {<br /> <span class="hljs-attr">templating</span>: { <span class="hljs-attr">ssr</span>: <span class="hljs-literal">false</span> }<br />};</code></pre>
|
|
186
|
+
<pre><code class="hljs bash"><span class="hljs-comment"># Development</span><br />node dist/index.js -r ./docs/src -c dev.config.js<br /><br /><span class="hljs-comment"># Production (serve pre-rendered output)</span><br />node dist/index.js -r ./docs/dist</code></pre>
|
|
187
|
+
</content>
|
|
188
|
+
</page>
|
package/{llm.txt → llms.txt}
RENAMED
|
@@ -9,7 +9,7 @@ npm install kempo-server
|
|
|
9
9
|
npx kempo-server -r ./my-root -p 3000
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Flags: `--root`/`-r` (default `./`), `--port`/`-p` (default `3000`), `--logging`/`-l` (0-4 or silent/minimal/verbose/debug, default 2), `--config`/`-c` path to config file (default `.config.json`).
|
|
12
|
+
Flags: `--root`/`-r` (default `./`), `--port`/`-p` (default `3000`), `--logging`/`-l` (0-4 or silent/minimal/verbose/debug, default 2), `--config`/`-c` path to config file (default `.config.js`, falls back to `.config.json`).
|
|
13
13
|
|
|
14
14
|
## File-Based Routing
|
|
15
15
|
|
|
@@ -68,32 +68,39 @@ export default async (req, res) => {
|
|
|
68
68
|
| `res.cookie(name, val, opts)` | Set cookie; opts: maxAge, domain, path, secure, httpOnly, sameSite |
|
|
69
69
|
| `res.clearCookie(name, opts)` | Clear cookie |
|
|
70
70
|
|
|
71
|
-
## Configuration (.config.
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
## Configuration (.config.js)
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
export default {
|
|
75
|
+
allowedMimes: { '.ext': { mime: 'type/subtype', encoding: 'utf8' } },
|
|
76
|
+
disallowedRegex: ['pattern'],
|
|
77
|
+
customRoutes: { '/old': '/new', '/spa/*': '/app.html' },
|
|
78
|
+
routeFiles: ['GET.js', 'index.js'],
|
|
79
|
+
noRescanPaths: ['pattern'],
|
|
80
|
+
maxRescanAttempts: 3,
|
|
81
|
+
middleware: {
|
|
82
|
+
cors: { enabled: false, origin: '*', methods: 'GET,POST', headers: '*' },
|
|
83
|
+
compression: { enabled: false, threshold: 1024 },
|
|
84
|
+
rateLimit: { enabled: false, windowMs: 60000, max: 100 },
|
|
85
|
+
security: { enabled: true, headers: { 'X-Frame-Options': 'DENY' } },
|
|
86
|
+
logging: { enabled: true },
|
|
87
|
+
custom: ['/middleware/auth.js']
|
|
88
88
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
cache: {
|
|
90
|
+
enabled: false,
|
|
91
|
+
maxSize: 500,
|
|
92
|
+
maxMemoryMB: 256,
|
|
93
|
+
ttlMs: 300000,
|
|
94
|
+
watchFiles: true
|
|
95
|
+
},
|
|
96
|
+
templating: {
|
|
97
|
+
preRender: false,
|
|
98
|
+
ssr: false,
|
|
99
|
+
globals: {},
|
|
100
|
+
state: {},
|
|
101
|
+
maxFragmentDepth: 10
|
|
95
102
|
}
|
|
96
|
-
}
|
|
103
|
+
};
|
|
97
104
|
```
|
|
98
105
|
|
|
99
106
|
`customRoutes` values: exact path string or wildcard pattern mapped to a file or directory path. `*` matches one path segment; `**` matches multiple. When a route resolves to a directory, the server looks for route files inside it using the same priority as normal routing: `METHOD.js`, `METHOD.html`, `index.js`, `index.html`.
|
|
@@ -122,16 +129,79 @@ posts/[slug]/index.js → /posts/my-title (req.params.slug === 'my-title')
|
|
|
122
129
|
|
|
123
130
|
Use `customRoutes` to redirect all page paths to the SPA entry:
|
|
124
131
|
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
```js
|
|
133
|
+
export default {
|
|
134
|
+
customRoutes: {
|
|
135
|
+
'/': '/app.html',
|
|
136
|
+
'/*.html': '/app.html'
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Templating
|
|
142
|
+
|
|
143
|
+
XML-based templating system with templates, pages, fragments, variables, conditionals, and loops.
|
|
144
|
+
|
|
145
|
+
### File Conventions
|
|
146
|
+
|
|
147
|
+
- `*.template.html` — Layout file with `<location name="...">` placeholders
|
|
148
|
+
- `*.page.html` — Content file with `<page template="name">` root and `<content location="...">` blocks
|
|
149
|
+
- `*.fragment.html` — Reusable snippet included via `<fragment name="..." />`
|
|
150
|
+
|
|
151
|
+
Templates and fragments are found by walking up from the page file's directory to the root.
|
|
152
|
+
|
|
153
|
+
### Example
|
|
154
|
+
|
|
155
|
+
**default.template.html:**
|
|
156
|
+
```html
|
|
157
|
+
<html><head><title>{{title}}</title></head>
|
|
158
|
+
<body><fragment name="nav" /><main><location name="main" /></main></body></html>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**index.page.html:**
|
|
162
|
+
```html
|
|
163
|
+
<page template="default" title="Home">
|
|
164
|
+
<content location="main"><h1>Welcome</h1></content>
|
|
165
|
+
</page>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Built-in Variables
|
|
169
|
+
|
|
170
|
+
`{{pathToRoot}}` `{{year}}` `{{date}}` `{{datetime}}` `{{timestamp}}` `{{version}}` `{{env}}`
|
|
171
|
+
|
|
172
|
+
### Conditionals and Loops
|
|
173
|
+
|
|
174
|
+
```html
|
|
175
|
+
<if condition="count > 0">{{count}} items</if>
|
|
176
|
+
<foreach in="items" as="item"><li>{{item.name}}</li></foreach>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Conditions: `===` `!==` `>` `<` `>=` `<=` `&&` `||` `!` parentheses, string/number/boolean literals, dot-path variables.
|
|
180
|
+
|
|
181
|
+
### CLI Rendering
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
kempo-render <inputDir> [outputDir] [stateFile]
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Programmatic API
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
import { renderPage, renderDir } from 'kempo-server/templating';
|
|
191
|
+
const html = await renderPage(pageFilePath, rootDir, globals, state, maxDepth);
|
|
192
|
+
const count = await renderDir(inputDir, outputDir, globals, state, maxDepth);
|
|
130
193
|
```
|
|
131
194
|
|
|
132
195
|
## Utility Modules
|
|
133
196
|
|
|
134
197
|
```js
|
|
198
|
+
import rescan from 'kempo-server/rescan';
|
|
199
|
+
// rescan() → Promise<number> — triggers a file rescan on the running server, returns new file count
|
|
200
|
+
|
|
201
|
+
import { renderPage, renderDir } from 'kempo-server/templating';
|
|
202
|
+
// renderPage(pageFilePath, rootDir, globals?, state?, maxDepth?) → Promise<string>
|
|
203
|
+
// renderDir(inputDir, outputDir, globals?, state?, maxDepth?) → Promise<number>
|
|
204
|
+
|
|
135
205
|
import { getArgs } from 'kempo-server/utils/cli';
|
|
136
206
|
// getArgs(mapping?) → parsed argv object
|
|
137
207
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kempo-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"description": "A lightweight, zero-dependency, file based routing server.",
|
|
6
6
|
"exports": {
|
|
7
|
+
"./rescan": "./dist/rescan.js",
|
|
8
|
+
"./templating": "./dist/templating/index.js",
|
|
7
9
|
"./utils/cli": "./dist/utils/cli.js",
|
|
8
10
|
"./utils/fs-utils": "./dist/utils/fs-utils.js"
|
|
9
11
|
},
|
|
10
12
|
"bin": {
|
|
11
|
-
"kempo-server": "./dist/index.js"
|
|
13
|
+
"kempo-server": "./dist/index.js",
|
|
14
|
+
"kempo-server-render": "./dist/render.js"
|
|
12
15
|
},
|
|
13
16
|
"scripts": {
|
|
14
17
|
"build": "node scripts/build.js",
|
|
15
|
-
"docs": "node dist/index.js -r ./docs",
|
|
18
|
+
"docs": "node dist/index.js -r ./docs/dist",
|
|
19
|
+
"docs-src": "node dist/index.js -r ./docs/src",
|
|
16
20
|
"spa": "node dist/index.js -r ./spa",
|
|
17
21
|
"test": "npx kempo-test",
|
|
18
22
|
"test:gui": "npx kempo-test --gui",
|
package/scripts/build.js
CHANGED
|
@@ -2,13 +2,13 @@ import { readdir, readFile, writeFile, mkdir, copyFile } from 'fs/promises';
|
|
|
2
2
|
import { join, dirname } from 'path';
|
|
3
3
|
import { minify } from 'terser';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
+
import { renderDir } from '../src/templating/index.js';
|
|
5
6
|
|
|
6
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
8
|
const rootDir = join(__dirname, '..');
|
|
8
9
|
const srcDir = join(rootDir, 'src');
|
|
9
10
|
const utilsDir = join(rootDir, 'utils');
|
|
10
11
|
const distDir = join(rootDir, 'dist');
|
|
11
|
-
const docsDir = join(rootDir, 'docs');
|
|
12
12
|
|
|
13
13
|
/*
|
|
14
14
|
File Processing Helper
|
|
@@ -79,19 +79,27 @@ const build = async () => {
|
|
|
79
79
|
await processJsFile(join(utilsDir, file), join(distDir, 'utils', file));
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
// Process src/templating directory
|
|
83
|
+
const templatingDir = join(srcDir, 'templating');
|
|
84
|
+
await mkdir(join(distDir, 'templating'), { recursive: true });
|
|
85
|
+
const templatingFiles = await readdir(templatingDir);
|
|
86
|
+
const templatingJsFiles = templatingFiles.filter(file => file.endsWith('.js'));
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const cssTarget = join(docsDir, 'kempo.min.css');
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
await copyFile(cssSource, cssTarget);
|
|
90
|
-
console.log('✓ Copied kempo.min.css to docs');
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.warn('⚠ Could not copy kempo.min.css:', error.message);
|
|
88
|
+
for (const file of templatingJsFiles) {
|
|
89
|
+
await processJsFile(join(templatingDir, file), join(distDir, 'templating', file));
|
|
93
90
|
}
|
|
94
91
|
|
|
92
|
+
// Process render CLI script
|
|
93
|
+
const scriptsDir = join(rootDir, 'scripts');
|
|
94
|
+
await processJsFile(join(scriptsDir, 'render.js'), join(distDir, 'render.js'));
|
|
95
|
+
|
|
96
|
+
// Render docs
|
|
97
|
+
console.log('Rendering docs...');
|
|
98
|
+
const docsSrcDir = join(rootDir, 'docs', 'src');
|
|
99
|
+
const docsDistDir = join(rootDir, 'docs', 'dist');
|
|
100
|
+
const docsCount = await renderDir(docsSrcDir, docsDistDir);
|
|
101
|
+
console.log(`✓ Rendered ${docsCount} doc pages`);
|
|
102
|
+
|
|
95
103
|
console.log('Build completed successfully!');
|
|
96
104
|
|
|
97
105
|
} catch (error) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { join, resolve, dirname } from 'path';
|
|
4
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
5
|
+
import { renderDir } from './templating/index.js';
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const inputDir = args[0];
|
|
9
|
+
|
|
10
|
+
if(!inputDir){
|
|
11
|
+
console.error('Usage: kempo-render <inputDir> [outputDir] [stateFile]');
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const outputDir = args[1] || inputDir;
|
|
16
|
+
const stateFile = args[2];
|
|
17
|
+
const resolvedInput = resolve(inputDir);
|
|
18
|
+
const resolvedOutput = resolve(outputDir);
|
|
19
|
+
|
|
20
|
+
let globals = {};
|
|
21
|
+
let state = {};
|
|
22
|
+
let maxDepth = 10;
|
|
23
|
+
|
|
24
|
+
const loadConfig = async dir => {
|
|
25
|
+
const jsPath = join(dir, '.config.js');
|
|
26
|
+
try {
|
|
27
|
+
const mod = await import(pathToFileURL(jsPath).href);
|
|
28
|
+
return mod.default;
|
|
29
|
+
} catch(e){
|
|
30
|
+
try {
|
|
31
|
+
const json = await readFile(join(dir, '.config.json'), 'utf8');
|
|
32
|
+
return JSON.parse(json);
|
|
33
|
+
} catch(e2){
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const config = await loadConfig(resolvedInput);
|
|
40
|
+
if(config?.templating){
|
|
41
|
+
globals = config.templating.globals || {};
|
|
42
|
+
state = config.templating.state || {};
|
|
43
|
+
maxDepth = config.templating.maxFragmentDepth || 10;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if(stateFile){
|
|
47
|
+
const resolvedState = resolve(stateFile);
|
|
48
|
+
if(resolvedState.endsWith('.js')){
|
|
49
|
+
const mod = await import(pathToFileURL(resolvedState).href);
|
|
50
|
+
state = {...state, ...mod.default};
|
|
51
|
+
} else {
|
|
52
|
+
const json = await readFile(resolvedState, 'utf8');
|
|
53
|
+
state = {...state, ...JSON.parse(json)};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const count = await renderDir(resolvedInput, resolvedOutput, globals, state, maxDepth);
|
|
58
|
+
console.log(`Rendered ${count} page${count !== 1 ? 's' : ''}`);
|
package/src/defaultConfig.js
CHANGED
|
@@ -44,7 +44,8 @@ export default {
|
|
|
44
44
|
},
|
|
45
45
|
disallowedRegex: [
|
|
46
46
|
"^/\\..*",
|
|
47
|
-
"\\.config$",
|
|
47
|
+
"\\.config\\.js$",
|
|
48
|
+
"\\.config\\.json$",
|
|
48
49
|
"\\.env$",
|
|
49
50
|
"\\.git/",
|
|
50
51
|
"\\.htaccess$",
|
|
@@ -59,7 +60,10 @@ export default {
|
|
|
59
60
|
"wp-config\\.php$",
|
|
60
61
|
"\\.DS_Store$",
|
|
61
62
|
"package\\.json$",
|
|
62
|
-
"package-lock\\.json$"
|
|
63
|
+
"package-lock\\.json$",
|
|
64
|
+
"\\.template\\.html$",
|
|
65
|
+
"\\.fragment\\.html$",
|
|
66
|
+
"\\.page\\.html$"
|
|
63
67
|
],
|
|
64
68
|
routeFiles: [
|
|
65
69
|
'GET.js',
|
|
@@ -138,5 +142,13 @@ export default {
|
|
|
138
142
|
memoryCheckInterval: 30000, // Memory check interval (30 seconds)
|
|
139
143
|
watchFiles: true, // Auto-invalidate on file changes
|
|
140
144
|
enableMemoryMonitoring: true // Enable automatic memory monitoring
|
|
145
|
+
},
|
|
146
|
+
templating: {
|
|
147
|
+
preRender: false,
|
|
148
|
+
ssr: false,
|
|
149
|
+
ssrPriority: false,
|
|
150
|
+
globals: {},
|
|
151
|
+
state: {},
|
|
152
|
+
maxFragmentDepth: 10
|
|
141
153
|
}
|
|
142
154
|
}
|
package/src/index.js
CHANGED
package/src/rescan.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
const emitter = new EventEmitter();
|
|
4
|
+
|
|
5
|
+
export const onRescan = callback => {
|
|
6
|
+
emitter.on('rescan', callback);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default () => new Promise((resolve, reject) => {
|
|
10
|
+
emitter.emit('rescan', (error, fileCount) => {
|
|
11
|
+
if(error) reject(error);
|
|
12
|
+
else resolve(fileCount);
|
|
13
|
+
});
|
|
14
|
+
});
|