create-kerf-component 5.0.0-beta.11 → 5.0.0-beta.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -3
- package/catalog.js +1219 -0
- package/component-catalog-extension.schema.json +104 -0
- package/component-composition.schema.json +444 -0
- package/component-metadata.schema.json +413 -0
- package/index.js +31 -3
- package/package.json +10 -2
- package/template/README.md +53 -10
- package/template/component-composition.json +144 -0
- package/template/kerf.components.json +71 -0
- package/template/package.json +15 -3
- package/template/src/counter.css +38 -0
- package/template/src/counter.tsx +18 -3
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://raw.githubusercontent.com/brianwestphal/kerf/main/create-kerf-component/component-metadata.schema.json",
|
|
4
|
+
"title": "Kerf consumer component metadata source",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["schemaVersion", "components"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": { "type": "string" },
|
|
9
|
+
"schemaVersion": { "const": 1 },
|
|
10
|
+
"componentCatalog": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"minLength": 1,
|
|
13
|
+
"description": "Relative path to the package's component (selection) catalog, copied into the generated composition catalog's compatibility.componentCatalog. When package.json#kerfComponentCatalog.selectionOutput is configured and this is absent or \"not-applicable\", the generator derives it from that output path; otherwise it defaults to \"not-applicable\"."
|
|
14
|
+
},
|
|
15
|
+
"description": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"minLength": 1,
|
|
18
|
+
"description": "One-line description of the package's components, emitted as the selection catalog's description. Required when package.json#kerfComponentCatalog.selectionOutput is configured."
|
|
19
|
+
},
|
|
20
|
+
"components": {
|
|
21
|
+
"type": "array",
|
|
22
|
+
"items": { "$ref": "#/$defs/component" }
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"additionalProperties": false,
|
|
26
|
+
"$defs": {
|
|
27
|
+
"propCondition": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"required": ["prop", "equals"],
|
|
30
|
+
"properties": {
|
|
31
|
+
"prop": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"pattern": "^[A-Za-z][A-Za-z0-9]*$",
|
|
34
|
+
"description": "A JSX prop of the element."
|
|
35
|
+
},
|
|
36
|
+
"equals": {
|
|
37
|
+
"anyOf": [
|
|
38
|
+
{ "type": "string" },
|
|
39
|
+
{ "type": "number" },
|
|
40
|
+
{ "type": "boolean" }
|
|
41
|
+
],
|
|
42
|
+
"description": "The statically written value that satisfies the condition. A bare boolean prop (<Card flush />) equals true."
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"additionalProperties": false
|
|
46
|
+
},
|
|
47
|
+
"stateAttribute": {
|
|
48
|
+
"type": "object",
|
|
49
|
+
"required": ["name", "on", "helper", "meaning"],
|
|
50
|
+
"properties": {
|
|
51
|
+
"name": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"minLength": 1,
|
|
54
|
+
"pattern": "^data-[a-z0-9]+(-[a-z0-9]+)*$"
|
|
55
|
+
},
|
|
56
|
+
"on": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"minLength": 1,
|
|
59
|
+
"description": "The element that carries it: a public class, or the element passed to the helper."
|
|
60
|
+
},
|
|
61
|
+
"helper": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"minLength": 1,
|
|
64
|
+
"description": "The helper, one of wiring.helpers, that writes it."
|
|
65
|
+
},
|
|
66
|
+
"meaning": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"minLength": 1,
|
|
69
|
+
"description": "What its presence or value means."
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"additionalProperties": false
|
|
73
|
+
},
|
|
74
|
+
"repositoryPath": {
|
|
75
|
+
"description": "A package-relative POSIX path without traversal or empty segments.",
|
|
76
|
+
"type": "string",
|
|
77
|
+
"pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*$"
|
|
78
|
+
},
|
|
79
|
+
"selection": {
|
|
80
|
+
"description": "Selection facts for the generated selection catalog (package.json#kerfComponentCatalog.selectionOutput). name, kind, purpose, source, publicClasses, publicTokens, and geometry are derived from the component; only the facts the composition metadata cannot express live here. Required on every component and composition when selectionOutput is configured; recipes are not selection entries.",
|
|
81
|
+
"type": "object",
|
|
82
|
+
"required": ["useWhen", "avoidWhen"],
|
|
83
|
+
"properties": {
|
|
84
|
+
"useWhen": {
|
|
85
|
+
"type": "array",
|
|
86
|
+
"items": { "type": "string", "minLength": 1 },
|
|
87
|
+
"minItems": 1
|
|
88
|
+
},
|
|
89
|
+
"avoidWhen": {
|
|
90
|
+
"type": "array",
|
|
91
|
+
"items": { "type": "string", "minLength": 1 },
|
|
92
|
+
"minItems": 1
|
|
93
|
+
},
|
|
94
|
+
"uses": {
|
|
95
|
+
"description": "Directly composed catalog entry ids: this package's own component ids or @kerfjs/ui selection catalog ids.",
|
|
96
|
+
"$ref": "#/$defs/stringList"
|
|
97
|
+
},
|
|
98
|
+
"styleSources": {
|
|
99
|
+
"description": "Stylesheets this component owns, relative to the package root.",
|
|
100
|
+
"type": "array",
|
|
101
|
+
"items": {
|
|
102
|
+
"allOf": [
|
|
103
|
+
{ "$ref": "#/$defs/repositoryPath" },
|
|
104
|
+
{ "pattern": "\\.css$" }
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"minItems": 1,
|
|
108
|
+
"uniqueItems": true
|
|
109
|
+
},
|
|
110
|
+
"demoSource": { "$ref": "#/$defs/repositoryPath" },
|
|
111
|
+
"documentation": { "type": "string", "minLength": 1 },
|
|
112
|
+
"geometry": {
|
|
113
|
+
"description": "Overrides composition.layout.geometry in the selection catalog. Required when that geometry uses the composition-only owner \"composed\".",
|
|
114
|
+
"type": "object",
|
|
115
|
+
"required": ["margin", "border", "padding"],
|
|
116
|
+
"properties": {
|
|
117
|
+
"margin": { "$ref": "#/$defs/selectionGeometryOwner" },
|
|
118
|
+
"border": { "$ref": "#/$defs/selectionGeometryOwner" },
|
|
119
|
+
"padding": { "$ref": "#/$defs/selectionGeometryOwner" },
|
|
120
|
+
"notes": {
|
|
121
|
+
"type": "array",
|
|
122
|
+
"items": { "type": "string", "minLength": 1 },
|
|
123
|
+
"minItems": 1
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"additionalProperties": false
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"additionalProperties": false
|
|
130
|
+
},
|
|
131
|
+
"selectionGeometryOwner": {
|
|
132
|
+
"enum": ["self", "parent", "child", "none", "conditional"]
|
|
133
|
+
},
|
|
134
|
+
"stringList": {
|
|
135
|
+
"type": "array",
|
|
136
|
+
"items": { "type": "string", "minLength": 1 },
|
|
137
|
+
"uniqueItems": true
|
|
138
|
+
},
|
|
139
|
+
"cardinality": {
|
|
140
|
+
"type": "object",
|
|
141
|
+
"required": ["min", "max"],
|
|
142
|
+
"properties": {
|
|
143
|
+
"min": { "type": "integer", "minimum": 0 },
|
|
144
|
+
"max": {
|
|
145
|
+
"anyOf": [
|
|
146
|
+
{ "type": "integer", "minimum": 1 },
|
|
147
|
+
{ "const": "unbounded" }
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"additionalProperties": false
|
|
152
|
+
},
|
|
153
|
+
"diagnostic": {
|
|
154
|
+
"type": "object",
|
|
155
|
+
"required": ["id", "severity", "when", "message"],
|
|
156
|
+
"properties": {
|
|
157
|
+
"id": { "type": "string", "pattern": "^KUI-C[0-9]{3}$" },
|
|
158
|
+
"severity": { "enum": ["error", "warning"] },
|
|
159
|
+
"when": { "type": "string", "minLength": 1 },
|
|
160
|
+
"message": { "type": "string", "minLength": 1 }
|
|
161
|
+
},
|
|
162
|
+
"additionalProperties": false
|
|
163
|
+
},
|
|
164
|
+
"component": {
|
|
165
|
+
"type": "object",
|
|
166
|
+
"required": [
|
|
167
|
+
"id",
|
|
168
|
+
"name",
|
|
169
|
+
"kind",
|
|
170
|
+
"purpose",
|
|
171
|
+
"source",
|
|
172
|
+
"publicExports",
|
|
173
|
+
"sourceLinks",
|
|
174
|
+
"composition",
|
|
175
|
+
"boundaries",
|
|
176
|
+
"accessibility",
|
|
177
|
+
"diagnostics",
|
|
178
|
+
"provenance"
|
|
179
|
+
],
|
|
180
|
+
"properties": {
|
|
181
|
+
"id": { "type": "string", "minLength": 1 },
|
|
182
|
+
"name": { "type": "string", "minLength": 1 },
|
|
183
|
+
"kind": { "enum": ["component", "composition", "recipe"] },
|
|
184
|
+
"purpose": { "type": "string", "minLength": 1 },
|
|
185
|
+
"source": { "type": "string", "minLength": 1 },
|
|
186
|
+
"publicExports": {
|
|
187
|
+
"type": "array",
|
|
188
|
+
"minItems": 1,
|
|
189
|
+
"description": "Each export's name and package.json#exports subpath. A private application (package.json#private) may omit subpath; the name is then verified against the component's source file.",
|
|
190
|
+
"items": {
|
|
191
|
+
"type": "object",
|
|
192
|
+
"required": ["name"],
|
|
193
|
+
"properties": {
|
|
194
|
+
"name": { "type": "string", "minLength": 1 },
|
|
195
|
+
"subpath": { "type": "string", "pattern": "^\\." }
|
|
196
|
+
},
|
|
197
|
+
"additionalProperties": false
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
"sourceLinks": { "$ref": "#/$defs/stringList" },
|
|
201
|
+
"composition": { "$ref": "#/$defs/composition" },
|
|
202
|
+
"boundaries": {
|
|
203
|
+
"type": "object",
|
|
204
|
+
"required": ["rootClass", "publicClasses", "publicTokens"],
|
|
205
|
+
"properties": {
|
|
206
|
+
"rootClass": {
|
|
207
|
+
"oneOf": [
|
|
208
|
+
{ "type": "string", "minLength": 1 },
|
|
209
|
+
{ "type": "null" }
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
"publicClasses": { "$ref": "#/$defs/stringList" },
|
|
213
|
+
"placeableClasses": {
|
|
214
|
+
"$ref": "#/$defs/stringList",
|
|
215
|
+
"description": "The subset of publicClasses an application may place on its own elements (a layout utility, item geometry on another carrier). Absent means none: every public class is the component's rendered anatomy, which eslint-plugin-kerfjs reports on an application-owned element as KUI-L103 with the component to render."
|
|
216
|
+
},
|
|
217
|
+
"rootElement": {
|
|
218
|
+
"type": "string",
|
|
219
|
+
"pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
|
|
220
|
+
"description": "The intrinsic element the component renders around its own placeableClasses. A placeable class on a plain element of this tag is the component recreated (KUI-L103); another carrier element keeps it. Requires placeableClasses."
|
|
221
|
+
},
|
|
222
|
+
"publicTokens": { "$ref": "#/$defs/stringList" }
|
|
223
|
+
},
|
|
224
|
+
"additionalProperties": false
|
|
225
|
+
},
|
|
226
|
+
"accessibility": {
|
|
227
|
+
"type": "object",
|
|
228
|
+
"required": ["obligations"],
|
|
229
|
+
"properties": { "obligations": { "$ref": "#/$defs/stringList" } },
|
|
230
|
+
"additionalProperties": false
|
|
231
|
+
},
|
|
232
|
+
"diagnostics": {
|
|
233
|
+
"type": "array",
|
|
234
|
+
"items": { "$ref": "#/$defs/diagnostic" }
|
|
235
|
+
},
|
|
236
|
+
"provenance": {
|
|
237
|
+
"type": "object",
|
|
238
|
+
"required": ["selection", "composition"],
|
|
239
|
+
"properties": {
|
|
240
|
+
"selection": { "type": "string", "minLength": 1 },
|
|
241
|
+
"composition": { "type": "string", "minLength": 1 }
|
|
242
|
+
},
|
|
243
|
+
"additionalProperties": false
|
|
244
|
+
},
|
|
245
|
+
"selection": { "$ref": "#/$defs/selection" }
|
|
246
|
+
},
|
|
247
|
+
"additionalProperties": false
|
|
248
|
+
},
|
|
249
|
+
"composition": {
|
|
250
|
+
"type": "object",
|
|
251
|
+
"required": [
|
|
252
|
+
"parents",
|
|
253
|
+
"contexts",
|
|
254
|
+
"zones",
|
|
255
|
+
"children",
|
|
256
|
+
"state",
|
|
257
|
+
"wiring",
|
|
258
|
+
"responsive",
|
|
259
|
+
"layout"
|
|
260
|
+
],
|
|
261
|
+
"properties": {
|
|
262
|
+
"rendersAs": {
|
|
263
|
+
"description": "For a wrapper component: the cataloged roots it renders (package-qualified keys such as @kerfjs/ui:toolbar-control-group), any one of them or nothing. UI composition checks treat the wrapper as each declared root.",
|
|
264
|
+
"type": "array",
|
|
265
|
+
"minItems": 1,
|
|
266
|
+
"items": { "type": "string", "pattern": "^[^:]+:[^:]+$" },
|
|
267
|
+
"uniqueItems": true
|
|
268
|
+
},
|
|
269
|
+
"insetFreeChildren": {
|
|
270
|
+
"description": "Prop values under which this component's direct JSX children must bring no content-item inset (for example an embedded appearance that already insets its content). While any condition holds, a child whose layout.geometry is self on margin, border, and padding double-insets this component unless one of the child's insetFreeWhen conditions holds; eslint-plugin-kerfjs reports it as KUI-L204.",
|
|
271
|
+
"type": "array",
|
|
272
|
+
"items": { "$ref": "#/$defs/propCondition" },
|
|
273
|
+
"minItems": 1
|
|
274
|
+
},
|
|
275
|
+
"insetFreeWhen": {
|
|
276
|
+
"description": "Prop values that render this inset-bearing component with no margin, border, or padding of its own (for example a flush prop). Any one condition makes the element inset-free inside a parent that declares insetFreeChildren.",
|
|
277
|
+
"type": "array",
|
|
278
|
+
"items": { "$ref": "#/$defs/propCondition" },
|
|
279
|
+
"minItems": 1
|
|
280
|
+
},
|
|
281
|
+
"parents": {
|
|
282
|
+
"type": "object",
|
|
283
|
+
"required": ["mode", "entries"],
|
|
284
|
+
"properties": {
|
|
285
|
+
"mode": { "enum": ["any", "root", "listed"] },
|
|
286
|
+
"entries": { "$ref": "#/$defs/stringList" }
|
|
287
|
+
},
|
|
288
|
+
"additionalProperties": false
|
|
289
|
+
},
|
|
290
|
+
"contexts": { "$ref": "#/$defs/stringList" },
|
|
291
|
+
"zones": {
|
|
292
|
+
"type": "array",
|
|
293
|
+
"items": {
|
|
294
|
+
"type": "object",
|
|
295
|
+
"required": ["id", "accepts", "cardinality", "exclusiveWith"],
|
|
296
|
+
"properties": {
|
|
297
|
+
"id": { "type": "string", "minLength": 1 },
|
|
298
|
+
"jsx": {
|
|
299
|
+
"description": "The JSX prop that fills this zone (children for the default slot), so composition checks can map a prop's value to its zone. Unique per component.",
|
|
300
|
+
"type": "object",
|
|
301
|
+
"required": ["prop"],
|
|
302
|
+
"properties": {
|
|
303
|
+
"prop": { "type": "string", "minLength": 1 }
|
|
304
|
+
},
|
|
305
|
+
"additionalProperties": false
|
|
306
|
+
},
|
|
307
|
+
"accepts": { "$ref": "#/$defs/stringList" },
|
|
308
|
+
"cardinality": { "$ref": "#/$defs/cardinality" },
|
|
309
|
+
"exclusiveWith": { "$ref": "#/$defs/stringList" }
|
|
310
|
+
},
|
|
311
|
+
"additionalProperties": false
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
"children": {
|
|
315
|
+
"type": "object",
|
|
316
|
+
"required": ["mode", "concepts", "requiredConcepts"],
|
|
317
|
+
"properties": {
|
|
318
|
+
"mode": { "enum": ["any", "none", "listed"] },
|
|
319
|
+
"concepts": { "$ref": "#/$defs/stringList" },
|
|
320
|
+
"requiredConcepts": { "$ref": "#/$defs/stringList" }
|
|
321
|
+
},
|
|
322
|
+
"additionalProperties": false
|
|
323
|
+
},
|
|
324
|
+
"state": {
|
|
325
|
+
"type": "array",
|
|
326
|
+
"items": {
|
|
327
|
+
"type": "object",
|
|
328
|
+
"required": ["id", "owner", "required"],
|
|
329
|
+
"properties": {
|
|
330
|
+
"id": { "type": "string", "minLength": 1 },
|
|
331
|
+
"owner": { "enum": ["application", "controlled", "component"] },
|
|
332
|
+
"required": { "type": "boolean" }
|
|
333
|
+
},
|
|
334
|
+
"additionalProperties": false
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
"wiring": {
|
|
338
|
+
"type": "object",
|
|
339
|
+
"required": ["required", "helpers", "obligations"],
|
|
340
|
+
"properties": {
|
|
341
|
+
"required": { "type": "boolean" },
|
|
342
|
+
"scope": {
|
|
343
|
+
"description": "Where a required helper must run: application (default) anywhere reachable from a profile wiring entry, or module in the module that renders the component.",
|
|
344
|
+
"enum": ["application", "module"]
|
|
345
|
+
},
|
|
346
|
+
"helpers": { "$ref": "#/$defs/stringList" },
|
|
347
|
+
"sources": {
|
|
348
|
+
"description": "Where each application-owned helper in helpers is defined: its export name and source file relative to the package root. UI lint resolves relative imports of these helpers to verify page-root wiring (KUI-L401).",
|
|
349
|
+
"type": "array",
|
|
350
|
+
"items": {
|
|
351
|
+
"type": "object",
|
|
352
|
+
"required": ["export", "source"],
|
|
353
|
+
"properties": {
|
|
354
|
+
"export": { "type": "string", "minLength": 1 },
|
|
355
|
+
"source": { "type": "string", "minLength": 1 }
|
|
356
|
+
},
|
|
357
|
+
"additionalProperties": false
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
"actions": {
|
|
361
|
+
"description": "data-action values the application must handle with a root-delegated listener (delegate or delegateActions) instead of a named helper. Required wiring names at least one helper or action; UI lint verifies a reachable handler (KUI-L401).",
|
|
362
|
+
"$ref": "#/$defs/stringList"
|
|
363
|
+
},
|
|
364
|
+
"obligations": { "$ref": "#/$defs/stringList" },
|
|
365
|
+
"stateAttributes": {
|
|
366
|
+
"description": "Optional wiring-owned state attributes: data-* attributes a wiring helper writes at runtime, which the application must not render, remove, or treat as its own state.",
|
|
367
|
+
"type": "array",
|
|
368
|
+
"items": { "$ref": "#/$defs/stateAttribute" }
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
"additionalProperties": false
|
|
372
|
+
},
|
|
373
|
+
"responsive": {
|
|
374
|
+
"type": "object",
|
|
375
|
+
"required": ["owner", "behaviors"],
|
|
376
|
+
"properties": {
|
|
377
|
+
"owner": {
|
|
378
|
+
"enum": ["application", "component", "shared", "not-applicable"]
|
|
379
|
+
},
|
|
380
|
+
"behaviors": { "$ref": "#/$defs/stringList" }
|
|
381
|
+
},
|
|
382
|
+
"additionalProperties": false
|
|
383
|
+
},
|
|
384
|
+
"layout": {
|
|
385
|
+
"type": "object",
|
|
386
|
+
"required": ["roles", "geometry"],
|
|
387
|
+
"properties": {
|
|
388
|
+
"roles": {
|
|
389
|
+
"description": "One or more grouping roles for selection and catalog navigation. Prefer @kerfjs/ui's vocabulary so merged catalogs group consistently: structure, navigation, controls, actions, forms, feedback, foundation, media, layout, helpers, reference-composition (see docs/13-component-packages.md, Layout roles).",
|
|
390
|
+
"$ref": "#/$defs/stringList"
|
|
391
|
+
},
|
|
392
|
+
"geometry": {
|
|
393
|
+
"type": "object",
|
|
394
|
+
"required": ["margin", "border", "padding"],
|
|
395
|
+
"properties": {
|
|
396
|
+
"margin": { "$ref": "#/$defs/geometryOwner" },
|
|
397
|
+
"border": { "$ref": "#/$defs/geometryOwner" },
|
|
398
|
+
"padding": { "$ref": "#/$defs/geometryOwner" },
|
|
399
|
+
"notes": { "$ref": "#/$defs/stringList" }
|
|
400
|
+
},
|
|
401
|
+
"additionalProperties": false
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
"additionalProperties": false
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
"additionalProperties": false
|
|
408
|
+
},
|
|
409
|
+
"geometryOwner": {
|
|
410
|
+
"enum": ["self", "parent", "child", "none", "conditional", "composed"]
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
package/index.js
CHANGED
|
@@ -17,8 +17,18 @@
|
|
|
17
17
|
// kerf-component` alone just works. No third-party dependencies — the
|
|
18
18
|
// initializer is plain Node so `npm create` runs it with zero install latency.
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
copyFileSync,
|
|
22
|
+
cpSync,
|
|
23
|
+
existsSync,
|
|
24
|
+
mkdirSync,
|
|
25
|
+
readdirSync,
|
|
26
|
+
readFileSync,
|
|
27
|
+
renameSync,
|
|
28
|
+
writeFileSync,
|
|
29
|
+
} from 'node:fs';
|
|
21
30
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
31
|
+
import process from 'node:process';
|
|
22
32
|
import { createInterface } from 'node:readline/promises';
|
|
23
33
|
import { fileURLToPath } from 'node:url';
|
|
24
34
|
|
|
@@ -41,7 +51,9 @@ const USAGE =
|
|
|
41
51
|
async function promptForTarget() {
|
|
42
52
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
43
53
|
try {
|
|
44
|
-
const answer = await rl.question(
|
|
54
|
+
const answer = await rl.question(
|
|
55
|
+
`Directory (\`.\` for current) [${DEFAULT_NAME}]: `,
|
|
56
|
+
);
|
|
45
57
|
return answer.trim() || DEFAULT_NAME;
|
|
46
58
|
} finally {
|
|
47
59
|
rl.close();
|
|
@@ -117,6 +129,20 @@ async function main(argv) {
|
|
|
117
129
|
// verbatim (`_gitignore` → `.gitignore`).
|
|
118
130
|
mkdirSync(targetDir, { recursive: true });
|
|
119
131
|
cpSync(TEMPLATE_DIR, targetDir, { recursive: true });
|
|
132
|
+
mkdirSync(join(targetDir, 'scripts'), { recursive: true });
|
|
133
|
+
copyFileSync(
|
|
134
|
+
join(dirname(fileURLToPath(import.meta.url)), 'catalog.js'),
|
|
135
|
+
join(targetDir, 'scripts', 'kerf-component-catalog.mjs'),
|
|
136
|
+
);
|
|
137
|
+
for (const schema of [
|
|
138
|
+
'component-metadata.schema.json',
|
|
139
|
+
'component-composition.schema.json',
|
|
140
|
+
'component-catalog-extension.schema.json',
|
|
141
|
+
])
|
|
142
|
+
copyFileSync(
|
|
143
|
+
join(dirname(fileURLToPath(import.meta.url)), schema),
|
|
144
|
+
join(targetDir, 'scripts', schema),
|
|
145
|
+
);
|
|
120
146
|
|
|
121
147
|
for (const file of walk(targetDir)) {
|
|
122
148
|
const text = readFileSync(file, 'utf8');
|
|
@@ -136,8 +162,10 @@ async function main(argv) {
|
|
|
136
162
|
cdHint +
|
|
137
163
|
' npm install\n' +
|
|
138
164
|
' npm run build # tsup → ESM + .d.ts (kerfjs stays external)\n' +
|
|
165
|
+
' npm run catalog:check # verify AI metadata and public exports\n' +
|
|
166
|
+
' npm run check:styles # each component styles only itself (kerf-ui-analyze)\n' +
|
|
139
167
|
' npm run typecheck\n\n' +
|
|
140
|
-
'Edit src/counter.tsx, then publish with `npm publish --access public`.\n',
|
|
168
|
+
'Edit src/counter.tsx, src/counter.css, and kerf.components.json, then publish with `npm publish --access public`.\n',
|
|
141
169
|
);
|
|
142
170
|
}
|
|
143
171
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-kerf-component",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.111",
|
|
4
4
|
"description": "Scaffold a publishable kerf component package that already follows kerf's hard packaging rules.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,15 +26,23 @@
|
|
|
26
26
|
"node": ">=18.0.0"
|
|
27
27
|
},
|
|
28
28
|
"bin": {
|
|
29
|
-
"create-kerf-component": "index.js"
|
|
29
|
+
"create-kerf-component": "index.js",
|
|
30
|
+
"kerf-component-catalog": "catalog.js"
|
|
30
31
|
},
|
|
31
32
|
"files": [
|
|
32
33
|
"index.js",
|
|
34
|
+
"catalog.js",
|
|
35
|
+
"component-metadata.schema.json",
|
|
36
|
+
"component-composition.schema.json",
|
|
37
|
+
"component-catalog-extension.schema.json",
|
|
33
38
|
"template",
|
|
34
39
|
"README.md",
|
|
35
40
|
"LICENSE"
|
|
36
41
|
],
|
|
37
42
|
"scripts": {
|
|
38
43
|
"test": "node --test tests/*.test.js"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"typescript": "^5.0.0 || ^6.0.0"
|
|
39
47
|
}
|
|
40
48
|
}
|
package/template/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# **PKG_NAME**
|
|
2
2
|
|
|
3
3
|
A reusable [kerf](https://github.com/brianwestphal/kerf) component package,
|
|
4
4
|
scaffolded with `create-kerf-component`.
|
|
@@ -7,8 +7,10 @@ scaffolded with `create-kerf-component`.
|
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
9
|
npm install
|
|
10
|
-
npm run build
|
|
10
|
+
npm run build # tsup → dist/ (ESM + .d.ts); kerfjs stays external
|
|
11
11
|
npm run typecheck
|
|
12
|
+
npm run catalog:check # verify component-composition.json is current
|
|
13
|
+
npm run check:styles # each component styles only itself (kerf-ui-analyze)
|
|
12
14
|
```
|
|
13
15
|
|
|
14
16
|
## Use it
|
|
@@ -17,13 +19,14 @@ A kerf app that already has `jsxImportSource: "kerfjs"` configured can import an
|
|
|
17
19
|
render the component like any local function — there's no extra toolchain:
|
|
18
20
|
|
|
19
21
|
```tsx
|
|
20
|
-
import { mount } from
|
|
21
|
-
import { Counter, createCounter, wireCounter } from
|
|
22
|
+
import { mount } from "kerfjs";
|
|
23
|
+
import { Counter, createCounter, wireCounter } from "__PKG_NAME__";
|
|
24
|
+
import "__PKG_NAME__/counter.css";
|
|
22
25
|
|
|
23
|
-
const counter = createCounter(0);
|
|
24
|
-
const root = document.getElementById(
|
|
26
|
+
const counter = createCounter(0); // per-instance state (a factory)
|
|
27
|
+
const root = document.getElementById("app")!;
|
|
25
28
|
|
|
26
|
-
mount(root, () => <Counter store={counter} label="Clicks" />);
|
|
29
|
+
mount(root, () => <Counter store={counter} label="Clicks" size="compact" />);
|
|
27
30
|
|
|
28
31
|
const dispose = wireCounter(root, counter); // delegation disposer (call on teardown)
|
|
29
32
|
```
|
|
@@ -31,7 +34,7 @@ const dispose = wireCounter(root, counter); // delegation disposer (call on tear
|
|
|
31
34
|
## The rules this package follows
|
|
32
35
|
|
|
33
36
|
These are kerf's hard packaging rules (see the kerf docs,
|
|
34
|
-
|
|
37
|
+
_Building reusable component packages_). The scaffold encodes them so you don't
|
|
35
38
|
have to:
|
|
36
39
|
|
|
37
40
|
- **`kerfjs` is a `peerDependency` and is `external` in the build — never
|
|
@@ -43,9 +46,17 @@ have to:
|
|
|
43
46
|
- **No inline JSX event handlers.** Components are pure `(props) => SafeHtml`
|
|
44
47
|
string-builders; emit `data-action` hooks and let the host wire events with
|
|
45
48
|
`delegate()` (see `wireCounter`), which returns a disposer.
|
|
49
|
+
- **Each component owns its styles; configure, never override.** `counter.css`
|
|
50
|
+
styles only `.kerf-counter` and its own internals and writes only
|
|
51
|
+
`--_kerf-counter-*` private variables (context it provides is named after
|
|
52
|
+
Counter). Consumers configure it through props (`size`) and its public token
|
|
53
|
+
(`--kerf-counter-gap`); when it must adapt inside a parent, Counter does so
|
|
54
|
+
in its own stylesheet (`.kui-toolbar .kerf-counter`). A needed variation with
|
|
55
|
+
no prop is a gap to add here, not an override for consumers.
|
|
56
|
+
`npm run check:styles` enforces this with `kerf-ui-analyze`.
|
|
46
57
|
- **Build emits ESM + `.d.ts`; `tsconfig` sets `jsxImportSource: "kerfjs"`.**
|
|
47
58
|
- **Never import `kerfjs/dev`.** kerf's dev diagnostics install global hooks, so
|
|
48
|
-
installing them is the consuming
|
|
59
|
+
installing them is the consuming _app's_ call, not a library's — the app
|
|
49
60
|
writes `if (import.meta.env.DEV) await import('kerfjs/dev')` in its own entry.
|
|
50
61
|
To get the diagnostics while developing this package, add that line to your own
|
|
51
62
|
test harness or demo page instead (it belongs to the harness, not to `src/`).
|
|
@@ -56,4 +67,36 @@ have to:
|
|
|
56
67
|
npm publish --access public
|
|
57
68
|
```
|
|
58
69
|
|
|
59
|
-
`prepublishOnly` runs the build
|
|
70
|
+
`prepublishOnly` checks the catalog and runs the build; `files` ships `dist/`,
|
|
71
|
+
the metadata/catalog pair, the README, and the license.
|
|
72
|
+
|
|
73
|
+
## AI component metadata
|
|
74
|
+
|
|
75
|
+
`kerf.components.json` is the author-owned source for the component's purpose,
|
|
76
|
+
public exports, composition rules, geometry ownership, tokens, accessibility,
|
|
77
|
+
and source links. `boundaries.rootClass` explicitly names the public class that
|
|
78
|
+
owns runtime geometry (or is `null` when none does); `publicClasses` order has no
|
|
79
|
+
semantic meaning. Every public class is the component's rendered anatomy unless
|
|
80
|
+
`boundaries.placeableClasses` lists it: once an app's `.kerf-ui-profile.json`
|
|
81
|
+
declares this package's catalog under `catalogs`, `eslint-plugin-kerfjs`
|
|
82
|
+
reports an app that writes `kerf-counter` onto its own `<div>` (`KUI-L103`) and
|
|
83
|
+
tells it to render `Counter` instead. List a class there only when apps may legitimately
|
|
84
|
+
place it themselves (a layout utility, item geometry on another carrier), and
|
|
85
|
+
add `rootElement` when the component itself renders those classes on that tag.
|
|
86
|
+
Keep decisions explicit: the generator deliberately does not
|
|
87
|
+
derive semantic or geometry ownership from rendered appearance. It validates
|
|
88
|
+
both this source and the generated catalog against the schema copies beside the
|
|
89
|
+
checker, including rejection of unknown fields. Named exports must exist in
|
|
90
|
+
the TypeScript/TSX syntax tree; JSX text, nested scopes, comments, and literals
|
|
91
|
+
are not exports. The checker uses this package's installed TypeScript compiler,
|
|
92
|
+
so run `npm install` before the first local catalog command.
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm run catalog:generate # write component-composition.json
|
|
96
|
+
npm run catalog:check # no writes; fail when metadata, source, or output drift
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The generated catalog ships with the package. AI tools join each entry to
|
|
100
|
+
Kerf's catalog by its `package:id` key, search this package first for
|
|
101
|
+
application-specific concepts, and retain both packages' identities when
|
|
102
|
+
following cross-catalog composition references.
|