@astryxdesign/cli 0.6.3-canary.1f30d4e → 0.6.3-canary.1ffe66d
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 +19 -17
- package/api/component/_adapter.d.mts +6 -12
- package/api/component/_adapter.mjs +20 -10
- package/api/component/component.mjs +60 -12
- package/api/component/list/list.mjs +3 -2
- package/api/docs/_adapter.d.mts +209 -28
- package/api/docs/_adapter.mjs +667 -35
- package/api/docs/detail/detail.mjs +11 -3
- package/api/docs/detail/section/section.mjs +20 -3
- package/api/docs/docs.d.mts +5 -3
- package/api/docs/docs.doc.mjs +35 -15
- package/api/docs/docs.mjs +44 -8
- package/api/docs/docs.test.mjs +158 -4
- package/api/docs/docs.type.d.mts +165 -2
- package/api/docs/docs.type.mjs +101 -3
- package/api/docs/index/index.mjs +11 -3
- package/api/docs/index/index.test.mjs +1 -1
- package/api/docs/integration-tree.test.mjs +547 -0
- package/api/docs/integrationDocs.test.mjs +14 -14
- package/api/docs/list/list.mjs +25 -5
- package/api/docs/node/node.d.mts +43 -0
- package/api/docs/node/node.mjs +192 -0
- package/api/doctor/doctor.d.mts +30 -2
- package/api/doctor/doctor.mjs +146 -7
- package/api/doctor/doctor.test.mjs +89 -1
- package/api/index.d.mts +1 -1
- package/api/index.mjs +1 -0
- package/api/init/init.doc.mjs +1 -1
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +107 -5
- package/api/integration/add-contribution.test.mjs +137 -0
- package/api/integration/authoring-checks.mjs +125 -28
- package/api/integration/authoring-checks.test.mjs +171 -3
- package/api/integration/authoring-checks.type.mjs +6 -1
- package/api/integration/integration-authoring.type.d.mts +2 -0
- package/api/integration/integration-authoring.type.mjs +2 -0
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddDoc.doc.mjs +7 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationPackCheck.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
- package/api/integration/integrationTemplateConflicts.doc.mjs +3 -0
- package/api/integration/pack-check.mjs +34 -0
- package/api/integration/pack-check.test.mjs +121 -0
- package/api/integration/pack-check.type.d.mts +26 -2
- package/api/integration/pack-check.type.mjs +14 -1
- package/api/integration/template-conflict-compatibility.test.mjs +73 -0
- package/api/integration/validate-integration.test.mjs +3 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/json/index.ts +2 -0
- package/api/layout/_adapter.mjs +20 -5
- package/api/search/search.d.mts +26 -1
- package/api/search/search.doc.mjs +4 -3
- package/api/search/search.mjs +308 -29
- package/api/search/search.test.mjs +91 -2
- package/api/search/search.type.d.mts +13 -1
- package/api/search/search.type.mjs +4 -1
- package/api/template/list/list.mjs +1 -0
- package/api/template/template-integration.test.mjs +1022 -3
- package/api/template/template.doc.mjs +27 -7
- package/api/template/template.mjs +45 -8
- package/api/template/template.type.d.mts +6 -8
- package/api/template/template.type.mjs +3 -2
- package/api/theme/template/template.test.mjs +5 -0
- package/api/theme/themeTemplate.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/principles.doc.mjs +6 -6
- package/assets/docs/styling-libraries.doc.mjs +2 -2
- package/assets/docs/styling.doc.mjs +4 -4
- package/assets/docs/theme.doc.mjs +3 -3
- package/assets/docs/tokens.doc.mjs +1 -1
- package/assets/docs/tree/api.doc.mjs +30 -0
- package/assets/docs/tree/cli.doc.mjs +23 -0
- package/assets/docs/tree/commands.doc.mjs +25 -0
- package/assets/docs/{cli-integrations.doc.mjs → tree/integrations.doc.mjs} +37 -9
- package/assets/docs/tree/integrations.test.mjs +62 -0
- package/assets/docs/tree/writing-docs.doc.mjs +286 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/base/graph-fields.doc.mjs +7 -5
- package/authoring/doctypes/base/type.ts +6 -5
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/command/type.ts +2 -2
- package/authoring/doctypes/enum/enum.doc.mjs +1 -1
- package/authoring/doctypes/enum/type.ts +1 -1
- package/authoring/doctypes/function/function.doc.mjs +3 -2
- package/authoring/doctypes/function/type.ts +3 -2
- package/authoring/doctypes/namespace/namespace.doc.mjs +5 -9
- package/authoring/doctypes/reference/reference.doc.mjs +3 -3
- package/authoring/doctypes/reference/type.ts +3 -0
- package/authoring/doctypes/schema/schema.doc.mjs +1 -1
- package/authoring/doctypes/schema/type.ts +1 -1
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +4 -0
- package/authoring/doctypes/template/parse.test.mjs +18 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +8 -0
- package/authoring/identity/identity.doc.mjs +2 -2
- package/authoring/integration/type.ts +1 -1
- package/clients/cli/commands/build-theme.mjs +1 -1
- package/clients/cli/commands/build.mjs +5 -2
- package/clients/cli/commands/component/index.mjs +1 -1
- package/clients/cli/commands/component-ownership.test.mjs +3 -3
- package/clients/cli/commands/discover.broken-integration.test.mjs +7 -8
- package/clients/cli/commands/discover.mjs +1 -1
- package/clients/cli/commands/docs.doc.mjs +20 -8
- package/clients/cli/commands/docs.mjs +175 -18
- package/clients/cli/commands/docs.test.mjs +114 -7
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +2 -2
- package/clients/cli/commands/doctor-integration-templates.doc.mjs +14 -7
- package/clients/cli/commands/doctor-integration.test.mjs +75 -1
- package/clients/cli/commands/doctor.mjs +53 -16
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration.mjs +1 -0
- package/clients/cli/commands/search.mjs +11 -2
- package/clients/cli/commands/setup-nudge.test.mjs +6 -0
- package/clients/cli/commands/template.doc.mjs +23 -6
- package/clients/cli/commands/template.mjs +4 -91
- package/clients/cli/commands/text-json-parity.test.mjs +2 -1
- package/clients/cli/index.mjs +8 -0
- package/clients/cli/lib/manifest.mjs +9 -2
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +10 -1
- package/foundation/config/project.d.mts +12 -11
- package/foundation/config/project.mjs +73 -59
- package/foundation/config/project.test.mjs +141 -5
- package/foundation/discovery/authoring-self-docs.test.mjs +17 -7
- package/foundation/discovery/cli-self-docs.d.mts +40 -34
- package/foundation/discovery/cli-self-docs.mjs +91 -115
- package/foundation/discovery/cli-self-docs.test.mjs +104 -166
- package/foundation/discovery/component-discovery.d.mts +38 -0
- package/foundation/discovery/component-discovery.mjs +48 -0
- package/foundation/discovery/docs-discovery.d.mts +105 -8
- package/foundation/discovery/docs-discovery.mjs +177 -13
- package/foundation/discovery/docs-discovery.test.mjs +56 -17
- package/foundation/discovery/docs-output-budget.d.mts +2 -2
- package/foundation/discovery/docs-output-budget.mjs +1 -1
- package/foundation/discovery/docs-section-key.d.mts +9 -2
- package/foundation/discovery/docs-section-key.mjs +15 -1
- package/foundation/discovery/template-adapter.d.mts +92 -6
- package/foundation/discovery/template-adapter.mjs +453 -17
- package/foundation/discovery/template-adapter.test.mjs +42 -0
- package/foundation/discovery/template-conflict-release.d.mts +13 -0
- package/foundation/discovery/template-conflict-release.mjs +40 -0
- package/foundation/discovery/template-conflict-release.test.mjs +40 -0
- package/foundation/doc-compiler/bundle.mjs +61 -1
- package/foundation/doc-compiler/bundle.test.mjs +21 -10
- package/foundation/doc-compiler/compile.d.mts +113 -132
- package/foundation/doc-compiler/compile.mjs +52 -6
- package/foundation/doc-compiler/diagnostics.mjs +28 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
- package/foundation/doc-compiler/inputs.d.mts +2 -2
- package/foundation/doc-compiler/inputs.mjs +6 -1
- package/foundation/doc-compiler/ir.mjs +7 -0
- package/foundation/doc-compiler/lenses.d.mts +3 -2
- package/foundation/doc-compiler/lenses.mjs +2 -1
- package/foundation/doc-compiler/links.d.mts +135 -0
- package/foundation/doc-compiler/links.mjs +253 -0
- package/foundation/doc-compiler/links.test.mjs +139 -0
- package/foundation/doc-compiler/lower-doc.test.mjs +5 -2
- package/foundation/doc-compiler/read.d.mts +3 -2
- package/foundation/doc-compiler/read.mjs +6 -1
- package/foundation/doc-compiler/tree.d.mts +288 -0
- package/foundation/doc-compiler/tree.mjs +876 -0
- package/foundation/doc-compiler/tree.test.mjs +598 -0
- package/foundation/integrations/autolink.test.mjs +1 -1
- package/foundation/integrations/cli-requirement.d.mts +45 -0
- package/foundation/integrations/cli-requirement.mjs +154 -0
- package/foundation/integrations/cli-requirement.test.mjs +109 -0
- package/foundation/integrations/contribution-inventory.d.mts +2 -1
- package/foundation/integrations/contribution-inventory.mjs +10 -4
- package/foundation/integrations/contribution-inventory.test.mjs +19 -0
- package/foundation/integrations/integration-warnings.d.mts +9 -2
- package/foundation/integrations/integration-warnings.mjs +51 -26
- package/foundation/integrations/integration-warnings.test.mjs +74 -1
- package/foundation/integrations/validate-contributions.mjs +25 -27
- package/foundation/response/response-types.doc.d.mts +5 -1
- package/foundation/response/response-types.doc.mjs +18 -9
- package/foundation/xle/expand.mjs +1 -1
- package/foundation/xle/xle.test.mjs +13 -0
- package/package.json +9 -9
- package/assets/docs/cli.doc.mjs +0 -15
package/api/search/search.mjs
CHANGED
|
@@ -54,7 +54,7 @@ import {readDocView} from '../../foundation/doc-compiler/read.mjs';
|
|
|
54
54
|
import {findCoreDir} from '../../foundation/fs/paths.mjs';
|
|
55
55
|
import {
|
|
56
56
|
discoverComponents,
|
|
57
|
-
|
|
57
|
+
discoverValidIntegrationComponents,
|
|
58
58
|
findComponentReadme,
|
|
59
59
|
resolveImportPath,
|
|
60
60
|
resolveIntegrationImportPath,
|
|
@@ -66,7 +66,20 @@ import {
|
|
|
66
66
|
import {loadIntegrationsSafely} from '../component/_adapter.mjs';
|
|
67
67
|
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
68
68
|
import {discoverTemplates, extractComponents} from '../template/template.mjs';
|
|
69
|
-
import {
|
|
69
|
+
import {templateLookupIds} from '../../foundation/discovery/template-adapter.mjs';
|
|
70
|
+
import {
|
|
71
|
+
guideEntry,
|
|
72
|
+
loadDocsCatalog,
|
|
73
|
+
lowerTopic,
|
|
74
|
+
projectTree,
|
|
75
|
+
holdsOwnName,
|
|
76
|
+
} from '../docs/_adapter.mjs';
|
|
77
|
+
import {unlinkText} from '../../foundation/doc-compiler/links.mjs';
|
|
78
|
+
import {nodeView} from '../docs/node/node.mjs';
|
|
79
|
+
import {
|
|
80
|
+
sectionKey,
|
|
81
|
+
sectionSummary,
|
|
82
|
+
} from '../../foundation/discovery/docs-section-key.mjs';
|
|
70
83
|
import {AstryxError} from '../error.mjs';
|
|
71
84
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
72
85
|
import {setResultCoverage} from './coverage.mjs';
|
|
@@ -84,8 +97,18 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
84
97
|
* @property {string[]} [guidance]
|
|
85
98
|
* @property {string} [_import]
|
|
86
99
|
* @property {string} [_title]
|
|
100
|
+
* @property {string} [_topic] - A doc result's topic or docs-tree route.
|
|
101
|
+
* @property {string} [_section] - A doc result's section key, when it is one section.
|
|
102
|
+
* @property {string} [_command] - The command that reads exactly this doc part.
|
|
103
|
+
* @property {string} [_parent] - The command that opens the level above a doc
|
|
104
|
+
* part: its topic's section list, or the docs-tree namespace it sits in.
|
|
105
|
+
* @property {string} [_package] - The npm package that authored a docs-tree
|
|
106
|
+
* doc part. Flat topics carry none: an extension's sections can come from
|
|
107
|
+
* another package.
|
|
87
108
|
* @property {string} [_displayName]
|
|
88
109
|
* @property {'page'|'block'} [_kind]
|
|
110
|
+
* @property {string} [_resultName]
|
|
111
|
+
* @property {string} [_commandName]
|
|
89
112
|
*/
|
|
90
113
|
|
|
91
114
|
/**
|
|
@@ -647,7 +670,8 @@ async function gatherIntegrationComponents(cwd) {
|
|
|
647
670
|
/** @type {Candidate[]} */
|
|
648
671
|
const candidates = [];
|
|
649
672
|
for (const integration of loadedIntegrations) {
|
|
650
|
-
|
|
673
|
+
const {components} = await discoverValidIntegrationComponents(integration);
|
|
674
|
+
for (const rec of components) {
|
|
651
675
|
const doc = await loadModuleDoc(rec.docPath);
|
|
652
676
|
candidates.push({
|
|
653
677
|
domain: 'component',
|
|
@@ -730,7 +754,11 @@ async function gatherHooks(coreDir) {
|
|
|
730
754
|
}
|
|
731
755
|
|
|
732
756
|
/**
|
|
733
|
-
* Build doc
|
|
757
|
+
* Build doc candidates at the grain a reader reads them: each section of a
|
|
758
|
+
* topic, whose command reads just that section; each topic as a whole, whose
|
|
759
|
+
* command lists its sections; and each docs-tree node by its route. The tree's
|
|
760
|
+
* guides split into sections like topics, and its typed docs also match by
|
|
761
|
+
* their own name, so `assertResponse` finds `cli/api/functions/assert-response`.
|
|
734
762
|
*
|
|
735
763
|
* Reads the project's catalog rather than the CLI's own docs directory, so a
|
|
736
764
|
* topic an integration contributed (or replaced) is searchable exactly like a
|
|
@@ -748,38 +776,268 @@ async function gatherDocs(cwd) {
|
|
|
748
776
|
} catch {
|
|
749
777
|
return candidates;
|
|
750
778
|
}
|
|
779
|
+
let tree = null;
|
|
780
|
+
try {
|
|
781
|
+
tree = await projectTree(catalog);
|
|
782
|
+
} catch {
|
|
783
|
+
// `astryx doctor` reports a tree that fails to build; search still
|
|
784
|
+
// indexes the topics.
|
|
785
|
+
}
|
|
751
786
|
for (const entry of catalog.entries()) {
|
|
752
|
-
|
|
787
|
+
// A topic whose name opens another doc (spec:AST-046 FR11) is not
|
|
788
|
+
// offered: every hit's command must open the hit.
|
|
789
|
+
if (tree && !holdsOwnName(tree, catalog, entry)) continue;
|
|
790
|
+
let lowered = null;
|
|
753
791
|
try {
|
|
754
|
-
|
|
792
|
+
lowered = await lowerTopic(catalog, entry);
|
|
755
793
|
} catch {
|
|
756
794
|
// A topic that cannot be loaded is reported by the commands that own
|
|
757
795
|
// integration issues; search just cannot index it.
|
|
758
796
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
}
|
|
797
|
+
const doc = lowered?.doc ?? null;
|
|
798
|
+
// A flat topic lives in the Unorganized level; its hits say so, and name
|
|
799
|
+
// the package each section came from.
|
|
800
|
+
const home = tree?.get(entry.name);
|
|
801
|
+
const placed = home?.ref?.flatTopic === entry.name ? home : null;
|
|
802
|
+
/** @type {Map<string, string>} */
|
|
803
|
+
const packages = new Map([
|
|
804
|
+
[entry.providerId ?? entry.package, entry.package],
|
|
805
|
+
...entry.extensions.map(
|
|
806
|
+
ext => /** @type {[string, string]} */ ([ext.providerId ?? ext.package, ext.package]),
|
|
807
|
+
),
|
|
808
|
+
]);
|
|
809
|
+
candidates.push(
|
|
810
|
+
...topicCandidates(
|
|
811
|
+
entry.name,
|
|
812
|
+
doc,
|
|
813
|
+
entry.title,
|
|
814
|
+
'',
|
|
815
|
+
placed && tree
|
|
816
|
+
? [
|
|
817
|
+
...tree.ancestors(placed).map(a => a.title),
|
|
818
|
+
doc?.title || entry.title || entry.name,
|
|
819
|
+
].join(' › ')
|
|
820
|
+
: undefined,
|
|
821
|
+
placed ? `astryx docs ${placed.parent}` : undefined,
|
|
822
|
+
entry.package,
|
|
823
|
+
key =>
|
|
824
|
+
packages.get(lowered?.sectionProviders?.[key] ?? '') ?? entry.package,
|
|
825
|
+
),
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
if (tree == null) return candidates;
|
|
829
|
+
for (const node of tree.nodes.values()) {
|
|
830
|
+
// A flat topic is indexed above, as a topic.
|
|
831
|
+
if (node.ref?.flatTopic) continue;
|
|
832
|
+
// A tree hit names where it lives: its ancestors' titles, then its own.
|
|
833
|
+
const path = [...tree.ancestors(node).map(a => a.title), node.title];
|
|
834
|
+
if (node.kind === 'generic') {
|
|
835
|
+
let doc = null;
|
|
836
|
+
try {
|
|
837
|
+
doc = (await lowerTopic(catalog, guideEntry(node))).doc;
|
|
838
|
+
} catch {
|
|
839
|
+
// As above: the owning commands report it.
|
|
769
840
|
}
|
|
841
|
+
candidates.push(
|
|
842
|
+
...topicCandidates(
|
|
843
|
+
node.route,
|
|
844
|
+
doc,
|
|
845
|
+
node.title,
|
|
846
|
+
node.summary,
|
|
847
|
+
path.join(' › '),
|
|
848
|
+
node.parent == null ? undefined : `astryx docs ${node.parent}`,
|
|
849
|
+
node.provider,
|
|
850
|
+
),
|
|
851
|
+
);
|
|
852
|
+
continue;
|
|
853
|
+
}
|
|
854
|
+
const selfDoc = /** @type {any} */ (node.ref)?.selfDoc;
|
|
855
|
+
// A typed doc's content is what `astryx docs <route>` prints. The first
|
|
856
|
+
// column of its tables names what the doc defines (an error code, an
|
|
857
|
+
// option, a parameter), so each is a keyword the doc answers to.
|
|
858
|
+
/** @type {any[]} */
|
|
859
|
+
const content = (await nodeView(catalog, tree, node)).content ?? [];
|
|
860
|
+
/** @type {string[]} */
|
|
861
|
+
const defined = [];
|
|
862
|
+
for (const block of content) {
|
|
863
|
+
if (block.type !== 'table' || !Array.isArray(block.rows)) continue;
|
|
864
|
+
for (const row of block.rows)
|
|
865
|
+
if (row[0] != null) defined.push(plain(row[0]));
|
|
770
866
|
}
|
|
771
867
|
candidates.push({
|
|
772
868
|
domain: 'doc',
|
|
773
|
-
name:
|
|
774
|
-
keywords: [
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
869
|
+
name: node.name,
|
|
870
|
+
keywords: [
|
|
871
|
+
node.route.slice(node.route.lastIndexOf('/') + 1),
|
|
872
|
+
...(Array.isArray(selfDoc?.keywords) ? selfDoc.keywords : []),
|
|
873
|
+
...defined,
|
|
874
|
+
...codeTerms({content}),
|
|
875
|
+
],
|
|
876
|
+
description: node.summary || '',
|
|
877
|
+
prose: sectionProse({title: node.title, content}),
|
|
878
|
+
_topic: node.route,
|
|
879
|
+
_title: path.join(' › '),
|
|
880
|
+
_command: `astryx docs ${node.route}`,
|
|
881
|
+
_parent: node.parent == null ? 'astryx docs' : `astryx docs ${node.parent}`,
|
|
882
|
+
_package: node.provider,
|
|
778
883
|
});
|
|
779
884
|
}
|
|
780
885
|
return candidates;
|
|
781
886
|
}
|
|
782
887
|
|
|
888
|
+
/**
|
|
889
|
+
* The words one section says: its prose, headings, and list items.
|
|
890
|
+
* @param {any} section
|
|
891
|
+
* @returns {string[]}
|
|
892
|
+
*/
|
|
893
|
+
function sectionProse(section) {
|
|
894
|
+
/** @type {string[]} */
|
|
895
|
+
const prose = [];
|
|
896
|
+
if (section?.title) prose.push(section.title);
|
|
897
|
+
for (const block of section?.content || []) {
|
|
898
|
+
if ((block.type === 'prose' || block.type === 'heading') && block.text) {
|
|
899
|
+
prose.push(block.text);
|
|
900
|
+
} else if (block.type === 'list' && Array.isArray(block.items)) {
|
|
901
|
+
for (const item of block.items) {
|
|
902
|
+
const text = typeof item === 'string' ? item : item?.text;
|
|
903
|
+
if (typeof text === 'string') prose.push(text);
|
|
904
|
+
}
|
|
905
|
+
} else if (block.type === 'table' && Array.isArray(block.rows)) {
|
|
906
|
+
for (const row of block.rows) prose.push(row.map(plain).join(' '));
|
|
907
|
+
} else if (block.type === 'code' && typeof block.code === 'string') {
|
|
908
|
+
prose.push([block.label, block.code].filter(Boolean).join(' '));
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return prose;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* The identifiers a doc part names in code ticks (`token-ref`,
|
|
916
|
+
* `ERR_UNKNOWN_SECTION`). Each is a keyword: a reader who types one exactly
|
|
917
|
+
* wants the part that defines or explains it.
|
|
918
|
+
* @param {any} part - a section, or `{content}` of a typed doc
|
|
919
|
+
* @returns {string[]}
|
|
920
|
+
*/
|
|
921
|
+
function codeTerms(part) {
|
|
922
|
+
/** @type {Set<string>} */
|
|
923
|
+
const terms = new Set();
|
|
924
|
+
/** @param {unknown} text */
|
|
925
|
+
const scan = text => {
|
|
926
|
+
for (const m of String(text ?? '').matchAll(/`([^`\s]{2,40})`/g)) {
|
|
927
|
+
terms.add(m[1]);
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
for (const block of part?.content || []) {
|
|
931
|
+
if (block.type === 'prose') scan(block.text);
|
|
932
|
+
else if (block.type === 'list' && Array.isArray(block.items)) {
|
|
933
|
+
for (const item of block.items) {
|
|
934
|
+
scan(typeof item === 'string' ? item : item?.text);
|
|
935
|
+
}
|
|
936
|
+
} else if (block.type === 'table' && Array.isArray(block.rows)) {
|
|
937
|
+
for (const row of block.rows) for (const cell of row) scan(cell);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return [...terms];
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* The headings inside a section. Each names a subsection, so a query that
|
|
945
|
+
* names one should find the section as surely as one that names its title.
|
|
946
|
+
* @param {any} section
|
|
947
|
+
* @returns {string[]}
|
|
948
|
+
*/
|
|
949
|
+
function headings(section) {
|
|
950
|
+
return (section?.content || [])
|
|
951
|
+
.filter(
|
|
952
|
+
(/** @type {any} */ block) => block.type === 'heading' && block.text,
|
|
953
|
+
)
|
|
954
|
+
.map((/** @type {any} */ block) => String(block.text));
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* A table cell as plain words, without its code ticks.
|
|
959
|
+
* @param {unknown} cell
|
|
960
|
+
* @returns {string}
|
|
961
|
+
*/
|
|
962
|
+
function plain(cell) {
|
|
963
|
+
return unlinkText(String(cell ?? '')).replaceAll('`', '');
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* The candidates one topic yields: the topic itself, and one per section when
|
|
968
|
+
* it has more than one. A topic's command lists its sections, and a section's
|
|
969
|
+
* command reads only that section, so a hit never costs a whole-topic read.
|
|
970
|
+
* @param {string} name - the topic name, or a placed guide's route
|
|
971
|
+
* @param {any} doc - the lowered topic, or null when it did not load
|
|
972
|
+
* @param {string} [title]
|
|
973
|
+
* @param {string} [summary]
|
|
974
|
+
* @param {string} [path] - where the topic lives in the docs tree, as titles
|
|
975
|
+
* joined by ` › `; a flat topic is its own title
|
|
976
|
+
* @param {string} [parent] - the command that opens the level above the
|
|
977
|
+
* topic: its namespace, or the Unorganized level for a flat topic
|
|
978
|
+
* @param {string} [pkg] - the npm package that authored the topic
|
|
979
|
+
* @param {(key: string) => string} [sectionPackage] - the npm package a
|
|
980
|
+
* section came from: an extension's section names the extension's package
|
|
981
|
+
* @returns {Candidate[]}
|
|
982
|
+
*/
|
|
983
|
+
function topicCandidates(
|
|
984
|
+
name,
|
|
985
|
+
doc,
|
|
986
|
+
title,
|
|
987
|
+
summary = '',
|
|
988
|
+
path,
|
|
989
|
+
parent,
|
|
990
|
+
pkg,
|
|
991
|
+
sectionPackage,
|
|
992
|
+
) {
|
|
993
|
+
/** @type {any[]} */
|
|
994
|
+
const sections = doc?.sections ?? [];
|
|
995
|
+
const docTitle = path || doc?.title || title || name;
|
|
996
|
+
const split = sections.length > 1;
|
|
997
|
+
/** @type {Candidate[]} */
|
|
998
|
+
const out = [
|
|
999
|
+
{
|
|
1000
|
+
domain: 'doc',
|
|
1001
|
+
name,
|
|
1002
|
+
keywords: [
|
|
1003
|
+
...(doc?.title || title ? [doc?.title || title] : []),
|
|
1004
|
+
...(Array.isArray(doc?.keywords) ? doc.keywords : []),
|
|
1005
|
+
],
|
|
1006
|
+
description: doc?.description || summary,
|
|
1007
|
+
prose: split
|
|
1008
|
+
? sections.map(section => section.title).filter(Boolean)
|
|
1009
|
+
: sections.flatMap(sectionProse),
|
|
1010
|
+
_topic: name,
|
|
1011
|
+
_title: docTitle,
|
|
1012
|
+
_command: split ? `astryx docs ${name} --index` : `astryx docs ${name}`,
|
|
1013
|
+
...(parent ? {_parent: parent} : {}),
|
|
1014
|
+
...(pkg ? {_package: pkg} : {}),
|
|
1015
|
+
},
|
|
1016
|
+
];
|
|
1017
|
+
if (!split) return out;
|
|
1018
|
+
for (const section of sections) {
|
|
1019
|
+
const key = sectionKey(section);
|
|
1020
|
+
out.push({
|
|
1021
|
+
domain: 'doc',
|
|
1022
|
+
name: key,
|
|
1023
|
+
keywords: [
|
|
1024
|
+
...(section.title ? [section.title] : []),
|
|
1025
|
+
...headings(section),
|
|
1026
|
+
...codeTerms(section),
|
|
1027
|
+
],
|
|
1028
|
+
description: sectionSummary(section),
|
|
1029
|
+
prose: sectionProse(section),
|
|
1030
|
+
_topic: name,
|
|
1031
|
+
_section: key,
|
|
1032
|
+
_title: `${docTitle} › ${section.title}`,
|
|
1033
|
+
_command: `astryx docs ${name} ${key}`,
|
|
1034
|
+
_parent: `astryx docs ${name} --index`,
|
|
1035
|
+
...((sectionPackage?.(key) ?? pkg) ? {_package: sectionPackage?.(key) ?? pkg} : {}),
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
return out;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
783
1041
|
/**
|
|
784
1042
|
* Build template candidates (page + block) from the template discovery API.
|
|
785
1043
|
* @param {string} cwd
|
|
@@ -793,6 +1051,13 @@ async function gatherTemplates(cwd) {
|
|
|
793
1051
|
return [];
|
|
794
1052
|
}
|
|
795
1053
|
return templates.map(t => {
|
|
1054
|
+
// A replacement's target is its canonical unqualified lookup id. Keep the
|
|
1055
|
+
// integration-owned id as a keyword and response label, but score and print
|
|
1056
|
+
// commands against the id that `template()` resolves back to this entry.
|
|
1057
|
+
// This matters for replacement chains: one replacement's own id can be the
|
|
1058
|
+
// target of another, so using that shadowed id as the command would select
|
|
1059
|
+
// the other template.
|
|
1060
|
+
const commandName = t.replaces ?? t.dirName;
|
|
796
1061
|
// Blocks ship an authored componentsUsed; page templates don't, so derive
|
|
797
1062
|
// them from the source. Category words (e.g. "Dashboard - Analytics") are
|
|
798
1063
|
// strong intent signal for pages, which otherwise only index on name +
|
|
@@ -805,6 +1070,7 @@ async function gatherTemplates(cwd) {
|
|
|
805
1070
|
const keywords = Array.isArray(t.componentsUsed)
|
|
806
1071
|
? [...t.componentsUsed]
|
|
807
1072
|
: [];
|
|
1073
|
+
keywords.push(...templateLookupIds(t).filter(id => id !== commandName));
|
|
808
1074
|
/** @type {string[]} */
|
|
809
1075
|
let weakKeywords = [];
|
|
810
1076
|
if (t.type === 'page') {
|
|
@@ -820,12 +1086,14 @@ async function gatherTemplates(cwd) {
|
|
|
820
1086
|
}
|
|
821
1087
|
return {
|
|
822
1088
|
domain: 'template',
|
|
823
|
-
name:
|
|
1089
|
+
name: commandName,
|
|
824
1090
|
keywords,
|
|
825
1091
|
weakKeywords,
|
|
826
1092
|
description: t.description || '',
|
|
827
1093
|
_displayName: t.name,
|
|
828
1094
|
_kind: t.type, // 'page' | 'block'
|
|
1095
|
+
_resultName: t.dirName,
|
|
1096
|
+
_commandName: commandName,
|
|
829
1097
|
};
|
|
830
1098
|
});
|
|
831
1099
|
}
|
|
@@ -844,7 +1112,7 @@ async function gatherTemplates(cwd) {
|
|
|
844
1112
|
function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
845
1113
|
const base = {
|
|
846
1114
|
domain: c.domain,
|
|
847
|
-
name: c.name,
|
|
1115
|
+
name: c._resultName ?? c.name,
|
|
848
1116
|
score,
|
|
849
1117
|
reason,
|
|
850
1118
|
description: c.description || '',
|
|
@@ -866,10 +1134,16 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
866
1134
|
};
|
|
867
1135
|
break;
|
|
868
1136
|
case 'doc':
|
|
1137
|
+
// A doc result names its topic or route, plus the section when the
|
|
1138
|
+
// hit is one section; its command reads exactly that part.
|
|
869
1139
|
result = {
|
|
870
1140
|
...base,
|
|
1141
|
+
name: c._topic ?? c.name,
|
|
1142
|
+
...(c._section ? {section: c._section} : {}),
|
|
871
1143
|
title: c._title,
|
|
872
|
-
command: `astryx docs ${c.name}`,
|
|
1144
|
+
command: c._command ?? `astryx docs ${c.name}`,
|
|
1145
|
+
...(c._parent ? {parent: c._parent} : {}),
|
|
1146
|
+
...(c._package ? {package: c._package} : {}),
|
|
873
1147
|
};
|
|
874
1148
|
break;
|
|
875
1149
|
case 'template':
|
|
@@ -877,7 +1151,7 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
877
1151
|
...base,
|
|
878
1152
|
displayName: c._displayName,
|
|
879
1153
|
kind: c._kind,
|
|
880
|
-
command: `astryx template ${c.name}`,
|
|
1154
|
+
command: `astryx template ${c._commandName ?? c.name} --type ${c._kind}`,
|
|
881
1155
|
};
|
|
882
1156
|
break;
|
|
883
1157
|
default:
|
|
@@ -929,8 +1203,11 @@ export async function search(query, options = {}) {
|
|
|
929
1203
|
const term = String(query).trim().toLowerCase();
|
|
930
1204
|
const tokens = tokenizeQuery(term);
|
|
931
1205
|
|
|
932
|
-
|
|
933
|
-
|
|
1206
|
+
// `astryx docs` reads docs without @astryxdesign/core, so a docs-only
|
|
1207
|
+
// search must too. Every other domain reads core.
|
|
1208
|
+
const docsOnly = type === 'doc';
|
|
1209
|
+
const coreDir = docsOnly ? null : findCoreDir(cwd);
|
|
1210
|
+
if (!docsOnly && !coreDir) {
|
|
934
1211
|
throw new AstryxError(
|
|
935
1212
|
'Could not find @astryxdesign/core package',
|
|
936
1213
|
undefined,
|
|
@@ -942,8 +1219,10 @@ export async function search(query, options = {}) {
|
|
|
942
1219
|
/** @param {string} d */
|
|
943
1220
|
const wants = d => !type || type === d;
|
|
944
1221
|
const [components, hooks, docTopics, templates] = await Promise.all([
|
|
945
|
-
wants('component')
|
|
946
|
-
|
|
1222
|
+
wants('component')
|
|
1223
|
+
? gatherComponents(/** @type {string} */ (coreDir), cwd)
|
|
1224
|
+
: [],
|
|
1225
|
+
wants('hook') ? gatherHooks(/** @type {string} */ (coreDir)) : [],
|
|
947
1226
|
wants('doc') ? gatherDocs(cwd) : [],
|
|
948
1227
|
wants('template') ? gatherTemplates(cwd) : [],
|
|
949
1228
|
]);
|
|
@@ -84,7 +84,8 @@ describe('search leaf — per-domain result fields', () => {
|
|
|
84
84
|
expect(res.import).toMatch(/\S/);
|
|
85
85
|
} else if (res.domain === 'doc') {
|
|
86
86
|
expect(res.title).toMatch(/\S/);
|
|
87
|
-
|
|
87
|
+
const read = `astryx docs ${res.name}`;
|
|
88
|
+
expect([read, `${read} --index`, `${read} ${res.section}`]).toContain(res.command);
|
|
88
89
|
} else {
|
|
89
90
|
expect(res.displayName).toMatch(/\S/);
|
|
90
91
|
expect(['page', 'block']).toContain(res.kind);
|
|
@@ -93,6 +94,88 @@ describe('search leaf — per-domain result fields', () => {
|
|
|
93
94
|
}, SLOW);
|
|
94
95
|
});
|
|
95
96
|
|
|
97
|
+
describe('search leaf — docs at the grain a reader reads them', () => {
|
|
98
|
+
it(
|
|
99
|
+
'finds one section of a guide, and a docs-tree leaf by its own name',
|
|
100
|
+
async () => {
|
|
101
|
+
const guide = await search('codemod protected files', {cwd, type: 'doc'});
|
|
102
|
+
expect(guide.data.results.slice(0, 3)).toContainEqual(
|
|
103
|
+
expect.objectContaining({
|
|
104
|
+
domain: 'doc',
|
|
105
|
+
name: 'cli/integrations',
|
|
106
|
+
section: 'codemods',
|
|
107
|
+
title: 'Astryx CLI › CLI Integrations › Codemods',
|
|
108
|
+
parent: 'astryx docs cli/integrations --index',
|
|
109
|
+
command: 'astryx docs cli/integrations codemods',
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
const block = await search('token-ref', {cwd});
|
|
113
|
+
expect(block.data.results[0]).toMatchObject({
|
|
114
|
+
name: 'authoring',
|
|
115
|
+
section: 'reference-doc',
|
|
116
|
+
command: 'astryx docs authoring reference-doc',
|
|
117
|
+
});
|
|
118
|
+
const fn = await search('assertResponse', {cwd, type: 'doc'});
|
|
119
|
+
expect(fn.data.results[0]).toMatchObject({
|
|
120
|
+
name: 'cli/api/functions/assert-response',
|
|
121
|
+
title: 'Astryx CLI › API › Functions › assertResponse()',
|
|
122
|
+
parent: 'astryx docs cli/api/functions',
|
|
123
|
+
command: 'astryx docs cli/api/functions/assert-response',
|
|
124
|
+
});
|
|
125
|
+
expect(fn.data.results[0]).not.toHaveProperty('section');
|
|
126
|
+
},
|
|
127
|
+
SLOW,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
it(
|
|
131
|
+
'gives a top-level namespace hit the topic list as its parent',
|
|
132
|
+
async () => {
|
|
133
|
+
for (const [query, route] of [['unorganized', 'unorganized'], ['Astryx CLI', 'cli']]) {
|
|
134
|
+
const r = await search(query, {cwd, type: 'doc'});
|
|
135
|
+
expect(r.data.results).toContainEqual(
|
|
136
|
+
expect.objectContaining({
|
|
137
|
+
name: route,
|
|
138
|
+
command: `astryx docs ${route}`,
|
|
139
|
+
parent: 'astryx docs',
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
SLOW,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
it(
|
|
148
|
+
'points a topic hit at its index, never a whole-topic read',
|
|
149
|
+
async () => {
|
|
150
|
+
const r = await search('cli/integrations', {cwd, type: 'doc'});
|
|
151
|
+
expect(r.data.results[0]).toMatchObject({
|
|
152
|
+
name: 'cli/integrations',
|
|
153
|
+
command: 'astryx docs cli/integrations --index',
|
|
154
|
+
});
|
|
155
|
+
expect(r.data.results[0]).not.toHaveProperty('section');
|
|
156
|
+
},
|
|
157
|
+
SLOW,
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
it(
|
|
161
|
+
'searches docs where @astryxdesign/core is not installed',
|
|
162
|
+
async () => {
|
|
163
|
+
const bare = fs.mkdtempSync(
|
|
164
|
+
path.join(os.tmpdir(), 'astryx-search-bare-'),
|
|
165
|
+
);
|
|
166
|
+
try {
|
|
167
|
+
const r = await search('assertResponse', {cwd: bare, type: 'doc'});
|
|
168
|
+
expect(r.data.results[0].name).toBe(
|
|
169
|
+
'cli/api/functions/assert-response',
|
|
170
|
+
);
|
|
171
|
+
} finally {
|
|
172
|
+
fs.rmSync(bare, {recursive: true, force: true});
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
SLOW,
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
|
|
96
179
|
describe('search leaf — matchCount is the total, not the cap', () => {
|
|
97
180
|
it('reports every match while `results` stays bounded by the limit', async () => {
|
|
98
181
|
// The regression: `matchCount` used to be `results.length`, so a query
|
|
@@ -247,12 +330,18 @@ describe('search leaf — integration components', () => {
|
|
|
247
330
|
);
|
|
248
331
|
fs.writeFileSync(
|
|
249
332
|
path.join(widgetsDir, 'components', 'FancyGizmo.doc.mjs'),
|
|
250
|
-
`export
|
|
333
|
+
`export default {
|
|
334
|
+
type: 'component',
|
|
251
335
|
name: 'FancyGizmo',
|
|
252
336
|
keywords: ['gizmo', 'widget'],
|
|
253
337
|
usage: {description: 'A fancy gizmo widget.'},
|
|
338
|
+
props: [],
|
|
254
339
|
};\n`,
|
|
255
340
|
);
|
|
341
|
+
fs.writeFileSync(
|
|
342
|
+
path.join(widgetsDir, 'components', 'FancyGizmo.tsx'),
|
|
343
|
+
`export function FancyGizmo() { return null; }\n`,
|
|
344
|
+
);
|
|
256
345
|
|
|
257
346
|
return dir;
|
|
258
347
|
}
|
|
@@ -14,7 +14,7 @@ export type SearchResultEntry = {
|
|
|
14
14
|
*/
|
|
15
15
|
domain: SearchDomain;
|
|
16
16
|
/**
|
|
17
|
-
* - Primary identifier (component/hook name, doc topic, template dir).
|
|
17
|
+
* - Primary identifier (component/hook name, doc topic or docs-tree route, template dir).
|
|
18
18
|
*/
|
|
19
19
|
name: string;
|
|
20
20
|
/**
|
|
@@ -41,6 +41,18 @@ export type SearchResultEntry = {
|
|
|
41
41
|
* - Doc title — present for doc results.
|
|
42
42
|
*/
|
|
43
43
|
title?: string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* - Section key — present when a doc result is one section of a topic; `command` reads only that section.
|
|
46
|
+
*/
|
|
47
|
+
section?: string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* - The npm package that authored a doc result; for a section, the package whose file the section came from.
|
|
50
|
+
*/
|
|
51
|
+
package?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* - Command that opens the level above a doc result — its topic's section list for a section, the docs-tree namespace it sits in for a tree node — so a reader can see the siblings and open another.
|
|
54
|
+
*/
|
|
55
|
+
parent?: string | undefined;
|
|
44
56
|
/**
|
|
45
57
|
* - Friendly display name — present for template results.
|
|
46
58
|
*/
|
|
@@ -16,13 +16,16 @@
|
|
|
16
16
|
* A single ranked search result, tagged with its domain.
|
|
17
17
|
* @typedef {object} SearchResultEntry
|
|
18
18
|
* @property {SearchDomain} domain - Which content domain this result came from.
|
|
19
|
-
* @property {string} name - Primary identifier (component/hook name, doc topic, template dir).
|
|
19
|
+
* @property {string} name - Primary identifier (component/hook name, doc topic or docs-tree route, template dir).
|
|
20
20
|
* @property {number} score - Relevance score (higher is better).
|
|
21
21
|
* @property {string} reason - Human-readable reason the candidate matched (e.g. `keyword "button"`).
|
|
22
22
|
* @property {string} description - One-line description, when available.
|
|
23
23
|
* @property {string} command - Follow-up command to act on this result (e.g. `astryx component Button`).
|
|
24
24
|
* @property {string} [import] - Import path — present for component and hook results.
|
|
25
25
|
* @property {string} [title] - Doc title — present for doc results.
|
|
26
|
+
* @property {string} [section] - Section key — present when a doc result is one section of a topic; `command` reads only that section.
|
|
27
|
+
* @property {string} [package] - The npm package that authored a doc result; for a section, the package whose file the section came from.
|
|
28
|
+
* @property {string} [parent] - Command that opens the level above a doc result — its topic's section list for a section, the docs-tree namespace it sits in for a tree node — so a reader can see the siblings and open another.
|
|
26
29
|
* @property {string} [displayName] - Friendly display name — present for template results.
|
|
27
30
|
* @property {'page' | 'block'} [kind] - Template kind (`page` | `block`) — present for template results.
|
|
28
31
|
*/
|
|
@@ -32,6 +32,7 @@ export function templateList(templates, options = {}) {
|
|
|
32
32
|
description: t.description,
|
|
33
33
|
type: t.type,
|
|
34
34
|
package: pkgOf(t),
|
|
35
|
+
replaces: t.replaces,
|
|
35
36
|
category: t.category || undefined,
|
|
36
37
|
componentsUsed: t.componentsUsed ?? undefined,
|
|
37
38
|
aspectRatio: t.aspectRatio,
|