create-foliwake 0.0.0-stage → 0.3.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/LICENSE +202 -0
  3. package/README.md +60 -2
  4. package/dist/bin.d.ts +2 -0
  5. package/dist/bin.js +16 -0
  6. package/dist/cli.d.ts +8 -0
  7. package/dist/cli.js +88 -0
  8. package/dist/create.d.ts +50 -0
  9. package/dist/create.js +250 -0
  10. package/dist/destination.d.ts +47 -0
  11. package/dist/destination.js +243 -0
  12. package/dist/editor-files.d.ts +6 -0
  13. package/dist/editor-files.js +39 -0
  14. package/dist/files.d.ts +26 -0
  15. package/dist/files.js +94 -0
  16. package/dist/git.d.ts +22 -0
  17. package/dist/git.js +64 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.js +7 -0
  20. package/dist/install.d.ts +12 -0
  21. package/dist/install.js +18 -0
  22. package/dist/options.d.ts +48 -0
  23. package/dist/options.js +54 -0
  24. package/dist/prompts.d.ts +16 -0
  25. package/dist/prompts.js +67 -0
  26. package/dist/starters.d.ts +20 -0
  27. package/dist/starters.js +61 -0
  28. package/dist/validate.d.ts +3 -0
  29. package/dist/validate.js +12 -0
  30. package/package.json +64 -3
  31. package/starters/examples/components/quiz/quiz.css +33 -0
  32. package/starters/examples/components/quiz/quiz.example.md +29 -0
  33. package/starters/examples/components/quiz/quiz.js +36 -0
  34. package/starters/examples/components/quiz/quiz.json +14 -0
  35. package/starters/examples/components/steps/steps.css +38 -0
  36. package/starters/examples/components/steps/steps.example.md +25 -0
  37. package/starters/examples/components/steps/steps.json +8 -0
  38. package/starters/examples/content/blocks.md +49 -0
  39. package/starters/examples/content/index.md +44 -0
  40. package/starters/minimal/components/note/note.css +15 -0
  41. package/starters/minimal/components/note/note.example.md +23 -0
  42. package/starters/minimal/components/note/note.json +8 -0
  43. package/starters/minimal/content/images/foliwake-logo.png +0 -0
  44. package/starters/minimal/content/index.md +32 -0
  45. package/starters/react/components/poll/poll.css +32 -0
  46. package/starters/react/components/poll/poll.example.md +26 -0
  47. package/starters/react/components/poll/poll.js +35 -0
  48. package/starters/react/components/poll/poll.json +13 -0
  49. package/starters/react/scripts/react-view.js +22 -0
  50. package/starters/shared/README.md +104 -0
  51. package/starters/shared/_github/actions/foliwake-request/action.yml +45 -0
  52. package/starters/shared/_github/scripts/foliwake-report.py +68 -0
  53. package/starters/shared/_github/workflows/branch-preview.yml +104 -0
  54. package/starters/shared/_github/workflows/frontend-checks.yml +28 -0
  55. package/starters/shared/_github/workflows/production.yml +134 -0
  56. package/starters/shared/_gitignore +8 -0
  57. package/starters/shared/jsconfig.json +16 -0
  58. package/starters/shared/scripts/components.js +284 -0
  59. package/starters/shared/site.yaml +2 -0
  60. package/starters/shared/styles/styles.css +106 -0
  61. package/starters/shared/tests/site.test.mjs +21 -0
  62. package/starters/shared/tests/workflows.test.mjs +84 -0
  63. package/starters/storybook/_storybook/main.js +46 -0
  64. package/starters/storybook/_storybook/preview.js +7 -0
  65. package/starters/storybook/_storybook/run.mjs +25 -0
  66. package/starters/storybook/pnpm-workspace.yaml +8 -0
  67. package/vendor/react.LICENSE.txt +21 -0
  68. package/vendor/react.js +32 -0
