create-kerf-component 5.0.0-beta.14 → 5.0.0-beta.140
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 +109 -4
- package/catalog/export-discovery.js +112 -0
- package/catalog/generate.js +308 -0
- package/catalog/schema-validate.js +140 -0
- package/catalog/schemas.js +19 -0
- package/catalog/selection.js +243 -0
- package/catalog/validate-component.js +524 -0
- package/catalog/workspace.js +62 -0
- package/catalog.js +65 -0
- package/component-catalog-extension.schema.json +104 -0
- package/component-composition.schema.json +694 -0
- package/component-metadata.schema.json +453 -0
- package/index.js +117 -20
- package/package.json +23 -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,453 @@
|
|
|
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
|
+
"interactiveRules": {
|
|
28
|
+
"type": "array",
|
|
29
|
+
"minItems": 1,
|
|
30
|
+
"items": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"required": ["kind"],
|
|
33
|
+
"properties": {
|
|
34
|
+
"kind": { "enum": ["root", "contains"] },
|
|
35
|
+
"whenProps": {
|
|
36
|
+
"description": "Props that turn the rule on when any one is set to a value other than false. Omitted, the rule always applies.",
|
|
37
|
+
"type": "array",
|
|
38
|
+
"minItems": 1,
|
|
39
|
+
"uniqueItems": true,
|
|
40
|
+
"items": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9]*$" }
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"additionalProperties": false
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"propCondition": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"required": ["prop", "equals"],
|
|
49
|
+
"properties": {
|
|
50
|
+
"prop": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"pattern": "^[A-Za-z][A-Za-z0-9]*$",
|
|
53
|
+
"description": "A JSX prop of the element."
|
|
54
|
+
},
|
|
55
|
+
"equals": {
|
|
56
|
+
"anyOf": [
|
|
57
|
+
{ "type": "string" },
|
|
58
|
+
{ "type": "number" },
|
|
59
|
+
{ "type": "boolean" }
|
|
60
|
+
],
|
|
61
|
+
"description": "The statically written value that satisfies the condition. A bare boolean prop (<Card flush />) equals true."
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"additionalProperties": false
|
|
65
|
+
},
|
|
66
|
+
"stateAttribute": {
|
|
67
|
+
"type": "object",
|
|
68
|
+
"required": ["name", "on", "helper", "meaning"],
|
|
69
|
+
"properties": {
|
|
70
|
+
"name": {
|
|
71
|
+
"type": "string",
|
|
72
|
+
"minLength": 1,
|
|
73
|
+
"pattern": "^data-[a-z0-9]+(-[a-z0-9]+)*$"
|
|
74
|
+
},
|
|
75
|
+
"on": {
|
|
76
|
+
"type": "string",
|
|
77
|
+
"minLength": 1,
|
|
78
|
+
"description": "The element that carries it: a public class, or the element passed to the helper."
|
|
79
|
+
},
|
|
80
|
+
"helper": {
|
|
81
|
+
"type": "string",
|
|
82
|
+
"minLength": 1,
|
|
83
|
+
"description": "The helper, one of wiring.helpers, that writes it."
|
|
84
|
+
},
|
|
85
|
+
"meaning": {
|
|
86
|
+
"type": "string",
|
|
87
|
+
"minLength": 1,
|
|
88
|
+
"description": "What its presence or value means."
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"additionalProperties": false
|
|
92
|
+
},
|
|
93
|
+
"repositoryPath": {
|
|
94
|
+
"description": "A package-relative POSIX path without traversal or empty segments.",
|
|
95
|
+
"type": "string",
|
|
96
|
+
"pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*$"
|
|
97
|
+
},
|
|
98
|
+
"selection": {
|
|
99
|
+
"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.",
|
|
100
|
+
"type": "object",
|
|
101
|
+
"required": ["useWhen", "avoidWhen"],
|
|
102
|
+
"properties": {
|
|
103
|
+
"useWhen": {
|
|
104
|
+
"type": "array",
|
|
105
|
+
"items": { "type": "string", "minLength": 1 },
|
|
106
|
+
"minItems": 1
|
|
107
|
+
},
|
|
108
|
+
"avoidWhen": {
|
|
109
|
+
"type": "array",
|
|
110
|
+
"items": { "type": "string", "minLength": 1 },
|
|
111
|
+
"minItems": 1
|
|
112
|
+
},
|
|
113
|
+
"uses": {
|
|
114
|
+
"description": "Directly composed catalog entry ids: this package's own component ids or @kerfjs/ui selection catalog ids.",
|
|
115
|
+
"$ref": "#/$defs/stringList"
|
|
116
|
+
},
|
|
117
|
+
"styleSources": {
|
|
118
|
+
"description": "Stylesheets this component owns, relative to the package root.",
|
|
119
|
+
"type": "array",
|
|
120
|
+
"items": {
|
|
121
|
+
"allOf": [
|
|
122
|
+
{ "$ref": "#/$defs/repositoryPath" },
|
|
123
|
+
{ "pattern": "\\.css$" }
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
"minItems": 1,
|
|
127
|
+
"uniqueItems": true
|
|
128
|
+
},
|
|
129
|
+
"demoSource": { "$ref": "#/$defs/repositoryPath" },
|
|
130
|
+
"documentation": { "type": "string", "minLength": 1 },
|
|
131
|
+
"geometry": {
|
|
132
|
+
"description": "Overrides composition.layout.geometry in the selection catalog. Required when that geometry uses the composition-only owner \"composed\".",
|
|
133
|
+
"type": "object",
|
|
134
|
+
"required": ["margin", "border", "padding"],
|
|
135
|
+
"properties": {
|
|
136
|
+
"margin": { "$ref": "#/$defs/selectionGeometryOwner" },
|
|
137
|
+
"border": { "$ref": "#/$defs/selectionGeometryOwner" },
|
|
138
|
+
"padding": { "$ref": "#/$defs/selectionGeometryOwner" },
|
|
139
|
+
"notes": {
|
|
140
|
+
"type": "array",
|
|
141
|
+
"items": { "type": "string", "minLength": 1 },
|
|
142
|
+
"minItems": 1
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
"additionalProperties": false
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
"additionalProperties": false
|
|
149
|
+
},
|
|
150
|
+
"selectionGeometryOwner": {
|
|
151
|
+
"enum": ["self", "parent", "child", "none", "conditional"]
|
|
152
|
+
},
|
|
153
|
+
"stringList": {
|
|
154
|
+
"type": "array",
|
|
155
|
+
"items": { "type": "string", "minLength": 1 },
|
|
156
|
+
"uniqueItems": true
|
|
157
|
+
},
|
|
158
|
+
"cardinality": {
|
|
159
|
+
"type": "object",
|
|
160
|
+
"required": ["min", "max"],
|
|
161
|
+
"properties": {
|
|
162
|
+
"min": { "type": "integer", "minimum": 0 },
|
|
163
|
+
"max": {
|
|
164
|
+
"anyOf": [
|
|
165
|
+
{ "type": "integer", "minimum": 1 },
|
|
166
|
+
{ "const": "unbounded" }
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
"additionalProperties": false
|
|
171
|
+
},
|
|
172
|
+
"diagnostic": {
|
|
173
|
+
"type": "object",
|
|
174
|
+
"required": ["id", "severity", "when", "message"],
|
|
175
|
+
"properties": {
|
|
176
|
+
"id": { "type": "string", "pattern": "^KUI-C[0-9]{3}$" },
|
|
177
|
+
"severity": { "enum": ["error", "warning"] },
|
|
178
|
+
"when": { "type": "string", "minLength": 1 },
|
|
179
|
+
"message": { "type": "string", "minLength": 1 }
|
|
180
|
+
},
|
|
181
|
+
"additionalProperties": false
|
|
182
|
+
},
|
|
183
|
+
"component": {
|
|
184
|
+
"type": "object",
|
|
185
|
+
"required": [
|
|
186
|
+
"id",
|
|
187
|
+
"name",
|
|
188
|
+
"kind",
|
|
189
|
+
"purpose",
|
|
190
|
+
"source",
|
|
191
|
+
"publicExports",
|
|
192
|
+
"sourceLinks",
|
|
193
|
+
"composition",
|
|
194
|
+
"boundaries",
|
|
195
|
+
"accessibility",
|
|
196
|
+
"diagnostics",
|
|
197
|
+
"provenance"
|
|
198
|
+
],
|
|
199
|
+
"properties": {
|
|
200
|
+
"id": { "type": "string", "minLength": 1 },
|
|
201
|
+
"name": { "type": "string", "minLength": 1 },
|
|
202
|
+
"kind": { "enum": ["component", "composition", "recipe"] },
|
|
203
|
+
"purpose": { "type": "string", "minLength": 1 },
|
|
204
|
+
"source": { "type": "string", "minLength": 1 },
|
|
205
|
+
"publicExports": {
|
|
206
|
+
"type": "array",
|
|
207
|
+
"minItems": 1,
|
|
208
|
+
"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.",
|
|
209
|
+
"items": {
|
|
210
|
+
"type": "object",
|
|
211
|
+
"required": ["name"],
|
|
212
|
+
"properties": {
|
|
213
|
+
"name": { "type": "string", "minLength": 1 },
|
|
214
|
+
"subpath": { "type": "string", "pattern": "^\\." }
|
|
215
|
+
},
|
|
216
|
+
"additionalProperties": false
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
"sourceLinks": { "$ref": "#/$defs/stringList" },
|
|
220
|
+
"composition": { "$ref": "#/$defs/composition" },
|
|
221
|
+
"boundaries": {
|
|
222
|
+
"type": "object",
|
|
223
|
+
"required": ["rootClass", "publicClasses", "publicTokens"],
|
|
224
|
+
"properties": {
|
|
225
|
+
"rootClass": {
|
|
226
|
+
"oneOf": [
|
|
227
|
+
{ "type": "string", "minLength": 1 },
|
|
228
|
+
{ "type": "null" }
|
|
229
|
+
]
|
|
230
|
+
},
|
|
231
|
+
"publicClasses": { "$ref": "#/$defs/stringList" },
|
|
232
|
+
"placeableClasses": {
|
|
233
|
+
"$ref": "#/$defs/stringList",
|
|
234
|
+
"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."
|
|
235
|
+
},
|
|
236
|
+
"rootElement": {
|
|
237
|
+
"type": "string",
|
|
238
|
+
"pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
|
|
239
|
+
"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."
|
|
240
|
+
},
|
|
241
|
+
"publicTokens": { "$ref": "#/$defs/stringList" }
|
|
242
|
+
},
|
|
243
|
+
"additionalProperties": false
|
|
244
|
+
},
|
|
245
|
+
"accessibility": {
|
|
246
|
+
"type": "object",
|
|
247
|
+
"required": ["obligations"],
|
|
248
|
+
"properties": { "obligations": { "$ref": "#/$defs/stringList" } },
|
|
249
|
+
"additionalProperties": false
|
|
250
|
+
},
|
|
251
|
+
"diagnostics": {
|
|
252
|
+
"type": "array",
|
|
253
|
+
"items": { "$ref": "#/$defs/diagnostic" }
|
|
254
|
+
},
|
|
255
|
+
"provenance": {
|
|
256
|
+
"type": "object",
|
|
257
|
+
"required": ["selection", "composition"],
|
|
258
|
+
"properties": {
|
|
259
|
+
"selection": { "type": "string", "minLength": 1 },
|
|
260
|
+
"composition": { "type": "string", "minLength": 1 }
|
|
261
|
+
},
|
|
262
|
+
"additionalProperties": false
|
|
263
|
+
},
|
|
264
|
+
"selection": { "$ref": "#/$defs/selection" }
|
|
265
|
+
},
|
|
266
|
+
"additionalProperties": false
|
|
267
|
+
},
|
|
268
|
+
"composition": {
|
|
269
|
+
"type": "object",
|
|
270
|
+
"required": [
|
|
271
|
+
"parents",
|
|
272
|
+
"contexts",
|
|
273
|
+
"zones",
|
|
274
|
+
"children",
|
|
275
|
+
"state",
|
|
276
|
+
"wiring",
|
|
277
|
+
"responsive",
|
|
278
|
+
"layout"
|
|
279
|
+
],
|
|
280
|
+
"properties": {
|
|
281
|
+
"rendersAs": {
|
|
282
|
+
"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.",
|
|
283
|
+
"type": "array",
|
|
284
|
+
"minItems": 1,
|
|
285
|
+
"items": { "type": "string", "pattern": "^[^:]+:[^:]+$" },
|
|
286
|
+
"uniqueItems": true
|
|
287
|
+
},
|
|
288
|
+
"insetFreeChildren": {
|
|
289
|
+
"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.",
|
|
290
|
+
"type": "array",
|
|
291
|
+
"items": { "$ref": "#/$defs/propCondition" },
|
|
292
|
+
"minItems": 1
|
|
293
|
+
},
|
|
294
|
+
"insetFreeWhen": {
|
|
295
|
+
"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.",
|
|
296
|
+
"type": "array",
|
|
297
|
+
"items": { "$ref": "#/$defs/propCondition" },
|
|
298
|
+
"minItems": 1
|
|
299
|
+
},
|
|
300
|
+
"content": {
|
|
301
|
+
"description": "Whether the component renders interactive content (a native button, link, form control, label, or summary). A root rule means the control is the component's own root, so its zones may hold no control or component that renders one; a contains rule means it renders one inside. The @kerfjs/ui view validator reports KUI-V014 for those placements. exports gives the same rules per additional JSX export, which do not inherit the component's. Omitted, placements are unchecked.",
|
|
302
|
+
"type": "object",
|
|
303
|
+
"minProperties": 1,
|
|
304
|
+
"properties": {
|
|
305
|
+
"interactive": { "$ref": "#/$defs/interactiveRules" },
|
|
306
|
+
"exports": {
|
|
307
|
+
"type": "object",
|
|
308
|
+
"additionalProperties": {
|
|
309
|
+
"type": "object",
|
|
310
|
+
"required": ["interactive"],
|
|
311
|
+
"properties": {
|
|
312
|
+
"interactive": { "$ref": "#/$defs/interactiveRules" }
|
|
313
|
+
},
|
|
314
|
+
"additionalProperties": false
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
"additionalProperties": false
|
|
319
|
+
},
|
|
320
|
+
"parents": {
|
|
321
|
+
"type": "object",
|
|
322
|
+
"required": ["mode", "entries"],
|
|
323
|
+
"properties": {
|
|
324
|
+
"mode": { "enum": ["any", "root", "listed"] },
|
|
325
|
+
"entries": { "$ref": "#/$defs/stringList" }
|
|
326
|
+
},
|
|
327
|
+
"additionalProperties": false
|
|
328
|
+
},
|
|
329
|
+
"contexts": { "$ref": "#/$defs/stringList" },
|
|
330
|
+
"zones": {
|
|
331
|
+
"type": "array",
|
|
332
|
+
"items": {
|
|
333
|
+
"type": "object",
|
|
334
|
+
"required": ["id", "accepts", "cardinality", "exclusiveWith"],
|
|
335
|
+
"properties": {
|
|
336
|
+
"id": { "type": "string", "minLength": 1 },
|
|
337
|
+
"jsx": {
|
|
338
|
+
"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.",
|
|
339
|
+
"type": "object",
|
|
340
|
+
"required": ["prop"],
|
|
341
|
+
"properties": {
|
|
342
|
+
"prop": { "type": "string", "minLength": 1 }
|
|
343
|
+
},
|
|
344
|
+
"additionalProperties": false
|
|
345
|
+
},
|
|
346
|
+
"accepts": { "$ref": "#/$defs/stringList" },
|
|
347
|
+
"cardinality": { "$ref": "#/$defs/cardinality" },
|
|
348
|
+
"exclusiveWith": { "$ref": "#/$defs/stringList" }
|
|
349
|
+
},
|
|
350
|
+
"additionalProperties": false
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
"children": {
|
|
354
|
+
"type": "object",
|
|
355
|
+
"required": ["mode", "concepts", "requiredConcepts"],
|
|
356
|
+
"properties": {
|
|
357
|
+
"mode": { "enum": ["any", "none", "listed"] },
|
|
358
|
+
"concepts": { "$ref": "#/$defs/stringList" },
|
|
359
|
+
"requiredConcepts": { "$ref": "#/$defs/stringList" }
|
|
360
|
+
},
|
|
361
|
+
"additionalProperties": false
|
|
362
|
+
},
|
|
363
|
+
"state": {
|
|
364
|
+
"type": "array",
|
|
365
|
+
"items": {
|
|
366
|
+
"type": "object",
|
|
367
|
+
"required": ["id", "owner", "required"],
|
|
368
|
+
"properties": {
|
|
369
|
+
"id": { "type": "string", "minLength": 1 },
|
|
370
|
+
"owner": { "enum": ["application", "controlled", "component"] },
|
|
371
|
+
"required": { "type": "boolean" }
|
|
372
|
+
},
|
|
373
|
+
"additionalProperties": false
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
"wiring": {
|
|
377
|
+
"type": "object",
|
|
378
|
+
"required": ["required", "helpers", "obligations"],
|
|
379
|
+
"properties": {
|
|
380
|
+
"required": { "type": "boolean" },
|
|
381
|
+
"scope": {
|
|
382
|
+
"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.",
|
|
383
|
+
"enum": ["application", "module"]
|
|
384
|
+
},
|
|
385
|
+
"helpers": { "$ref": "#/$defs/stringList" },
|
|
386
|
+
"sources": {
|
|
387
|
+
"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).",
|
|
388
|
+
"type": "array",
|
|
389
|
+
"items": {
|
|
390
|
+
"type": "object",
|
|
391
|
+
"required": ["export", "source"],
|
|
392
|
+
"properties": {
|
|
393
|
+
"export": { "type": "string", "minLength": 1 },
|
|
394
|
+
"source": { "type": "string", "minLength": 1 },
|
|
395
|
+
"returnsDisposer": { "type": "boolean" }
|
|
396
|
+
},
|
|
397
|
+
"additionalProperties": false
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
"actions": {
|
|
401
|
+
"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).",
|
|
402
|
+
"$ref": "#/$defs/stringList"
|
|
403
|
+
},
|
|
404
|
+
"obligations": { "$ref": "#/$defs/stringList" },
|
|
405
|
+
"stateAttributes": {
|
|
406
|
+
"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.",
|
|
407
|
+
"type": "array",
|
|
408
|
+
"items": { "$ref": "#/$defs/stateAttribute" }
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
"additionalProperties": false
|
|
412
|
+
},
|
|
413
|
+
"responsive": {
|
|
414
|
+
"type": "object",
|
|
415
|
+
"required": ["owner", "behaviors"],
|
|
416
|
+
"properties": {
|
|
417
|
+
"owner": {
|
|
418
|
+
"enum": ["application", "component", "shared", "not-applicable"]
|
|
419
|
+
},
|
|
420
|
+
"behaviors": { "$ref": "#/$defs/stringList" }
|
|
421
|
+
},
|
|
422
|
+
"additionalProperties": false
|
|
423
|
+
},
|
|
424
|
+
"layout": {
|
|
425
|
+
"type": "object",
|
|
426
|
+
"required": ["roles", "geometry"],
|
|
427
|
+
"properties": {
|
|
428
|
+
"roles": {
|
|
429
|
+
"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).",
|
|
430
|
+
"$ref": "#/$defs/stringList"
|
|
431
|
+
},
|
|
432
|
+
"geometry": {
|
|
433
|
+
"type": "object",
|
|
434
|
+
"required": ["margin", "border", "padding"],
|
|
435
|
+
"properties": {
|
|
436
|
+
"margin": { "$ref": "#/$defs/geometryOwner" },
|
|
437
|
+
"border": { "$ref": "#/$defs/geometryOwner" },
|
|
438
|
+
"padding": { "$ref": "#/$defs/geometryOwner" },
|
|
439
|
+
"notes": { "$ref": "#/$defs/stringList" }
|
|
440
|
+
},
|
|
441
|
+
"additionalProperties": false
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
"additionalProperties": false
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
"additionalProperties": false
|
|
448
|
+
},
|
|
449
|
+
"geometryOwner": {
|
|
450
|
+
"enum": ["self", "parent", "child", "none", "conditional", "composed"]
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
package/index.js
CHANGED
|
@@ -7,18 +7,32 @@
|
|
|
7
7
|
// delegation disposer.
|
|
8
8
|
//
|
|
9
9
|
// Usage:
|
|
10
|
-
// npm create kerf-component@latest <dir>
|
|
10
|
+
// npm create kerf-component@latest <dir> [--name <package-name>]
|
|
11
11
|
// npm init kerf-component <dir>
|
|
12
12
|
// npx create-kerf-component <dir>
|
|
13
13
|
//
|
|
14
14
|
// <dir> is the target directory; its basename is the default package name (pass
|
|
15
|
-
// `.` to scaffold into the current directory).
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
// `.` to scaffold into the current directory). `--name` sets the package name
|
|
16
|
+
// instead, which is how to scaffold a scoped package (`--name @acme/widgets`).
|
|
17
|
+
// Run with NO argument and it prompts for the directory (or reads it from piped
|
|
18
|
+
// stdin) — `npm create kerf-component` alone just works. The initializer itself
|
|
19
|
+
// is plain Node; TypeScript is only an optional peer of the
|
|
20
|
+
// `kerf-component-catalog` bin, which runs inside a TypeScript project, so
|
|
21
|
+
// `npm create` installs nothing beyond this package.
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
copyFileSync,
|
|
25
|
+
cpSync,
|
|
26
|
+
existsSync,
|
|
27
|
+
mkdirSync,
|
|
28
|
+
readdirSync,
|
|
29
|
+
readFileSync,
|
|
30
|
+
renameSync,
|
|
31
|
+
statSync,
|
|
32
|
+
writeFileSync,
|
|
33
|
+
} from 'node:fs';
|
|
21
34
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
35
|
+
import process from 'node:process';
|
|
22
36
|
import { createInterface } from 'node:readline/promises';
|
|
23
37
|
import { fileURLToPath } from 'node:url';
|
|
24
38
|
|
|
@@ -32,16 +46,49 @@ function fail(msg) {
|
|
|
32
46
|
}
|
|
33
47
|
|
|
34
48
|
const USAGE =
|
|
35
|
-
'Usage: npm create kerf-component@latest <dir
|
|
36
|
-
' (or: npx create-kerf-component <dir>)\n\n' +
|
|
37
|
-
'Scaffolds a kerf component package into <dir>. Pass `.` for the current directory.\n'
|
|
49
|
+
'Usage: npm create kerf-component@latest <dir> [--name <package-name>]\n' +
|
|
50
|
+
' (or: npx create-kerf-component <dir> [--name <package-name>])\n\n' +
|
|
51
|
+
'Scaffolds a kerf component package into <dir>. Pass `.` for the current directory.\n' +
|
|
52
|
+
'The package name defaults to the directory name; use --name for a scoped name\n' +
|
|
53
|
+
'(for example --name @acme/widgets).\n';
|
|
54
|
+
|
|
55
|
+
// Split the command line into the target directory and options. Anything that
|
|
56
|
+
// starts with `-` is an option: an unknown one is an error rather than a
|
|
57
|
+
// directory named `--foo`.
|
|
58
|
+
function parseArgs(args) {
|
|
59
|
+
const parsed = { target: undefined, name: undefined, help: false };
|
|
60
|
+
for (let index = 0; index < args.length; index++) {
|
|
61
|
+
const arg = args[index];
|
|
62
|
+
if (arg === '--help' || arg === '-h') parsed.help = true;
|
|
63
|
+
else if (arg === '--name') {
|
|
64
|
+
const value = args[++index];
|
|
65
|
+
if (value === undefined || value.startsWith('-'))
|
|
66
|
+
throw new Error(
|
|
67
|
+
'--name needs a package name, e.g. --name @acme/widgets.',
|
|
68
|
+
);
|
|
69
|
+
parsed.name = value;
|
|
70
|
+
} else if (arg.startsWith('--name=')) parsed.name = arg.slice(7);
|
|
71
|
+
else if (arg.startsWith('-'))
|
|
72
|
+
throw new Error(
|
|
73
|
+
`unknown option "${arg}". Run with --help for usage. (To use a directory whose name starts with "-", pass it as ./${arg}.)`,
|
|
74
|
+
);
|
|
75
|
+
else if (parsed.target === undefined) parsed.target = arg;
|
|
76
|
+
else
|
|
77
|
+
throw new Error(
|
|
78
|
+
`expected one target directory, received "${parsed.target}" and "${arg}".`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return parsed;
|
|
82
|
+
}
|
|
38
83
|
|
|
39
84
|
// Ask for the target directory when none was passed. `npm create kerf-component`
|
|
40
85
|
// (no arg) is the most natural invocation, so prompt rather than error.
|
|
41
86
|
async function promptForTarget() {
|
|
42
87
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
43
88
|
try {
|
|
44
|
-
const answer = await rl.question(
|
|
89
|
+
const answer = await rl.question(
|
|
90
|
+
`Directory (\`.\` for current) [${DEFAULT_NAME}]: `,
|
|
91
|
+
);
|
|
45
92
|
return answer.trim() || DEFAULT_NAME;
|
|
46
93
|
} finally {
|
|
47
94
|
rl.close();
|
|
@@ -79,12 +126,17 @@ function walk(dir) {
|
|
|
79
126
|
}
|
|
80
127
|
|
|
81
128
|
async function main(argv) {
|
|
82
|
-
let
|
|
83
|
-
|
|
84
|
-
|
|
129
|
+
let options;
|
|
130
|
+
try {
|
|
131
|
+
options = parseArgs(argv.slice(2));
|
|
132
|
+
} catch (error) {
|
|
133
|
+
fail(error.message);
|
|
134
|
+
}
|
|
135
|
+
if (options.help) {
|
|
85
136
|
process.stdout.write(USAGE);
|
|
86
137
|
process.exit(0);
|
|
87
138
|
}
|
|
139
|
+
let target = options.target;
|
|
88
140
|
|
|
89
141
|
if (target == null || target === '') {
|
|
90
142
|
// No directory given. Prompt interactively when attached to a terminal (the
|
|
@@ -102,21 +154,64 @@ async function main(argv) {
|
|
|
102
154
|
}
|
|
103
155
|
|
|
104
156
|
const targetDir = resolve(process.cwd(), target);
|
|
105
|
-
const pkgName =
|
|
157
|
+
const pkgName =
|
|
158
|
+
options.name ?? (target === '.' ? basename(targetDir) : basename(target));
|
|
106
159
|
|
|
107
160
|
if (!isValidPackageName(pkgName)) {
|
|
108
|
-
fail(
|
|
161
|
+
fail(
|
|
162
|
+
options.name === undefined
|
|
163
|
+
? `"${pkgName}" (from the directory name) is not a valid npm package name; pass --name <package-name> or choose another directory.`
|
|
164
|
+
: `"${pkgName}" is not a valid npm package name.`,
|
|
165
|
+
);
|
|
109
166
|
}
|
|
110
167
|
|
|
111
|
-
if (existsSync(targetDir)
|
|
112
|
-
|
|
168
|
+
if (existsSync(targetDir)) {
|
|
169
|
+
if (!statSync(targetDir).isDirectory())
|
|
170
|
+
fail(
|
|
171
|
+
`target "${target}" already exists and is a file, not a directory; choose a new directory name.`,
|
|
172
|
+
);
|
|
173
|
+
if (readdirSync(targetDir).length > 0)
|
|
174
|
+
fail(`target directory "${target}" already exists and is not empty.`);
|
|
113
175
|
}
|
|
114
176
|
|
|
115
177
|
// Copy the whole template tree, then post-process each file in place: replace
|
|
116
178
|
// the package-name token and rename the dotfile placeholders npm can't ship
|
|
117
179
|
// verbatim (`_gitignore` → `.gitignore`).
|
|
118
|
-
|
|
180
|
+
try {
|
|
181
|
+
mkdirSync(targetDir, { recursive: true });
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (error?.code === 'ENOTDIR' || error?.code === 'EEXIST')
|
|
184
|
+
fail(
|
|
185
|
+
`cannot create "${target}": part of that path is an existing file, not a directory.`,
|
|
186
|
+
);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
119
189
|
cpSync(TEMPLATE_DIR, targetDir, { recursive: true });
|
|
190
|
+
mkdirSync(join(targetDir, 'scripts'), { recursive: true });
|
|
191
|
+
copyFileSync(
|
|
192
|
+
join(dirname(fileURLToPath(import.meta.url)), 'catalog.js'),
|
|
193
|
+
join(targetDir, 'scripts', 'kerf-component-catalog.mjs'),
|
|
194
|
+
);
|
|
195
|
+
// The command's modules, imported relatively by the entry above. Their
|
|
196
|
+
// own package.json keeps them ES modules whatever the host package's type.
|
|
197
|
+
cpSync(
|
|
198
|
+
join(dirname(fileURLToPath(import.meta.url)), 'catalog'),
|
|
199
|
+
join(targetDir, 'scripts', 'catalog'),
|
|
200
|
+
{ recursive: true },
|
|
201
|
+
);
|
|
202
|
+
writeFileSync(
|
|
203
|
+
join(targetDir, 'scripts', 'catalog', 'package.json'),
|
|
204
|
+
'{ "type": "module" }\n',
|
|
205
|
+
);
|
|
206
|
+
for (const schema of [
|
|
207
|
+
'component-metadata.schema.json',
|
|
208
|
+
'component-composition.schema.json',
|
|
209
|
+
'component-catalog-extension.schema.json',
|
|
210
|
+
])
|
|
211
|
+
copyFileSync(
|
|
212
|
+
join(dirname(fileURLToPath(import.meta.url)), schema),
|
|
213
|
+
join(targetDir, 'scripts', schema),
|
|
214
|
+
);
|
|
120
215
|
|
|
121
216
|
for (const file of walk(targetDir)) {
|
|
122
217
|
const text = readFileSync(file, 'utf8');
|
|
@@ -136,8 +231,10 @@ async function main(argv) {
|
|
|
136
231
|
cdHint +
|
|
137
232
|
' npm install\n' +
|
|
138
233
|
' npm run build # tsup → ESM + .d.ts (kerfjs stays external)\n' +
|
|
234
|
+
' npm run catalog:check # verify AI metadata and public exports\n' +
|
|
235
|
+
' npm run check:styles # each component styles only itself (kerf-ui-analyze)\n' +
|
|
139
236
|
' npm run typecheck\n\n' +
|
|
140
|
-
'Edit src/counter.tsx, then publish with `npm publish --access public`.\n',
|
|
237
|
+
'Edit src/counter.tsx, src/counter.css, and kerf.components.json, then publish with `npm publish --access public`.\n',
|
|
141
238
|
);
|
|
142
239
|
}
|
|
143
240
|
|