@bendyline/gezel-cli 1.2.7 → 1.2.9
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 +1 -1
- package/dist/LICENSE-HankenGrotesk-OFL-1.1.txt +94 -0
- package/dist/LICENSE-PTSerif-OFL-1.1.txt +94 -0
- package/dist/app-author-command.js +394 -96
- package/dist/app-command.js +2 -1
- package/dist/bin/gezel-main.js +187 -20
- package/dist/handboek-export.js +114 -28
- package/dist/knowledge-command.js +1 -0
- package/dist/page-typography.css +88 -0
- package/dist/tui/index.js +26 -13
- package/package.json +11 -11
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/app-author-command.ts
|
|
4
|
-
import { mkdir as
|
|
5
|
-
import { dirname as
|
|
4
|
+
import { mkdir as mkdir3, readFile as readFile2, readdir, stat, writeFile as writeFile3 } from "fs/promises";
|
|
5
|
+
import { dirname as dirname3, isAbsolute, join as join4 } from "path";
|
|
6
|
+
import { ProjectTypeVersionManifestSchema } from "@bendyline/gezel";
|
|
6
7
|
import {
|
|
7
8
|
GezappSourceError,
|
|
8
9
|
packGezappFromSource,
|
|
@@ -12,117 +13,290 @@ import {
|
|
|
12
13
|
verifyGezapp
|
|
13
14
|
} from "@bendyline/gezel-service/gezapp";
|
|
14
15
|
|
|
15
|
-
// src/app-scaffold.ts
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export const meta = defineScript({
|
|
28
|
-
name: 'records-store',
|
|
29
|
-
description: 'Add and list records in data.json.',
|
|
30
|
-
kind: 'action',
|
|
31
|
-
inputs: {
|
|
32
|
-
action: { type: 'string', description: "'add' or 'list'.", default: 'list' },
|
|
33
|
-
title: { type: 'string', description: 'Title for a new record.', default: '' },
|
|
34
|
-
},
|
|
35
|
-
outputs: {
|
|
36
|
-
records: { type: 'json', description: 'The records after the operation.' },
|
|
37
|
-
},
|
|
38
|
-
requires: ['workspace.read', 'workspace.write'],
|
|
39
|
-
} as const);
|
|
40
|
-
|
|
41
|
-
const input = gezel.input as InferredInput<typeof meta>;
|
|
42
|
-
const raw = await gezel.fs.read('data.json').catch(() => '{"records":[]}');
|
|
43
|
-
const data = JSON.parse(raw) as { records: Array<{ title: string; at: string }> };
|
|
44
|
-
if (input.action === 'add' && input.title) {
|
|
45
|
-
data.records.push({ title: input.title, at: new Date().toISOString() });
|
|
46
|
-
await gezel.fs.write('data.json', JSON.stringify(data, null, 2));
|
|
16
|
+
// src/app-scaffold-page.ts
|
|
17
|
+
function escapeHtml(text) {
|
|
18
|
+
return text.replace(/[&<>"']/g, (character) => {
|
|
19
|
+
const entities = {
|
|
20
|
+
"&": "&",
|
|
21
|
+
"<": "<",
|
|
22
|
+
">": ">",
|
|
23
|
+
'"': """,
|
|
24
|
+
"'": "'"
|
|
25
|
+
};
|
|
26
|
+
return entities[character];
|
|
27
|
+
});
|
|
47
28
|
}
|
|
48
|
-
gezel.output({ records: data.records });
|
|
49
|
-
`;
|
|
50
29
|
function dashboardHtml(name) {
|
|
51
30
|
return `<!doctype html>
|
|
52
31
|
<html lang="en">
|
|
53
32
|
<head>
|
|
54
33
|
<meta charset="utf-8" />
|
|
55
34
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
35
|
+
<meta name="gezel-demo" content="standalone" />
|
|
36
|
+
<title>${escapeHtml(name)}</title>
|
|
56
37
|
<style>
|
|
38
|
+
/* Gezel injects font roles, not a CSS reset or a control/layout framework. */
|
|
57
39
|
:root {
|
|
58
40
|
color-scheme: light dark;
|
|
59
|
-
--bg: #f7f4ee;
|
|
60
|
-
--
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
--bg: #f7f4ee; --ink: #2c2925; --card: #fffdf9;
|
|
42
|
+
--line: #c2b9ab; --muted: #61594f; --accent: #5c6a4a; --error: #a52d28;
|
|
43
|
+
}
|
|
44
|
+
:root[data-theme="light"] { color-scheme: light; }
|
|
45
|
+
:root[data-theme="dark"] {
|
|
46
|
+
color-scheme: dark;
|
|
47
|
+
--bg: #211e1a; --ink: #e8e2d8; --card: #2b2723;
|
|
48
|
+
--line: #766c60; --muted: #c0b6a8; --accent: #bac9a5; --error: #ffb4ab;
|
|
63
49
|
}
|
|
50
|
+
/* The OS is a fallback only; an explicit host theme always wins. */
|
|
64
51
|
@media (prefers-color-scheme: dark) {
|
|
65
|
-
:root {
|
|
66
|
-
|
|
67
|
-
--ink: #e8e2d8;
|
|
68
|
-
--
|
|
69
|
-
--line: #47413a;
|
|
52
|
+
:root:not([data-theme]) {
|
|
53
|
+
color-scheme: dark;
|
|
54
|
+
--bg: #211e1a; --ink: #e8e2d8; --card: #2b2723;
|
|
55
|
+
--line: #766c60; --muted: #c0b6a8; --accent: #bac9a5; --error: #ffb4ab;
|
|
70
56
|
}
|
|
71
57
|
}
|
|
58
|
+
* { box-sizing: border-box; }
|
|
59
|
+
[hidden] { display: none !important; }
|
|
72
60
|
body {
|
|
73
|
-
margin: 0;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
font: 15px/1.5 system-ui, sans-serif;
|
|
61
|
+
margin: 0; padding: clamp(1rem, 4vw, 2rem);
|
|
62
|
+
background: var(--bg); color: var(--ink);
|
|
63
|
+
font-family: var(--font-body, system-ui, sans-serif);
|
|
64
|
+
font-size: 1rem; line-height: 1.5;
|
|
78
65
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
66
|
+
main { max-width: 44rem; margin: auto; }
|
|
67
|
+
h1 { font-family: var(--font-heading, Georgia, serif); font-size: 1.75rem; margin: 0 0 .5rem; }
|
|
68
|
+
p { margin: .5rem 0 1rem; }
|
|
69
|
+
.muted { color: var(--muted); }
|
|
70
|
+
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin: 1rem 0; }
|
|
71
|
+
.toolbar p { flex: 1; margin: 0; }
|
|
72
|
+
[data-gezel-demo-banner] { padding: .75rem; border: 1px solid var(--line); border-radius: 6px; }
|
|
73
|
+
ul { list-style: none; margin: 1rem 0; padding: 0; }
|
|
74
|
+
li { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .75rem; margin-bottom: .5rem; overflow-wrap: anywhere; }
|
|
75
|
+
li time { display: block; color: var(--muted); font-size: .875rem; }
|
|
76
|
+
label { display: block; margin-bottom: .25rem; }
|
|
77
|
+
.entry { display: flex; flex-wrap: wrap; gap: .5rem; }
|
|
78
|
+
input { flex: 1 1 12rem; min-width: 0; }
|
|
79
|
+
button, input {
|
|
80
|
+
font-family: var(--font-ui, system-ui, sans-serif); font-size: 1rem; line-height: 1.5;
|
|
81
|
+
background: var(--card); color: var(--ink); border: 1px solid var(--line);
|
|
82
|
+
border-radius: 6px; padding: .5rem .75rem;
|
|
95
83
|
}
|
|
84
|
+
button { cursor: pointer; }
|
|
85
|
+
button:hover:not(:disabled) { border-color: var(--accent); }
|
|
86
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
|
|
87
|
+
:disabled { opacity: .6; cursor: default; }
|
|
88
|
+
[role="alert"] { color: var(--error); overflow-wrap: anywhere; }
|
|
96
89
|
</style>
|
|
97
90
|
</head>
|
|
98
91
|
<body>
|
|
99
|
-
<
|
|
100
|
-
<
|
|
101
|
-
<
|
|
92
|
+
<main>
|
|
93
|
+
<aside class="toolbar" data-gezel-demo-banner hidden aria-label="Demo">
|
|
94
|
+
<p>Demo \u2014 sample records, saved only for this visit.</p>
|
|
95
|
+
<button id="reset" type="button">Reset demo</button>
|
|
96
|
+
</aside>
|
|
97
|
+
<h1>${escapeHtml(name)}</h1>
|
|
98
|
+
<p class="muted">A place for the things worth keeping.</p>
|
|
99
|
+
<div class="toolbar">
|
|
100
|
+
<p id="status" class="muted" role="status">Loading records\u2026</p>
|
|
101
|
+
<button id="refresh" type="button">Refresh</button>
|
|
102
|
+
</div>
|
|
103
|
+
<p id="load-error" role="alert" hidden></p>
|
|
104
|
+
<ul id="records" aria-label="Records"></ul>
|
|
105
|
+
<p id="readonly" class="muted" hidden>This preview is read-only. Open the page in Gezel to add records.</p>
|
|
106
|
+
<div role="group" aria-label="Add a record">
|
|
107
|
+
<label for="title">New record</label>
|
|
108
|
+
<div class="entry">
|
|
109
|
+
<input id="title" name="title" required autocomplete="off" disabled />
|
|
110
|
+
<button id="add" type="button" disabled>Add record</button>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
<p id="action-error" role="alert" hidden></p>
|
|
114
|
+
</main>
|
|
102
115
|
<script>
|
|
116
|
+
(() => {
|
|
117
|
+
'use strict';
|
|
118
|
+
// The demo initializer never replaces an injected host, including on errors.
|
|
119
|
+
const samples = () => ({ records: [
|
|
120
|
+
{ title: 'Plan the next small step', at: '2026-01-01T12:00:00.000Z' },
|
|
121
|
+
{ title: 'Keep a useful discovery', at: '2026-01-02T12:00:00.000Z' },
|
|
122
|
+
] });
|
|
123
|
+
let demoData = samples();
|
|
124
|
+
const api = window.gezel || window.makeDemoGezel({
|
|
125
|
+
page: { entry: 'dashboard/index.html', typeName: document.title },
|
|
126
|
+
data: { 'data.json': () => structuredClone(demoData) },
|
|
127
|
+
tools: {
|
|
128
|
+
page_add_record: ({ title }) => {
|
|
129
|
+
if (typeof title !== 'string' || !title.trim()) throw new Error('Enter a title for the record.');
|
|
130
|
+
demoData.records.push({
|
|
131
|
+
title: title.trim(),
|
|
132
|
+
at: new Date(Date.UTC(2026, 0, demoData.records.length + 1, 12)).toISOString(),
|
|
133
|
+
});
|
|
134
|
+
return structuredClone(demoData);
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
const demoMode = api.page.mode === 'demo';
|
|
139
|
+
const readOnly = api.page.mode === 'browser';
|
|
103
140
|
const list = document.querySelector('#records');
|
|
141
|
+
const status = document.querySelector('#status');
|
|
142
|
+
const loadError = document.querySelector('#load-error');
|
|
143
|
+
const actionError = document.querySelector('#action-error');
|
|
144
|
+
const title = document.querySelector('#title');
|
|
145
|
+
const add = document.querySelector('#add');
|
|
146
|
+
document.querySelector('[data-gezel-demo-banner]').hidden = !demoMode;
|
|
147
|
+
document.querySelector('#readonly').hidden = !readOnly;
|
|
148
|
+
let ready = false, busy = false, active = false, revision = 0;
|
|
149
|
+
let unwatch = () => {}, untheme = () => {};
|
|
150
|
+
|
|
151
|
+
function errorText(error) {
|
|
152
|
+
return error instanceof Error ? error.message : String(error);
|
|
153
|
+
}
|
|
154
|
+
function showError(element, message = '') {
|
|
155
|
+
element.textContent = message;
|
|
156
|
+
element.hidden = !message;
|
|
157
|
+
}
|
|
158
|
+
function updateControls() {
|
|
159
|
+
title.disabled = add.disabled = readOnly || !ready || busy;
|
|
160
|
+
add.textContent = busy ? 'Adding\u2026' : 'Add record';
|
|
161
|
+
}
|
|
104
162
|
function render(data) {
|
|
163
|
+
if (!data || !Array.isArray(data.records) || data.records.some(record =>
|
|
164
|
+
!record || typeof record.title !== 'string' || typeof record.at !== 'string')) {
|
|
165
|
+
throw new Error('Expected records with a title and date.');
|
|
166
|
+
}
|
|
105
167
|
list.replaceChildren();
|
|
106
168
|
for (const record of data.records) {
|
|
107
169
|
const item = document.createElement('li');
|
|
108
|
-
|
|
170
|
+
const date = document.createElement('time');
|
|
171
|
+
// Workspace strings are content, never HTML.
|
|
172
|
+
item.textContent = record.title;
|
|
173
|
+
date.textContent = record.at.slice(0, 10);
|
|
174
|
+
date.dateTime = record.at;
|
|
175
|
+
item.append(date);
|
|
109
176
|
list.append(item);
|
|
110
177
|
}
|
|
178
|
+
status.textContent = data.records.length
|
|
179
|
+
? data.records.length + (data.records.length === 1 ? ' record' : ' records')
|
|
180
|
+
: 'No records yet. Add the first one below.';
|
|
111
181
|
}
|
|
112
182
|
async function refresh() {
|
|
113
|
-
|
|
183
|
+
const current = ++revision;
|
|
184
|
+
status.textContent = 'Loading records\u2026';
|
|
185
|
+
try {
|
|
186
|
+
const data = await api.data.read('data.json', { as: 'json' });
|
|
187
|
+
if (!active || current !== revision) return;
|
|
188
|
+
render(data);
|
|
189
|
+
ready = true;
|
|
190
|
+
showError(loadError);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (!active || current !== revision) return;
|
|
193
|
+
ready = false;
|
|
194
|
+
status.textContent = 'Records could not be refreshed.';
|
|
195
|
+
showError(loadError, errorText(error) + ' Use Refresh to try again.');
|
|
196
|
+
}
|
|
197
|
+
if (active && current === revision) updateControls();
|
|
114
198
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
await refresh();
|
|
199
|
+
// Gezel's iframe allows scripts, not native form submissions.
|
|
200
|
+
title.addEventListener('keydown', event => {
|
|
201
|
+
if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); add.click(); }
|
|
119
202
|
});
|
|
120
|
-
|
|
203
|
+
add.addEventListener('click', async () => {
|
|
204
|
+
if (busy || readOnly || !ready) return;
|
|
205
|
+
if (!title.value.trim()) {
|
|
206
|
+
showError(actionError, 'Enter a title for the record.');
|
|
207
|
+
title.focus();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
busy = true;
|
|
211
|
+
updateControls();
|
|
212
|
+
showError(actionError);
|
|
213
|
+
try {
|
|
214
|
+
await api.tools.invoke('page_add_record', { title: title.value.trim() });
|
|
215
|
+
if (!active) return;
|
|
216
|
+
title.value = '';
|
|
217
|
+
await refresh();
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (active) showError(actionError, errorText(error));
|
|
220
|
+
} finally {
|
|
221
|
+
busy = false;
|
|
222
|
+
if (active) { updateControls(); if (!title.disabled) title.focus(); }
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
document.querySelector('#refresh').addEventListener('click', refresh);
|
|
226
|
+
document.querySelector('#reset').addEventListener('click', () => {
|
|
227
|
+
if (!demoMode || busy) return;
|
|
228
|
+
demoData = samples();
|
|
229
|
+
title.value = '';
|
|
230
|
+
showError(actionError);
|
|
231
|
+
refresh();
|
|
232
|
+
});
|
|
233
|
+
function applyTheme(theme) {
|
|
234
|
+
document.documentElement.dataset.theme = theme.mode === 'dark' ? 'dark' : 'light';
|
|
235
|
+
}
|
|
236
|
+
function start() {
|
|
237
|
+
if (active) return;
|
|
238
|
+
active = true;
|
|
239
|
+
applyTheme(api.ui.theme);
|
|
240
|
+
untheme = api.ui.onTheme(applyTheme);
|
|
241
|
+
unwatch = api.data.watch('data.json', refresh);
|
|
242
|
+
refresh();
|
|
243
|
+
}
|
|
244
|
+
window.addEventListener('pagehide', () => {
|
|
245
|
+
active = false;
|
|
246
|
+
++revision; // Ignore any read that completes after teardown.
|
|
247
|
+
unwatch(); untheme();
|
|
248
|
+
});
|
|
249
|
+
window.addEventListener('pageshow', start); // Also resume after back/forward cache restoration.
|
|
250
|
+
start();
|
|
251
|
+
})();
|
|
121
252
|
</script>
|
|
122
253
|
</body>
|
|
123
254
|
</html>
|
|
124
255
|
`;
|
|
125
256
|
}
|
|
257
|
+
|
|
258
|
+
// src/app-scaffold.ts
|
|
259
|
+
var SCAFFOLD_ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,63}$/;
|
|
260
|
+
function titleCase(id) {
|
|
261
|
+
return id.split("-").map((part) => part ? part[0].toUpperCase() + part.slice(1) : part).join(" ");
|
|
262
|
+
}
|
|
263
|
+
function shard(id) {
|
|
264
|
+
return id.slice(0, 2).toLowerCase();
|
|
265
|
+
}
|
|
266
|
+
var json = (value) => `${JSON.stringify(value, null, 2)}
|
|
267
|
+
`;
|
|
268
|
+
var STORE_SCRIPT = `import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
|
|
269
|
+
|
|
270
|
+
export const meta = defineScript({
|
|
271
|
+
name: 'records-store',
|
|
272
|
+
description: 'Add and list records in data.json.',
|
|
273
|
+
kind: 'action',
|
|
274
|
+
inputs: {
|
|
275
|
+
action: { type: 'string', description: "'add' or 'list'.", default: 'list' },
|
|
276
|
+
title: { type: 'string', description: 'Title for a new record.', default: '' },
|
|
277
|
+
},
|
|
278
|
+
outputs: {
|
|
279
|
+
records: { type: 'json', description: 'The records after the operation.' },
|
|
280
|
+
},
|
|
281
|
+
requires: ['workspace.read', 'workspace.write'],
|
|
282
|
+
} as const);
|
|
283
|
+
|
|
284
|
+
const input = gezel.input as InferredInput<typeof meta>;
|
|
285
|
+
// The installer seeds this file. A missing/unreadable file is an error, not an empty store.
|
|
286
|
+
const raw = await gezel.fs.read('data.json');
|
|
287
|
+
const data = JSON.parse(raw) as { records: Array<{ title: string; at: string }> };
|
|
288
|
+
if (!Array.isArray(data.records) || data.records.some(record =>
|
|
289
|
+
!record || typeof record.title !== 'string' || typeof record.at !== 'string')) {
|
|
290
|
+
throw new Error('data.json must contain a records array with title and at strings.');
|
|
291
|
+
}
|
|
292
|
+
if (input.action === 'add') {
|
|
293
|
+
const title = input.title.trim();
|
|
294
|
+
if (!title) throw new Error('Enter a title for the record.');
|
|
295
|
+
data.records.push({ title, at: new Date().toISOString() });
|
|
296
|
+
await gezel.fs.write('data.json', JSON.stringify(data, null, 2));
|
|
297
|
+
}
|
|
298
|
+
gezel.output({ records: data.records });
|
|
299
|
+
`;
|
|
126
300
|
function scaffoldGezappSource(id, opts) {
|
|
127
301
|
if (!SCAFFOLD_ID_PATTERN.test(id)) {
|
|
128
302
|
throw new Error(
|
|
@@ -133,6 +307,16 @@ function scaffoldGezappSource(id, opts) {
|
|
|
133
307
|
const roleId = `${id}-lead`;
|
|
134
308
|
const typeDir = `items/project-types/${shard(id)}/${id}`;
|
|
135
309
|
const roleDir = `items/gezel-templates/${shard(roleId)}/${roleId}`;
|
|
310
|
+
const addRecord = {
|
|
311
|
+
description: "Add one record to data.json.",
|
|
312
|
+
script: "records-store",
|
|
313
|
+
inputs: {
|
|
314
|
+
type: "object",
|
|
315
|
+
properties: { title: { type: "string", minLength: 1 } },
|
|
316
|
+
required: ["title"]
|
|
317
|
+
},
|
|
318
|
+
bind: { action: "add" }
|
|
319
|
+
};
|
|
136
320
|
const files = [
|
|
137
321
|
[
|
|
138
322
|
"gezapp.json",
|
|
@@ -153,6 +337,29 @@ The loop:
|
|
|
153
337
|
2. \`gezel app validate .\`
|
|
154
338
|
3. \`gezel app pack .\`
|
|
155
339
|
4. \`gezel app add ${id}-1.0.0.gezapp --yes\` then \`gezel app apply ${id}\` in a project folder.
|
|
340
|
+
|
|
341
|
+
The keeper uses \`add_record\` to update the seeded \`data.json\` through
|
|
342
|
+
\`records-store\`. Read failures are errors; they never reset existing data.
|
|
343
|
+
${opts?.withPage ? `
|
|
344
|
+
Run \`gezel app demo . --out ../${id}-demo\`, then open its
|
|
345
|
+
\`pages/dashboard/index.html\` to try the standalone demo. Sample records stay in memory; **Reset demo** restores them.
|
|
346
|
+
Inside Gezel the same page uses real project data and the page-only
|
|
347
|
+
\`page_add_record\` alias. Names in \`pages.tools\` are excluded from the gezel's
|
|
348
|
+
tool roster, so keep its \`add_record\` alias separate. Both call \`records-store\`.
|
|
349
|
+
The browser preview is read-only; embedded and shared-site modes can run actions
|
|
350
|
+
when the host permits them. A host error never switches the page to demo data.
|
|
351
|
+
|
|
352
|
+
Fonts come from Gezel's injected \`--font-body\`, \`--font-ui\`, and
|
|
353
|
+
\`--font-heading\` variables. The demo exporter supplies the same fonts and components.
|
|
354
|
+
Keep platform assets out of the authored page. The page owns its layout/colors, follows host theme updates, and
|
|
355
|
+
unsubscribes from theme/file watches on teardown. Use explicit button/keyboard
|
|
356
|
+
handlers: the embedded sandbox blocks native form submissions.
|
|
357
|
+
` : ""}
|
|
358
|
+
Authoring references:
|
|
359
|
+
|
|
360
|
+
- [Building Gezel apps](https://github.com/bendyline/gezel/blob/main/docs/building-gezel-apps.md)
|
|
361
|
+
- [Page APIs](https://github.com/bendyline/gezel/blob/main/docs/output-pane-api.md)
|
|
362
|
+
- [Page style guide](https://github.com/bendyline/gezel/blob/main/docs/handboek/technical/gezel-app-page-style-guide.md)
|
|
156
363
|
`
|
|
157
364
|
],
|
|
158
365
|
[
|
|
@@ -192,17 +399,8 @@ The loop:
|
|
|
192
399
|
missionTemplate: "mission.md",
|
|
193
400
|
gezels: [{ templateId: roleId, voorman: true }],
|
|
194
401
|
tools: [
|
|
195
|
-
{
|
|
196
|
-
|
|
197
|
-
description: "Add one record to data.json.",
|
|
198
|
-
script: "records-store",
|
|
199
|
-
inputs: {
|
|
200
|
-
type: "object",
|
|
201
|
-
properties: { title: { type: "string" } },
|
|
202
|
-
required: ["title"]
|
|
203
|
-
},
|
|
204
|
-
bind: { action: "add" }
|
|
205
|
-
}
|
|
402
|
+
{ name: "add_record", ...addRecord },
|
|
403
|
+
...opts?.withPage ? [{ name: "page_add_record", ...addRecord }] : []
|
|
206
404
|
],
|
|
207
405
|
workspaceSeed: ["data.json"],
|
|
208
406
|
...opts?.withPage ? {
|
|
@@ -210,7 +408,7 @@ The loop:
|
|
|
210
408
|
entry: "dashboard/index.html",
|
|
211
409
|
api: 1,
|
|
212
410
|
reads: [{ source: "workspace", path: "data.json" }],
|
|
213
|
-
tools: ["
|
|
411
|
+
tools: ["page_add_record"]
|
|
214
412
|
}
|
|
215
413
|
} : {}
|
|
216
414
|
})
|
|
@@ -280,6 +478,7 @@ import {
|
|
|
280
478
|
gezelNamesInUse,
|
|
281
479
|
pickUnusedGezelName,
|
|
282
480
|
projectLeadGezelId,
|
|
481
|
+
roleForMatching,
|
|
283
482
|
setLogLevel,
|
|
284
483
|
setLogOutput
|
|
285
484
|
} from "@bendyline/gezel";
|
|
@@ -312,9 +511,80 @@ var CliError = class extends Error {
|
|
|
312
511
|
}
|
|
313
512
|
};
|
|
314
513
|
|
|
514
|
+
// src/page-demo-export.ts
|
|
515
|
+
import { createHash as createHash2 } from "crypto";
|
|
516
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
517
|
+
import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
518
|
+
import { dirname as dirname2, join as join3, relative } from "path";
|
|
519
|
+
import { fileURLToPath } from "url";
|
|
520
|
+
import { injectPageDemo, pageDemoBootstrapSource } from "@bendyline/gezel";
|
|
521
|
+
|
|
522
|
+
// ../../scripts/project-page-typography.mjs
|
|
523
|
+
import { readFileSync } from "fs";
|
|
524
|
+
import { join as join2 } from "path";
|
|
525
|
+
function buildProjectPageTypography(uiRoot) {
|
|
526
|
+
const fonts = join2(uiRoot, "src/assets/fonts");
|
|
527
|
+
const faces = readFileSync(join2(fonts, "ui-fonts.css"), "utf8").replace(
|
|
528
|
+
/url\("\.\/([a-z0-9-]+\.woff2)"\)/g,
|
|
529
|
+
(_, name) => `url("data:font/woff2;base64,${readFileSync(join2(fonts, name)).toString("base64")}")`
|
|
530
|
+
);
|
|
531
|
+
return [
|
|
532
|
+
faces,
|
|
533
|
+
readFileSync(join2(fonts, "typography-tokens.css"), "utf8"),
|
|
534
|
+
readFileSync(join2(fonts, "page-defaults.css"), "utf8")
|
|
535
|
+
].join("\n");
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// src/page-demo-export.ts
|
|
539
|
+
function pageDemoAssets() {
|
|
540
|
+
const sourceMode = import.meta.url.endsWith(".ts");
|
|
541
|
+
const fonts = fileURLToPath(new URL("../../ui/src/assets/fonts/", import.meta.url));
|
|
542
|
+
const css = sourceMode ? buildProjectPageTypography(fileURLToPath(new URL("../../ui", import.meta.url))) : readFileSync2(new URL("./page-typography.css", import.meta.url), "utf8");
|
|
543
|
+
const versioned = (stem, extension, source) => ({
|
|
544
|
+
path: `${stem}-${createHash2("sha256").update(source).digest("hex").slice(0, 16)}.${extension}`,
|
|
545
|
+
bytes: Buffer.from(source)
|
|
546
|
+
});
|
|
547
|
+
return [
|
|
548
|
+
versioned("bootstrap", "js", pageDemoBootstrapSource()),
|
|
549
|
+
versioned("typography", "css", css),
|
|
550
|
+
...["LICENSE-HankenGrotesk-OFL-1.1.txt", "LICENSE-PTSerif-OFL-1.1.txt"].map((path) => ({
|
|
551
|
+
path,
|
|
552
|
+
bytes: readFileSync2(sourceMode ? join3(fonts, path) : new URL(`./${path}`, import.meta.url))
|
|
553
|
+
}))
|
|
554
|
+
];
|
|
555
|
+
}
|
|
556
|
+
async function writePageDemoAssets(directory) {
|
|
557
|
+
const assets = pageDemoAssets();
|
|
558
|
+
await mkdir2(directory, { recursive: true });
|
|
559
|
+
for (const asset of assets) await writeFile2(join3(directory, asset.path), asset.bytes);
|
|
560
|
+
return assets;
|
|
561
|
+
}
|
|
562
|
+
async function writePageDemo(directory, files, config, shared) {
|
|
563
|
+
const script = shared.assets.find((file) => file.path.endsWith(".js"));
|
|
564
|
+
const style = shared.assets.find((file) => file.path.endsWith(".css"));
|
|
565
|
+
for (const file of files) {
|
|
566
|
+
if (!file.path || file.path.split(/[\\/]/).some((part) => !part || part === "." || part === "..") || /[:\\]/.test(file.path)) {
|
|
567
|
+
throw new Error(`Unsafe demo asset path: ${file.path}`);
|
|
568
|
+
}
|
|
569
|
+
const target = join3(directory, file.path);
|
|
570
|
+
let bytes = file.bytes;
|
|
571
|
+
if (/\.html?$/i.test(file.path)) {
|
|
572
|
+
const url = (name) => relative(dirname2(target), join3(shared.directory, name)).split(/[\\/]/).map((part) => part === ".." ? part : encodeURIComponent(part)).join("/");
|
|
573
|
+
bytes = Buffer.from(
|
|
574
|
+
injectPageDemo(bytes.toString("utf8"), config, {
|
|
575
|
+
scriptUrl: url(script.path),
|
|
576
|
+
styleUrl: url(style.path)
|
|
577
|
+
})
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
await mkdir2(dirname2(target), { recursive: true });
|
|
581
|
+
await writeFile2(target, bytes);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
315
585
|
// src/app-author-command.ts
|
|
316
586
|
function resolvePath(input) {
|
|
317
|
-
return isAbsolute(input) ? input :
|
|
587
|
+
return isAbsolute(input) ? input : join4(process.cwd(), input);
|
|
318
588
|
}
|
|
319
589
|
function formatFinding(finding) {
|
|
320
590
|
const where = finding.file || ".";
|
|
@@ -388,7 +658,7 @@ async function runAppPack(folder, opts = {}) {
|
|
|
388
658
|
const out = resolvePath(
|
|
389
659
|
opts.out ?? `${packed.manifest.entry.projectType}-${packed.manifest.entry.version}.gezapp`
|
|
390
660
|
);
|
|
391
|
-
await
|
|
661
|
+
await writeFile3(out, packed.buffer);
|
|
392
662
|
if (opts.json) {
|
|
393
663
|
console.log(
|
|
394
664
|
JSON.stringify(
|
|
@@ -420,13 +690,40 @@ async function runAppPack(folder, opts = {}) {
|
|
|
420
690
|
process.exitCode = 1;
|
|
421
691
|
}
|
|
422
692
|
}
|
|
693
|
+
async function runAppDemo(folder, opts) {
|
|
694
|
+
const source = resolvePath(folder);
|
|
695
|
+
const packed = await packGezappFromSource(source);
|
|
696
|
+
const parsed = readGezapp(packed.buffer);
|
|
697
|
+
const { projectType, version } = parsed.manifest.entry;
|
|
698
|
+
const prefix = `items/project-types/${projectType.slice(0, 2)}/${projectType}/versions/${version}/`;
|
|
699
|
+
const manifest = ProjectTypeVersionManifestSchema.parse(
|
|
700
|
+
JSON.parse(parsed.files.get(`${prefix}manifest.json`).toString("utf8"))
|
|
701
|
+
);
|
|
702
|
+
if (!manifest.pages) throw new CliError("This app does not have a page to preview.");
|
|
703
|
+
const pagePrefix = `${prefix}pages/`;
|
|
704
|
+
const files = [...parsed.files].filter(([path]) => path.startsWith(pagePrefix)).map(([path, bytes]) => ({ path: path.slice(pagePrefix.length), bytes }));
|
|
705
|
+
if (!files.some((file) => file.path === manifest.pages.entry))
|
|
706
|
+
throw new CliError("The page entry is missing.");
|
|
707
|
+
const out = resolvePath(opts.out);
|
|
708
|
+
await mkdir3(dirname3(out), { recursive: true });
|
|
709
|
+
await mkdir3(out);
|
|
710
|
+
const directory = join4(out, "_gezel-demo");
|
|
711
|
+
const assets = await writePageDemoAssets(directory);
|
|
712
|
+
await writePageDemo(
|
|
713
|
+
join4(out, "pages"),
|
|
714
|
+
files,
|
|
715
|
+
{ imports: manifest.pages.imports },
|
|
716
|
+
{ directory, assets }
|
|
717
|
+
);
|
|
718
|
+
console.log(`Demo exported. Open ${join4(out, "pages", manifest.pages.entry)}`);
|
|
719
|
+
}
|
|
423
720
|
async function runAppNew(id, opts = {}) {
|
|
424
721
|
if (!SCAFFOLD_ID_PATTERN.test(id)) {
|
|
425
722
|
throw new CliError(
|
|
426
723
|
`"${id}" is not a valid app id \u2014 use lowercase letters, digits, and hyphens (2-64 chars).`
|
|
427
724
|
);
|
|
428
725
|
}
|
|
429
|
-
const target =
|
|
726
|
+
const target = join4(opts.dir ? resolvePath(opts.dir) : process.cwd(), id);
|
|
430
727
|
const existing = await statKind(target);
|
|
431
728
|
if (existing === "file") throw new CliError(`${target} already exists.`);
|
|
432
729
|
if (existing === "dir" && (await readdir(target)).length > 0) {
|
|
@@ -436,9 +733,9 @@ async function runAppNew(id, opts = {}) {
|
|
|
436
733
|
...opts.withPage ? { withPage: true } : {}
|
|
437
734
|
});
|
|
438
735
|
for (const [rel, content] of files) {
|
|
439
|
-
const abs =
|
|
440
|
-
await
|
|
441
|
-
await
|
|
736
|
+
const abs = join4(target, rel);
|
|
737
|
+
await mkdir3(dirname3(abs), { recursive: true });
|
|
738
|
+
await writeFile3(abs, content);
|
|
442
739
|
}
|
|
443
740
|
console.log(`Scaffolded ${id} (${files.length} files) in ${target}`);
|
|
444
741
|
console.log("Next:");
|
|
@@ -457,9 +754,9 @@ async function runAppSchemas(opts = {}) {
|
|
|
457
754
|
}
|
|
458
755
|
if (opts.out) {
|
|
459
756
|
const dir = resolvePath(opts.out);
|
|
460
|
-
await
|
|
757
|
+
await mkdir3(dir, { recursive: true });
|
|
461
758
|
for (const [filename, content] of files) {
|
|
462
|
-
await
|
|
759
|
+
await writeFile3(join4(dir, filename), content);
|
|
463
760
|
}
|
|
464
761
|
console.log(`Wrote ${files.length} JSON Schemas to ${dir}`);
|
|
465
762
|
return;
|
|
@@ -469,6 +766,7 @@ async function runAppSchemas(opts = {}) {
|
|
|
469
766
|
console.log("Use --out <dir> to write the files, or --json for one combined object.");
|
|
470
767
|
}
|
|
471
768
|
export {
|
|
769
|
+
runAppDemo,
|
|
472
770
|
runAppNew,
|
|
473
771
|
runAppPack,
|
|
474
772
|
runAppSchemas,
|
package/dist/app-command.js
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
gezelNamesInUse,
|
|
18
18
|
pickUnusedGezelName,
|
|
19
19
|
projectLeadGezelId,
|
|
20
|
+
roleForMatching,
|
|
20
21
|
setLogLevel,
|
|
21
22
|
setLogOutput
|
|
22
23
|
} from "@bendyline/gezel";
|
|
@@ -325,7 +326,7 @@ function parseParamFlags(flags) {
|
|
|
325
326
|
}
|
|
326
327
|
function printPlan(plan) {
|
|
327
328
|
const roles = plan.gezels.map(
|
|
328
|
-
(gezel) => `${gezel.templateId}${gezel.voorman ? " (
|
|
329
|
+
(gezel) => `${gezel.templateId}${gezel.voorman ? " (crew lead" : " ("}${gezel.reuse ? ", reused)" : gezel.voorman ? ", new)" : "new)"}`
|
|
329
330
|
);
|
|
330
331
|
if (roles.length > 0) console.log(` roles: ${roles.join(", ")}`);
|
|
331
332
|
if (plan.scripts.length > 0) console.log(` scripts: ${plan.scripts.join(", ")}`);
|