@@ -0,0 +1,29 @@
1
+ # Quiz
2
+
3
+ A question with answers to choose from; `[x]` marks the right ones, and `{#id}` at the end of an answer names it in the events (all answers or none; without ids the answers are `o1`, `o2`, … in their order). The page shows the answers as buttons (`quiz.js`, with block-kit): a click sends the event `block:answer`, the first right answer also `block:complete`.
4
+
5
+ <!-- example: One right answer -->
6
+
7
+ :::quiz
8
+
9
+ ### Which file defines the fields of a block?
10
+
11
+ - [ ] `styles/styles.css` {#styles}
12
+ - [x] `components/<name>/<name>.json` {#definition}
13
+ - [ ] `content/index.md` {#page}
14
+
15
+ :::
16
+
17
+ <!-- example: With an explanation {#explained} -->
18
+
19
+ :::quiz
20
+
21
+ ### Which of these are block files?
22
+
23
+ - [x] `components/quiz/quiz.css` {#css}
24
+ - [x] `components/quiz/quiz.js` {#js}
25
+ - [ ] `content/blocks.md` {#page}
26
+
27
+ The explanation is shown after an answer.
28
+
29
+ :::
@@ -0,0 +1,36 @@
1
+ // quiz: turns each answer into a button and says whether it was right.
2
+ // The loader (scripts/components.js) calls the block's init once for every
3
+ // <div data-component="quiz"> on the page; defineBlock('quiz', …) makes it from
4
+ // the setup below, which gets the fields by name (data-field, never by position,
5
+ // so editors can add an explanation freely) and `ctx`. ctx.list renders a button
6
+ // into each answer of the server list, ctx.state re-renders them when it changes,
7
+ // ctx.emit sends the bubbling events "block:answer" and "block:complete" with
8
+ // {key, block, ...detail}, and ctx.t reads the labels of quiz.json `ui`.
9
+ // An answer's id is its `{#id}`; without ids (they are optional) it is o1, o2, … by position.
10
+ import { defineBlock, html, nothing } from '@foliwake/block-kit';
11
+
12
+ export default defineBlock('quiz', ({ options = [] }, ctx) => {
13
+ const answered = ctx.state([]); // indexes of the answers clicked, in order
14
+ const content = new Map(); // each answer's authored nodes, moved into its button
15
+ let complete = false;
16
+
17
+ function choose(index) {
18
+ if (!answered.value.includes(index)) answered.value = [...answered.value, index];
19
+ const { id, correct } = options[index];
20
+ ctx.emit('answer', { selected: [id || `o${index + 1}`], correct, graded: 'local' });
21
+ if (correct && !complete) {
22
+ complete = true;
23
+ ctx.emit('complete', {});
24
+ }
25
+ }
26
+
27
+ ctx.list('options', (item, option, index) => {
28
+ if (!content.has(item)) content.set(item, [...item.childNodes]);
29
+ const result = answered.value.includes(index) ? (option.correct ? 'right' : 'wrong') : null;
30
+ return html`<button type="button" data-answer=${index} data-result=${result ?? nothing}
31
+ aria-label=${result ? `${option.text}: ${ctx.t(result)}` : nothing} @click=${() => choose(index)}>${content.get(item)}</button>`;
32
+ });
33
+ ctx.effect(() => {
34
+ ctx.root.dataset.quiz = answered.value.length > 0 ? 'answered' : 'ready';
35
+ });
36
+ });
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "../../.foliwake/schemas/block-1.schema.json",
3
+ "label": { "en": "Quiz" },
4
+ "fields": [
5
+ { "name": "question", "type": "heading", "level": 3, "label": { "en": "Question" } },
6
+ { "name": "options", "type": "choices", "correct": { "": "at-least-one" }, "label": { "en": "Answers" } },
7
+ { "name": "explanation", "type": "text", "min": 0, "max": null, "label": { "en": "Explanation, shown after an answer" } }
8
+ ],
9
+ "ui": { "en": { "right": "right", "wrong": "not right" } },
10
+ "events": {
11
+ "answer": { "detail": { "selected": "string[]", "correct": "boolean", "graded": "string" } },
12
+ "complete": {}
13
+ }
14
+ }
@@ -0,0 +1,38 @@
1
+ /* steps: a numbered sequence, written as a bullet list. CSS only (no steps.js).
2
+ HTML: <div data-component="steps">[<h3 data-field="title">]<ul data-field="items"><li data-item>… */
3
+
4
+ @layer blocks {
5
+ [data-component="steps"] {
6
+ & [data-field="title"] { margin: 0 0 0.75rem; font-size: 1.05rem; }
7
+
8
+ & [data-field="items"] {
9
+ counter-reset: step;
10
+ list-style: none;
11
+ margin: 0;
12
+ padding: 0;
13
+ }
14
+
15
+ & [data-item] {
16
+ counter-increment: step;
17
+ position: relative;
18
+ padding-left: 2.5rem;
19
+ margin: 0.5rem 0;
20
+ }
21
+
22
+ & [data-item]::before {
23
+ content: counter(step);
24
+ position: absolute;
25
+ left: 0;
26
+ top: 0.1rem;
27
+ width: 1.75rem;
28
+ height: 1.75rem;
29
+ border-radius: 50%;
30
+ display: grid;
31
+ place-items: center;
32
+ font-size: 0.85rem;
33
+ font-weight: 600;
34
+ color: var(--color-page);
35
+ background: var(--color-accent);
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,25 @@
1
+ # Steps
2
+
3
+ A numbered list of steps, with an optional title.
4
+
5
+ <!-- example: Two steps -->
6
+
7
+ :::steps
8
+
9
+ - Write the page.
10
+ - Publish it.
11
+
12
+ :::
13
+
14
+ <!-- example: With a title {#titled} -->
15
+
16
+ :::steps
17
+
18
+ ### Publish a change
19
+
20
+ - Edit a page or a block.
21
+ - Check it locally with `foliwake dev`.
22
+ - Push a branch: the branch preview shows it.
23
+ - Merge into main and release the preview.
24
+
25
+ :::
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "../../.foliwake/schemas/block-1.schema.json",
3
+ "label": { "en": "Steps" },
4
+ "fields": [
5
+ { "name": "title", "type": "heading", "level": 3, "min": 0, "label": { "en": "Title" } },
6
+ { "name": "items", "type": "list", "minItems": 2, "label": { "en": "Steps" } }
7
+ ]
8
+ }
@@ -0,0 +1,49 @@
1
+ ---
2
+ id: blocks
3
+ path: /blocks
4
+ title: Blocks
5
+ description: Every block of the examples template.
6
+ ---
7
+
8
+ # Blocks
9
+
10
+ A block starts with a line `:::name` and ends with a line `:::`. Inside, each field is ordinary Markdown: a heading, a paragraph, a list. The engine checks every block against its definition (`components/<name>/<name>.json`) and reports a clear error instead of guessing.
11
+
12
+ ## Note
13
+
14
+ :::note
15
+
16
+ A note needs only text; the title is optional.
17
+
18
+ :::
19
+
20
+ ## Steps
21
+
22
+ :::steps
23
+
24
+ ### Publish a change
25
+
26
+ - Edit a page or a block.
27
+ - Check it locally with `foliwake dev`.
28
+ - Push a branch: the branch preview shows it.
29
+ - Merge into main: the preview is rebuilt, and you release it in the admin.
30
+
31
+ :::
32
+
33
+ ---
34
+
35
+ ## Quiz
36
+
37
+ The quiz block has JavaScript (`components/quiz/quiz.js`). Mark the right answers with `[x]`; `{#id}` names each answer in the events the block sends.
38
+
39
+ :::quiz
40
+
41
+ ### Which file defines the fields of a block?
42
+
43
+ - [ ] `styles/styles.css` {#styles}
44
+ - [x] `components/<name>/<name>.json` {#definition}
45
+ - [ ] `content/index.md` {#page}
46
+
47
+ The definition lists the fields in order, each with its type.
48
+
49
+ :::
@@ -0,0 +1,44 @@
1
+ ---
2
+ id: home
3
+ path: /
4
+ title: Home
5
+ description: A Foliwake site created with create-foliwake (examples template).
6
+ ---
7
+
8
+ ![Foliwake](./images/foliwake-logo.png)
9
+
10
+ # Your Foliwake site is running
11
+
12
+ Foliwake turns Markdown pages like this one into fast, plain HTML, and the blocks in `components/` give them their look and behaviour.
13
+
14
+ ## Try this now
15
+
16
+ 1. **Edit this page.** Open `content/index.md`, change a sentence and save: the browser reloads.
17
+ 2. **See your blocks.** Open [the blocks page](/blocks) of this template, or [the block catalog](/_dev/blocks): every block with its examples.
18
+ 3. **Make your own block.** With the Foliwake CLI, run `foliwake blocks new callout --js --example`, then look for it in the catalog.
19
+
20
+ :::note
21
+
22
+ ### This is a block
23
+
24
+ The box around this text is the block `note`. Its fields are defined in `components/note/note.json` and its look in `components/note/note.css`.
25
+
26
+ :::
27
+
28
+ ---
29
+
30
+ ## Next steps
31
+
32
+ :::steps
33
+
34
+ - Change the look of every page in `styles/styles.css`.
35
+ - Write a page: a Markdown file in `content/` with `id`, `path` and `title` in its front matter, like this one.
36
+ - Commit and push: the GitHub workflows check every change (see `README.md`).
37
+
38
+ :::
39
+
40
+ ---
41
+
42
+ ## When you're ready
43
+
44
+ Check the code with `npx @foliwake/site-check`, push the repository to GitHub and connect it to your site in the Foliwake admin: every branch gets a preview. `README.md` has the rest, and the [Quickstart](https://docs.foliwake.dev/guide/quickstart) walks you through it.
@@ -0,0 +1,15 @@
1
+ /* note: a short remark with an optional title.
2
+ Definition: note.json. HTML: <div data-component="note">[<h3 data-field="title">]<div data-field="text"><p>… */
3
+
4
+ @layer blocks {
5
+ [data-component="note"] {
6
+ border-left: 4px solid var(--color-accent);
7
+
8
+ & [data-field="title"] {
9
+ margin: 0 0 0.5rem;
10
+ font-size: 1.05rem;
11
+ }
12
+
13
+ & p:last-child { margin-bottom: 0; }
14
+ }
15
+ }
@@ -0,0 +1,23 @@
1
+ # Note
2
+
3
+ A short remark next to the text. The engine shows these examples on `/_dev/blocks` (in `foliwake dev`) and in the block catalog for authors; each `<!-- example: … -->` line starts one example.
4
+
5
+ <!-- example: Text only -->
6
+
7
+ :::note
8
+
9
+ A note needs only text.
10
+
11
+ :::
12
+
13
+ <!-- example: With a title {#titled} -->
14
+
15
+ :::note
16
+
17
+ ### Remember
18
+
19
+ The title is optional: a `###` heading as the first line of the block.
20
+
21
+ The text can have **several** paragraphs.
22
+
23
+ :::
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "../../.foliwake/schemas/block-1.schema.json",
3
+ "label": { "en": "Note" },
4
+ "fields": [
5
+ { "name": "title", "type": "heading", "level": 3, "min": 0, "label": { "en": "Title" } },
6
+ { "name": "text", "type": "text", "min": 1, "max": null, "label": { "en": "Text" } }
7
+ ]
8
+ }
@@ -0,0 +1,32 @@
1
+ ---
2
+ id: home
3
+ path: /
4
+ title: Home
5
+ description: A Foliwake site created with create-foliwake.
6
+ ---
7
+
8
+ ![Foliwake](./images/foliwake-logo.png)
9
+
10
+ # Your Foliwake site is running
11
+
12
+ Foliwake turns Markdown pages like this one into fast, plain HTML, and the blocks in `components/` give them their look and behaviour.
13
+
14
+ ## Try this now
15
+
16
+ 1. **Edit this page.** Open `content/index.md`, change a sentence and save: the browser reloads.
17
+ 2. **See your blocks.** Open [the block catalog](/_dev/blocks): every block with its examples.
18
+ 3. **Make your own block.** With the Foliwake CLI, run `foliwake blocks new callout --js --example`, then look for it in the catalog.
19
+
20
+ :::note
21
+
22
+ ### This is a block
23
+
24
+ The box around this text is the block `note`. Its fields are defined in `components/note/note.json` and its look in `components/note/note.css`.
25
+
26
+ :::
27
+
28
+ ---
29
+
30
+ ## When you're ready
31
+
32
+ Check the code with `npx @foliwake/site-check`, push the repository to GitHub and connect it to your site in the Foliwake admin: every branch gets a preview. `README.md` has the rest, and the [Quickstart](https://docs.foliwake.dev/guide/quickstart) walks you through it.
@@ -0,0 +1,32 @@
1
+ /* poll: a question to vote on; poll.js renders it with React into <div data-react> at the end of the block.
2
+ Without JavaScript the options stay a readable list.
3
+ HTML: <div data-component="poll"><h3 data-field="question"><ul data-field="options" data-select="multiple">
4
+ <li data-item data-option-id="…" data-correct="false">…</li></ul></div> */
5
+
6
+ @layer blocks {
7
+ [data-component="poll"] {
8
+ margin-block: var(--space, 1rem);
9
+ padding: var(--space, 1rem);
10
+ border: 1px solid var(--color-border, #d4d4d8);
11
+ border-radius: var(--radius, 0.75rem);
12
+
13
+ & h3 { margin: 0 0 0.75rem; font-size: 1.05rem; }
14
+
15
+ & [role="group"] { display: flex; flex-wrap: wrap; gap: 0.5rem; }
16
+
17
+ & button[data-option-id] {
18
+ padding: 0.5rem 0.9rem;
19
+ border: 1px solid var(--color-border, #d4d4d8);
20
+ border-radius: 999px;
21
+ font: inherit;
22
+ color: inherit;
23
+ background: var(--color-page, transparent);
24
+ cursor: pointer;
25
+ }
26
+
27
+ & button[data-option-id]:focus-visible { outline: 2px solid var(--color-accent, #2563eb); outline-offset: 2px; }
28
+ & button[data-option-id][aria-pressed="true"] { border-color: var(--color-accent, #2563eb); box-shadow: inset 0 0 0 1px var(--color-accent, #2563eb); }
29
+ & button[data-option-id]:disabled { cursor: default; }
30
+ & [role="status"] { margin: 0.75rem 0 0; }
31
+ }
32
+ }
@@ -0,0 +1,26 @@
1
+ # Poll
2
+
3
+ A question to vote on. Each option is a task-list item with an id at its end, `{#id}`: the id the `answer` event reports. The page renders the poll with React (`poll.js` and the vendored `scripts/vendor/react.js`); without JavaScript the options stay a list.
4
+
5
+ <!-- example: Three options -->
6
+
7
+ :::poll
8
+
9
+ ### Which block do you build next?
10
+
11
+ - [ ] A callout {#callout}
12
+ - [ ] A gallery {#gallery}
13
+ - [ ] A rating {#rating}
14
+
15
+ :::
16
+
17
+ <!-- example: Two options {#yes-no} -->
18
+
19
+ :::poll
20
+
21
+ ### Was this page useful?
22
+
23
+ - [ ] Yes {#yes}
24
+ - [ ] No {#no}
25
+
26
+ :::
@@ -0,0 +1,35 @@
1
+ // poll: a question to vote on, rendered with React through block-kit's ctx.mount
2
+ // and the React view of scripts/react-view.js. React is the vendored
3
+ // scripts/vendor/react.js (no npm, no build step), loaded only when the shell does
4
+ // not give its own (host.has('react'): a React or Next app that embeds the page
5
+ // does). The authored list stays for readers without JavaScript: `replace: true`
6
+ // hides it while React shows the poll. A vote emits "block:answer"
7
+ // ({key, block, selected, correct: null, graded}) and "block:complete"; the
8
+ // component is exported too, for an app that renders it itself.
9
+ import { defineBlock } from '@foliwake/block-kit';
10
+ import { reactView } from '../../scripts/react-view.js';
11
+
12
+ /** The poll as a React component, for a given createElement. */
13
+ export function createPoll(h) {
14
+ return function Poll({ question, options, chosen, onVote, thanks }) {
15
+ const picked = options.find((option) => option.id === chosen);
16
+ return h(
17
+ 'div',
18
+ { className: 'poll' },
19
+ question ? h('h3', null, question) : null,
20
+ h('div', { role: 'group', 'aria-label': question || 'Poll' }, options.map((option) => h('button', { key: option.id, type: 'button', 'data-option-id': option.id, 'aria-pressed': option.id === chosen, disabled: chosen !== null, onClick: () => onVote(option.id) }, option.text))),
21
+ picked ? h('p', { role: 'status' }, `${thanks} “${picked.text}”.`) : null,
22
+ );
23
+ };
24
+ }
25
+
26
+ export default defineBlock('poll', async ({ question = '', options = [] }, ctx) => {
27
+ const react = ctx.host?.has?.('react') ? ctx.host.react : await import('../../scripts/vendor/react.js');
28
+ const props = { question, options, chosen: null, onVote, thanks: ctx.t('thanks') };
29
+ const view = ctx.mount(reactView(react, createPoll(react.createElement)), props, { replace: true });
30
+ function onVote(id) {
31
+ view.update({ ...props, chosen: id });
32
+ ctx.emit('answer', { selected: [id], correct: null, graded: 'local' });
33
+ ctx.emit('complete', {});
34
+ }
35
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "../../.foliwake/schemas/block-1.schema.json",
3
+ "label": { "en": "Poll" },
4
+ "fields": [
5
+ { "name": "question", "type": "heading", "level": 3, "label": { "en": "Question" } },
6
+ { "name": "options", "type": "choices", "ids": "required", "correct": { "": "any" }, "label": { "en": "Options" } }
7
+ ],
8
+ "ui": { "en": { "thanks": "Thank you! You chose" } },
9
+ "events": {
10
+ "answer": { "detail": { "selected": "string[]", "correct": "unknown", "graded": "string" } },
11
+ "complete": {}
12
+ }
13
+ }
@@ -0,0 +1,22 @@
1
+ // A React view for block-kit's ctx.mount (website/guide/write-a-block.md): `reactView(react, Component)`
2
+ // renders Component with the block's props into the element the kit gives it, with `react` being
3
+ // {createElement, createRoot}: the shell's (host.react) or the vendored scripts/vendor/react.js.
4
+ // A render error after the first commit (React 19 onUncaughtError) fails the view: the kit shows the
5
+ // authored HTML again and reports the block's `error` event.
6
+ export function reactView(react, Component) {
7
+ const roots = new WeakMap();
8
+ return {
9
+ render(element, props, { fail }) {
10
+ let root = roots.get(element);
11
+ if (!root) {
12
+ root = react.createRoot(element, { onUncaughtError: (error) => fail(error) });
13
+ roots.set(element, root);
14
+ }
15
+ root.render(react.createElement(Component, props));
16
+ },
17
+ unmount(element) {
18
+ roots.get(element)?.unmount();
19
+ roots.delete(element);
20
+ },
21
+ };
22
+ }
@@ -0,0 +1,104 @@
1
+ # {{name}}
2
+
3
+ The frontend of a Foliwake site: blocks, styles and a few local pages to work with. Created with `create-foliwake` {{createVersion}} (template `{{template}}`).
4
+
5
+ ```text
6
+ components/<name>/ one folder per block: <name>.json (its fields), <name>.css, optionally <name>.js and <name>.example.md
7
+ scripts/components.js the loader: loads each block's CSS and JS on the pages that use it
8
+ styles/styles.css styles of every page
9
+ site.yaml site settings for the engine (authoring dialect)
10
+ content/ local Markdown pages to develop against (not published by this repository)
11
+ tests/ quick checks of the vendored scripts and workflows (node --test "tests/*.test.mjs")
12
+ foliwake.config.json local configuration for the Foliwake CLI (`foliwake dev`); unused without it
13
+ .github/ checks, branch previews and production (inert until connected)
14
+ ```
15
+
16
+ There is no build step: the files in `components/`, `scripts/` and `styles/` are what the browser loads.{{reactNote}}
17
+
18
+ ## Develop
19
+
20
+ ### Without the Foliwake CLI
21
+
22
+ Check the code with the platform's own rules after every change:
23
+
24
+ ```bash
25
+ npx @foliwake/site-check
26
+ node --test "tests/*.test.mjs"
27
+ ```
28
+
29
+ `@foliwake/site-check` checks everything about the code that needs no rendering: block definitions, templates, `site.yaml`, the layout of the folders and the references of scripts and stylesheets. The platform runs the same checks first, so its messages are the same. The pages and the block examples are rendered by the platform: push a branch and open its preview (below).
30
+
31
+ ### With the Foliwake CLI
32
+
33
+ The Foliwake CLI (with the Docker image or Foliwake Cloud) adds a local preview and the page checks:
34
+
35
+ ```bash
36
+ foliwake dev --watch
37
+ ```
38
+
39
+ Open http://127.0.0.1:3000/. Edit a page in `content/`, a block or a stylesheet and save: the browser reloads. `dev` uses only local files; no server, store or account is needed. Every block and its examples are on http://127.0.0.1:3000/_dev/blocks: each example rendered with your CSS and JavaScript, its HTML and its problems. Authors see the same examples as a block catalog at `/_foliwake/blocks` on the preview.{{storybookNote}}
40
+
41
+ `foliwake page check` checks every page and block example too. Run it in this folder: the CLI finds `foliwake.config.json` here by itself; after cloning the repository or changing the file, read it and run `foliwake config trust` once (it decides where credentials are sent).
42
+
43
+ ### Add a block
44
+
45
+ 1. Create `components/<name>/<name>.json` with its fields, for example a title and text:
46
+
47
+ ```json
48
+ {
49
+ "label": { "en": "Tip" },
50
+ "fields": [
51
+ { "name": "title", "type": "heading", "level": 3, "min": 0 },
52
+ { "name": "text", "type": "text", "max": null }
53
+ ]
54
+ }
55
+ ```
56
+
57
+ Field types: `heading`, `text`, `list`, `choices`, `quote`, `image`.
58
+ 2. Add `components/<name>/<name>.css` (and `<name>.js` if it needs JavaScript: its default export is `init(root, host, meta)`, best made with block-kit: `import { defineBlock, html } from '@foliwake/block-kit'` and `defineBlock('<name>', (fields, ctx) => …)`; the page maps that import to the kit of the code release, so nothing is installed. `jsconfig.json` gives your editor the kit's types (`.foliwake/types/foliwake.d.ts`, from `@foliwake/block-kit`, written by create) and, with the Foliwake CLI, of your blocks (`foliwake dev` writes them to `.foliwake/types/blocks/`)). With the Foliwake CLI, `foliwake blocks new <name> --js --example` writes all the files.
59
+ 3. Use it in a page:
60
+
61
+ ```md
62
+ :::tip
63
+
64
+ ### A title
65
+
66
+ Some text.
67
+
68
+ :::
69
+ ```
70
+
71
+ 4. Show it in `components/<name>/<name>.example.md`: a line `<!-- example: Title -->` before each example, then the block as an author writes it. The examples appear in the authors' block catalog on the preview, on `/_dev/blocks` and in `foliwake blocks render` (fragments for Storybook); the platform renders them like pages.
72
+
73
+ The engine binds the content to the fields by their order and type and reports an error when the content does not fit, instead of guessing.
74
+
75
+ ## Preview a change before it is live
76
+
77
+ The code that a Foliwake server publishes is always a **commit**. Commit your work first:
78
+
79
+ ```bash
80
+ git add -A && git commit -m "Describe the change"
81
+ ```
82
+
83
+ With the repository connected to your site (below):
84
+
85
+ - **Push a branch** → the branch preview `https://<branch>--<site>.<branch host domain>/` shows the site's pages with that branch's code. Deleting the branch removes its preview.
86
+ - **Merge into `main`** → the checks run, the server prepares a code release from exactly that commit and rebuilds every page with it in the site's **preview**. Live does not change.
87
+ - **Release** → review the preview, then release it in the Foliwake admin: *Frontend → New code → Release*. A rollback is in the same place, or in GitHub: *Actions → Frontend production → Run workflow*.
88
+
89
+ ## Connect to Foliwake
90
+
91
+ The workflows in `.github/workflows/` do nothing until the repository is connected. The "Frontend checks" workflow runs on every push and pull request from the start; it needs no secrets.
92
+
93
+ 1. Push this repository to GitHub.
94
+ 2. In the Foliwake admin, connect the repository to your site (or ask the operator of your Foliwake server to): it needs the clone URL and gives you the **site id** and the SSH keys of the two deployment commands (branch previews and production){{siteIdNote}}.
95
+ 3. In the GitHub repository settings:
96
+ - **Environments**: `branch-previews` with the secrets `BRANCH_PREVIEW_SSH_KEY`, `BRANCH_PREVIEW_KNOWN_HOSTS`, `BRANCH_PREVIEW_SSH_TARGET`; `production` (deployment branches: `main` only) with `PRODUCTION_DEPLOY_SSH_KEY`, `PRODUCTION_DEPLOY_KNOWN_HOSTS`, `PRODUCTION_DEPLOY_SSH_TARGET`.
97
+ - **Variables**: `FOLIWAKE_SITE_ID` = the site id; `BRANCH_PREVIEWS_ENABLED` = `true` to turn on branch previews; `FRONTEND_PRODUCTION_DEPLOY_ENABLED` = `true` to turn on main → preview → live (with the site setting `codeRelease: auto`, the default, a merge to main is released when every page builds without problems; with `manual` it waits for Release in the admin); optionally `FOLIWAKE_PREVIEW_URL` and `FOLIWAKE_PRODUCTION_URL` (shown as links in GitHub).
98
+ - **Branch protection** for `main`: require the "frontend-checks" status check.
99
+
100
+ Each variable switches on one workflow, so you can enable branch previews first and production later. The keys only reach the server's fixed deployment commands: the branch-preview key can update branch previews of this one site; the production key can deploy the tip of `main` (released only when the server's checks pass, or kept in preview with `codeRelease: manual`) and roll back; it cannot release any other preview.
101
+
102
+ ## Content
103
+
104
+ The pages in `content/` are local sample content for development. The site's real content lives in its content source on the Foliwake server (Markdown, Google Docs, Drupal, …), not in this repository.
@@ -0,0 +1,45 @@
1
+ # One request to a Foliwake forced command over SSH: the request travels on stdin only, the key
2
+ # and known hosts exist only for this step (removed on exit), the JSON answer is left at
3
+ # $RUNNER_TEMP/foliwake-result.json. Used by production.yml and branch-preview.yml.
4
+ name: Foliwake request
5
+ description: Send one JSON request to a Foliwake forced command over SSH
6
+ inputs:
7
+ command:
8
+ description: 'frontend-production or branch-preview (ignored by the forced command; names the key in logs)'
9
+ required: true
10
+ request:
11
+ description: Path of the JSON request file
12
+ required: true
13
+ ssh-key:
14
+ required: true
15
+ known-hosts:
16
+ required: true
17
+ target:
18
+ required: true
19
+ outputs:
20
+ exit:
21
+ description: Exit status of the forced command (0 done, 1 refused or failed, 3 committed with a pending cache refresh)
22
+ value: ${{ steps.send.outputs.exit }}
23
+ runs:
24
+ using: composite
25
+ steps:
26
+ - id: send
27
+ shell: bash
28
+ env:
29
+ SSH_KEY: ${{ inputs.ssh-key }}
30
+ KNOWN_HOSTS: ${{ inputs.known-hosts }}
31
+ TARGET: ${{ inputs.target }}
32
+ COMMAND: ${{ inputs.command }}
33
+ REQUEST: ${{ inputs.request }}
34
+ run: |
35
+ set +e
36
+ material=$(mktemp -d)
37
+ trap 'rm -rf "$material"' EXIT
38
+ printf '%s\n' "$SSH_KEY" > "$material/key"
39
+ printf '%s\n' "$KNOWN_HOSTS" > "$material/known_hosts"
40
+ chmod 600 "$material/key" "$material/known_hosts"
41
+ cat "$REQUEST"
42
+ ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o IdentitiesOnly=yes -o UserKnownHostsFile="$material/known_hosts" -i "$material/key" "$TARGET" "$COMMAND" \
43
+ < "$REQUEST" > "$RUNNER_TEMP/foliwake-result.json"
44
+ echo "exit=$?" >> "$GITHUB_OUTPUT"
45
+ cat "$RUNNER_TEMP/foliwake-result.json"