create-dalila 1.1.6 → 1.1.8
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/index.js
CHANGED
|
@@ -101,14 +101,14 @@ function main() {
|
|
|
101
101
|
console.log(`${green('Done!')} Created ${bold(projectName)}\n`);
|
|
102
102
|
console.log('Next steps:\n');
|
|
103
103
|
console.log(` ${cyan('cd')} ${projectName}`);
|
|
104
|
-
console.log(` ${cyan('npm install')}`);
|
|
104
|
+
console.log(` ${cyan('npm install')} ${green('(routes will be generated automatically)')}`);
|
|
105
105
|
console.log(` ${cyan('npm run dev')}`);
|
|
106
106
|
console.log();
|
|
107
|
+
console.log(`Open ${cyan('http://localhost:4242')} to see your app.`);
|
|
108
|
+
console.log();
|
|
107
109
|
console.log('When you update files in src/app, regenerate routes with:');
|
|
108
110
|
console.log(` ${cyan('npm run routes')}`);
|
|
109
111
|
console.log();
|
|
110
|
-
console.log(`Open ${cyan('http://localhost:4242')} to see your app.`);
|
|
111
|
-
console.log();
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
main();
|
package/package.json
CHANGED
package/template/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// This file is auto-generated by 'dalila routes generate'
|
|
2
|
-
// Do not edit manually - your changes will be overwritten
|
|
3
|
-
|
|
4
|
-
import type { RouteManifestEntry } from 'dalila/router';
|
|
5
|
-
|
|
6
|
-
export const routeManifest: RouteManifestEntry[] = [
|
|
7
|
-
{
|
|
8
|
-
id: 'root',
|
|
9
|
-
pattern: '/',
|
|
10
|
-
score: 1000,
|
|
11
|
-
paramKeys: [],
|
|
12
|
-
tags: [],
|
|
13
|
-
modules: ["./src/app/page.js"],
|
|
14
|
-
load: () => import('./src/app/page.js').then(() => undefined)
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
id: 'about',
|
|
18
|
-
pattern: '/about',
|
|
19
|
-
score: 301,
|
|
20
|
-
paramKeys: [],
|
|
21
|
-
tags: [],
|
|
22
|
-
modules: ["./src/app/page.js"],
|
|
23
|
-
load: () => import('./src/app/page.js').then(() => undefined)
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
const manifestById = new Map(routeManifest.map(route => [route.id, route]));
|
|
28
|
-
|
|
29
|
-
export function getRouteManifestEntry(id: string): RouteManifestEntry | undefined {
|
|
30
|
-
return manifestById.get(id);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function prefetchRouteById(id: string): Promise<void> {
|
|
34
|
-
const entry = manifestById.get(id);
|
|
35
|
-
if (!entry) return;
|
|
36
|
-
await entry.load();
|
|
37
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// This file is auto-generated by 'dalila routes generate'
|
|
2
|
-
// Do not edit manually - your changes will be overwritten
|
|
3
|
-
|
|
4
|
-
import type { RouteTable } from 'dalila/router';
|
|
5
|
-
import { fromHtml } from 'dalila';
|
|
6
|
-
|
|
7
|
-
const layout_html = `<div class="app-shell">
|
|
8
|
-
<header class="app-header">
|
|
9
|
-
<div>
|
|
10
|
-
<h1>Dalila Router App</h1>
|
|
11
|
-
<p>File-based routing starter template</p>
|
|
12
|
-
</div>
|
|
13
|
-
<nav class="app-nav">
|
|
14
|
-
<a d-link="/">Home</a>
|
|
15
|
-
<a d-link="/about">About</a>
|
|
16
|
-
</nav>
|
|
17
|
-
</header>
|
|
18
|
-
|
|
19
|
-
<main class="app-main" data-slot="children"></main>
|
|
20
|
-
</div>
|
|
21
|
-
`;
|
|
22
|
-
const page_html = `<section class="card">
|
|
23
|
-
<h2>Counter: {count}</h2>
|
|
24
|
-
<p>Doubled: {doubled}</p>
|
|
25
|
-
|
|
26
|
-
<div class="buttons">
|
|
27
|
-
<button type="button" d-on-click="decrement">-</button>
|
|
28
|
-
<button type="button" d-on-click="increment">+</button>
|
|
29
|
-
</div>
|
|
30
|
-
</section>
|
|
31
|
-
|
|
32
|
-
<section class="card">
|
|
33
|
-
<p when={isEven}>The count is even.</p>
|
|
34
|
-
<p when={isOdd}>The count is odd.</p>
|
|
35
|
-
</section>
|
|
36
|
-
`;
|
|
37
|
-
const about_page_html = `<section class="card">
|
|
38
|
-
<h2>About</h2>
|
|
39
|
-
<p>This starter uses file-based routes from <code>src/app</code>.</p>
|
|
40
|
-
<p>Use <code>npm run routes</code> after changing route files.</p>
|
|
41
|
-
</section>
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
const page_lazy = () => import('./src/app/page.js');
|
|
45
|
-
|
|
46
|
-
export const routes: RouteTable[] = [
|
|
47
|
-
{
|
|
48
|
-
path: '/',
|
|
49
|
-
layout: (ctx, children) => fromHtml(layout_html, { data: { ...(ctx.params as Record<string, unknown>), params: ctx.params, query: ctx.query.toString(), path: ctx.path, fullPath: ctx.fullPath }, children, scope: ctx.scope }),
|
|
50
|
-
children: [
|
|
51
|
-
{ path: '', view: (ctx, data) => fromHtml(page_html, { data: { ...(ctx.params as Record<string, unknown>), ...((data ?? {}) as Record<string, unknown>), params: ctx.params, query: ctx.query.toString(), path: ctx.path, fullPath: ctx.fullPath }, scope: ctx.scope }), loader: (...args: any[]) => page_lazy().then(mod => {
|
|
52
|
-
const exported = (mod as any).loader;
|
|
53
|
-
if (typeof exported === 'function') {
|
|
54
|
-
return exported(...args);
|
|
55
|
-
}
|
|
56
|
-
return undefined;
|
|
57
|
-
}) },
|
|
58
|
-
{
|
|
59
|
-
path: 'about',
|
|
60
|
-
view: (ctx) => fromHtml(about_page_html, { data: { ...(ctx.params as Record<string, unknown>), params: ctx.params, query: ctx.query.toString(), path: ctx.path, fullPath: ctx.fullPath }, scope: ctx.scope }),
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
];
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// This file is auto-generated by 'dalila routes generate'
|
|
2
|
-
// Do not edit manually - your changes will be overwritten
|
|
3
|
-
|
|
4
|
-
export type RoutePattern = '/' | '/about';
|
|
5
|
-
|
|
6
|
-
export type RouteParamsByPattern = {
|
|
7
|
-
'/': {};
|
|
8
|
-
'/about': {};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type RouteSearchByPattern = {
|
|
12
|
-
[P in RoutePattern]: Record<string, string | string[]>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type RouteParams<P extends RoutePattern> = RouteParamsByPattern[P];
|
|
16
|
-
export type RouteSearch<P extends RoutePattern> = RouteSearchByPattern[P];
|
|
17
|
-
|
|
18
|
-
export function buildRoutePath<P extends RoutePattern>(pattern: P, params: RouteParams<P>): string {
|
|
19
|
-
const out: string[] = [];
|
|
20
|
-
for (const segment of pattern.split('/').filter(Boolean)) {
|
|
21
|
-
if (!segment.startsWith(':')) {
|
|
22
|
-
out.push(segment);
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const isOptionalCatchAll = segment.endsWith('*?');
|
|
27
|
-
const isCatchAll = isOptionalCatchAll || segment.endsWith('*');
|
|
28
|
-
const key = segment.slice(1, isCatchAll ? (isOptionalCatchAll ? -2 : -1) : undefined);
|
|
29
|
-
const value = (params as Record<string, unknown>)[key];
|
|
30
|
-
|
|
31
|
-
if (isCatchAll) {
|
|
32
|
-
if (value === undefined || value === null) {
|
|
33
|
-
if (isOptionalCatchAll) continue;
|
|
34
|
-
throw new Error(`Missing route param: ${key}`);
|
|
35
|
-
}
|
|
36
|
-
if (!Array.isArray(value)) {
|
|
37
|
-
throw new Error(`Route param "${key}" must be an array`);
|
|
38
|
-
}
|
|
39
|
-
if (value.length === 0) {
|
|
40
|
-
if (isOptionalCatchAll) continue;
|
|
41
|
-
throw new Error(`Route param "${key}" cannot be empty`);
|
|
42
|
-
}
|
|
43
|
-
out.push(...value.map(v => encodeURIComponent(String(v))));
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (value === undefined || value === null) {
|
|
48
|
-
throw new Error(`Missing route param: ${key}`);
|
|
49
|
-
}
|
|
50
|
-
out.push(encodeURIComponent(String(value)));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return out.length === 0 ? '/' : `/${out.join('/')}`;
|
|
54
|
-
}
|