@kerf-js/cli 0.0.0-stage → 0.1.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.
- package/LICENSE +16 -0
- package/README.md +554 -2
- package/bin/kerf.mjs +15 -0
- package/docs/async.md +50 -0
- package/docs/browser.md +53 -0
- package/docs/config.md +127 -0
- package/docs/core.md +30 -0
- package/docs/deploy.md +108 -0
- package/docs/design.md +106 -0
- package/docs/entrypoints.md +83 -0
- package/docs/fonts.md +118 -0
- package/docs/icons.md +108 -0
- package/docs/lists.md +25 -0
- package/docs/meta.md +92 -0
- package/docs/plugins.md +166 -0
- package/docs/props.md +88 -0
- package/docs/reactivity.md +26 -0
- package/docs/rules.md +39 -0
- package/docs/rust.md +253 -0
- package/docs/start-short.md +10 -0
- package/docs/start.md +642 -0
- package/docs/state.md +122 -0
- package/docs/style.md +82 -0
- package/docs/surface.md +158 -0
- package/docs/testing.md +81 -0
- package/docs/theme.md +263 -0
- package/docs/ui-state.md +105 -0
- package/docs/verify.md +61 -0
- package/package.json +47 -3
- package/src/add/config.mjs +93 -0
- package/src/add/errors.mjs +2 -0
- package/src/add/setup.mjs +88 -0
- package/src/add-rust.mjs +178 -0
- package/src/add.mjs +392 -0
- package/src/agents-md.mjs +240 -0
- package/src/alias.mjs +70 -0
- package/src/audit/page.mjs +313 -0
- package/src/audit/report.mjs +69 -0
- package/src/audit/utils.mjs +5 -0
- package/src/audit.mjs +319 -0
- package/src/browser/cli.mjs +53 -0
- package/src/browser/client.mjs +299 -0
- package/src/browser/commands.mjs +258 -0
- package/src/capture.mjs +21 -0
- package/src/catalog/audit.mjs +129 -0
- package/src/catalog/auth.mjs +40 -0
- package/src/catalog/compiler.mjs +337 -0
- package/src/catalog/contracts.mjs +18 -0
- package/src/catalog/database.mjs +52 -0
- package/src/catalog/deploy.mjs +117 -0
- package/src/catalog/design.mjs +159 -0
- package/src/catalog/forms.mjs +25 -0
- package/src/catalog/hydration.mjs +29 -0
- package/src/catalog/icons.mjs +24 -0
- package/src/catalog/media.mjs +163 -0
- package/src/catalog/metadata.mjs +116 -0
- package/src/catalog/plugins.mjs +228 -0
- package/src/catalog/realtime.mjs +195 -0
- package/src/catalog/rust.mjs +75 -0
- package/src/catalog/server-functions.mjs +100 -0
- package/src/catalog/state.mjs +39 -0
- package/src/catalog/style-groups.mjs +54 -0
- package/src/catalog/tests.mjs +127 -0
- package/src/catalog/text.mjs +200 -0
- package/src/catalog/ui-state.mjs +42 -0
- package/src/catalog.mjs +103 -0
- package/src/check/runtime.mjs +280 -0
- package/src/check.mjs +321 -0
- package/src/cli/authoring.mjs +213 -0
- package/src/cli/project.mjs +302 -0
- package/src/cli.mjs +340 -0
- package/src/config.d.ts +1 -0
- package/src/config.mjs +5 -0
- package/src/contributions.mjs +119 -0
- package/src/db-layer.mjs +41 -0
- package/src/deploy/cdn.mjs +142 -0
- package/src/deploy/files.mjs +266 -0
- package/src/deploy/fit.mjs +166 -0
- package/src/deploy/hosts.mjs +126 -0
- package/src/deploy/index/cli.mjs +20 -0
- package/src/deploy/index/environment.mjs +69 -0
- package/src/deploy/index/steps.mjs +87 -0
- package/src/deploy/index.mjs +387 -0
- package/src/deploy/needs.mjs +149 -0
- package/src/design-checks/accessible-names.mjs +62 -0
- package/src/design-checks/contrast.mjs +43 -0
- package/src/design-checks/csp.mjs +60 -0
- package/src/design-checks/files.mjs +59 -0
- package/src/design-checks/heading-links.mjs +61 -0
- package/src/design-checks/interaction.mjs +65 -0
- package/src/design-checks/jsx.mjs +67 -0
- package/src/design-checks/layout-values.mjs +68 -0
- package/src/design-checks/native-controls.mjs +48 -0
- package/src/design-checks/outline.mjs +39 -0
- package/src/design-checks/reporter.mjs +37 -0
- package/src/design-checks/rules.mjs +274 -0
- package/src/design-checks/values.mjs +262 -0
- package/src/design-checks.mjs +49 -0
- package/src/diag.mjs +98 -0
- package/src/docs.mjs +228 -0
- package/src/doctor.mjs +42 -0
- package/src/files.mjs +60 -0
- package/src/fix.mjs +48 -0
- package/src/gate/after.mjs +40 -0
- package/src/gate/before.mjs +54 -0
- package/src/gate/classify.mjs +72 -0
- package/src/gate/mutation.mjs +209 -0
- package/src/gate/resolve-cases.mjs +22 -0
- package/src/gate/result.mjs +63 -0
- package/src/gate/run.mjs +75 -0
- package/src/gate.mjs +178 -0
- package/src/index.mjs +9 -0
- package/src/infer/box-props.cjs +140 -0
- package/src/infer/core-boxes.cjs +46 -0
- package/src/infer/derived-writes.cjs +95 -0
- package/src/infer/engine/checks.cjs +193 -0
- package/src/infer/engine/flow.cjs +293 -0
- package/src/infer/engine/report.cjs +158 -0
- package/src/infer/engine/utils.cjs +15 -0
- package/src/infer/engine.cjs +265 -0
- package/src/infer/facts/sites.cjs +114 -0
- package/src/infer/facts.cjs +345 -0
- package/src/infer/hosts.cjs +161 -0
- package/src/infer/lsp.mjs +240 -0
- package/src/infer/session.cjs +161 -0
- package/src/infer/shadow.cjs +54 -0
- package/src/infer/worker.cjs +145 -0
- package/src/jsx-scan.mjs +128 -0
- package/src/kerf.mjs +98 -0
- package/src/load-config/schema.mjs +300 -0
- package/src/load-config.mjs +302 -0
- package/src/map.mjs +177 -0
- package/src/mcp/browser-tools.mjs +155 -0
- package/src/mcp.mjs +273 -0
- package/src/meta-table.mjs +63 -0
- package/src/mutate.mjs +224 -0
- package/src/plugin-checks.mjs +118 -0
- package/src/plugins.mjs +258 -0
- package/src/project.mjs +310 -0
- package/src/props-checks.mjs +64 -0
- package/src/props-listener.mjs +56 -0
- package/src/react-checks.mjs +67 -0
- package/src/server-state-checks.mjs +34 -0
- package/src/share-checks.mjs +158 -0
- package/src/site.mjs +46 -0
- package/src/slots.mjs +181 -0
- package/src/start/build.mjs +116 -0
- package/src/start/routes.mjs +38 -0
- package/src/start.mjs +394 -0
- package/src/state-checks/core-state.mjs +223 -0
- package/src/state-checks/modules.mjs +17 -0
- package/src/state-checks/scan.mjs +232 -0
- package/src/state-checks/server-graph.mjs +65 -0
- package/src/state-checks.mjs +189 -0
- package/src/style/find.mjs +121 -0
- package/src/style.mjs +327 -0
- package/src/surface-checks.mjs +384 -0
- package/src/tailwind.mjs +23 -0
- package/src/tasks.mjs +261 -0
- package/src/test-rules/context.mjs +109 -0
- package/src/test-rules/file-rules.mjs +279 -0
- package/src/test-rules/rule-helpers.mjs +244 -0
- package/src/test-rules/syntax.mjs +223 -0
- package/src/test-rules/test-rules.mjs +127 -0
- package/src/testdiff.mjs +219 -0
- package/src/tests.mjs +120 -0
- package/src/text-checks.mjs +332 -0
- package/src/tokens.mjs +33 -0
- package/src/trust/scan.mjs +95 -0
- package/src/trust.mjs +394 -0
- package/src/workspace.mjs +182 -0
- package/ts-plugin/context.js +57 -0
- package/ts-plugin/index.js +17 -0
- package/ts-plugin/mapping.js +65 -0
- package/ts-plugin/package.json +1 -0
- package/ts-plugin/proxy.js +144 -0
package/docs/theme.md
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# Theme: changing veneer's look
|
|
2
|
+
|
|
3
|
+
Three levels, in order. Stop at the first that gets you there; each one keeps the contrast check.
|
|
4
|
+
|
|
5
|
+
1. `veneer({ seed, dials, fields, radius, fonts, tokens })` in the kerf config. Checked by D010 at the stops `dials` leave.
|
|
6
|
+
For your own names, per-element looks and named themes: `colors`, `system`, `parts`, `themes` (below).
|
|
7
|
+
2. `src/theme.css`, unlayered: `[data-scope]` and `[data-part]` rules beat veneer with no `!important`.
|
|
8
|
+
3. Your own component, with veneer's tokens.
|
|
9
|
+
|
|
10
|
+
The Theme studio on the docs site (`/components/theme-studio`) edits level 1 with live components and contrast
|
|
11
|
+
ratios, and copies the result as `kerf.config.ts`.
|
|
12
|
+
|
|
13
|
+
## veneer() options
|
|
14
|
+
|
|
15
|
+
| Option | Does |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `seed.accent` | The hue family: `#rrggbb`, a name from `colors`, or `{ hue, chroma }`. Each theme solves its own lightness, and `kerf build` prints where it landed |
|
|
18
|
+
| `seed.neutral` | The tint of pages, surfaces and text, `#rrggbb` or `{ hue, chroma }` |
|
|
19
|
+
| `dials` | Default `expression` (quiet balanced vivid), `density`, `flair`, `theme`. With `theme: 'light'`, dark isn't checked |
|
|
20
|
+
| `fields` | `floating` (the default: the label floats in a notch) or `classic` (the label above the box) |
|
|
21
|
+
| `radius` | `sharp` (2px), `soft`, `round`. Below 2px, set the radius tokens |
|
|
22
|
+
| `fonts` | `body`, `display`, `mono`: a family or a whole stack |
|
|
23
|
+
| `tokens` | Any `--veneer-*`, set on every scope. Colours are `#rrggbb`, `oklch()`, `color-mix()` or `light-dark()` |
|
|
24
|
+
|
|
25
|
+
App-wide values go in `veneer()`. A `--veneer-color-*` set in CSS on `:root` skips the check and is undone inside any scope that
|
|
26
|
+
sets a dial, such as a Table's density.
|
|
27
|
+
|
|
28
|
+
## colors, system, parts, themes
|
|
29
|
+
|
|
30
|
+
| Option | Does |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `colors` | `{ brand: '#e8590c' }`: `--veneer-color-brand`, a tone (`tone="brand"`), and `bg-brand` via `.kerf/tokens/veneer.tailwind.css`. Lowercase names, `#rrggbb` |
|
|
33
|
+
| `system` | The scales: `radius`, `space`, `pad`, `control`, `font`, `shadow`, `duration`, `ease`, `border`, `icon`, `text.<role>` (veneer's roles or your own, below) |
|
|
34
|
+
| `parts` | One element, at rest and per state (`hover focus press active open disabled`). Numbers are px (ms for `duration`); names are system steps or `colors` |
|
|
35
|
+
| `themes` | `{ ocean: { seed, colors, system, parts } }` under `[data-palette="ocean"]`. `dials.palette` sets the default; `setPalette()` switches |
|
|
36
|
+
|
|
37
|
+
Every part takes `bg text border borderWidth radius padding paddingX paddingY gap margin height minHeight width size
|
|
38
|
+
shadow opacity scale duration easing font fontSize weight leading tracking case`. A part's own keys add to those or
|
|
39
|
+
replace one of the same name with its own meaning (an underline's `width` is its thickness):
|
|
40
|
+
|
|
41
|
+
| Part | For | Own keys | States |
|
|
42
|
+
|---|---|---|---|
|
|
43
|
+
| `button` | Button and ButtonLink | `bg` `text` `border` `radius` | hover focus press active open disabled |
|
|
44
|
+
| `button.soft` | | `bg` `text` `border` | hover focus press active open disabled |
|
|
45
|
+
| `button.outline` | | `bg` `text` `border` | hover focus press active open disabled |
|
|
46
|
+
| `button.ghost` | | `bg` `text` `border` | hover focus press active open disabled |
|
|
47
|
+
| `button.frame` | | `bg` `text` `border` | hover focus press active open disabled |
|
|
48
|
+
| `button.link` | | `bg` `text` `border` | hover focus press active open disabled |
|
|
49
|
+
| `iconButton` | A button that holds only an icon (copy, close, menu): square by default | `radius` `icon` | hover focus press active open disabled |
|
|
50
|
+
| `copy` | CopyButton | `radius` | hover focus press active open disabled |
|
|
51
|
+
| `close` | The close button of a dialog, sheet, drawer, alert or side nav | — | hover focus press active open disabled |
|
|
52
|
+
| `link` | Link: the text link with the drawn underline | — | hover focus press active open disabled |
|
|
53
|
+
| `link.underline` | | `color` `width` `offset` | hover focus |
|
|
54
|
+
| `nav` | Nav: the row or column of links with the sliding bar | — | — |
|
|
55
|
+
| `nav.item` | | — | hover focus press active open disabled |
|
|
56
|
+
| `nav.underline` | | `color` `width` `duration` | — |
|
|
57
|
+
| `tabs` | Tabs | — | — |
|
|
58
|
+
| `tabs.tab` | | `radius` | hover focus press active open disabled |
|
|
59
|
+
| `tabs.underline` | | `color` `width` | — |
|
|
60
|
+
| `pill` | Pill and PillLink | `radius` | hover focus press active open disabled |
|
|
61
|
+
| `badge` | Badge | — | hover focus press active open disabled |
|
|
62
|
+
| `chip` | Chip | `radius` | hover focus press active open disabled |
|
|
63
|
+
| `card` | Card and Surface | — | hover focus press active open disabled |
|
|
64
|
+
| `field` | Text fields, selects and pickers | `bg` `radius` | hover focus press active open disabled |
|
|
65
|
+
| `field.label` | | `text` | hover focus |
|
|
66
|
+
| `sweep` | The sweep: the stroke that draws round a control on hover and focus, and the text while it runs | `stroke` `base` `text` `width` `duration` | — |
|
|
67
|
+
| `dialog` | Modal and Dialog | — | — |
|
|
68
|
+
| `sheet` | Sheet and Drawer | — | — |
|
|
69
|
+
| `popover` | Popover, Menu and Tooltip panels | — | — |
|
|
70
|
+
| `toast` | Toast | — | — |
|
|
71
|
+
|
|
72
|
+
A solid's `bg` and `text` move its tone channels, so hover, pull-out and sweep follow. `hover.bg` is the hover fill. Text
|
|
73
|
+
set on a fill set in the same part is checked like a seed: below 4.5:1 is D010. Each named theme's seed is fitted the
|
|
74
|
+
same way as the main one.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
veneer({
|
|
78
|
+
colors: { brand: '#e8590c', ink: '#1b1b1f' },
|
|
79
|
+
parts: {
|
|
80
|
+
button: {
|
|
81
|
+
bg: 'brand',
|
|
82
|
+
text: 'ink',
|
|
83
|
+
radius: 'pill',
|
|
84
|
+
hover: { bg: 'ink', text: 'white' },
|
|
85
|
+
},
|
|
86
|
+
sweep: { stroke: 'brand', width: 2 },
|
|
87
|
+
nav: {
|
|
88
|
+
item: { hover: { text: 'brand' } },
|
|
89
|
+
underline: { color: 'brand', width: 3 },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
themes: {
|
|
93
|
+
ocean: {
|
|
94
|
+
seed: { accent: '#0b7285' },
|
|
95
|
+
colors: { brand: '#0b7285' },
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Text roles
|
|
102
|
+
|
|
103
|
+
`system.text` retunes veneer's roles (`display title heading body label caption eyebrow code prose control button`) and
|
|
104
|
+
names your own. Each property becomes a token, `--veneer-text-<role>-<property>`. A role of your own also gets a rule, so
|
|
105
|
+
`<Text role="narrative">` or any element with `data-scope="text" data-role="narrative"` takes it:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
veneer({
|
|
109
|
+
system: {
|
|
110
|
+
text: {
|
|
111
|
+
display: { size: 72, weight: 700, leading: 0.9 },
|
|
112
|
+
narrative: {
|
|
113
|
+
size: 28,
|
|
114
|
+
leading: 0.96,
|
|
115
|
+
tracking: '-0.05em',
|
|
116
|
+
font: '"Fraunces", "Fraunces Fallback", Georgia, serif',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The properties are `size weight leading tracking case font`. A number is px for `size` and `tracking`. A role's name is
|
|
124
|
+
lowercase. veneer's own roles take only the tokens veneer has for them.
|
|
125
|
+
|
|
126
|
+
Any property can change with the viewport: `base` holds below the first breakpoint, and each other key is a min-width
|
|
127
|
+
in px. `size` and `tracking` can also be fluid, `{ min, max, from, to }` in px: `min` at the `from` width, `max` at
|
|
128
|
+
`to`, held outside them. Inside a breakpoint, `from` is the breakpoint. Each breakpoint is a media query that sets the
|
|
129
|
+
tokens, so there is no script; a fluid line runs on `vw` to meet them, in the user's rem.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
veneer({
|
|
133
|
+
system: {
|
|
134
|
+
text: {
|
|
135
|
+
// 72 below 768, then 120 at 768 to 220 at 1680
|
|
136
|
+
display: {
|
|
137
|
+
size: { base: 72, 768: { min: 120, max: 220, to: 1680 } },
|
|
138
|
+
},
|
|
139
|
+
body: { size: { base: 16, 768: 14 } },
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Motion tokens
|
|
146
|
+
|
|
147
|
+
`system.duration` and `system.ease` retune veneer's steps (`instant fast base slow`) and curves (`in out in-out pop
|
|
148
|
+
spring sheet`) and name your own. Each becomes `--veneer-duration-<name>` or `--veneer-ease-<name>`. A duration is ms for a
|
|
149
|
+
number and exact: no dial rescales it. A curve is a CSS easing or cubic-bezier handles, `[x1, y1, x2, y2]`. A part's
|
|
150
|
+
`duration` and `easing` take the names:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { defineConfig } from '@kerf-js/core/config'
|
|
154
|
+
import { veneer } from '@kerf-js/veneer/plugin'
|
|
155
|
+
import { ui } from './src/motion'
|
|
156
|
+
|
|
157
|
+
export default defineConfig({
|
|
158
|
+
plugins: [
|
|
159
|
+
veneer({
|
|
160
|
+
system: {
|
|
161
|
+
duration: { state: 150, glide: 300 },
|
|
162
|
+
ease: { ui, scrub: [0.65, 0, 0.35, 1] },
|
|
163
|
+
},
|
|
164
|
+
parts: { button: { duration: 'state', easing: 'ui' } },
|
|
165
|
+
}),
|
|
166
|
+
],
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Your own CSS reads them as `transition: opacity var(--veneer-duration-glide) var(--veneer-ease-ui)`. The handles are the
|
|
171
|
+
shape a scroll timeline's key takes, so one constant serves both:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
// src/motion.ts
|
|
175
|
+
import { timeline } from '@kerf-js/scroll/timeline'
|
|
176
|
+
|
|
177
|
+
export const ui = [0.4, 0, 0.2, 1] as const
|
|
178
|
+
export const reveal = timeline({ opacity: [[0, 0], [1, 1, ui]] })
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Brutalist
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
veneer({
|
|
185
|
+
dials: { expression: 'quiet', flair: 'none' },
|
|
186
|
+
fonts: {
|
|
187
|
+
display: 'ui-monospace, monospace',
|
|
188
|
+
body: 'ui-monospace, monospace',
|
|
189
|
+
},
|
|
190
|
+
tokens: {
|
|
191
|
+
'--veneer-radius-mark': '0px',
|
|
192
|
+
'--veneer-radius-control': '0px',
|
|
193
|
+
'--veneer-radius-surface': '0px',
|
|
194
|
+
},
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```css
|
|
199
|
+
/* src/theme.css */
|
|
200
|
+
[data-scope="button"] {
|
|
201
|
+
--veneer-tone-edge: var(--veneer-color-text);
|
|
202
|
+
border-width: 2px;
|
|
203
|
+
box-shadow: 4px 4px 0 var(--veneer-color-text);
|
|
204
|
+
}
|
|
205
|
+
[data-scope="surface"] {
|
|
206
|
+
border: 2px solid var(--veneer-color-text);
|
|
207
|
+
box-shadow: none;
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Raw colours and shadows in `src/theme.css` or on a `[data-scope]` rule are D001 and D003 warnings, not errors.
|
|
212
|
+
|
|
213
|
+
## Warm editorial
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
veneer({
|
|
217
|
+
seed: { accent: '#9a3412', neutral: { hue: 70, chroma: 0.03 } },
|
|
218
|
+
dials: { expression: 'vivid' },
|
|
219
|
+
fonts: { display: '"Iowan Old Style", Georgia, serif' },
|
|
220
|
+
})
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## An exact brand
|
|
224
|
+
|
|
225
|
+
A seed gives the hue, not the colour. To pin it, set the fill and its hover for both themes. One alone never re-derives the other.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
veneer({
|
|
229
|
+
seed: { accent: '#c8102e' },
|
|
230
|
+
tokens: {
|
|
231
|
+
'--veneer-color-accent-solid': 'light-dark(#c8102e, #e5484d)',
|
|
232
|
+
'--veneer-color-accent-solid-hover':
|
|
233
|
+
'light-dark(#a50d26, #f2666a)',
|
|
234
|
+
},
|
|
235
|
+
})
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Button tone channels
|
|
239
|
+
|
|
240
|
+
A rule that sets a button's `background` leaves its hover layer on the accent. Set the channels and fill, ink, edge and hover
|
|
241
|
+
stay together, at every emphasis:
|
|
242
|
+
|
|
243
|
+
| Channel | Paints |
|
|
244
|
+
|---|---|
|
|
245
|
+
| `--veneer-tone-fill` | The background |
|
|
246
|
+
| `--veneer-tone-ink` | The text |
|
|
247
|
+
| `--veneer-tone-edge` | The border |
|
|
248
|
+
| `--veneer-tone-layer` | The hover layer that wipes across |
|
|
249
|
+
|
|
250
|
+
```css
|
|
251
|
+
[data-scope="button"][data-emphasis="solid"] {
|
|
252
|
+
--veneer-tone-fill: #111111;
|
|
253
|
+
--veneer-tone-ink: #ffffff;
|
|
254
|
+
--veneer-tone-layer: #333333;
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
The channels are on Button only. Fields read `--veneer-field-*`, tables `--veneer-table-*`.
|
|
259
|
+
|
|
260
|
+
## D010
|
|
261
|
+
|
|
262
|
+
Each failing pair is named with its stop. Change that token or the seed, or limit the stops with `dials`. `kerf build` stops on
|
|
263
|
+
it, because a refused config would ship veneer's default look.
|
package/docs/ui-state.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Shared UI state
|
|
2
|
+
|
|
3
|
+
Hover, focus and press are usually a pile of event handlers. `interaction()` makes them plain values you can read, draw and share. An app that doesn't use it ships none of it.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { derived, watch } from '@kerf-js/core'
|
|
7
|
+
import { interaction } from '@kerf-js/core/interaction'
|
|
8
|
+
import { Button, Checkbox } from '@kerf-js/veneer'
|
|
9
|
+
|
|
10
|
+
type Todo = { id: string; title: string }
|
|
11
|
+
|
|
12
|
+
export function TodoRow({ todo }: { todo: Todo }) {
|
|
13
|
+
const row = interaction({ share: () => `todo:${todo.id}` })
|
|
14
|
+
const seen = derived(() =>
|
|
15
|
+
row.remote.value.hover ? 'someone is here' : '',
|
|
16
|
+
)
|
|
17
|
+
// Only your own hover triggers the request.
|
|
18
|
+
watch(() => row.hover.value, on => {
|
|
19
|
+
if (on) void fetch(`/api/todos/${todo.id}`)
|
|
20
|
+
})
|
|
21
|
+
return (
|
|
22
|
+
<li>
|
|
23
|
+
<Checkbox ui={row}>{todo.title}</Checkbox>
|
|
24
|
+
<Button ui={row} emphasis="soft">Open</Button>
|
|
25
|
+
<small>{seen.value}</small>
|
|
26
|
+
</li>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Give a veneer component the row with `ui`, and it fills the row from real events and draws from it. Everything else is reading:
|
|
32
|
+
|
|
33
|
+
| Read | It means | Who writes it |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `row.hover.value`, `row.focus.value`, `row.pressed.value` | true or false, on this page | real events, or your code |
|
|
36
|
+
| `row.remote.value.hover`, `.focus`, `.pressed` | how many others have it: other tabs and other clients. A count, never who. | only the network |
|
|
37
|
+
|
|
38
|
+
**Yours and theirs never mix.** Someone else's hover can't set your `row.hover`, so a `watch` on it can't run for them and can't echo back. To draw both by hand, read both: `row.hover.value || row.remote.value.hover`. veneer does this for you: a row lit from anywhere gets `data-hold`, and `data-remote` when it's only others.
|
|
39
|
+
|
|
40
|
+
**What a press leaves behind is data.** `pressed` is true only while a button is held down, so others see the press and then it's gone. The tick a press leaves on a checkbox is the app's data, not UI state: share it the way you share any data, with `state(…, { persist, sync: 'tabs' })` for tabs or live data for other clients. The demo above does both.
|
|
41
|
+
|
|
42
|
+
## How far it reaches
|
|
43
|
+
|
|
44
|
+
| Where | How it travels | What you do |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| The same page | the same object: one key is one row | nothing |
|
|
47
|
+
| Other tabs of this browser | `BroadcastChannel`, one post a frame at most | nothing |
|
|
48
|
+
| Other browsers | one socket per browser, held by one tab | allow it, below |
|
|
49
|
+
|
|
50
|
+
Drop `share` and the row is private to that one `interaction()` call. An app without `@kerf-js/start` shares on the page only.
|
|
51
|
+
|
|
52
|
+
When the tab holding the socket closes or crashes, another tab takes over; nothing flashes, and nobody sees a gap except, for one round trip, a hover made during the handover. When a tab or client goes, what it held clears.
|
|
53
|
+
|
|
54
|
+
## Who may see what
|
|
55
|
+
|
|
56
|
+
Sharing with other clients is off until you say who may, in `src/realtime.server.ts`:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { realtime } from '@kerf-js/start'
|
|
60
|
+
|
|
61
|
+
export default realtime({
|
|
62
|
+
share: ({ ctx, key }) =>
|
|
63
|
+
ctx.user !== null && key.startsWith('todo:'),
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
That rule runs once per key. If it reads a database, a 200-row list means 200 queries, so answer them together instead. You get up to 400 keys in one call and give back the ones allowed:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { realtime } from '@kerf-js/start'
|
|
71
|
+
|
|
72
|
+
// One query returns the keys this user may see.
|
|
73
|
+
declare function visibleKeys(
|
|
74
|
+
userId: string, keys: string[],
|
|
75
|
+
): Promise<string[]>
|
|
76
|
+
|
|
77
|
+
export default realtime({
|
|
78
|
+
share: {
|
|
79
|
+
keys: async ({ ctx, keys }) =>
|
|
80
|
+
ctx.user ? visibleKeys(ctx.user.id, keys) : [],
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Either form runs when a client joins and at each session re-check, and uses the same `ctx` as a channel's `authorize`. A rule that throws refuses what it was asked. With no `share` the socket refuses every key (R011), and a refused key still works between tabs. `() => true` must be written out.
|
|
86
|
+
|
|
87
|
+
Peers see the three bits and an opaque connection id. No name, no pointer position, nothing typed. For names and cursors use `@kerf-js/multiplayer`.
|
|
88
|
+
|
|
89
|
+
**Hover tells people things.** What someone lingers on in a shared document, or which field of a form has focus, is a real signal. veneer never shares by default: you opt in row by row, and it's worth telling your users.
|
|
90
|
+
|
|
91
|
+
## Details
|
|
92
|
+
|
|
93
|
+
- **Keys** are read once, so a prop goes in as a function: `share: () => `todo:${props.id}``. A plain string is fine when it's fixed. To change key, give the component a new `key`.
|
|
94
|
+
- **Costs.** A 200-row list is one frame to join, and a joiner costs other clients nothing. High-frequency changes send at most one frame per 60 ms, carrying the latest value of every row that changed. `limits.shareKeys` (1000) caps keys per socket.
|
|
95
|
+
- **Touch** has no hover, so `row.hover` stays false on a phone; press still works, and a phone can show someone else's hover.
|
|
96
|
+
- **The server** renders every row as idle, so hydration has nothing to reconcile. Rows are live a moment after the page is.
|
|
97
|
+
- **Components that take `ui`:** Button, Checkbox, Switch, Radio, Toggle, Chip, Card. Remote state never touches `aria-*` or focus: it is decoration.
|
|
98
|
+
|
|
99
|
+
`kerf check` flags keys that can't match (U001), keys built from what a user typed (U002), `share` with no rule (U003), writing `remote` (U004) and `ui` on a component that doesn't take it (U005).
|
|
100
|
+
|
|
101
|
+
## One browser, one socket
|
|
102
|
+
|
|
103
|
+
All tabs of a browser share one WebSocket, held by one tab, and `share`, `channel` and `live` all ride it. You don't set this up. To your code and to the server each tab is still its own connection: `exceptSelf`, `left`, presence and rate limits work per tab as they did. `limits.connections` now counts browsers.
|
|
104
|
+
|
|
105
|
+
When the leader tab closes, another takes over within a few milliseconds. Every tab's channels rejoin and its live queries resubscribe, so presence in other tabs may blink once. A browser without Web Locks gives each tab its own socket. A host that can't do WebSockets falls back to `/_kerf/rt` over SSE for `live`.
|
package/docs/verify.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Verify your work
|
|
2
|
+
|
|
3
|
+
Two checks before a change is done: see it work in the running app, and get its tests through the gate.
|
|
4
|
+
|
|
5
|
+
## The running app: `kerf browser` or `__kerf__.agent`
|
|
6
|
+
|
|
7
|
+
Run the app in dev: `kerf dev`, or `vite` for an app without `@kerf-js/start`. In dev, every page loads
|
|
8
|
+
`@kerf-js/core/agent`, as long as `@testing-library/dom` and `@testing-library/user-event` are installed (they are what
|
|
9
|
+
`kerf docs testing` adds; without them a page gets only the devtools graph). Drive it whichever way you can reach it:
|
|
10
|
+
|
|
11
|
+
- **Your own browser** (a browser tool that runs JS, any agent): open the app's URL, then
|
|
12
|
+
`await __kerf__.agent.run('snapshot')`, `await __kerf__.agent.act({ role: 'button', name: 'Add' }, 'click')`, …
|
|
13
|
+
- **The CLI or MCP**: `kerf browser <command>` (tools `browser_*` in `kerf mcp`). The dev server relays each command to
|
|
14
|
+
the open tab. Nothing open? Open the URL in your browser, or `kerf browser launch` (a headless Chrome).
|
|
15
|
+
|
|
16
|
+
Commands (CLI form; the JS and MCP forms take the same params):
|
|
17
|
+
|
|
18
|
+
- `snapshot [--interactive] [--delta]`: roles, names and refs (`- button "Add Banana" [ref=e15]`), plus the reactive
|
|
19
|
+
graph with real names: `Cart.total = 4.5 ← Cart.lines → 1 binding in <Cart> (Cart.tsx:12)`. Big ones go to a file.
|
|
20
|
+
- `act button "Add Banana" click`, `act label Coupon fill SAVE10`, `act @e15 click`: user-event, like `user` in
|
|
21
|
+
@kerf-js/core/test. Returns what changed on the page.
|
|
22
|
+
- `assert status - text "Total: $4.50"`; expectations: visible, absent, text, exactText, value, checked, unchecked,
|
|
23
|
+
disabled, enabled, focused, count. Retries briefly for async loads.
|
|
24
|
+
- `graph Cart` and `set Cart.coupon '"SAVE10"'`: read the graph, write a box by name to reach a state fast.
|
|
25
|
+
- `time pause [--reload]`, `time advance 3000`, `time resume`: the page's clock (timers, intervals, rAF, Date).
|
|
26
|
+
`--reload` pauses from page load, so startup timers are faked too.
|
|
27
|
+
- `net offline|online|latency 300|drop|reset`: `navigator.onLine`, the events, `fetch`, open WebSockets and
|
|
28
|
+
EventSources. `drop` is a server restart; check the app reconnects.
|
|
29
|
+
- `record start` … `record code --component App --from ./App --out src/App.test.tsx`: what you did (acts, asserts,
|
|
30
|
+
clicks and typing from any browser tool) as a `@kerf-js/core/test` test. It then has to pass the gate.
|
|
31
|
+
- `logs`: console errors and uncaught errors, with the binding they came from.
|
|
32
|
+
|
|
33
|
+
## The test gate: `kerf test --gate`
|
|
34
|
+
|
|
35
|
+
Runs on the diff (`--base <ref>`, default the uncommitted change), in scratch copies; your working tree is never
|
|
36
|
+
touched.
|
|
37
|
+
|
|
38
|
+
- **T010, fail-before:** each new or changed test must fail on the code before the change. A test that passes on the
|
|
39
|
+
old code doesn't test the change.
|
|
40
|
+
- **T011, mutants:** each new test must kill at least one mutant of the changed lines (operators, boundaries,
|
|
41
|
+
literals, conditions, removed calls, JSX text). Surviving mutants come back with what to assert. Sampled within
|
|
42
|
+
`test.gate.mutationBudgetSec` (default 60) and `maxMutants` (40); when sampled, T011 is a warning.
|
|
43
|
+
- **T020, no weakening:** deleting, skipping or loosening an existing test (`toBe(3)` → `toBeTruthy()`) needs
|
|
44
|
+
`// kerf-allow T020: <reason>` on it.
|
|
45
|
+
- The static T-codes run on the changed tests; T005 (implementation queries) blocks here.
|
|
46
|
+
|
|
47
|
+
Tests added for code that didn't change have nothing to fail on: fail-before is skipped, and the mutants come from
|
|
48
|
+
the source files the tests import. `--refactor` promises no behavior change: then no test may change.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Indexing intent
|
|
52
|
+
|
|
53
|
+
For a site intended for public search, declare
|
|
54
|
+
`build: { audit: { indexing: 'public' } }`. L024 then fails the build or audit if
|
|
55
|
+
robots metadata or an HTTP X-Robots-Tag header says noindex. `private` or the
|
|
56
|
+
backward-compatible `auto` leaves this a warning; neither removes a directive.
|
|
57
|
+
After deployment, run `kerf audit --url https://your-site.example --indexing public`:
|
|
58
|
+
a host or proxy may add a header that a local build cannot see. Preserve intentional
|
|
59
|
+
preview/private exclusions. A noindex finding is an indexing policy issue, not
|
|
60
|
+
chat-agent traffic; use a clean profile before attributing other audit failures
|
|
61
|
+
to application or framework code.
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kerf-js/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The kerf command: dev, build, check, the agent layer and the MCP server",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Ravonus/kerf.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Ravonus/kerf/tree/main/packages/cli#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Ravonus/kerf/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"bin": {
|
|
17
|
+
"kerf": "./bin/kerf.mjs"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./src/index.mjs",
|
|
21
|
+
"./config": "./src/config.mjs"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=24"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"create-kerf": "0.1.0",
|
|
28
|
+
"axe-core": "4.14.0",
|
|
29
|
+
"typescript": "6.0.3",
|
|
30
|
+
"yaml": "2.9.1",
|
|
31
|
+
"zod": "4.6.7"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@kerf-js/core": "^0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"kerf"
|
|
41
|
+
],
|
|
42
|
+
"files": [
|
|
43
|
+
"bin",
|
|
44
|
+
"src",
|
|
45
|
+
"docs",
|
|
46
|
+
"ts-plugin",
|
|
47
|
+
"README.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
]
|
|
6
50
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import ts from 'typescript'
|
|
4
|
+
import { pluginFactory, pluginName } from '../load-config.mjs'
|
|
5
|
+
import { refused } from './errors.mjs'
|
|
6
|
+
|
|
7
|
+
/** The import to write: `<pkg>/plugin` when the package has one, and however it exports its factory. */
|
|
8
|
+
function pluginImport(root, pkg) {
|
|
9
|
+
const require = createRequire(join(root, 'package.json'))
|
|
10
|
+
const name = pluginName(pkg)
|
|
11
|
+
for (const spec of [`${pkg}/plugin`, pkg]) {
|
|
12
|
+
let path
|
|
13
|
+
try {
|
|
14
|
+
path = require.resolve(spec)
|
|
15
|
+
} catch {
|
|
16
|
+
continue
|
|
17
|
+
}
|
|
18
|
+
const factory = pluginFactory(createRequire(import.meta.url)(path), pkg)
|
|
19
|
+
if (!factory)
|
|
20
|
+
throw refused(`${spec} exports no plugin factory to call, so nothing was changed.`)
|
|
21
|
+
return {
|
|
22
|
+
name: factory.name,
|
|
23
|
+
line: `import ${factory.named ? `{ ${factory.name} }` : factory.name} from '${spec}'`,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { name, line: `import ${name} from '${pkg}'` } // not installed yet: only a dry run gets this far
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The object literal `export default` gives, directly or through `defineConfig(…)`. */
|
|
30
|
+
function configObject(sf) {
|
|
31
|
+
for (const st of sf.statements) {
|
|
32
|
+
if (!ts.isExportAssignment(st)) continue
|
|
33
|
+
const value = ts.isCallExpression(st.expression) ? st.expression.arguments[0] : st.expression
|
|
34
|
+
if (value && ts.isObjectLiteralExpression(value)) return value
|
|
35
|
+
}
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function addToTs(root, file, text, pkg) {
|
|
40
|
+
const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true)
|
|
41
|
+
const object = configObject(sf)
|
|
42
|
+
if (!object)
|
|
43
|
+
throw refused(
|
|
44
|
+
`${file} doesn't export a plain object, so \`kerf add\` can't edit it. Add \`${pkg}\` to \`plugins\` by hand.`,
|
|
45
|
+
)
|
|
46
|
+
const { name, line } = pluginImport(root, pkg)
|
|
47
|
+
const prop = object.properties.find((p) => p.name?.getText(sf) === 'plugins')
|
|
48
|
+
if (prop && !(ts.isPropertyAssignment(prop) && ts.isArrayLiteralExpression(prop.initializer)))
|
|
49
|
+
throw refused(
|
|
50
|
+
`\`plugins\` in ${file} isn't a plain array, so \`kerf add\` can't edit it. Add \`${pkg}\` by hand.`,
|
|
51
|
+
)
|
|
52
|
+
const edits = []
|
|
53
|
+
const imports = sf.statements.filter(ts.isImportDeclaration)
|
|
54
|
+
const after = imports.at(-1)?.end ?? 0
|
|
55
|
+
edits.push([after, `${imports.length ? '\n' : ''}${line}${imports.length ? '' : '\n'}`])
|
|
56
|
+
if (prop) {
|
|
57
|
+
const list = prop.initializer
|
|
58
|
+
const last = list.elements.at(-1)
|
|
59
|
+
edits.push(last ? [last.end, `, ${name}()`] : [list.getStart(sf) + 1, `${name}()`])
|
|
60
|
+
} else {
|
|
61
|
+
const last = object.properties.at(-1)
|
|
62
|
+
edits.push(
|
|
63
|
+
last
|
|
64
|
+
? [
|
|
65
|
+
object.properties.end,
|
|
66
|
+
`${object.properties.hasTrailingComma ? '' : ','}\n plugins: [${name}()],`,
|
|
67
|
+
]
|
|
68
|
+
: [object.getStart(sf) + 1, `\n plugins: [${name}()],\n`],
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
return edits
|
|
72
|
+
.toSorted((a, b) => b[0] - a[0])
|
|
73
|
+
.reduce((t, [at, insert]) => t.slice(0, at) + insert + t.slice(at), text)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function addToData(file, text, pkg) {
|
|
77
|
+
if (file.endsWith('.json')) {
|
|
78
|
+
const data = JSON.parse(text)
|
|
79
|
+
data.plugins = [...(data.plugins ?? []), pkg]
|
|
80
|
+
return `${JSON.stringify(data, null, 2)}\n`
|
|
81
|
+
}
|
|
82
|
+
const { parseDocument } = createRequire(import.meta.url)('yaml')
|
|
83
|
+
const doc = parseDocument(text)
|
|
84
|
+
if (doc.has('plugins')) doc.addIn(['plugins'], pkg)
|
|
85
|
+
else doc.set('plugins', [pkg])
|
|
86
|
+
return doc.toString()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const listed = (config, pkg) => (config.plugins ?? []).some((p) => p.name === pkg)
|
|
90
|
+
|
|
91
|
+
/** The config names the package already (imported or listed), which a read can tell without loading it. */
|
|
92
|
+
export const names = (text, pkg) =>
|
|
93
|
+
new RegExp(`['"]${pkg.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')}(/[\\w-]+)?['"]`).test(text)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
import { database } from '../map.mjs'
|
|
6
|
+
import { dbLayer } from '../db-layer.mjs'
|
|
7
|
+
import { refused } from './errors.mjs'
|
|
8
|
+
|
|
9
|
+
/** The plugin's `setup`, once the package is installed: a plain import, since the package can't run anything by being read. */
|
|
10
|
+
export async function setupOf(root, pkg) {
|
|
11
|
+
let path
|
|
12
|
+
try {
|
|
13
|
+
path = createRequire(join(root, 'package.json')).resolve(`${pkg}/plugin`)
|
|
14
|
+
} catch {
|
|
15
|
+
return undefined // no plugin entry, or a dry run before the install
|
|
16
|
+
}
|
|
17
|
+
const mod = await import(pathToFileURL(path).href)
|
|
18
|
+
const make = mod.default ?? Object.values(mod).find((v) => typeof v === 'function')
|
|
19
|
+
return make?.().contribute({ command: 'check', mode: 'development', root }).setup
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** What `setup` wants, checked in full before anything is written, so a refusal changes nothing. */
|
|
23
|
+
export async function planSetup(root, setup) {
|
|
24
|
+
const layer = await dbLayer(root)
|
|
25
|
+
if (setup.needs?.includes('db') && !layer)
|
|
26
|
+
throw refused('This needs a database: run `kerf add db` first. Nothing was changed.')
|
|
27
|
+
if (setup.needs?.includes('auth') && !existsSync(join(root, 'src/auth.server.ts')))
|
|
28
|
+
throw refused('This needs users: run `kerf add auth` first. Nothing was changed.')
|
|
29
|
+
const read = (rel) =>
|
|
30
|
+
existsSync(join(root, rel)) ? readFileSync(join(root, rel), 'utf8') : undefined
|
|
31
|
+
let plan
|
|
32
|
+
try {
|
|
33
|
+
plan = setup.run({
|
|
34
|
+
engine: layer ? database(root, layer).engine : null,
|
|
35
|
+
layer: layer?.layer ?? null,
|
|
36
|
+
read,
|
|
37
|
+
})
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw refused(`${error.message}. Nothing was changed.`)
|
|
40
|
+
}
|
|
41
|
+
const taken = Object.keys(plan.files ?? {}).filter((f) => existsSync(join(root, f)))
|
|
42
|
+
if (taken.length) throw refused(`${taken.join(', ')} already exist. Nothing was changed.`)
|
|
43
|
+
return plan
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function applySetup(root, plan) {
|
|
47
|
+
for (const [file, text] of Object.entries({ ...plan.files, ...plan.edits })) {
|
|
48
|
+
mkdirSync(dirname(join(root, file)), { recursive: true })
|
|
49
|
+
writeFileSync(join(root, file), text)
|
|
50
|
+
}
|
|
51
|
+
for (const name of ['.env', '.env.example']) {
|
|
52
|
+
const file = join(root, name)
|
|
53
|
+
const had = existsSync(file) ? readFileSync(file, 'utf8') : ''
|
|
54
|
+
const lines = Object.entries(plan.env ?? {})
|
|
55
|
+
.filter(([k]) => !had.includes(`${k}=`))
|
|
56
|
+
.map(([k, v]) => `${k}=${v}\n`)
|
|
57
|
+
if (lines.length) writeFileSync(file, `${had && `${had.trimEnd()}\n`}${lines.join('')}`)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const setupActions = (plan) => [
|
|
62
|
+
...Object.keys({ ...plan.files, ...plan.edits }).map((f) => `write ${f}`),
|
|
63
|
+
...(plan.env ? [`add ${Object.keys(plan.env).join(', ')} to .env and .env.example`] : []),
|
|
64
|
+
...(plan.next ?? []).map((n) => `next: ${n}`),
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
export function authEdits({ root, files, context, tables, envText, layer }) {
|
|
68
|
+
const edits = { ...files, 'src/context.server.ts': context }
|
|
69
|
+
if (!envText.includes('BETTER_AUTH_SECRET'))
|
|
70
|
+
edits['src/env.server.ts'] = envText.replace(
|
|
71
|
+
'server: {\n',
|
|
72
|
+
'server: {\n BETTER_AUTH_SECRET: z.string().min(32),\n',
|
|
73
|
+
)
|
|
74
|
+
if (layer.layer === 'drizzle') {
|
|
75
|
+
edits['src/db/auth.schema.ts'] = tables
|
|
76
|
+
edits['src/db/schema.ts'] =
|
|
77
|
+
`${readFileSync(join(root, 'src/db/schema.ts'), 'utf8').trimEnd()}\n\nexport * from './auth.schema'\n`
|
|
78
|
+
} else if (layer.layer === 'prisma') {
|
|
79
|
+
edits['prisma/schema.prisma'] =
|
|
80
|
+
`${readFileSync(join(root, 'prisma/schema.prisma'), 'utf8').trimEnd()}\n${tables}`
|
|
81
|
+
} else {
|
|
82
|
+
const next = existsSync(join(root, 'migrations'))
|
|
83
|
+
? readdirSync(join(root, 'migrations')).filter((f) => f.endsWith('.sql')).length
|
|
84
|
+
: 0
|
|
85
|
+
edits[`migrations/${String(next).padStart(4, '0')}_auth.sql`] = tables
|
|
86
|
+
}
|
|
87
|
+
return edits
|
|
88
|
+
}
|