create-start-serenojs 0.0.0-stage → 0.1.1
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/README.md +129 -2
- package/dist/args.d.ts +14 -0
- package/dist/args.js +54 -0
- package/dist/banner.d.ts +1 -0
- package/dist/banner.js +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +244 -0
- package/dist/pm.d.ts +9 -0
- package/dist/pm.js +17 -0
- package/dist/template.d.ts +12 -0
- package/dist/template.js +92 -0
- package/package.json +49 -3
- package/templates/starter/.agents/skills/serenojs-schema/SKILL.md +165 -0
- package/templates/starter/.agents/skills/serenojs-schema/assets/collection.template.ts +27 -0
- package/templates/starter/.agents/skills/serenojs-schema/references/fields.md +121 -0
- package/templates/starter/README.md +190 -0
- package/templates/starter/gitignore +11 -0
- package/templates/starter/package.json +33 -0
- package/templates/starter/public/.gitkeep +0 -0
- package/templates/starter/serenojs.config.ts +33 -0
- package/templates/starter/src/global.d.ts +1 -0
- package/templates/starter/src/middleware/no-trailing-slash.ts +14 -0
- package/templates/starter/src/middleware/serenojs.ts +9 -0
- package/templates/starter/src/pages/_layout.tsx +13 -0
- package/templates/starter/src/pages/index.tsx +319 -0
- package/templates/starter/src/pages.gen.ts +23 -0
- package/templates/starter/src/schemas/index.ts +17 -0
- package/templates/starter/src/schemas/locales.ts +27 -0
- package/templates/starter/src/schemas/todos.ts +38 -0
- package/templates/starter/src/styles.css +741 -0
- package/templates/starter/tsconfig.json +32 -0
- package/templates/starter/waku.config.ts +20 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { type FormEvent, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
type Todo = {
|
|
6
|
+
id: number;
|
|
7
|
+
title: string;
|
|
8
|
+
priority?: string;
|
|
9
|
+
done?: boolean;
|
|
10
|
+
dueDate?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const MONTHS = [
|
|
14
|
+
"Jan",
|
|
15
|
+
"Feb",
|
|
16
|
+
"Mar",
|
|
17
|
+
"Apr",
|
|
18
|
+
"May",
|
|
19
|
+
"Jun",
|
|
20
|
+
"Jul",
|
|
21
|
+
"Aug",
|
|
22
|
+
"Sep",
|
|
23
|
+
"Oct",
|
|
24
|
+
"Nov",
|
|
25
|
+
"Dec",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const priorityLabels: Record<string, string> = {
|
|
29
|
+
low: "Low",
|
|
30
|
+
medium: "Medium",
|
|
31
|
+
high: "High",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function formatDueDate(value: string): string {
|
|
35
|
+
const [year, month, day] = value.slice(0, 10).split("-");
|
|
36
|
+
const monthName = month ? MONTHS[Number(month) - 1] : undefined;
|
|
37
|
+
if (!year || !monthName || !day) return value;
|
|
38
|
+
return `${monthName} ${Number(day)}, ${year}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function readTodos(): Promise<Todo[]> {
|
|
42
|
+
const response = await fetch("/api/todos?limit=100");
|
|
43
|
+
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
|
|
44
|
+
const json = (await response.json()) as { items?: Todo[] };
|
|
45
|
+
return json.items ?? [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default function TodosPage() {
|
|
49
|
+
const [todos, setTodos] = useState<Todo[]>([]);
|
|
50
|
+
const [loading, setLoading] = useState(true);
|
|
51
|
+
const [error, setError] = useState<string | null>(null);
|
|
52
|
+
const [title, setTitle] = useState("");
|
|
53
|
+
const [editingId, setEditingId] = useState<number | null>(null);
|
|
54
|
+
const [editTitle, setEditTitle] = useState("");
|
|
55
|
+
|
|
56
|
+
const load = async () => {
|
|
57
|
+
setLoading(true);
|
|
58
|
+
setError(null);
|
|
59
|
+
try {
|
|
60
|
+
setTodos(await readTodos());
|
|
61
|
+
} catch {
|
|
62
|
+
setError("Could not load tasks.");
|
|
63
|
+
} finally {
|
|
64
|
+
setLoading(false);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
void load();
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
const mutate = async (
|
|
73
|
+
action: () => Promise<void>,
|
|
74
|
+
failureMessage: string,
|
|
75
|
+
): Promise<boolean> => {
|
|
76
|
+
setError(null);
|
|
77
|
+
try {
|
|
78
|
+
await action();
|
|
79
|
+
setTodos(await readTodos());
|
|
80
|
+
return true;
|
|
81
|
+
} catch {
|
|
82
|
+
setError(failureMessage);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const add = async (event: FormEvent) => {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
const value = title.trim();
|
|
90
|
+
if (!value) return;
|
|
91
|
+
|
|
92
|
+
const saved = await mutate(async () => {
|
|
93
|
+
const response = await fetch("/api/todos", {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers: { "Content-Type": "application/json" },
|
|
96
|
+
body: JSON.stringify({ title: value }),
|
|
97
|
+
});
|
|
98
|
+
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
|
|
99
|
+
}, "Could not add the task.");
|
|
100
|
+
|
|
101
|
+
if (saved) setTitle("");
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const toggle = (todo: Todo) =>
|
|
105
|
+
mutate(async () => {
|
|
106
|
+
const response = await fetch(`/api/todos/${todo.id}`, {
|
|
107
|
+
method: "PATCH",
|
|
108
|
+
headers: { "Content-Type": "application/json" },
|
|
109
|
+
body: JSON.stringify({ done: !todo.done }),
|
|
110
|
+
});
|
|
111
|
+
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
|
|
112
|
+
}, "Could not update the task.");
|
|
113
|
+
|
|
114
|
+
const remove = (id: number) =>
|
|
115
|
+
mutate(async () => {
|
|
116
|
+
const response = await fetch(`/api/todos/${id}`, { method: "DELETE" });
|
|
117
|
+
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
|
|
118
|
+
}, "Could not remove the task.");
|
|
119
|
+
|
|
120
|
+
const startEdit = (todo: Todo) => {
|
|
121
|
+
setEditingId(todo.id);
|
|
122
|
+
setEditTitle(todo.title);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const saveEdit = async () => {
|
|
126
|
+
const value = editTitle.trim();
|
|
127
|
+
if (!value || editingId === null) return;
|
|
128
|
+
|
|
129
|
+
const saved = await mutate(async () => {
|
|
130
|
+
const response = await fetch(`/api/todos/${editingId}`, {
|
|
131
|
+
method: "PATCH",
|
|
132
|
+
headers: { "Content-Type": "application/json" },
|
|
133
|
+
body: JSON.stringify({ title: value }),
|
|
134
|
+
});
|
|
135
|
+
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
|
|
136
|
+
}, "Could not save the task.");
|
|
137
|
+
|
|
138
|
+
if (saved) setEditingId(null);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const remaining = todos.filter((todo) => !todo.done).length;
|
|
142
|
+
const countLabel =
|
|
143
|
+
remaining === 0
|
|
144
|
+
? "All done"
|
|
145
|
+
: `${remaining} open ${remaining === 1 ? "task" : "tasks"}`;
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<main className="app">
|
|
149
|
+
<header className="topbar">
|
|
150
|
+
<a className="brand" href="/">
|
|
151
|
+
<span className="brand-mark" aria-hidden="true">
|
|
152
|
+
S
|
|
153
|
+
</span>
|
|
154
|
+
<span className="brand-name">SerenoJS</span>
|
|
155
|
+
<span className="brand-tag">Starter</span>
|
|
156
|
+
</a>
|
|
157
|
+
<a className="admin-link" href="/admin">
|
|
158
|
+
Open admin
|
|
159
|
+
</a>
|
|
160
|
+
</header>
|
|
161
|
+
|
|
162
|
+
<section className="intro">
|
|
163
|
+
<h1>Tasks</h1>
|
|
164
|
+
<p>A minimal CRUD app on top of the SerenoJS public API.</p>
|
|
165
|
+
</section>
|
|
166
|
+
|
|
167
|
+
<section className="panel" aria-label="Task list">
|
|
168
|
+
<form className="composer" onSubmit={(event) => void add(event)}>
|
|
169
|
+
<label htmlFor="todo-title">New task</label>
|
|
170
|
+
<div className="composer-row">
|
|
171
|
+
<input
|
|
172
|
+
id="todo-title"
|
|
173
|
+
value={title}
|
|
174
|
+
onChange={(event) => setTitle(event.target.value)}
|
|
175
|
+
placeholder="e.g. review the posts schema"
|
|
176
|
+
/>
|
|
177
|
+
<button className="btn btn-primary" type="submit">
|
|
178
|
+
Add
|
|
179
|
+
</button>
|
|
180
|
+
</div>
|
|
181
|
+
<p className="hint">
|
|
182
|
+
The task is created by the API at <code>/api/todos</code>.
|
|
183
|
+
</p>
|
|
184
|
+
</form>
|
|
185
|
+
|
|
186
|
+
<div className="list-head">
|
|
187
|
+
<h2>Your tasks</h2>
|
|
188
|
+
<span className="count" aria-live="polite">
|
|
189
|
+
{loading ? "Loading" : countLabel}
|
|
190
|
+
</span>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
{error ? (
|
|
194
|
+
<div className="state" role="alert">
|
|
195
|
+
<strong>Something went wrong</strong>
|
|
196
|
+
<p>{error}</p>
|
|
197
|
+
<button
|
|
198
|
+
className="btn btn-ghost btn-small"
|
|
199
|
+
type="button"
|
|
200
|
+
onClick={() => void load()}
|
|
201
|
+
>
|
|
202
|
+
Try again
|
|
203
|
+
</button>
|
|
204
|
+
</div>
|
|
205
|
+
) : loading ? (
|
|
206
|
+
<div className="skeleton" role="status" aria-label="Loading tasks">
|
|
207
|
+
{[0, 1, 2].map((index) => (
|
|
208
|
+
<div className="skeleton-row" key={index} aria-hidden="true">
|
|
209
|
+
<span className="skeleton-dot" />
|
|
210
|
+
<span className="skeleton-line" />
|
|
211
|
+
</div>
|
|
212
|
+
))}
|
|
213
|
+
</div>
|
|
214
|
+
) : todos.length === 0 ? (
|
|
215
|
+
<div className="state">
|
|
216
|
+
<strong>No tasks yet</strong>
|
|
217
|
+
<p>Add the first one above to see the API in action.</p>
|
|
218
|
+
</div>
|
|
219
|
+
) : (
|
|
220
|
+
<ul className="todo-list">
|
|
221
|
+
{todos.map((todo) => {
|
|
222
|
+
const done = Boolean(todo.done);
|
|
223
|
+
const priority = todo.priority
|
|
224
|
+
? (priorityLabels[todo.priority] ?? todo.priority)
|
|
225
|
+
: null;
|
|
226
|
+
const priorityClass =
|
|
227
|
+
todo.priority && priorityLabels[todo.priority]
|
|
228
|
+
? `chip chip-${todo.priority}`
|
|
229
|
+
: "chip";
|
|
230
|
+
|
|
231
|
+
return (
|
|
232
|
+
<li className={done ? "todo is-done" : "todo"} key={todo.id}>
|
|
233
|
+
<label className="check">
|
|
234
|
+
<input
|
|
235
|
+
type="checkbox"
|
|
236
|
+
checked={done}
|
|
237
|
+
onChange={() => void toggle(todo)}
|
|
238
|
+
/>
|
|
239
|
+
<span className="box" aria-hidden="true" />
|
|
240
|
+
<span className="sr-only">
|
|
241
|
+
{done ? "Reopen" : "Complete"} {todo.title}
|
|
242
|
+
</span>
|
|
243
|
+
</label>
|
|
244
|
+
|
|
245
|
+
<div className="todo-body">
|
|
246
|
+
{editingId === todo.id ? (
|
|
247
|
+
<input
|
|
248
|
+
className="edit-input"
|
|
249
|
+
value={editTitle}
|
|
250
|
+
onChange={(event) => setEditTitle(event.target.value)}
|
|
251
|
+
aria-label="Edit title"
|
|
252
|
+
autoFocus
|
|
253
|
+
/>
|
|
254
|
+
) : (
|
|
255
|
+
<span className="todo-title">{todo.title}</span>
|
|
256
|
+
)}
|
|
257
|
+
|
|
258
|
+
<div className="todo-meta">
|
|
259
|
+
{priority ? (
|
|
260
|
+
<span className={priorityClass}>{priority}</span>
|
|
261
|
+
) : null}
|
|
262
|
+
{todo.dueDate ? (
|
|
263
|
+
<span className="due">
|
|
264
|
+
{formatDueDate(todo.dueDate)}
|
|
265
|
+
</span>
|
|
266
|
+
) : null}
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
|
|
270
|
+
<div className="todo-actions">
|
|
271
|
+
{editingId === todo.id ? (
|
|
272
|
+
<>
|
|
273
|
+
<button
|
|
274
|
+
className="btn btn-small btn-primary"
|
|
275
|
+
type="button"
|
|
276
|
+
onClick={() => void saveEdit()}
|
|
277
|
+
>
|
|
278
|
+
Save
|
|
279
|
+
</button>
|
|
280
|
+
<button
|
|
281
|
+
className="btn btn-small btn-ghost"
|
|
282
|
+
type="button"
|
|
283
|
+
onClick={() => setEditingId(null)}
|
|
284
|
+
>
|
|
285
|
+
Cancel
|
|
286
|
+
</button>
|
|
287
|
+
</>
|
|
288
|
+
) : (
|
|
289
|
+
<>
|
|
290
|
+
<button
|
|
291
|
+
className="btn btn-small btn-ghost"
|
|
292
|
+
type="button"
|
|
293
|
+
onClick={() => startEdit(todo)}
|
|
294
|
+
>
|
|
295
|
+
Edit
|
|
296
|
+
</button>
|
|
297
|
+
<button
|
|
298
|
+
className="btn btn-small btn-danger"
|
|
299
|
+
type="button"
|
|
300
|
+
onClick={() => void remove(todo.id)}
|
|
301
|
+
>
|
|
302
|
+
Remove
|
|
303
|
+
</button>
|
|
304
|
+
</>
|
|
305
|
+
)}
|
|
306
|
+
</div>
|
|
307
|
+
</li>
|
|
308
|
+
);
|
|
309
|
+
})}
|
|
310
|
+
</ul>
|
|
311
|
+
)}
|
|
312
|
+
</section>
|
|
313
|
+
|
|
314
|
+
<footer className="foot">
|
|
315
|
+
Powered by <code><a href="https://www.npmjs.com/package/@eutobias/serenojs">@eutobias/serenojs</a></code>
|
|
316
|
+
</footer>
|
|
317
|
+
</main>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
// biome-ignore format: generated types do not need formatting
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
import type { PathsForPages } from 'waku/router';
|
|
5
|
+
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
type Page =
|
|
8
|
+
| { path: '/'; render: 'static' };
|
|
9
|
+
|
|
10
|
+
// prettier-ignore
|
|
11
|
+
type Layout =
|
|
12
|
+
| { path: '/' };
|
|
13
|
+
|
|
14
|
+
// prettier-ignore
|
|
15
|
+
declare module 'waku/router' {
|
|
16
|
+
interface RouteConfig {
|
|
17
|
+
paths: PathsForPages<Page>;
|
|
18
|
+
}
|
|
19
|
+
interface CreatePagesConfig {
|
|
20
|
+
pages: Page;
|
|
21
|
+
layouts: Layout;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CollectionDef } from "@eutobias/serenojs/config";
|
|
2
|
+
|
|
3
|
+
import { todos } from "./todos";
|
|
4
|
+
|
|
5
|
+
export { defaultLocale, localeLabel, locales } from "./locales";
|
|
6
|
+
export type { LocaleDef } from "./locales";
|
|
7
|
+
|
|
8
|
+
/** Title shown across the admin panel. */
|
|
9
|
+
export const schemaTitle = "SerenoJS";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Every collection available in the admin/API.
|
|
13
|
+
*
|
|
14
|
+
* To add a new collection: create a `<name>.ts` file in this folder exporting
|
|
15
|
+
* a `CollectionDef` and register it in the array below.
|
|
16
|
+
*/
|
|
17
|
+
export const collections: CollectionDef[] = [todos];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale registry for the i18n layer.
|
|
3
|
+
*
|
|
4
|
+
* The registry only provides display labels for the admin tabs. Which locales
|
|
5
|
+
* a collection actually stores is declared per collection via
|
|
6
|
+
* `CollectionDef.locales`; this array is the allowed set.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type LocaleDef = {
|
|
10
|
+
code: string;
|
|
11
|
+
label: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const locales: LocaleDef[] = [
|
|
15
|
+
{ code: "pt", label: "Português" },
|
|
16
|
+
{ code: "en", label: "English" },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/** Locale used as fallback and for the seed of legacy single-column data. */
|
|
20
|
+
export const defaultLocale = "pt";
|
|
21
|
+
|
|
22
|
+
/** Display label for a locale code (falls back to the uppercased code). */
|
|
23
|
+
export function localeLabel(code: string): string {
|
|
24
|
+
return (
|
|
25
|
+
locales.find((locale) => locale.code === code)?.label ?? code.toUpperCase()
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CollectionDef } from "@eutobias/serenojs/config";
|
|
2
|
+
|
|
3
|
+
export const todos: CollectionDef = {
|
|
4
|
+
slug: "todos",
|
|
5
|
+
label: "To Dos",
|
|
6
|
+
icon: "box",
|
|
7
|
+
description: "Example task list.",
|
|
8
|
+
access: { read: "public", create: "public", update: "public", delete: "public" },
|
|
9
|
+
list: ["id", "title", "priority", "done", "dueDate", "createdAt"],
|
|
10
|
+
fields: [
|
|
11
|
+
{
|
|
12
|
+
name: "title",
|
|
13
|
+
label: "Title",
|
|
14
|
+
type: "text",
|
|
15
|
+
required: true,
|
|
16
|
+
localized: false,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "description",
|
|
20
|
+
label: "Description",
|
|
21
|
+
type: "textarea",
|
|
22
|
+
localized: false,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "priority",
|
|
26
|
+
label: "Priority",
|
|
27
|
+
type: "select",
|
|
28
|
+
defaultValue: "medium",
|
|
29
|
+
options: [
|
|
30
|
+
{ label: "Low", value: "low" },
|
|
31
|
+
{ label: "Medium", value: "medium" },
|
|
32
|
+
{ label: "High", value: "high" },
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{ name: "done", label: "Done", type: "boolean", defaultValue: false },
|
|
36
|
+
{ name: "dueDate", label: "Due Date", type: "date" },
|
|
37
|
+
],
|
|
38
|
+
};
|