@bendyline/gezel-cli 1.2.7 → 1.2.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.
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/app-author-command.ts
4
- import { mkdir as mkdir2, readFile as readFile2, readdir, stat, writeFile as writeFile2 } from "fs/promises";
5
- import { dirname as dirname2, isAbsolute, join as join2 } from "path";
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
- var SCAFFOLD_ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,63}$/;
17
- function titleCase(id) {
18
- return id.split("-").map((part) => part ? part[0].toUpperCase() + part.slice(1) : part).join(" ");
19
- }
20
- function shard(id) {
21
- return id.slice(0, 2).toLowerCase();
22
- }
23
- var json = (value) => `${JSON.stringify(value, null, 2)}
24
- `;
25
- var STORE_SCRIPT = `import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
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
+ "&": "&amp;",
21
+ "<": "&lt;",
22
+ ">": "&gt;",
23
+ '"': "&quot;",
24
+ "'": "&#39;"
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
- --ink: #2c2925;
61
- --card: #fffdf9;
62
- --line: #d9d2c6;
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
- --bg: #211e1a;
67
- --ink: #e8e2d8;
68
- --card: #2b2723;
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
- padding: 1.5rem;
75
- background: var(--bg);
76
- color: var(--ink);
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
- h1 { font-size: 1.2rem; margin: 0 0 1rem; }
80
- ul { list-style: none; margin: 0; padding: 0; }
81
- li {
82
- background: var(--card);
83
- border: 1px solid var(--line);
84
- border-radius: 4px;
85
- padding: 0.5rem 0.75rem;
86
- margin-bottom: 0.5rem;
87
- }
88
- button {
89
- background: var(--card);
90
- color: var(--ink);
91
- border: 1px solid var(--line);
92
- border-radius: 4px;
93
- padding: 0.4rem 0.9rem;
94
- cursor: pointer;
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
- <h1>${name}</h1>
100
- <ul id="records"></ul>
101
- <button id="add">Add a record</button>
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
- item.textContent = record.title + ' \u2014 ' + record.at.slice(0, 10);
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
- render(await gezel.data.read('data.json', { as: 'json' }));
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
- gezel.data.watch('data.json', refresh);
116
- document.querySelector('#add').addEventListener('click', async () => {
117
- await gezel.tools.invoke('add_record', { title: 'Added from the page' });
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
- refresh();
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
- name: "add_record",
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: ["add_record"]
411
+ tools: ["page_add_record"]
214
412
  }
215
413
  } : {}
216
414
  })
@@ -312,9 +510,80 @@ var CliError = class extends Error {
312
510
  }
313
511
  };
314
512
 
513
+ // src/page-demo-export.ts
514
+ import { createHash as createHash2 } from "crypto";
515
+ import { readFileSync as readFileSync2 } from "fs";
516
+ import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
517
+ import { dirname as dirname2, join as join3, relative } from "path";
518
+ import { fileURLToPath } from "url";
519
+ import { injectPageDemo, pageDemoBootstrapSource } from "@bendyline/gezel";
520
+
521
+ // ../../scripts/project-page-typography.mjs
522
+ import { readFileSync } from "fs";
523
+ import { join as join2 } from "path";
524
+ function buildProjectPageTypography(uiRoot) {
525
+ const fonts = join2(uiRoot, "src/assets/fonts");
526
+ const faces = readFileSync(join2(fonts, "ui-fonts.css"), "utf8").replace(
527
+ /url\("\.\/([a-z0-9-]+\.woff2)"\)/g,
528
+ (_, name) => `url("data:font/woff2;base64,${readFileSync(join2(fonts, name)).toString("base64")}")`
529
+ );
530
+ return [
531
+ faces,
532
+ readFileSync(join2(fonts, "typography-tokens.css"), "utf8"),
533
+ readFileSync(join2(fonts, "page-defaults.css"), "utf8")
534
+ ].join("\n");
535
+ }
536
+
537
+ // src/page-demo-export.ts
538
+ function pageDemoAssets() {
539
+ const sourceMode = import.meta.url.endsWith(".ts");
540
+ const fonts = fileURLToPath(new URL("../../ui/src/assets/fonts/", import.meta.url));
541
+ const css = sourceMode ? buildProjectPageTypography(fileURLToPath(new URL("../../ui", import.meta.url))) : readFileSync2(new URL("./page-typography.css", import.meta.url), "utf8");
542
+ const versioned = (stem, extension, source) => ({
543
+ path: `${stem}-${createHash2("sha256").update(source).digest("hex").slice(0, 16)}.${extension}`,
544
+ bytes: Buffer.from(source)
545
+ });
546
+ return [
547
+ versioned("bootstrap", "js", pageDemoBootstrapSource()),
548
+ versioned("typography", "css", css),
549
+ ...["LICENSE-HankenGrotesk-OFL-1.1.txt", "LICENSE-PTSerif-OFL-1.1.txt"].map((path) => ({
550
+ path,
551
+ bytes: readFileSync2(sourceMode ? join3(fonts, path) : new URL(`./${path}`, import.meta.url))
552
+ }))
553
+ ];
554
+ }
555
+ async function writePageDemoAssets(directory) {
556
+ const assets = pageDemoAssets();
557
+ await mkdir2(directory, { recursive: true });
558
+ for (const asset of assets) await writeFile2(join3(directory, asset.path), asset.bytes);
559
+ return assets;
560
+ }
561
+ async function writePageDemo(directory, files, config, shared) {
562
+ const script = shared.assets.find((file) => file.path.endsWith(".js"));
563
+ const style = shared.assets.find((file) => file.path.endsWith(".css"));
564
+ for (const file of files) {
565
+ if (!file.path || file.path.split(/[\\/]/).some((part) => !part || part === "." || part === "..") || /[:\\]/.test(file.path)) {
566
+ throw new Error(`Unsafe demo asset path: ${file.path}`);
567
+ }
568
+ const target = join3(directory, file.path);
569
+ let bytes = file.bytes;
570
+ if (/\.html?$/i.test(file.path)) {
571
+ const url = (name) => relative(dirname2(target), join3(shared.directory, name)).split(/[\\/]/).map((part) => part === ".." ? part : encodeURIComponent(part)).join("/");
572
+ bytes = Buffer.from(
573
+ injectPageDemo(bytes.toString("utf8"), config, {
574
+ scriptUrl: url(script.path),
575
+ styleUrl: url(style.path)
576
+ })
577
+ );
578
+ }
579
+ await mkdir2(dirname2(target), { recursive: true });
580
+ await writeFile2(target, bytes);
581
+ }
582
+ }
583
+
315
584
  // src/app-author-command.ts
316
585
  function resolvePath(input) {
317
- return isAbsolute(input) ? input : join2(process.cwd(), input);
586
+ return isAbsolute(input) ? input : join4(process.cwd(), input);
318
587
  }
319
588
  function formatFinding(finding) {
320
589
  const where = finding.file || ".";
@@ -388,7 +657,7 @@ async function runAppPack(folder, opts = {}) {
388
657
  const out = resolvePath(
389
658
  opts.out ?? `${packed.manifest.entry.projectType}-${packed.manifest.entry.version}.gezapp`
390
659
  );
391
- await writeFile2(out, packed.buffer);
660
+ await writeFile3(out, packed.buffer);
392
661
  if (opts.json) {
393
662
  console.log(
394
663
  JSON.stringify(
@@ -420,13 +689,40 @@ async function runAppPack(folder, opts = {}) {
420
689
  process.exitCode = 1;
421
690
  }
422
691
  }
692
+ async function runAppDemo(folder, opts) {
693
+ const source = resolvePath(folder);
694
+ const packed = await packGezappFromSource(source);
695
+ const parsed = readGezapp(packed.buffer);
696
+ const { projectType, version } = parsed.manifest.entry;
697
+ const prefix = `items/project-types/${projectType.slice(0, 2)}/${projectType}/versions/${version}/`;
698
+ const manifest = ProjectTypeVersionManifestSchema.parse(
699
+ JSON.parse(parsed.files.get(`${prefix}manifest.json`).toString("utf8"))
700
+ );
701
+ if (!manifest.pages) throw new CliError("This app does not have a page to preview.");
702
+ const pagePrefix = `${prefix}pages/`;
703
+ const files = [...parsed.files].filter(([path]) => path.startsWith(pagePrefix)).map(([path, bytes]) => ({ path: path.slice(pagePrefix.length), bytes }));
704
+ if (!files.some((file) => file.path === manifest.pages.entry))
705
+ throw new CliError("The page entry is missing.");
706
+ const out = resolvePath(opts.out);
707
+ await mkdir3(dirname3(out), { recursive: true });
708
+ await mkdir3(out);
709
+ const directory = join4(out, "_gezel-demo");
710
+ const assets = await writePageDemoAssets(directory);
711
+ await writePageDemo(
712
+ join4(out, "pages"),
713
+ files,
714
+ { imports: manifest.pages.imports },
715
+ { directory, assets }
716
+ );
717
+ console.log(`Demo exported. Open ${join4(out, "pages", manifest.pages.entry)}`);
718
+ }
423
719
  async function runAppNew(id, opts = {}) {
424
720
  if (!SCAFFOLD_ID_PATTERN.test(id)) {
425
721
  throw new CliError(
426
722
  `"${id}" is not a valid app id \u2014 use lowercase letters, digits, and hyphens (2-64 chars).`
427
723
  );
428
724
  }
429
- const target = join2(opts.dir ? resolvePath(opts.dir) : process.cwd(), id);
725
+ const target = join4(opts.dir ? resolvePath(opts.dir) : process.cwd(), id);
430
726
  const existing = await statKind(target);
431
727
  if (existing === "file") throw new CliError(`${target} already exists.`);
432
728
  if (existing === "dir" && (await readdir(target)).length > 0) {
@@ -436,9 +732,9 @@ async function runAppNew(id, opts = {}) {
436
732
  ...opts.withPage ? { withPage: true } : {}
437
733
  });
438
734
  for (const [rel, content] of files) {
439
- const abs = join2(target, rel);
440
- await mkdir2(dirname2(abs), { recursive: true });
441
- await writeFile2(abs, content);
735
+ const abs = join4(target, rel);
736
+ await mkdir3(dirname3(abs), { recursive: true });
737
+ await writeFile3(abs, content);
442
738
  }
443
739
  console.log(`Scaffolded ${id} (${files.length} files) in ${target}`);
444
740
  console.log("Next:");
@@ -457,9 +753,9 @@ async function runAppSchemas(opts = {}) {
457
753
  }
458
754
  if (opts.out) {
459
755
  const dir = resolvePath(opts.out);
460
- await mkdir2(dir, { recursive: true });
756
+ await mkdir3(dir, { recursive: true });
461
757
  for (const [filename, content] of files) {
462
- await writeFile2(join2(dir, filename), content);
758
+ await writeFile3(join4(dir, filename), content);
463
759
  }
464
760
  console.log(`Wrote ${files.length} JSON Schemas to ${dir}`);
465
761
  return;
@@ -469,6 +765,7 @@ async function runAppSchemas(opts = {}) {
469
765
  console.log("Use --out <dir> to write the files, or --json for one combined object.");
470
766
  }
471
767
  export {
768
+ runAppDemo,
472
769
  runAppNew,
473
770
  runAppPack,
474
771
  runAppSchemas,