@astryxdesign/cli 0.6.5 → 0.6.6
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 +87 -0
- package/README.md +16 -15
- package/api/build/_adapter.d.mts +50 -2
- package/api/build/_adapter.mjs +98 -10
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +111 -2
- package/api/build/kit/kit.mjs +98 -22
- package/api/build/kit/rank.d.mts +32 -8
- package/api/build/kit/rank.mjs +291 -97
- package/api/build/kit/rank.test.mjs +231 -48
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +132 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +44 -1
- package/api/docs/docs.test.mjs +279 -0
- package/api/docs/docs.type.d.mts +38 -1
- package/api/docs/docs.type.mjs +18 -1
- package/api/docs/integration-tree.test.mjs +572 -0
- package/api/docs/integrationDocs.test.mjs +336 -0
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +146 -23
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/gap-report/gap-report.d.mts +3 -1
- package/api/gap-report/gap-report.mjs +12 -2
- package/api/gap-report/gap-report.test.mjs +106 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-theme.mjs +338 -26
- package/api/integration/add-theme.test.mjs +314 -1
- package/api/integration/authoring-checks.mjs +10 -7
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +12 -3
- package/api/integration/pack-check.test.mjs +52 -3
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +36 -5
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +194 -54
- package/api/search/search.test.mjs +825 -0
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/api/swizzle/copy/copy.mjs +66 -3
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/template/copy/copy.mjs +14 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +15 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/template-integration.test.mjs +14 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +381 -77
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +1 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/docs/theme.doc.mjs +3 -2
- package/assets/docs/tokens.doc.mjs +3 -3
- package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
- package/assets/docs/tree/versioning.doc.mjs +7 -6
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
- package/assets/templates/pages/blank/template.doc.mjs +3 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
- package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
- package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
- package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
- package/assets/templates/pages/documentation/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
- package/assets/templates/pages/editor/template.doc.mjs +9 -1
- package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
- package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
- package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
- package/assets/templates/pages/ide/template.doc.mjs +9 -1
- package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
- package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
- package/assets/templates/pages/library/template.doc.mjs +15 -1
- package/assets/templates/pages/login/template.doc.mjs +10 -1
- package/assets/templates/pages/login-card/template.doc.mjs +11 -1
- package/assets/templates/pages/login-split/template.doc.mjs +10 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
- package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
- package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/settings/template.doc.mjs +3 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/table/template.doc.mjs +11 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
- package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
- package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
- package/assets/templates/pages/table-page/template.doc.mjs +20 -1
- package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
- package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +1 -0
- package/authoring/doctypes/template/parse.test.mjs +21 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +10 -0
- package/clients/cli/commands/build-theme.mjs +8 -2
- package/clients/cli/commands/discover.mjs +29 -1
- package/clients/cli/commands/discover.no-source.test.mjs +75 -0
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +222 -5
- package/clients/cli/commands/docs.test.mjs +383 -0
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/gap-report.mjs +12 -0
- package/clients/cli/commands/gap-report.test.mjs +63 -0
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/search.doc.mjs +5 -4
- package/clients/cli/commands/search.mjs +30 -6
- package/clients/cli/commands/search.test.mjs +60 -16
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +19 -5
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +41 -0
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/foundation/agent-docs/agent-docs.mjs +2 -1
- package/foundation/agent-docs/agent-docs.test.mjs +1168 -0
- package/foundation/discovery/template-adapter.d.mts +14 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +21 -1
- package/foundation/discovery/theme-discovery.d.mts +6 -0
- package/foundation/discovery/theme-discovery.mjs +9 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/foundation/integrations/cli-requirement.d.mts +57 -13
- package/foundation/integrations/cli-requirement.mjs +84 -22
- package/foundation/integrations/cli-requirement.test.mjs +135 -8
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +1 -1
package/api/search/search.mjs
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* outputs. The CLI command handler is a thin wrapper around this function.
|
|
8
8
|
*
|
|
9
9
|
* `search(query)` is the single "I'm looking for X" entry point across ALL
|
|
10
|
-
* content domains — components, hooks, docs topics,
|
|
11
|
-
*
|
|
12
|
-
* (`component --list`, `hook --list`, `docs`, `template --list`)
|
|
13
|
-
* scanning; this collapses them into one ranked, typed result set.
|
|
10
|
+
* content domains — components, hooks, docs topics, templates (page + block),
|
|
11
|
+
* and themes. Finding the right thing otherwise takes separate list calls
|
|
12
|
+
* (`component --list`, `hook --list`, `docs`, `template --list`, `theme list`)
|
|
13
|
+
* plus manual scanning; this collapses them into one ranked, typed result set.
|
|
14
14
|
*
|
|
15
15
|
* Scoring is keyword + fuzzy ranking (NOT semantic / embeddings — that is a
|
|
16
16
|
* deliberate future follow-up). It reuses the same signal weighting as the
|
|
@@ -89,6 +89,7 @@ import {loadIntegrationsSafely} from '../component/_adapter.mjs';
|
|
|
89
89
|
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
90
90
|
import {discoverTemplates, extractComponents} from '../template/template.mjs';
|
|
91
91
|
import {templateLookupIds} from '../../foundation/discovery/template-adapter.mjs';
|
|
92
|
+
import {listAvailableThemes} from '../theme/_adapter.mjs';
|
|
92
93
|
import {
|
|
93
94
|
guideEntry,
|
|
94
95
|
loadDocsCatalog,
|
|
@@ -110,8 +111,10 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
110
111
|
* A search candidate gathered from one content domain. Extra underscore-
|
|
111
112
|
* prefixed fields carry domain-specific payload used only by {@link toResult}.
|
|
112
113
|
* @typedef {object} Candidate
|
|
113
|
-
* @property {'component'|'hook'|'doc'|'template'} domain
|
|
114
|
+
* @property {'component'|'hook'|'doc'|'template'|'theme'} domain
|
|
114
115
|
* @property {string} name
|
|
116
|
+
* @property {string[]} [aliases] - Other names the candidate answers to, scored
|
|
117
|
+
* with the same name signals: a theme's display name.
|
|
115
118
|
* @property {string[]} [keywords]
|
|
116
119
|
* @property {string[]} [weakKeywords]
|
|
117
120
|
* @property {string} [description]
|
|
@@ -291,7 +294,13 @@ const isTypo = (a, b, dist) =>
|
|
|
291
294
|
TYPO_MIN_LENGTH[/** @type {1 | 2 | 3} */ (dist)];
|
|
292
295
|
|
|
293
296
|
/** Valid domain filters for `--type`. */
|
|
294
|
-
export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template'];
|
|
297
|
+
export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template', 'theme'];
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The domains a search reads without @astryxdesign/core. An open search outside
|
|
301
|
+
* an app covers these alone.
|
|
302
|
+
*/
|
|
303
|
+
const CORELESS_DOMAINS = ['doc', 'theme'];
|
|
295
304
|
|
|
296
305
|
/**
|
|
297
306
|
* Filler words stripped from multi-word queries so natural-language phrasing
|
|
@@ -618,6 +627,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
618
627
|
// strong hits, then reward coverage so candidates matching more terms win.
|
|
619
628
|
let strongest = 0;
|
|
620
629
|
let matched = 0;
|
|
630
|
+
let tokenSum = 0;
|
|
621
631
|
/** @type {string[]} */
|
|
622
632
|
const hitTerms = [];
|
|
623
633
|
for (const tok of tokens) {
|
|
@@ -626,6 +636,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
626
636
|
if (h.score > strongest) strongest = h.score;
|
|
627
637
|
matched++;
|
|
628
638
|
hitTerms.push(tok);
|
|
639
|
+
tokenSum += h.score;
|
|
629
640
|
}
|
|
630
641
|
}
|
|
631
642
|
// The reverse of the title tier, a step lower: the query holds a whole title
|
|
@@ -650,14 +661,25 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
650
661
|
// (50 + bonus + coverage = 77) lost to thirty docs that each match
|
|
651
662
|
// `integration` alone, by name or in a code tick (98-108). The reader asked for
|
|
652
663
|
// both; a candidate that has both comes first, ordered among its peers by
|
|
653
|
-
// how strong its
|
|
664
|
+
// how strong its matches are. It needs one keyword-strength hit:
|
|
654
665
|
// every word mentioned in prose, or rendered by a page, is breadth, and
|
|
655
666
|
// stays on the token sum below an exact hit on one word.
|
|
667
|
+
//
|
|
668
|
+
// The TOTAL quality of matches orders candidates within this tier, not
|
|
669
|
+
// just the strongest single hit. A doc matching both words by keyword
|
|
670
|
+
// (90 + 90 = 180) outranks one matching keyword + prose (90 + 50 = 140).
|
|
671
|
+
// Before this, every all-word match whose strongest hit was a keyword (90)
|
|
672
|
+
// scored 157, burying the better match among dozens of ties.
|
|
656
673
|
if (matched === tokens.length && strongest >= STRONG_TOKEN_SCORE) {
|
|
657
674
|
return {
|
|
658
675
|
score:
|
|
659
676
|
FULL_COVERAGE_SCORE +
|
|
660
|
-
Math.
|
|
677
|
+
Math.min(
|
|
678
|
+
Math.floor(
|
|
679
|
+
(tokenSum - matched * MIN_TOKEN_SCORE) / (matched * 5),
|
|
680
|
+
),
|
|
681
|
+
8,
|
|
682
|
+
),
|
|
661
683
|
reason,
|
|
662
684
|
matched,
|
|
663
685
|
total,
|
|
@@ -697,6 +719,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
697
719
|
* @param {string} term - Lowercased search term.
|
|
698
720
|
* @param {object} candidate
|
|
699
721
|
* @param {string} candidate.name - Primary identifier (component/hook name, topic, template name).
|
|
722
|
+
* @param {string[]} [candidate.aliases] - Other names, scored like the name (a theme's display name).
|
|
700
723
|
* @param {string} [candidate.domain] - A component, hook, or template name
|
|
701
724
|
* also matches typed as words: `command palette` is CommandPalette.
|
|
702
725
|
* @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
|
|
@@ -711,6 +734,7 @@ export function scoreCandidate(
|
|
|
711
734
|
term,
|
|
712
735
|
{
|
|
713
736
|
name,
|
|
737
|
+
aliases = [],
|
|
714
738
|
domain,
|
|
715
739
|
keywords = [],
|
|
716
740
|
weakKeywords = [],
|
|
@@ -733,40 +757,44 @@ export function scoreCandidate(
|
|
|
733
757
|
}
|
|
734
758
|
};
|
|
735
759
|
|
|
736
|
-
const nameLower = name.toLowerCase();
|
|
737
|
-
// A placed guide's name is its route, and the route's last segment is its
|
|
738
|
-
// name too, as a flat topic's is: `codemods` is cli/integrations/codemods.
|
|
739
|
-
const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
|
|
740
|
-
|
|
741
760
|
// ── Name signals ────────────────────────────────────────────────
|
|
742
|
-
//
|
|
743
|
-
//
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
//
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
);
|
|
761
|
+
// An alias is a name too: a theme answers to its display name as well as
|
|
762
|
+
// its slug.
|
|
763
|
+
for (const candidateName of [name, ...aliases.filter(Boolean)]) {
|
|
764
|
+
const nameLower = candidateName.toLowerCase();
|
|
765
|
+
// A placed guide's name is its route, and the route's last segment is its
|
|
766
|
+
// name too, as a flat topic's is: `codemods` is cli/integrations/codemods.
|
|
767
|
+
const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
|
|
768
|
+
|
|
769
|
+
// A plural of the name is the name: `integration` is the `integrations`
|
|
770
|
+
// guides, `tab` the `tabs` doc.
|
|
771
|
+
// A component, hook, or template name typed as words is its name:
|
|
772
|
+
// `command palette` is CommandPalette. A doc's name is a route or key,
|
|
773
|
+
// matched as written.
|
|
774
|
+
const spelled =
|
|
775
|
+
domain !== 'doc' &&
|
|
776
|
+
!/[\s_-]/.test(nameLower) &&
|
|
777
|
+
nameLower === term.replace(/\s+/g, '');
|
|
778
|
+
if (nameLower === term || leafLower === term || spelled) {
|
|
779
|
+
consider(100, 'exact name');
|
|
780
|
+
} else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
|
|
781
|
+
// One point under the exact spelling, so the doc named `tokens` still
|
|
782
|
+
// outranks the Token component for `tokens`.
|
|
783
|
+
consider(99, 'plural of the name');
|
|
784
|
+
} else {
|
|
785
|
+
if (sameWord(term, nameLower)) consider(95, `name "${candidateName}"`);
|
|
786
|
+
// The term is a word of the name, or starts one: "input" in TextInput.
|
|
787
|
+
else if (startsAWordOf(term, candidateName)) {
|
|
788
|
+
consider(60, `name contains "${term}"`);
|
|
789
|
+
}
|
|
790
|
+
if (fuzzy) {
|
|
791
|
+
const dist = levenshteinDistance(term, nameLower);
|
|
792
|
+
if (isTypo(term, nameLower, dist)) {
|
|
793
|
+
consider(
|
|
794
|
+
dist === 1 ? 80 : dist === 2 ? 40 : 20,
|
|
795
|
+
`similar name (distance ${dist})`,
|
|
796
|
+
);
|
|
797
|
+
}
|
|
770
798
|
}
|
|
771
799
|
}
|
|
772
800
|
}
|
|
@@ -1007,6 +1035,64 @@ async function gatherComponents(coreDir, cwd) {
|
|
|
1007
1035
|
return [...core, ...integrations];
|
|
1008
1036
|
}
|
|
1009
1037
|
|
|
1038
|
+
/**
|
|
1039
|
+
* The components each search response was scored against, by response:
|
|
1040
|
+
* `build` reads them to tell a part of a page from a page without gathering
|
|
1041
|
+
* them again. Module-private, so they never enter search's JSON.
|
|
1042
|
+
* @type {WeakMap<object, {name: string, keywords: string[]}[]>}
|
|
1043
|
+
*/
|
|
1044
|
+
const searchedComponentsOf = new WeakMap();
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* The components (name and keywords) a search response was scored against, or
|
|
1048
|
+
* null when that search was narrowed away from components.
|
|
1049
|
+
* @param {object} response
|
|
1050
|
+
* @returns {{name: string, keywords: string[]}[] | null}
|
|
1051
|
+
*/
|
|
1052
|
+
export function searchedComponents(response) {
|
|
1053
|
+
return searchedComponentsOf.get(response) ?? null;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Every component the project can use, Core's and its integrations', with the
|
|
1058
|
+
* keywords its own doc declares: the discovery and doc reads search's own
|
|
1059
|
+
* candidates use, without the import paths and prose a result carries. `build`
|
|
1060
|
+
* reads it to tell a part of a page from a page when its search was narrowed
|
|
1061
|
+
* away from components.
|
|
1062
|
+
* @param {string} coreDir
|
|
1063
|
+
* @param {string} cwd
|
|
1064
|
+
* @returns {Promise<{name: string, keywords: string[]}[]>}
|
|
1065
|
+
*/
|
|
1066
|
+
export async function componentKeywords(coreDir, cwd) {
|
|
1067
|
+
/** @param {any} doc */
|
|
1068
|
+
const keywordsOf = doc => (Array.isArray(doc?.keywords) ? doc.keywords : []);
|
|
1069
|
+
const core = Object.values(discoverComponents(coreDir))
|
|
1070
|
+
.flat()
|
|
1071
|
+
.map(async name => {
|
|
1072
|
+
const readme = findComponentReadme(coreDir, name);
|
|
1073
|
+
const doc =
|
|
1074
|
+
readme && readme.endsWith('.doc.mjs')
|
|
1075
|
+
? await loadModuleDoc(readme)
|
|
1076
|
+
: null;
|
|
1077
|
+
return {name, keywords: keywordsOf(doc)};
|
|
1078
|
+
});
|
|
1079
|
+
const integrations = (await loadIntegrationsSafely(cwd)).map(
|
|
1080
|
+
async integration => {
|
|
1081
|
+
const {components} = await discoverValidIntegrationComponents(integration);
|
|
1082
|
+
return Promise.all(
|
|
1083
|
+
components.map(async rec => ({
|
|
1084
|
+
name: rec.name,
|
|
1085
|
+
keywords: keywordsOf(await loadModuleDoc(rec.docPath)),
|
|
1086
|
+
})),
|
|
1087
|
+
);
|
|
1088
|
+
},
|
|
1089
|
+
);
|
|
1090
|
+
return [
|
|
1091
|
+
...(await Promise.all(core)),
|
|
1092
|
+
...(await Promise.all(integrations)).flat(),
|
|
1093
|
+
];
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1010
1096
|
/**
|
|
1011
1097
|
* Build hook candidates: name + keywords + usage/description from the hook's
|
|
1012
1098
|
* .doc.mjs.
|
|
@@ -1393,6 +1479,10 @@ async function gatherTemplates(cwd) {
|
|
|
1393
1479
|
keywords,
|
|
1394
1480
|
weakKeywords,
|
|
1395
1481
|
description: t.description || '',
|
|
1482
|
+
// A template's own keywords name the many ideas it serves, so they score
|
|
1483
|
+
// as its prose does, not as a name: one of them matching one word of a
|
|
1484
|
+
// short idea is not a direct match.
|
|
1485
|
+
prose: t.keywords ?? [],
|
|
1396
1486
|
_displayName: t.name,
|
|
1397
1487
|
_kind: t.type, // 'page' | 'block'
|
|
1398
1488
|
_resultName: t.dirName,
|
|
@@ -1401,6 +1491,36 @@ async function gatherTemplates(cwd) {
|
|
|
1401
1491
|
});
|
|
1402
1492
|
}
|
|
1403
1493
|
|
|
1494
|
+
/**
|
|
1495
|
+
* Build theme candidates from bundled and integration-provided themes. Without
|
|
1496
|
+
* this, an integration's themes are invisible to `search` even though
|
|
1497
|
+
* `theme list` and `discover` already resolve them.
|
|
1498
|
+
*
|
|
1499
|
+
* A theme's slug and display name are its names, and its description is prose
|
|
1500
|
+
* (`spec:AST-050/FR14`). A theme declares no keywords, so a word it shares with
|
|
1501
|
+
* the query only through its description is a description mention: read as a
|
|
1502
|
+
* keyword, every word of the description would outrank the components and docs
|
|
1503
|
+
* that declare that word.
|
|
1504
|
+
* @param {string} cwd
|
|
1505
|
+
* @returns {Promise<Candidate[]>}
|
|
1506
|
+
*/
|
|
1507
|
+
async function gatherThemes(cwd) {
|
|
1508
|
+
let themes;
|
|
1509
|
+
try {
|
|
1510
|
+
themes = await listAvailableThemes(cwd);
|
|
1511
|
+
} catch {
|
|
1512
|
+
return [];
|
|
1513
|
+
}
|
|
1514
|
+
return themes.map(t => ({
|
|
1515
|
+
domain: 'theme',
|
|
1516
|
+
name: t.slug,
|
|
1517
|
+
aliases: t.displayName ? [t.displayName] : [],
|
|
1518
|
+
description: t.description || '',
|
|
1519
|
+
_displayName: t.displayName,
|
|
1520
|
+
_package: t.package,
|
|
1521
|
+
}));
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1404
1524
|
/**
|
|
1405
1525
|
* Map a scored candidate to its public, actionable result shape. Each result
|
|
1406
1526
|
* carries enough to act on it: the domain, name, a one-line description, and
|
|
@@ -1457,6 +1577,14 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1457
1577
|
command: `astryx template ${c._commandName ?? c.name} --type ${c._kind}`,
|
|
1458
1578
|
};
|
|
1459
1579
|
break;
|
|
1580
|
+
case 'theme':
|
|
1581
|
+
result = {
|
|
1582
|
+
...base,
|
|
1583
|
+
displayName: c._displayName,
|
|
1584
|
+
command: `astryx theme add ${c.name}`,
|
|
1585
|
+
...(c._package ? {package: c._package} : {}),
|
|
1586
|
+
};
|
|
1587
|
+
break;
|
|
1460
1588
|
default:
|
|
1461
1589
|
result = base;
|
|
1462
1590
|
}
|
|
@@ -1464,12 +1592,12 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1464
1592
|
}
|
|
1465
1593
|
|
|
1466
1594
|
/**
|
|
1467
|
-
* Unified ranked search across components, hooks, docs, and
|
|
1595
|
+
* Unified ranked search across components, hooks, docs, templates, and themes.
|
|
1468
1596
|
*
|
|
1469
1597
|
* @param {string} query - Free-text search term.
|
|
1470
1598
|
* @param {object} [options]
|
|
1471
1599
|
* @param {string} [options.cwd]
|
|
1472
|
-
* @param {'component'|'hook'|'doc'|'template'} [options.type] - Restrict to one domain.
|
|
1600
|
+
* @param {'component'|'hook'|'doc'|'template'|'theme'} [options.type] - Restrict to one domain.
|
|
1473
1601
|
* @param {number} [options.limit] - Max results (default 20).
|
|
1474
1602
|
* @returns {Promise<import('./search.type.mjs').SearchResponse>}
|
|
1475
1603
|
*/
|
|
@@ -1506,12 +1634,14 @@ export async function search(query, options = {}) {
|
|
|
1506
1634
|
const term = String(query).trim().toLowerCase();
|
|
1507
1635
|
const tokens = tokenizeQuery(term);
|
|
1508
1636
|
|
|
1509
|
-
// `astryx docs` reads docs without @astryxdesign/core,
|
|
1510
|
-
//
|
|
1511
|
-
//
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1637
|
+
// `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
|
|
1638
|
+
// list` reads themes without it (bundled themes need no project), so a
|
|
1639
|
+
// search of either must too. Every other domain reads core: asked for by
|
|
1640
|
+
// name, it is an error without core; an open search then covers the docs
|
|
1641
|
+
// and themes alone.
|
|
1642
|
+
const needsCore = !type || !CORELESS_DOMAINS.includes(type);
|
|
1643
|
+
const coreDir = needsCore ? findCoreDir(cwd) : null;
|
|
1644
|
+
if (type && needsCore && !coreDir) {
|
|
1515
1645
|
throw new AstryxError(
|
|
1516
1646
|
'Could not find @astryxdesign/core package',
|
|
1517
1647
|
undefined,
|
|
@@ -1521,17 +1651,19 @@ export async function search(query, options = {}) {
|
|
|
1521
1651
|
|
|
1522
1652
|
// Gather candidates from each requested domain in parallel.
|
|
1523
1653
|
/** @param {string} d */
|
|
1524
|
-
const wants = d =>
|
|
1525
|
-
|
|
1654
|
+
const wants = d =>
|
|
1655
|
+
(!type && (coreDir != null || CORELESS_DOMAINS.includes(d))) || type === d;
|
|
1656
|
+
const [components, hooks, docTopics, templates, themes] = await Promise.all([
|
|
1526
1657
|
wants('component')
|
|
1527
1658
|
? gatherComponents(/** @type {string} */ (coreDir), cwd)
|
|
1528
1659
|
: [],
|
|
1529
1660
|
wants('hook') ? gatherHooks(/** @type {string} */ (coreDir)) : [],
|
|
1530
1661
|
wants('doc') ? gatherDocs(cwd) : [],
|
|
1531
1662
|
wants('template') ? gatherTemplates(cwd) : [],
|
|
1663
|
+
wants('theme') ? gatherThemes(cwd) : [],
|
|
1532
1664
|
]);
|
|
1533
1665
|
|
|
1534
|
-
const all = [...components, ...hooks, ...docTopics, ...templates];
|
|
1666
|
+
const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
|
|
1535
1667
|
|
|
1536
1668
|
// Score every candidate on its own merits. The consumer groups results by
|
|
1537
1669
|
// role (page / block / component) and takes the top of each, so there's no
|
|
@@ -1548,7 +1680,7 @@ export async function search(query, options = {}) {
|
|
|
1548
1680
|
|
|
1549
1681
|
// Sort by score desc, then domain (stable order), then name.
|
|
1550
1682
|
/** @type {Record<string, number>} */
|
|
1551
|
-
const domainOrder = {component: 0, hook: 1, doc: 2, template: 3};
|
|
1683
|
+
const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
|
|
1552
1684
|
scored.sort(
|
|
1553
1685
|
(a, b) =>
|
|
1554
1686
|
b.score - a.score ||
|
|
@@ -1563,7 +1695,8 @@ export async function search(query, options = {}) {
|
|
|
1563
1695
|
// 57 things and one matching exactly 20 would be indistinguishable.
|
|
1564
1696
|
const limited = scored.slice(0, limit);
|
|
1565
1697
|
|
|
1566
|
-
|
|
1698
|
+
/** @type {import('./search.type.mjs').SearchResponse} */
|
|
1699
|
+
const response = {
|
|
1567
1700
|
type: 'search',
|
|
1568
1701
|
data: {
|
|
1569
1702
|
query: String(query).trim(),
|
|
@@ -1574,4 +1707,11 @@ export async function search(query, options = {}) {
|
|
|
1574
1707
|
),
|
|
1575
1708
|
},
|
|
1576
1709
|
};
|
|
1710
|
+
if (wants('component')) {
|
|
1711
|
+
searchedComponentsOf.set(
|
|
1712
|
+
response,
|
|
1713
|
+
components.map(c => ({name: c.name, keywords: c.keywords ?? []})),
|
|
1714
|
+
);
|
|
1715
|
+
}
|
|
1716
|
+
return response;
|
|
1577
1717
|
}
|