@astryxdesign/cli 0.6.5-canary.f6c5c7c → 0.6.5-vanilla-poc.b2a96ac
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/CHANGELOG.md +3 -0
- package/README.md +36 -3
- package/api/_vanilla-assets.d.mts +10 -0
- package/api/_vanilla-assets.mjs +59 -0
- package/api/build/_adapter.d.mts +0 -14
- package/api/build/_adapter.mjs +1 -58
- package/api/build/build.test.mjs +1 -74
- package/api/build/kit/kit.mjs +7 -39
- package/api/build/kit/rank.d.mts +0 -8
- package/api/build/kit/rank.mjs +0 -14
- package/api/component/_adapter.d.mts +37 -0
- package/api/component/_adapter.mjs +80 -1
- package/api/component/component.d.mts +9 -1
- package/api/component/component.doc.mjs +45 -4
- package/api/component/component.mjs +78 -0
- package/api/component/component.type.d.mts +8 -0
- package/api/component/component.type.mjs +6 -0
- package/api/component/html/html.d.mts +12 -0
- package/api/component/html/html.doc.d.mts +5 -0
- package/api/component/html/html.doc.mjs +66 -0
- package/api/component/html/html.mjs +25 -0
- package/api/component/html/html.test.mjs +61 -0
- package/api/component/html/html.type.d.mts +23 -0
- package/api/component/html/html.type.mjs +27 -0
- package/api/component/web-components/web-components.d.mts +12 -0
- package/api/component/web-components/web-components.doc.d.mts +5 -0
- package/api/component/web-components/web-components.doc.mjs +70 -0
- package/api/component/web-components/web-components.mjs +32 -0
- package/api/component/web-components/web-components.test.mjs +50 -0
- package/api/component/web-components/web-components.type.d.mts +23 -0
- package/api/component/web-components/web-components.type.mjs +27 -0
- package/api/docs/docs.d.mts +0 -6
- package/api/docs/docs.doc.mjs +2 -31
- package/api/docs/docs.mjs +1 -44
- package/api/docs/docs.type.d.mts +1 -38
- package/api/docs/docs.type.mjs +1 -18
- package/api/docs/node/node.d.mts +3 -28
- package/api/docs/node/node.mjs +23 -146
- package/api/gap-report/gap-report.d.mts +1 -3
- package/api/gap-report/gap-report.mjs +2 -12
- package/api/gap-report/gap-report.test.mjs +0 -106
- package/api/hook/list/list.d.mts +1 -1
- package/api/index.d.mts +8 -0
- package/api/index.mjs +8 -0
- package/api/integration/add-theme.mjs +3 -93
- package/api/integration/add-theme.test.mjs +0 -100
- package/api/integration/integrationAddTheme.doc.mjs +1 -1
- package/api/search/search.d.mts +5 -12
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +53 -123
- package/api/search/search.test.mjs +8 -123
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/api/template/_adapter.d.mts +38 -0
- package/api/template/_adapter.mjs +90 -0
- package/api/template/html/html.d.mts +17 -0
- package/api/template/html/html.doc.d.mts +5 -0
- package/api/template/html/html.doc.mjs +72 -0
- package/api/template/html/html.mjs +61 -0
- package/api/template/html/html.test.mjs +71 -0
- package/api/template/html/html.type.d.mts +26 -0
- package/api/template/html/html.type.mjs +28 -0
- package/api/template/template.d.mts +6 -0
- package/api/template/template.doc.mjs +56 -4
- package/api/template/template.mjs +82 -0
- package/api/template/template.type.d.mts +12 -0
- package/api/template/template.type.mjs +7 -0
- package/api/template/web-components/web-components.d.mts +13 -0
- package/api/template/web-components/web-components.doc.d.mts +5 -0
- package/api/template/web-components/web-components.doc.mjs +69 -0
- package/api/template/web-components/web-components.mjs +51 -0
- package/api/template/web-components/web-components.test.mjs +73 -0
- package/api/template/web-components/web-components.type.d.mts +26 -0
- package/api/template/web-components/web-components.type.mjs +28 -0
- package/api/theme/build/build.mjs +69 -146
- package/api/theme/build/build.test.mjs +1 -190
- package/api/theme/themeBuild.doc.d.mts +1 -4
- package/api/theme/themeBuild.doc.mjs +3 -14
- package/assets/docs/theme.doc.mjs +1 -2
- package/assets/docs/tree/add-a-theme.doc.mjs +0 -4
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/assets/vanilla/elements-markup/Avatar.html +27 -0
- package/assets/vanilla/elements-markup/Badge.html +16 -0
- package/assets/vanilla/elements-markup/Banner.html +32 -0
- package/assets/vanilla/elements-markup/Breadcrumbs.html +23 -0
- package/assets/vanilla/elements-markup/Button.html +25 -0
- package/assets/vanilla/elements-markup/Card.html +24 -0
- package/assets/vanilla/elements-markup/CheckboxInput.html +28 -0
- package/assets/vanilla/elements-markup/Collapsible.html +26 -0
- package/assets/vanilla/elements-markup/DateInput.html +28 -0
- package/assets/vanilla/elements-markup/Dialog.html +33 -0
- package/assets/vanilla/elements-markup/Divider.html +20 -0
- package/assets/vanilla/elements-markup/DropdownMenu.html +26 -0
- package/assets/vanilla/elements-markup/EmptyState.html +27 -0
- package/assets/vanilla/elements-markup/Heading.html +18 -0
- package/assets/vanilla/elements-markup/HoverCard.html +29 -0
- package/assets/vanilla/elements-markup/Layout.html +28 -0
- package/assets/vanilla/elements-markup/Lightbox.html +33 -0
- package/assets/vanilla/elements-markup/Link.html +23 -0
- package/assets/vanilla/elements-markup/NumberInput.html +34 -0
- package/assets/vanilla/elements-markup/ProgressBar.html +22 -0
- package/assets/vanilla/elements-markup/RadioList.html +28 -0
- package/assets/vanilla/elements-markup/Selector.html +34 -0
- package/assets/vanilla/elements-markup/SideNav.html +32 -0
- package/assets/vanilla/elements-markup/Skeleton.html +18 -0
- package/assets/vanilla/elements-markup/Slider.html +31 -0
- package/assets/vanilla/elements-markup/Stack.html +33 -0
- package/assets/vanilla/elements-markup/StatusDot.html +19 -0
- package/assets/vanilla/elements-markup/Switch.html +28 -0
- package/assets/vanilla/elements-markup/Tab.html +18 -0
- package/assets/vanilla/elements-markup/TabList.html +31 -0
- package/assets/vanilla/elements-markup/Table.html +31 -0
- package/assets/vanilla/elements-markup/Text.html +24 -0
- package/assets/vanilla/elements-markup/TextArea.html +32 -0
- package/assets/vanilla/elements-markup/TextInput.html +39 -0
- package/assets/vanilla/elements-markup/Theme.html +16 -0
- package/assets/vanilla/elements-markup/TimeInput.html +29 -0
- package/assets/vanilla/elements-markup/Toast.html +22 -0
- package/assets/vanilla/elements-markup/Tooltip.html +30 -0
- package/assets/vanilla/elements-markup/TopNav.html +29 -0
- package/assets/vanilla/elements-markup/Typeahead.html +31 -0
- package/assets/vanilla/elements-templates/dashboard.html +167 -0
- package/assets/vanilla/elements-templates/detail-page.html +145 -0
- package/assets/vanilla/elements-templates/form-two-column.html +135 -0
- package/assets/vanilla/elements-templates/kanban-board.html +141 -0
- package/assets/vanilla/elements-templates/login.html +100 -0
- package/assets/vanilla/elements-templates/product-detail.html +128 -0
- package/assets/vanilla/elements-templates/settings.html +130 -0
- package/assets/vanilla/elements-templates/shell-side-nav.html +160 -0
- package/assets/vanilla/elements-templates/table-filter.html +154 -0
- package/assets/vanilla/markup/Avatar.html +24 -0
- package/assets/vanilla/markup/Badge.html +12 -0
- package/assets/vanilla/markup/Banner.html +49 -0
- package/assets/vanilla/markup/Breadcrumbs.html +38 -0
- package/assets/vanilla/markup/Button.html +17 -0
- package/assets/vanilla/markup/Card.html +16 -0
- package/assets/vanilla/markup/CheckboxInput.html +45 -0
- package/assets/vanilla/markup/Collapsible.html +9 -0
- package/assets/vanilla/markup/DateInput.html +42 -0
- package/assets/vanilla/markup/Dialog.html +45 -0
- package/assets/vanilla/markup/Divider.html +9 -0
- package/assets/vanilla/markup/DropdownMenu.html +30 -0
- package/assets/vanilla/markup/EmptyState.html +41 -0
- package/assets/vanilla/markup/Heading.html +9 -0
- package/assets/vanilla/markup/HoverCard.html +59 -0
- package/assets/vanilla/markup/Layout.html +35 -0
- package/assets/vanilla/markup/Lightbox.html +107 -0
- package/assets/vanilla/markup/Link.html +6 -0
- package/assets/vanilla/markup/NumberInput.html +55 -0
- package/assets/vanilla/markup/ProgressBar.html +37 -0
- package/assets/vanilla/markup/RadioList.html +90 -0
- package/assets/vanilla/markup/Selector.html +92 -0
- package/assets/vanilla/markup/SideNav.html +82 -0
- package/assets/vanilla/markup/Skeleton.html +26 -0
- package/assets/vanilla/markup/Slider.html +65 -0
- package/assets/vanilla/markup/Stack.html +13 -0
- package/assets/vanilla/markup/StatusDot.html +22 -0
- package/assets/vanilla/markup/Switch.html +47 -0
- package/assets/vanilla/markup/TabList.html +56 -0
- package/assets/vanilla/markup/Table.html +75 -0
- package/assets/vanilla/markup/Text.html +9 -0
- package/assets/vanilla/markup/TextArea.html +37 -0
- package/assets/vanilla/markup/TextInput.html +30 -0
- package/assets/vanilla/markup/Theme.html +29 -0
- package/assets/vanilla/markup/TimeInput.html +43 -0
- package/assets/vanilla/markup/Toast.html +42 -0
- package/assets/vanilla/markup/Tooltip.html +18 -0
- package/assets/vanilla/markup/TopNav.html +37 -0
- package/assets/vanilla/markup/Typeahead.html +60 -0
- package/assets/vanilla/templates/dashboard.html +462 -0
- package/assets/vanilla/templates/detail-page.html +536 -0
- package/assets/vanilla/templates/form-two-column.html +438 -0
- package/assets/vanilla/templates/kanban-board.html +443 -0
- package/assets/vanilla/templates/login.html +199 -0
- package/assets/vanilla/templates/product-detail.html +335 -0
- package/assets/vanilla/templates/settings.html +374 -0
- package/assets/vanilla/templates/shell-side-nav.html +440 -0
- package/assets/vanilla/templates/table-filter.html +514 -0
- package/clients/cli/commands/build-theme.mjs +2 -8
- package/clients/cli/commands/component/index.mjs +33 -1
- package/clients/cli/commands/component.doc.mjs +23 -2
- package/clients/cli/commands/discover.mjs +1 -29
- package/clients/cli/commands/docs.doc.mjs +2 -15
- package/clients/cli/commands/docs.mjs +5 -222
- package/clients/cli/commands/gap-report.mjs +0 -12
- package/clients/cli/commands/gap-report.test.mjs +0 -63
- package/clients/cli/commands/integration-add.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +4 -5
- package/clients/cli/commands/search.mjs +6 -30
- package/clients/cli/commands/search.test.mjs +16 -60
- package/clients/cli/commands/template.doc.mjs +31 -3
- package/clients/cli/commands/template.mjs +37 -2
- package/clients/cli/commands/vanilla-html.test.mjs +245 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -2
- package/foundation/agent-docs/agent-docs.test.mjs +0 -8
- package/foundation/discovery/theme-discovery.d.mts +0 -6
- package/foundation/discovery/theme-discovery.mjs +0 -9
- package/foundation/doc-compiler/doc-loads.test.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +38 -0
- package/package.json +11 -9
- package/api/build/kit/weights.d.mts +0 -82
- package/api/build/kit/weights.json +0 -1
- package/api/build/kit/weights.mjs +0 -305
- package/api/build/kit/weights.test.mjs +0 -190
- package/api/docs/docs.depth.test.mjs +0 -132
- package/api/theme/build/build.icon-lineage.test.mjs +0 -117
- package/api/theme/build/build.icon-preservation.test.mjs +0 -639
- package/api/theme/build/icon-imports.d.mts +0 -47
- package/api/theme/build/icon-imports.mjs +0 -691
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +0 -15
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +0 -38
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +0 -20
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +0 -48
- package/clients/cli/commands/discover.no-source.test.mjs +0 -75
- package/clients/cli/commands/docs.depth.test.mjs +0 -219
- package/clients/cli/commands/theme-list.behavior.test.mjs +0 -41
package/CHANGELOG.md
CHANGED
|
@@ -17,16 +17,19 @@
|
|
|
17
17
|
One source file that four codemods each changed was reported as four files changed, so `filesChanged` matched `transformsApplied` and the documented meaning, "Total files changed", was not true. The human summary said the same thing: "Found 4 changes across 4 files" for one file.
|
|
18
18
|
|
|
19
19
|
`filesChanged` is now the count of distinct files. `transformsApplied` is unchanged: a code or config codemod counts once for each file it changed, and a project codemod counts once. A file that both a core codemod and an integration codemod changed counts once in `filesChanged`.
|
|
20
|
+
|
|
20
21
|
- A parse error prints the Astryx error format in text mode.
|
|
21
22
|
`astryx theme list --lang zh-Hans` printed Commander's own line — `error: option '--lang <locale>' argument 'zh-Hans' is invalid…` — while every other CLI error prints `Error: …`. `--json` was already correct (`ERR_INVALID_LANG`), so the two modes agreed only on the exit code.
|
|
22
23
|
|
|
23
24
|
Commander writes that line before any Astryx code runs, so the JSON shim — the one place that already sees every parse failure — now suppresses it and writes the Astryx line itself, from the same message, for both modes. Every parse failure is covered: unknown option, unknown command, missing argument, and an invalid value for a global option. `--help` and `--version` are untouched and still exit 0.
|
|
25
|
+
|
|
24
26
|
- The CLI reference now matches what the commands do. Every `--help` ends with the command's examples and a `More:` line that names its full docs page. Function docs show each parameter's default, mark required parameters, list the error codes each function throws, and use examples that run. The response-type list adds `help`, `version`, and `upgrade.registry`, and `astryx manifest` now lists `upgrade.registry` for `upgrade`. The `--zh`, `--dense`, `--lang`, and `--detail` descriptions name the commands they change, and command summaries say when to use each command. When `astryx template` refuses to overwrite a file, it now says to re-run with `--overwrite` (or `-f`). The `upgrade` command page (`astryx docs cli/commands/upgrade`) now explains which files codemods never edit, what happens when one of them needs a change, and how to regenerate it.
|
|
25
27
|
- `astryx integration pack --check` now checks the tarball when a `prepack`, `prepare`, or `postpack` script prints to stdout. Before, any lifecycle output made the check fail with "npm pack produced unparseable JSON output" before it looked at the tarball. A failing lifecycle script still fails the check, and its output stays in the `pack_failed` message.
|
|
26
28
|
- `astryx doctor integration docs` fails when a namespace doc or a placement fails, as its help says.
|
|
27
29
|
Such a failure hides the doc from the docs tree, so it now exits 1 with an `invalid_doc_graph` error instead of a warning. A link that names no doc still only warns, since it prints as written. `doctor integration docs` and `doctor integration components` also no longer print an `[ok]` line after a check that failed.
|
|
28
30
|
|
|
29
31
|
A mistyped subcommand under `doctor` now fails and lists the subcommands the group has: `astryx doctor integrations` used to run the project checks, and `astryx doctor integration bogus` exited 0 in text though it exited 1 with `--json`.
|
|
32
|
+
|
|
30
33
|
- A package that ships a theme, or a doc section with an `id`, now declares the CLI that can read it.
|
|
31
34
|
A stable CLI before 0.7.0 rejects both: it cannot read the typed theme descriptors that `astryx integration add theme` writes, and it rejects a section `id`. Either way it hides the package's themes or doc topics with no warning. `astryx integration add theme` now adds `"@astryxdesign/cli": ">=0.7.0"` to `peerDependencies`, marked optional, and `astryx integration verify` fails with `themes_need_cli` or `section_ids_need_cli` when a package needs that peer range and does not declare it.
|
|
32
35
|
- `astryx integration verify` resolves every public import in the packed package, not in your source folder.
|
package/README.md
CHANGED
|
@@ -15,6 +15,31 @@ npx @astryxdesign/cli template --list
|
|
|
15
15
|
|
|
16
16
|
Once it's a project dependency (`npm install -D @astryxdesign/cli`), drop the scope and use the shorter `astryx` — e.g. `npx astryx component Button` or `pnpm exec astryx component Button`. Bare `astryx` resolves to an unrelated npm package until the CLI is installed, so prefer the scoped form above for first-run/one-off use.
|
|
17
17
|
|
|
18
|
+
## Install the preview CLI
|
|
19
|
+
|
|
20
|
+
Install the self-contained vanilla HTML preview from its immutable commit:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g https://cdn.jsdelivr.net/gh/facebook/astryx@ce7b98c3c01705bb8d71b96861828bfbc07283ac/packages/vanilla/dist/cli/astryx-cli-vanilla.tgz
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The preview package is `@astryxdesign/cli@0.6.5-vanilla.b32f55c9b`; it is not published to npm.
|
|
27
|
+
|
|
28
|
+
## Choosing a framework
|
|
29
|
+
|
|
30
|
+
`component` and `template` default to the React catalog. Use `--framework html`
|
|
31
|
+
for the no-build vanilla markup, or `--framework web-components` for the
|
|
32
|
+
custom-element markup. Both alternatives support named reads and `--list`:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
astryx component Button --framework html
|
|
36
|
+
astryx component Button --framework web-components
|
|
37
|
+
astryx template dashboard --framework html
|
|
38
|
+
astryx template dashboard --framework web-components
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`--html` remains a deprecated alias for `--framework html`.
|
|
42
|
+
|
|
18
43
|
## Reading the CLI's own docs
|
|
19
44
|
|
|
20
45
|
The CLI documents itself, so these commands print what the installed version does:
|
|
@@ -69,7 +94,7 @@ Results for "button" (20 of 239):
|
|
|
69
94
|
|
|
70
95
|
Options:
|
|
71
96
|
|
|
72
|
-
- `--type <component|hook|doc|template
|
|
97
|
+
- `--type <component|hook|doc|template>`: restrict to a single domain
|
|
73
98
|
- `--limit <n>`: cap the number of results (default 20)
|
|
74
99
|
- `--verbose`: also print each result's match score and reason
|
|
75
100
|
- `--json`: typed `{ apiVersion, type: 'search', data: { query, matchCount, results } }` envelope — `matchCount` is how many candidates matched in total, `results` the slice `--limit` allowed
|
|
@@ -91,9 +116,9 @@ Options:
|
|
|
91
116
|
| `init` | Initialize the design system in your project |
|
|
92
117
|
| `integration` | Author and verify an Astryx integration package |
|
|
93
118
|
| `layout` | Generate XDS layouts from compressed expressions (XLE/XLO) |
|
|
94
|
-
| `search` | Search components, hooks, docs,
|
|
119
|
+
| `search` | Search components, hooks, docs, and templates in one ranked list |
|
|
95
120
|
| `swizzle` | Copy component source for customization |
|
|
96
|
-
| `template` | List, show, or
|
|
121
|
+
| `template` | List, show, scaffold, or render page and block templates |
|
|
97
122
|
| `theme` | Create and build themes: add a shipped one, compile to CSS, or list what a theme can override |
|
|
98
123
|
| `upgrade` | Update your code after upgrading Astryx, and refresh ShadCN-copied components |
|
|
99
124
|
|
|
@@ -431,6 +456,10 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
431
456
|
| `component.detail.source` | One component's source file, as {component, source}. |
|
|
432
457
|
| `component.detail.showcase` | One component's showcase example, as {component, aspectRatio, source}. |
|
|
433
458
|
| `component.detail.blocks` | One component's example blocks, as {component, showcase, examples, related} of BlockEntry. |
|
|
459
|
+
| `component.html.list` | The sorted packages/vanilla/markup files as {name, file}. |
|
|
460
|
+
| `component.html` | One vanilla component markup file as {component, file, source}, preserving docs and variant comments verbatim. |
|
|
461
|
+
| `component.web-components.list` | The sorted packages/vanilla/elements-markup files as {name, file}. |
|
|
462
|
+
| `component.web-components` | One vanilla web-component markup file as {component, file, source}, preserving generated docs and variant comments verbatim. |
|
|
434
463
|
| `docs.list` | All reference-doc topics as DocsListEntry[] ({topic, description, package, replaces?}), in read order; meta.namespaces lists the docs tree's top-level namespaces, and meta.notLoaded each package whose docs did not load. |
|
|
435
464
|
| `docs.detail` | One topic's full ReferenceDoc (the JSON read of a topic, --full, --dense, or a topic with one section), with token-ref blocks inlined, plus links ({up, previous, next}: the commands that open the level it sits in and its neighbors there). |
|
|
436
465
|
| `docs.index` | One topic's section index, the text read of a topic with more than one section (and --index): the topic's name, title, and description, plus sections, each {id, title, summary} (pass the id as the section argument; summary is the section's one-line summary), and links ({up, previous, next}: the commands that open the level it sits in and its neighbors there). |
|
|
@@ -455,6 +484,10 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
455
484
|
| `template.skeleton` | A layout skeleton (structural tags with spatial annotations) plus the template's description and the components it composes. |
|
|
456
485
|
| `template.copy` | A scaffold receipt: template id, output directory, written file name, file count, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media). |
|
|
457
486
|
| `template.cdn` | A write receipt for the no-build-step CDN starter page: the path (relative to cwd), the Astryx version every CDN URL was pinned to, whether it was written, and the reason it was not. `exists` when a file was already there, which is a success. |
|
|
487
|
+
| `template.html.list` | The sorted packages/vanilla/templates files as {id, file}. |
|
|
488
|
+
| `template.html` | One vanilla standalone page as {template, file, cdnRef, cdnBase, source}, with every CDN placeholder substituted. |
|
|
489
|
+
| `template.web-components.list` | The sorted packages/vanilla/elements-templates files as {id, file}. |
|
|
490
|
+
| `template.web-components` | One vanilla web-component page as {template, file, cdnRef, cdnBase, source}, with every CDN placeholder substituted. |
|
|
458
491
|
| `hook.list` | The hook catalog grouped by category: `detail` (the level: names \| compact \| full) and `components`, the grouped map of hook names, brief entries, or a full HookDoc per entry. |
|
|
459
492
|
| `hook.detail` | One hook's full authored HookDoc. |
|
|
460
493
|
| `hook.detail.params` | Just one hook's parameters table (HookParamDoc[]). |
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Prefer live checkout assets while developing, then fall back to the generated
|
|
6
|
+
* copy included in the published CLI package.
|
|
7
|
+
* @param {string} cwd
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
export function requireVanillaAssetsDir(cwd: string): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Resolves vanilla framework assets from the source checkout or the CLI bundle.
|
|
5
|
+
*
|
|
6
|
+
* @input A caller working directory.
|
|
7
|
+
* @output The checkout's packages/vanilla directory when present, otherwise the
|
|
8
|
+
* generated assets/vanilla copy shipped with @astryxdesign/cli.
|
|
9
|
+
* @position Shared environment adapter used only by the component and template
|
|
10
|
+
* vanilla framework adapters so installed and source-checkout behavior agree.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import * as path from 'node:path';
|
|
15
|
+
import {ERROR_CODES} from '../foundation/response/error-codes.mjs';
|
|
16
|
+
import {AstryxError} from './error.mjs';
|
|
17
|
+
|
|
18
|
+
const BUNDLED_VANILLA_DIR = path.resolve(
|
|
19
|
+
import.meta.dirname,
|
|
20
|
+
'../assets/vanilla',
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/** @param {string} candidate @returns {boolean} */
|
|
24
|
+
function isDirectory(candidate) {
|
|
25
|
+
return fs.existsSync(candidate) && fs.statSync(candidate).isDirectory();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @param {string} cwd @returns {string | null} */
|
|
29
|
+
function findCheckoutVanillaDir(cwd) {
|
|
30
|
+
let cursor = path.resolve(cwd);
|
|
31
|
+
while (true) {
|
|
32
|
+
const direct =
|
|
33
|
+
path.basename(cursor) === 'vanilla' &&
|
|
34
|
+
path.basename(path.dirname(cursor)) === 'packages'
|
|
35
|
+
? cursor
|
|
36
|
+
: path.join(cursor, 'packages', 'vanilla');
|
|
37
|
+
if (isDirectory(direct)) return direct;
|
|
38
|
+
const parent = path.dirname(cursor);
|
|
39
|
+
if (parent === cursor) return null;
|
|
40
|
+
cursor = parent;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Prefer live checkout assets while developing, then fall back to the generated
|
|
46
|
+
* copy included in the published CLI package.
|
|
47
|
+
* @param {string} cwd
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
export function requireVanillaAssetsDir(cwd) {
|
|
51
|
+
const checkoutDir = findCheckoutVanillaDir(cwd);
|
|
52
|
+
if (checkoutDir) return checkoutDir;
|
|
53
|
+
if (isDirectory(BUNDLED_VANILLA_DIR)) return BUNDLED_VANILLA_DIR;
|
|
54
|
+
throw new AstryxError(
|
|
55
|
+
`Could not find vanilla framework assets from "${cwd}" or in the installed CLI`,
|
|
56
|
+
undefined,
|
|
57
|
+
ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
58
|
+
);
|
|
59
|
+
}
|
package/api/build/_adapter.d.mts
CHANGED
|
@@ -40,20 +40,6 @@ export function loadPageTemplates(cwd: string): Promise<PageTemplate[]>;
|
|
|
40
40
|
* @returns {Promise<ComponentWords[]>}
|
|
41
41
|
*/
|
|
42
42
|
export function loadComponents(cwd: string): Promise<ComponentWords[]>;
|
|
43
|
-
/**
|
|
44
|
-
* The matcher weights checked in beside the kit (`kit/weights.json`), read
|
|
45
|
-
* once; null when the file is absent or unreadable.
|
|
46
|
-
* @returns {import('./kit/weights.mjs').WeightsFile | null}
|
|
47
|
-
*/
|
|
48
|
-
export function loadWeights(): import("./kit/weights.mjs").WeightsFile | null;
|
|
49
|
-
/**
|
|
50
|
-
* Whether a parsed weights file has the shape the kit reads: every row has a
|
|
51
|
-
* weight per candidate, every bias a number per candidate, and three blend
|
|
52
|
-
* numbers per member (the tables plus the ranker) and one for the shell.
|
|
53
|
-
* @param {any} file
|
|
54
|
-
* @returns {file is import('./kit/weights.mjs').WeightsFile}
|
|
55
|
-
*/
|
|
56
|
-
export function isWeightsFile(file: any): file is import("./kit/weights.mjs").WeightsFile;
|
|
57
43
|
/**
|
|
58
44
|
* A page template the kit can recommend starting from.
|
|
59
45
|
*/
|
package/api/build/_adapter.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file The build subject's environment access: the page templates a project
|
|
5
|
-
* can scaffold, the components it can use
|
|
5
|
+
* can scaffold, and the components it can use.
|
|
6
6
|
*
|
|
7
7
|
* @input Template and component discovery for `cwd` — the CLI's own templates
|
|
8
8
|
* and Core's components, plus any that the project's configured integrations
|
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
* from the template subject's, components from search's.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import fs from 'node:fs';
|
|
20
|
-
|
|
21
19
|
import {discoverTemplates} from '../template/template.mjs';
|
|
22
20
|
import {componentKeywords} from '../search/search.mjs';
|
|
23
21
|
import {findCoreDir} from '../../foundation/fs/paths.mjs';
|
|
@@ -91,58 +89,3 @@ export async function loadComponents(cwd) {
|
|
|
91
89
|
return [];
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
|
-
|
|
95
|
-
/** @type {import('./kit/weights.mjs').WeightsFile | null | undefined} */
|
|
96
|
-
let weights;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* The matcher weights checked in beside the kit (`kit/weights.json`), read
|
|
100
|
-
* once; null when the file is absent or unreadable.
|
|
101
|
-
* @returns {import('./kit/weights.mjs').WeightsFile | null}
|
|
102
|
-
*/
|
|
103
|
-
export function loadWeights() {
|
|
104
|
-
if (weights === undefined) {
|
|
105
|
-
try {
|
|
106
|
-
const file = JSON.parse(
|
|
107
|
-
fs.readFileSync(new URL('./kit/weights.json', import.meta.url), 'utf8'),
|
|
108
|
-
);
|
|
109
|
-
weights = isWeightsFile(file) ? file : null;
|
|
110
|
-
} catch {
|
|
111
|
-
weights = null;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return weights ?? null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Whether a parsed weights file has the shape the kit reads: every row has a
|
|
119
|
-
* weight per candidate, every bias a number per candidate, and three blend
|
|
120
|
-
* numbers per member (the tables plus the ranker) and one for the shell.
|
|
121
|
-
* @param {any} file
|
|
122
|
-
* @returns {file is import('./kit/weights.mjs').WeightsFile}
|
|
123
|
-
*/
|
|
124
|
-
export function isWeightsFile(file) {
|
|
125
|
-
const n = Array.isArray(file?.candidates) ? file.candidates.length : 0;
|
|
126
|
-
return (
|
|
127
|
-
n > 0 &&
|
|
128
|
-
Array.isArray(file.tables) &&
|
|
129
|
-
file.tables.length > 0 &&
|
|
130
|
-
file.tables.every(
|
|
131
|
-
(/** @type {any} */ t) =>
|
|
132
|
-
Array.isArray(t?.words) &&
|
|
133
|
-
Array.isArray(t.rows) &&
|
|
134
|
-
t.rows.length === t.words.length &&
|
|
135
|
-
t.rows.every(
|
|
136
|
-
(/** @type {any} */ r) => typeof r === 'string' && r.length === n,
|
|
137
|
-
) &&
|
|
138
|
-
Array.isArray(t.bias) &&
|
|
139
|
-
t.bias.length === n &&
|
|
140
|
-
t.bias.every((/** @type {any} */ b) => Number.isFinite(b)) &&
|
|
141
|
-
Number.isFinite(t.clip) &&
|
|
142
|
-
Number.isFinite(t.step),
|
|
143
|
-
) &&
|
|
144
|
-
Array.isArray(file.blend) &&
|
|
145
|
-
file.blend.length === 3 * (file.tables.length + 1) + 1 &&
|
|
146
|
-
file.blend.every((/** @type {any} */ x) => Number.isFinite(x))
|
|
147
|
-
);
|
|
148
|
-
}
|
package/api/build/build.test.mjs
CHANGED
|
@@ -269,7 +269,7 @@ describe('build kit — a thin kit says what to try next', () => {
|
|
|
269
269
|
// A skeleton is a 35-line excerpt: a reader who studies it and composes
|
|
270
270
|
// the rest loses the spacing the template exists to carry. A loose match
|
|
271
271
|
// is still the best start there is, so `start` scaffolds it.
|
|
272
|
-
const r = await build('
|
|
272
|
+
const r = await build('quarterly business review', {cwd: REPO});
|
|
273
273
|
expect(r.type).toBe('build.kit');
|
|
274
274
|
if (r.type !== 'build.kit') return;
|
|
275
275
|
expect(r.data.directMatch).toBe(false);
|
|
@@ -477,79 +477,6 @@ describe('build kit — every page starts from a template', () => {
|
|
|
477
477
|
expect(r.data.pages.map(p => p.name)).not.toContain('side-gallery');
|
|
478
478
|
});
|
|
479
479
|
|
|
480
|
-
it('names a direct match the start does not use, and calls the start direct only when it is', async () => {
|
|
481
|
-
for (const idea of ['a login form', 'a docs site for our API', 'contact form']) {
|
|
482
|
-
const r = await build(idea, {cwd: REPO});
|
|
483
|
-
if (r.type !== 'build.kit') throw new Error(r.type);
|
|
484
|
-
expect(r.data.directMatch).toBe(true);
|
|
485
|
-
const match = r.data.pages[0].name;
|
|
486
|
-
if (r.data.start?.name === match) {
|
|
487
|
-
expect(r.data.start?.basis).toBe('direct');
|
|
488
|
-
} else {
|
|
489
|
-
expect(['closest', 'fallback']).toContain(r.data.start?.basis);
|
|
490
|
-
expect(r.data.start?.reason).toContain(`\`${match}\``);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
it('keeps a template search matched directly rather than the app shell', async () => {
|
|
496
|
-
for (const [idea, name] of [
|
|
497
|
-
['a login screen', 'login'],
|
|
498
|
-
['a checkout wizard', 'checkout-wizard'],
|
|
499
|
-
]) {
|
|
500
|
-
const r = await build(idea, {cwd: REPO});
|
|
501
|
-
if (r.type !== 'build.kit') throw new Error(r.type);
|
|
502
|
-
expect(r.data.directMatch).toBe(true);
|
|
503
|
-
expect(r.data.start?.name).toBe(name);
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
it('lets the weights choose another template over a direct match', async () => {
|
|
508
|
-
const r = await build('a login form', {cwd: REPO});
|
|
509
|
-
if (r.type !== 'build.kit') throw new Error(r.type);
|
|
510
|
-
expect(r.data.directMatch).toBe(true);
|
|
511
|
-
const match = r.data.pages[0].name;
|
|
512
|
-
expect(r.data.start?.name).not.toBe('shell-top-nav');
|
|
513
|
-
expect(r.data.start?.name).not.toBe(match);
|
|
514
|
-
expect(r.data.start?.reason).toContain(`\`${match}\``);
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
it('starts a part that names no page from the app shell', async () => {
|
|
518
|
-
for (const idea of ['a kanban card', 'a date range picker']) {
|
|
519
|
-
const r = await build(idea, {cwd: REPO});
|
|
520
|
-
if (r.type !== 'build.kit') throw new Error(r.type);
|
|
521
|
-
expect(r.data.start).toMatchObject({name: 'shell-top-nav', basis: 'fallback'});
|
|
522
|
-
expect(r.data.start?.reason).toMatch(/part of a page/);
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
it('does not keep a loose match over the app shell', async () => {
|
|
527
|
-
// Search matches no template directly, so the ranker's closest page does
|
|
528
|
-
// not override the shell the weights choose.
|
|
529
|
-
const r = await build('quarterly business review', {cwd: REPO});
|
|
530
|
-
if (r.type !== 'build.kit') throw new Error(r.type);
|
|
531
|
-
expect(r.data.directMatch).toBe(false);
|
|
532
|
-
expect(r.data.start).toMatchObject({name: 'shell-top-nav', basis: 'fallback'});
|
|
533
|
-
expect(r.data.start?.reason).toMatch(/closest/);
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
it('starts a new page with no matching template from the app shell', async () => {
|
|
537
|
-
const r = await build('a new page', {cwd: REPO});
|
|
538
|
-
if (r.type !== 'build.kit') throw new Error(r.type);
|
|
539
|
-
expect(r.data.start?.name).toBe('shell-top-nav');
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
it('starts a page the words describe from its template', async () => {
|
|
543
|
-
for (const [idea, name] of [
|
|
544
|
-
['a weekly report of sales by region', 'dashboard-scorecard'],
|
|
545
|
-
['a pricing page with three plans and a comparison table', 'table-page'],
|
|
546
|
-
]) {
|
|
547
|
-
const r = await build(idea, {cwd: REPO});
|
|
548
|
-
if (r.type !== 'build.kit') throw new Error(r.type);
|
|
549
|
-
expect(r.data.start?.name).toBe(name);
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
|
|
553
480
|
it('starts a component in a container from a template with that frame', async () => {
|
|
554
481
|
// "in a modal": the modal is the frame, so the dialog template leads
|
|
555
482
|
// instead of the app shell.
|
package/api/build/kit/kit.mjs
CHANGED
|
@@ -32,15 +32,8 @@ import {findCoreDir} from '../../../foundation/fs/paths.mjs';
|
|
|
32
32
|
import {AstryxError} from '../../error.mjs';
|
|
33
33
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
34
34
|
import {getResultCoverage} from '../../search/coverage.mjs';
|
|
35
|
-
import {loadComponents, loadPageTemplates
|
|
36
|
-
import {
|
|
37
|
-
asksForNewPage,
|
|
38
|
-
ideaKind,
|
|
39
|
-
pickAlternatives,
|
|
40
|
-
pickStart,
|
|
41
|
-
rankPages,
|
|
42
|
-
} from './rank.mjs';
|
|
43
|
-
import {weighStart} from './weights.mjs';
|
|
35
|
+
import {loadComponents, loadPageTemplates} from '../_adapter.mjs';
|
|
36
|
+
import {ideaKind, pickAlternatives, pickStart, rankPages} from './rank.mjs';
|
|
44
37
|
|
|
45
38
|
/** A page at/above this score is a confident direct match. */
|
|
46
39
|
const PAGE_DIRECT = 95;
|
|
@@ -158,10 +151,9 @@ function placement(kind, inPage) {
|
|
|
158
151
|
* @param {SearchResultEntry[]} pages
|
|
159
152
|
* @param {boolean} directMatch
|
|
160
153
|
* @param {PageTemplate[]} catalog
|
|
161
|
-
* @param {string} idea
|
|
162
154
|
* @returns {Omit<BuildStart, 'alternatives'> | null}
|
|
163
155
|
*/
|
|
164
|
-
function chooseStart(ranked, kind, pages, directMatch, catalog
|
|
156
|
+
function chooseStart(ranked, kind, pages, directMatch, catalog) {
|
|
165
157
|
const direct = directMatch ? pages[0].name : null;
|
|
166
158
|
const unready =
|
|
167
159
|
direct && !catalog.some(t => t.name === direct) ? direct : null;
|
|
@@ -178,27 +170,7 @@ function chooseStart(ranked, kind, pages, directMatch, catalog, idea) {
|
|
|
178
170
|
direct && direct !== startName
|
|
179
171
|
? `Search matched \`${direct}\` by name, but ${place}`
|
|
180
172
|
: place[0].toUpperCase() + place.slice(1);
|
|
181
|
-
const
|
|
182
|
-
// The checked-in word weights (weights.mjs), blended with the ranker's
|
|
183
|
-
// scores, decide the start of a whole page. A part or an edit starts where
|
|
184
|
-
// the ranker's placement rules put it (spec:AST-048/FR3).
|
|
185
|
-
const weighed =
|
|
186
|
-
kind === 'page'
|
|
187
|
-
? weighStart(idea, ranked, proposed, catalog, {
|
|
188
|
-
weights: loadWeights(),
|
|
189
|
-
newPage: asksForNewPage(idea, catalog),
|
|
190
|
-
})
|
|
191
|
-
: undefined;
|
|
192
|
-
// A shell start keeps the shell the ranker named, if any, and never replaces
|
|
193
|
-
// the template the ranker chose for a page search matched directly.
|
|
194
|
-
const pick =
|
|
195
|
-
weighed === undefined
|
|
196
|
-
? proposed
|
|
197
|
-
: weighed === null
|
|
198
|
-
? proposed?.family === 'Shell' || (proposed && direct && !unready)
|
|
199
|
-
? proposed
|
|
200
|
-
: null
|
|
201
|
-
: (ranked.find(r => r.name === weighed) ?? proposed);
|
|
173
|
+
const pick = pickStart(ranked, kind);
|
|
202
174
|
const closest = pick && catalog.find(t => t.name === pick.name);
|
|
203
175
|
if (pick && closest) {
|
|
204
176
|
const agrees = closest.name === direct;
|
|
@@ -222,9 +194,7 @@ function chooseStart(ranked, kind, pages, directMatch, catalog, idea) {
|
|
|
222
194
|
if (shell) {
|
|
223
195
|
// The shell can also be the ranker's best guess without the evidence to
|
|
224
196
|
// lead ("horizontal site navigation"); say so rather than "no match".
|
|
225
|
-
const nearest =
|
|
226
|
-
(ranked[0]?.name === shell.name && ranked[0].hits > 0) ||
|
|
227
|
-
(weighed === null && !!proposed && proposed.family !== 'Shell');
|
|
197
|
+
const nearest = ranked[0]?.name === shell.name && ranked[0].hits > 0;
|
|
228
198
|
const place = placement(kind, false);
|
|
229
199
|
return {
|
|
230
200
|
...asTemplate(shell),
|
|
@@ -234,9 +204,7 @@ function chooseStart(ranked, kind, pages, directMatch, catalog, idea) {
|
|
|
234
204
|
: place
|
|
235
205
|
? placed(place, shell.name)
|
|
236
206
|
: direct
|
|
237
|
-
?
|
|
238
|
-
? `Search matched \`${direct}\` by name, but the app shell is the closer start.`
|
|
239
|
-
: `Search matched \`${direct}\` by name, but too little of the idea fits it, so start from the app shell.`
|
|
207
|
+
? `Search matched \`${direct}\` by name, but too little of the idea fits it, so start from the app shell.`
|
|
240
208
|
: nearest
|
|
241
209
|
? 'No template is a clear match; the app shell is the closest.'
|
|
242
210
|
: loose
|
|
@@ -378,7 +346,7 @@ export async function buildKit(query, options = {}) {
|
|
|
378
346
|
)
|
|
379
347
|
: 'page';
|
|
380
348
|
const chosen = wantsPages
|
|
381
|
-
? chooseStart(ranked, kind, matchedPages, directMatch, catalog
|
|
349
|
+
? chooseStart(ranked, kind, matchedPages, directMatch, catalog)
|
|
382
350
|
: null;
|
|
383
351
|
// Name the ranker's next two templates beside the start: the reader judges
|
|
384
352
|
// meaning better than keywords do, and an acceptable template is in these
|
package/api/build/kit/rank.d.mts
CHANGED
|
@@ -21,14 +21,6 @@ export function rankPages(query: string, pages: PageTemplate[]): RankedPage[];
|
|
|
21
21
|
* @returns {IdeaKind}
|
|
22
22
|
*/
|
|
23
23
|
export function ideaKind(query: string, pages: PageTemplate[], components: ComponentWords[]): IdeaKind;
|
|
24
|
-
/**
|
|
25
|
-
* Whether an idea asks for a new page (see `asksNewPage`), from the idea and
|
|
26
|
-
* the project's page templates.
|
|
27
|
-
* @param {string} query
|
|
28
|
-
* @param {PageTemplate[]} pages
|
|
29
|
-
* @returns {boolean}
|
|
30
|
-
*/
|
|
31
|
-
export function asksForNewPage(query: string, pages: PageTemplate[]): boolean;
|
|
32
24
|
/**
|
|
33
25
|
* The next closest templates after the start, best first: the ones a reader
|
|
34
26
|
* should check the idea against when the start's shape is wrong. Each matched
|
package/api/build/kit/rank.mjs
CHANGED
|
@@ -543,20 +543,6 @@ function asksNewPage(phrases, familyWords) {
|
|
|
543
543
|
});
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
-
/**
|
|
547
|
-
* Whether an idea asks for a new page (see `asksNewPage`), from the idea and
|
|
548
|
-
* the project's page templates.
|
|
549
|
-
* @param {string} query
|
|
550
|
-
* @param {PageTemplate[]} pages
|
|
551
|
-
* @returns {boolean}
|
|
552
|
-
*/
|
|
553
|
-
export function asksForNewPage(query, pages) {
|
|
554
|
-
return asksNewPage(
|
|
555
|
-
String(query).toLowerCase().split(PHRASE_END),
|
|
556
|
-
familyWordsOf(pages),
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
546
|
/**
|
|
561
547
|
* The words of a component's name: "DateRangeInput" is date, range, input.
|
|
562
548
|
* @param {ComponentWords} component
|
|
@@ -60,6 +60,43 @@
|
|
|
60
60
|
* @returns {string}
|
|
61
61
|
*/
|
|
62
62
|
export function requireCoreDir(cwd: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* List the component markup files for a vanilla framework.
|
|
65
|
+
* @param {string} cwd
|
|
66
|
+
* @param {'html'|'web-components'} framework
|
|
67
|
+
* @returns {{name: string, file: string}[]}
|
|
68
|
+
*/
|
|
69
|
+
export function listVanillaComponentMarkup(cwd: string, framework: "html" | "web-components"): {
|
|
70
|
+
name: string;
|
|
71
|
+
file: string;
|
|
72
|
+
}[];
|
|
73
|
+
/** @param {string} cwd @returns {{name: string, file: string}[]} */
|
|
74
|
+
export function listVanillaComponentHtml(cwd: string): {
|
|
75
|
+
name: string;
|
|
76
|
+
file: string;
|
|
77
|
+
}[];
|
|
78
|
+
/**
|
|
79
|
+
* Read one exact component markup file without permitting path traversal.
|
|
80
|
+
* @param {string} name
|
|
81
|
+
* @param {string} cwd
|
|
82
|
+
* @param {'html'|'web-components'} framework
|
|
83
|
+
* @returns {{component: string, file: string, source: string}}
|
|
84
|
+
*/
|
|
85
|
+
export function readVanillaComponentMarkup(name: string, cwd: string, framework: "html" | "web-components"): {
|
|
86
|
+
component: string;
|
|
87
|
+
file: string;
|
|
88
|
+
source: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* @param {string} name
|
|
92
|
+
* @param {string} cwd
|
|
93
|
+
* @returns {{component: string, file: string, source: string}}
|
|
94
|
+
*/
|
|
95
|
+
export function readVanillaComponentHtml(name: string, cwd: string): {
|
|
96
|
+
component: string;
|
|
97
|
+
file: string;
|
|
98
|
+
source: string;
|
|
99
|
+
};
|
|
63
100
|
/**
|
|
64
101
|
* Load the configured integrations for `cwd`, swallowing any config errors so
|
|
65
102
|
* component discovery never hard-fails on a malformed/absent integration. An
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file Shared resolver for the `component` command leaves.
|
|
5
5
|
*
|
|
6
|
-
* @input a component name (+ cwd / package scope) and doc-load options
|
|
6
|
+
* @input a component name (+ cwd / package scope) and doc-load options;
|
|
7
|
+
* vanilla HTML reads resolve checkout assets before the bundled copy
|
|
7
8
|
* @output resolved subjects the leaves project into their one `{type, data}`
|
|
8
9
|
* envelope — owners across core/integration, the scoped/legacy/fuzzy
|
|
9
10
|
* resolution, and the doc-loading / prop-extraction / ownership shaping
|
|
@@ -40,6 +41,7 @@ import {Project} from '../../foundation/config/project.mjs';
|
|
|
40
41
|
import {loadComponentDoc as loadValidatedComponentDoc} from '../../foundation/discovery/component-loader.mjs';
|
|
41
42
|
import {searchComponents} from '../../foundation/text/string-utils.mjs';
|
|
42
43
|
import {AstryxError} from '../error.mjs';
|
|
44
|
+
import {requireVanillaAssetsDir} from '../_vanilla-assets.mjs';
|
|
43
45
|
|
|
44
46
|
export {CORE_PACKAGE};
|
|
45
47
|
|
|
@@ -120,6 +122,83 @@ export function requireCoreDir(cwd) {
|
|
|
120
122
|
return coreDir;
|
|
121
123
|
}
|
|
122
124
|
|
|
125
|
+
/**
|
|
126
|
+
* List the component markup files for a vanilla framework.
|
|
127
|
+
* @param {string} cwd
|
|
128
|
+
* @param {'html'|'web-components'} framework
|
|
129
|
+
* @returns {{name: string, file: string}[]}
|
|
130
|
+
*/
|
|
131
|
+
export function listVanillaComponentMarkup(cwd, framework) {
|
|
132
|
+
const assetDir =
|
|
133
|
+
framework === 'web-components' ? 'elements-markup' : 'markup';
|
|
134
|
+
const markupDir = path.join(requireVanillaAssetsDir(cwd), assetDir);
|
|
135
|
+
if (!fs.existsSync(markupDir)) return [];
|
|
136
|
+
return fs
|
|
137
|
+
.readdirSync(markupDir, {withFileTypes: true})
|
|
138
|
+
.filter(entry => entry.isFile() && entry.name.endsWith('.html'))
|
|
139
|
+
.map(entry => ({
|
|
140
|
+
name: entry.name.slice(0, -'.html'.length),
|
|
141
|
+
file: entry.name,
|
|
142
|
+
}))
|
|
143
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** @param {string} cwd @returns {{name: string, file: string}[]} */
|
|
147
|
+
export function listVanillaComponentHtml(cwd) {
|
|
148
|
+
return listVanillaComponentMarkup(cwd, 'html');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Read one exact component markup file without permitting path traversal.
|
|
153
|
+
* @param {string} name
|
|
154
|
+
* @param {string} cwd
|
|
155
|
+
* @param {'html'|'web-components'} framework
|
|
156
|
+
* @returns {{component: string, file: string, source: string}}
|
|
157
|
+
*/
|
|
158
|
+
export function readVanillaComponentMarkup(name, cwd, framework) {
|
|
159
|
+
const entries = listVanillaComponentMarkup(cwd, framework);
|
|
160
|
+
if (!/^[A-Za-z][A-Za-z0-9]*$/.test(name)) {
|
|
161
|
+
throw new AstryxError(
|
|
162
|
+
`Invalid vanilla component name "${name}"`,
|
|
163
|
+
undefined,
|
|
164
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const match = entries.find(entry => entry.name === name);
|
|
168
|
+
const label = framework === 'web-components' ? 'web-component' : 'HTML';
|
|
169
|
+
if (!match) {
|
|
170
|
+
throw new AstryxError(
|
|
171
|
+
`No vanilla ${label} markup found for component "${name}"`,
|
|
172
|
+
entries.map(entry => ({
|
|
173
|
+
name: entry.name,
|
|
174
|
+
reason: `vanilla ${label} component`,
|
|
175
|
+
})),
|
|
176
|
+
ERROR_CODES.ERR_UNKNOWN_COMPONENT,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
const assetDir =
|
|
180
|
+
framework === 'web-components' ? 'elements-markup' : 'markup';
|
|
181
|
+
const filePath = path.join(
|
|
182
|
+
requireVanillaAssetsDir(cwd),
|
|
183
|
+
assetDir,
|
|
184
|
+
match.file,
|
|
185
|
+
);
|
|
186
|
+
return {
|
|
187
|
+
component: name,
|
|
188
|
+
file: match.file,
|
|
189
|
+
source: fs.readFileSync(filePath, 'utf8'),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @param {string} name
|
|
195
|
+
* @param {string} cwd
|
|
196
|
+
* @returns {{component: string, file: string, source: string}}
|
|
197
|
+
*/
|
|
198
|
+
export function readVanillaComponentHtml(name, cwd) {
|
|
199
|
+
return readVanillaComponentMarkup(name, cwd, 'html');
|
|
200
|
+
}
|
|
201
|
+
|
|
123
202
|
/**
|
|
124
203
|
* Load the configured integrations for `cwd`, swallowing any config errors so
|
|
125
204
|
* component discovery never hard-fails on a malformed/absent integration. An
|