@astryxdesign/cli 0.7.3-canary.f94e962 → 0.7.3-canary.fba04ed
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 +68 -68
- package/api/build/_adapter.mjs +37 -25
- package/api/build/blocks/blocks.d.mts +68 -18
- package/api/build/blocks/blocks.mjs +475 -116
- package/api/build/blocks/blocks.test.mjs +191 -61
- package/api/build/blocks/blocks.weights.json +1 -1
- package/api/build/build.type.mjs +1 -1
- package/api/build/kit/answer.d.mts +9 -5
- package/api/build/kit/answer.mjs +123 -13
- package/api/build/kit/answer.test.mjs +73 -3
- package/api/build/kit/signals.d.mts +19 -0
- package/api/build/kit/signals.mjs +18 -7
- package/api/build/tree.mjs +2 -1
- package/api/build/tree.test.mjs +37 -29
- package/api/component/_adapter.mjs +39 -5
- package/api/component/component-replacement.test.mjs +1 -0
- package/api/component/component.mjs +1 -1
- package/api/component/doc-links.test.mjs +2 -2
- package/api/discover/_adapter.d.mts +1 -2
- package/api/discover/_adapter.mjs +6 -8
- package/api/discover/discover.mjs +0 -1
- package/api/docs/_adapter.d.mts +2 -2
- package/api/docs/_adapter.mjs +65 -18
- package/api/docs/docs-homes.test.mjs +127 -0
- package/api/docs/docs.doc.mjs +3 -3
- package/api/docs/docs.test.mjs +28 -18
- package/api/docs/integration-tree.test.mjs +20 -20
- package/api/docs/integrationDocs.test.mjs +1 -1
- package/api/docs/namespace-section.test.mjs +6 -6
- package/api/docs/reference-blocks.test.mjs +2 -2
- package/api/doctor/_adapter.d.mts +33 -13
- package/api/doctor/_adapter.mjs +55 -25
- package/api/doctor/doctor.d.mts +23 -5
- package/api/doctor/doctor.mjs +97 -28
- package/api/doctor/doctor.test.mjs +67 -9
- package/api/hook/hook.mjs +1 -1
- package/api/integration/validate-integration-fixes.test.mjs +6 -5
- package/api/integration/validate-integration-gaps.test.mjs +12 -1
- package/api/integration/validate-integration.d.mts +4 -0
- package/api/integration/validate-integration.mjs +48 -7
- package/api/integration/validate-integration.type.d.mts +36 -5
- package/api/integration/validate-integration.type.mjs +27 -6
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.d.mts +16 -0
- package/api/search/_adapter.mjs +39 -0
- package/api/search/_adapter.test.mjs +173 -0
- package/api/search/_candidate-score.mjs +1 -1
- package/api/search/_entries.d.mts +11 -0
- package/api/search/_entries.mjs +35 -17
- package/api/search/_entries.test.mjs +48 -0
- package/api/search/_gather-docs.mjs +3 -3
- package/api/search/_gather-templates.d.mts +0 -1
- package/api/search/_gather-templates.mjs +25 -0
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.integration-block.test.mjs +100 -0
- package/api/search/search.mjs +6 -2
- package/api/search/search.test.mjs +14 -14
- package/api/template/template.mjs +5 -1
- package/assets/docs/author-a-theme.doc.mjs +2 -2
- package/assets/docs/tree/add-a-component.doc.mjs +1 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
- package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
- package/assets/docs/tree/block-template.doc.mjs +1 -1
- package/assets/docs/tree/build-the-template.doc.mjs +1 -1
- package/assets/docs/tree/building-blocks.doc.mjs +2 -2
- package/assets/docs/tree/check-the-props.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +2 -2
- package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
- package/assets/docs/tree/cli-command.doc.mjs +1 -1
- package/assets/docs/tree/cli.doc.mjs +1 -1
- package/assets/docs/tree/codemods.doc.mjs +1 -1
- package/assets/docs/tree/component-family.doc.mjs +1 -1
- package/assets/docs/tree/component-imports.doc.mjs +1 -1
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/configuration.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/describe-the-component.doc.mjs +1 -1
- package/assets/docs/tree/docs.doc.mjs +1 -1
- package/assets/docs/tree/document-the-template.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
- package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
- package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
- package/assets/docs/tree/global-integrations.doc.mjs +2 -2
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
- package/assets/docs/tree/help.doc.mjs +2 -2
- package/assets/docs/tree/links.doc.mjs +1 -1
- package/assets/docs/tree/package-and-test.doc.mjs +1 -1
- package/assets/docs/tree/page-template.doc.mjs +1 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -1
- package/assets/docs/tree/quick-start.doc.mjs +1 -1
- package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
- package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/ship.doc.mjs +2 -2
- package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
- package/assets/docs/tree/single-component.doc.mjs +1 -1
- package/assets/docs/tree/start-a-template.doc.mjs +1 -1
- package/assets/docs/tree/subcomponent.doc.mjs +1 -1
- package/assets/docs/tree/template-assets.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
- package/assets/docs/tree/template-fonts.doc.mjs +1 -1
- package/assets/docs/tree/template-grading-rubric.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +1 -1
- package/assets/docs/tree/template-images-media.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/templates.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
- package/assets/docs/tree/themes.doc.mjs +1 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
- package/assets/docs/tree/upgrading.doc.mjs +1 -1
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +5 -1
- package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
- package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
- package/assets/docs/use-integrations.doc.mjs +120 -0
- package/authoring/doctypes/schema/schema.doc.mjs +1 -1
- package/authoring/integration/integration.doc.mjs +1 -1
- package/authoring/integration/type.ts +1 -1
- package/clients/cli/command-result-coverage.test.mjs +6 -5
- package/clients/cli/commands/build-theme.color-scheme.test.mjs +1 -1
- package/clients/cli/commands/{component/index.mjs → component.mjs} +37 -37
- package/clients/cli/commands/component.test.mjs +6 -6
- package/clients/cli/commands/docs.doc.mjs +2 -2
- package/clients/cli/commands/docs.mjs +1 -1
- package/clients/cli/commands/docs.test.mjs +14 -14
- package/clients/cli/commands/doctor-integration.test.mjs +49 -1
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/doctor.mjs +10 -0
- package/clients/cli/commands/{hook/index.mjs → hook.mjs} +22 -22
- package/clients/cli/commands/import-hint-correctness.test.mjs +1 -1
- package/clients/cli/commands/integration.doc.mjs +1 -1
- package/clients/cli/commands/manifest.doc.mjs +1 -1
- package/clients/cli/commands/manifest.mjs +67 -0
- package/clients/cli/commands/outside-project.test.mjs +99 -0
- package/clients/cli/commands/postinstall.doc.mjs +23 -0
- package/clients/cli/commands/postinstall.mjs +31 -0
- package/clients/cli/commands/setup-nudge.test.mjs +17 -0
- package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
- package/clients/cli/index.mjs +35 -93
- package/clients/cli/lib/component-format.mjs +1 -1
- package/clients/cli/lib/define-command.mjs +12 -7
- package/clients/cli/lib/exit-codes.test.mjs +5 -0
- package/clients/cli/lib/manifest.test.mjs +12 -0
- package/clients/cli/lib/welcome-box.mjs +50 -0
- package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
- package/foundation/agent-docs/agent-doc-state.mjs +24 -2
- package/foundation/agent-docs/agent-docs.mjs +7 -6
- package/foundation/agent-docs/agent-docs.test.mjs +5 -4
- package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
- package/foundation/agent-docs/computer-agent-text.mjs +135 -8
- package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
- package/foundation/discovery/authoring-self-docs.d.mts +7 -0
- package/foundation/discovery/authoring-self-docs.mjs +16 -4
- package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
- package/foundation/discovery/authoring-surface.d.mts +1 -1
- package/foundation/discovery/authoring-surface.mjs +2 -2
- package/foundation/discovery/authoring-surface.test.mjs +1 -1
- package/foundation/discovery/cli-self-docs.d.mts +2 -1
- package/foundation/discovery/cli-self-docs.mjs +4 -3
- package/foundation/discovery/cli-self-docs.test.mjs +2 -2
- package/foundation/discovery/runner-commands.mjs +1 -0
- package/foundation/discovery/stray-pointers.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +21 -9
- package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
- package/foundation/doc-compiler/tree.d.mts +32 -6
- package/foundation/doc-compiler/tree.mjs +77 -43
- package/foundation/doc-compiler/tree.test.mjs +7 -7
- package/foundation/fs/read-record.d.mts +18 -0
- package/foundation/fs/read-record.mjs +131 -0
- package/foundation/fs/read-record.test.mjs +77 -0
- package/foundation/integrations/cli-peer-version.d.mts +36 -0
- package/foundation/integrations/cli-peer-version.mjs +132 -0
- package/foundation/integrations/cli-peer-version.test.mjs +354 -0
- package/foundation/integrations/exports-subpaths.d.mts +57 -0
- package/foundation/integrations/exports-subpaths.mjs +113 -0
- package/foundation/integrations/public-imports.d.mts +118 -0
- package/foundation/integrations/public-imports.mjs +1769 -0
- package/foundation/integrations/public-imports.test.mjs +1793 -0
- package/foundation/release/cache.test.mjs +24 -21
- package/foundation/release/global-state.d.mts +8 -4
- package/foundation/release/global-state.mjs +4 -2
- package/foundation/release/notices.d.mts +62 -8
- package/foundation/release/notices.mjs +136 -25
- package/foundation/release/notices.test.mjs +21 -0
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/text/string-utils.d.mts +2 -1
- package/foundation/text/string-utils.mjs +16 -5
- package/foundation/text/suggest-order.d.mts +72 -0
- package/foundation/text/suggest-order.mjs +363 -0
- package/foundation/text/suggest-order.test.mjs +259 -0
- package/package.json +9 -9
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Tests for search's adapter: a long-running caller reuses the gathered
|
|
5
|
+
* candidates while their inputs are unchanged (gatherCandidatesReused), and
|
|
6
|
+
* gathers again when an input changes or for another folder or `type`.
|
|
7
|
+
*
|
|
8
|
+
* Whether inputs changed is read-record's answer (tested in
|
|
9
|
+
* read-record.test.mjs). Other tests running at the same time change shared
|
|
10
|
+
* folders a gather reads (the temp folder, the repository root), so here the
|
|
11
|
+
* reuse case holds that answer at "unchanged", and every other case only
|
|
12
|
+
* checks that a change forces a new gather, which concurrent changes cannot
|
|
13
|
+
* undo.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {describe, it, expect, vi} from 'vitest';
|
|
17
|
+
import * as fs from 'node:fs';
|
|
18
|
+
import * as os from 'node:os';
|
|
19
|
+
import * as path from 'node:path';
|
|
20
|
+
import * as readRecord from '../../foundation/fs/read-record.mjs';
|
|
21
|
+
import {gatherCandidates, gatherCandidatesReused} from './_adapter.mjs';
|
|
22
|
+
|
|
23
|
+
vi.mock('../../foundation/fs/read-record.mjs', async original => {
|
|
24
|
+
const real = /** @type {typeof readRecord} */ (await original());
|
|
25
|
+
return {...real, unchangedSince: vi.fn(real.unchangedSince)};
|
|
26
|
+
});
|
|
27
|
+
const unchangedSince = vi.mocked(readRecord.unchangedSince);
|
|
28
|
+
|
|
29
|
+
const SLOW = 60_000;
|
|
30
|
+
|
|
31
|
+
/** A folder with only a package.json: a docs search there reads the CLI's docs. */
|
|
32
|
+
function scratchProject() {
|
|
33
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-gather-reuse-'));
|
|
34
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"app"}');
|
|
35
|
+
return dir;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('gatherCandidatesReused', () => {
|
|
39
|
+
it(
|
|
40
|
+
'reuses the gathered candidates while the inputs are unchanged',
|
|
41
|
+
async () => {
|
|
42
|
+
const cwd = scratchProject();
|
|
43
|
+
const first = await gatherCandidatesReused({cwd, type: 'doc'});
|
|
44
|
+
unchangedSince.mockReturnValueOnce(true);
|
|
45
|
+
expect(await gatherCandidatesReused({cwd, type: 'doc'})).toBe(first);
|
|
46
|
+
expect(first.all.length).toBeGreaterThan(0);
|
|
47
|
+
// The same candidates a fresh gather finds.
|
|
48
|
+
expect(JSON.parse(JSON.stringify(first))).toEqual(
|
|
49
|
+
JSON.parse(JSON.stringify(await gatherCandidates({cwd, type: 'doc'}))),
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
SLOW,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
it(
|
|
56
|
+
'gathers again when an input file changes',
|
|
57
|
+
async () => {
|
|
58
|
+
const cwd = scratchProject();
|
|
59
|
+
const first = await gatherCandidatesReused({cwd, type: 'doc'});
|
|
60
|
+
const later = new Date(Date.now() + 5_000);
|
|
61
|
+
fs.utimesSync(path.join(cwd, 'package.json'), later, later);
|
|
62
|
+
expect(await gatherCandidatesReused({cwd, type: 'doc'})).not.toBe(first);
|
|
63
|
+
fs.writeFileSync(
|
|
64
|
+
path.join(cwd, 'astryx.config.mjs'),
|
|
65
|
+
'export default {};\n',
|
|
66
|
+
);
|
|
67
|
+
expect(await gatherCandidatesReused({cwd, type: 'doc'})).not.toBe(first);
|
|
68
|
+
},
|
|
69
|
+
SLOW,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
it(
|
|
73
|
+
'keeps one entry per folder and type',
|
|
74
|
+
async () => {
|
|
75
|
+
const cwd = scratchProject();
|
|
76
|
+
const docs = await gatherCandidatesReused({cwd, type: 'doc'});
|
|
77
|
+
const themes = await gatherCandidatesReused({cwd, type: 'theme'});
|
|
78
|
+
expect(themes).not.toBe(docs);
|
|
79
|
+
expect(themes.all.every(c => c.domain === 'theme')).toBe(true);
|
|
80
|
+
expect(
|
|
81
|
+
await gatherCandidatesReused({cwd: scratchProject(), type: 'doc'}),
|
|
82
|
+
).not.toBe(docs);
|
|
83
|
+
},
|
|
84
|
+
SLOW,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
it(
|
|
88
|
+
'gathers again when a file the gather read changes, in a linked package too',
|
|
89
|
+
async () => {
|
|
90
|
+
// A consumer whose integration is a symlink to a package folder
|
|
91
|
+
// elsewhere, as a workspace package is.
|
|
92
|
+
const dir = fs.mkdtempSync(
|
|
93
|
+
path.join(process.cwd(), '.astryx-gather-reuse-'),
|
|
94
|
+
);
|
|
95
|
+
const pkg = fs.mkdtempSync(
|
|
96
|
+
path.join(os.tmpdir(), 'astryx-linked-widgets-'),
|
|
97
|
+
);
|
|
98
|
+
try {
|
|
99
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"consumer"}');
|
|
100
|
+
fs.writeFileSync(
|
|
101
|
+
path.join(dir, 'astryx.config.mjs'),
|
|
102
|
+
"export default { integrations: ['@acme/widgets'] };\n",
|
|
103
|
+
);
|
|
104
|
+
fs.mkdirSync(
|
|
105
|
+
path.join(dir, 'node_modules', '@astryxdesign', 'core', 'src'),
|
|
106
|
+
{
|
|
107
|
+
recursive: true,
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
fs.mkdirSync(path.join(pkg, 'components'));
|
|
111
|
+
fs.writeFileSync(
|
|
112
|
+
path.join(pkg, 'package.json'),
|
|
113
|
+
'{"name":"@acme/widgets","version":"1.0.0"}',
|
|
114
|
+
);
|
|
115
|
+
fs.writeFileSync(
|
|
116
|
+
path.join(pkg, 'astryx.integration.mjs'),
|
|
117
|
+
"export default { components: './components' };\n",
|
|
118
|
+
);
|
|
119
|
+
fs.writeFileSync(
|
|
120
|
+
path.join(pkg, 'components', 'FancyGizmo.doc.mjs'),
|
|
121
|
+
`export default {
|
|
122
|
+
type: 'component',
|
|
123
|
+
name: 'FancyGizmo',
|
|
124
|
+
keywords: ['gizmo'],
|
|
125
|
+
usage: {description: 'A fancy part.'},
|
|
126
|
+
props: [],
|
|
127
|
+
};\n`,
|
|
128
|
+
);
|
|
129
|
+
fs.writeFileSync(
|
|
130
|
+
path.join(pkg, 'components', 'FancyGizmo.tsx'),
|
|
131
|
+
'export function FancyGizmo() { return null; }\n',
|
|
132
|
+
);
|
|
133
|
+
fs.mkdirSync(path.join(dir, 'node_modules', '@acme'));
|
|
134
|
+
fs.symlinkSync(
|
|
135
|
+
pkg,
|
|
136
|
+
path.join(dir, 'node_modules', '@acme', 'widgets'),
|
|
137
|
+
'dir',
|
|
138
|
+
);
|
|
139
|
+
const options = {cwd: dir, type: 'component'};
|
|
140
|
+
const first = await gatherCandidatesReused(options);
|
|
141
|
+
expect(first.all.map(c => c.name)).toContain('FancyGizmo');
|
|
142
|
+
|
|
143
|
+
// A new component in the linked package: its folder changed.
|
|
144
|
+
fs.writeFileSync(
|
|
145
|
+
path.join(pkg, 'components', 'TinySprocket.doc.mjs'),
|
|
146
|
+
`export default {
|
|
147
|
+
type: 'component',
|
|
148
|
+
name: 'TinySprocket',
|
|
149
|
+
keywords: ['sprocket'],
|
|
150
|
+
usage: {description: 'A small part.'},
|
|
151
|
+
props: [],
|
|
152
|
+
};\n`,
|
|
153
|
+
);
|
|
154
|
+
fs.writeFileSync(
|
|
155
|
+
path.join(pkg, 'components', 'TinySprocket.tsx'),
|
|
156
|
+
'export function TinySprocket() { return null; }\n',
|
|
157
|
+
);
|
|
158
|
+
const second = await gatherCandidatesReused(options);
|
|
159
|
+
expect(second).not.toBe(first);
|
|
160
|
+
expect(second.all.map(c => c.name)).toContain('TinySprocket');
|
|
161
|
+
|
|
162
|
+
// An edited file the gather read: the linked package's manifest.
|
|
163
|
+
const later = new Date(Date.now() + 5_000);
|
|
164
|
+
fs.utimesSync(path.join(pkg, 'package.json'), later, later);
|
|
165
|
+
expect(await gatherCandidatesReused(options)).not.toBe(second);
|
|
166
|
+
} finally {
|
|
167
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
168
|
+
fs.rmSync(pkg, {recursive: true, force: true});
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
SLOW,
|
|
172
|
+
);
|
|
173
|
+
});
|
|
@@ -104,7 +104,7 @@ export function scoreCandidate(
|
|
|
104
104
|
for (const candidateName of [name, ...aliases.filter(Boolean)]) {
|
|
105
105
|
const nameLower = candidateName.toLowerCase();
|
|
106
106
|
// A placed guide's name is its route, and the route's last segment is its
|
|
107
|
-
// name too, as a flat topic's is: `codemods` is
|
|
107
|
+
// name too, as a flat topic's is: `codemods` is authoring/building-blocks/codemods.
|
|
108
108
|
const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
|
|
109
109
|
|
|
110
110
|
// A plural of the name is the name: `integration` is the `integrations`
|
|
@@ -13,6 +13,16 @@ export function entryTable(all: any[], cards: Record<string, {
|
|
|
13
13
|
synonyms?: string[];
|
|
14
14
|
props?: string[];
|
|
15
15
|
}>): EntryTable;
|
|
16
|
+
/**
|
|
17
|
+
* @param {any[]} all
|
|
18
|
+
* @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
|
|
19
|
+
* @returns {EntryTable}
|
|
20
|
+
*/
|
|
21
|
+
export function buildTable(all: any[], cards: Record<string, {
|
|
22
|
+
what?: string;
|
|
23
|
+
synonyms?: string[];
|
|
24
|
+
props?: string[];
|
|
25
|
+
}>): EntryTable;
|
|
16
26
|
export function entryOf(table: {
|
|
17
27
|
index: Map<string, number>;
|
|
18
28
|
}, res: {
|
|
@@ -22,6 +32,7 @@ export function entryOf(table: {
|
|
|
22
32
|
section?: string;
|
|
23
33
|
}): number | undefined;
|
|
24
34
|
export function entryId(c: any): string;
|
|
35
|
+
export const HASHED_FIELDS: readonly string[];
|
|
25
36
|
export type EntryTable = {
|
|
26
37
|
/**
|
|
27
38
|
* every returnable `<domain>:<name>`, in code-point order
|
package/api/search/_entries.mjs
CHANGED
|
@@ -77,6 +77,29 @@ let last = null;
|
|
|
77
77
|
const cardIds = new WeakMap();
|
|
78
78
|
let nextCardId = 0;
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* The candidate fields buildTable reads, all of them hashed by fingerprint;
|
|
82
|
+
* `_entries.test.mjs` fails if buildTable starts reading another.
|
|
83
|
+
*/
|
|
84
|
+
/** How many guidance lines and prose paragraphs of a candidate the index reads. */
|
|
85
|
+
const GUIDANCE_LINES = 10;
|
|
86
|
+
const PROSE_PARAGRAPHS = 4;
|
|
87
|
+
|
|
88
|
+
export const HASHED_FIELDS = Object.freeze([
|
|
89
|
+
'domain',
|
|
90
|
+
'name',
|
|
91
|
+
'_topic',
|
|
92
|
+
'_section',
|
|
93
|
+
'_resultName',
|
|
94
|
+
'_package',
|
|
95
|
+
'description',
|
|
96
|
+
'keywords',
|
|
97
|
+
'aliases',
|
|
98
|
+
'titles',
|
|
99
|
+
'guidance',
|
|
100
|
+
'prose',
|
|
101
|
+
]);
|
|
102
|
+
|
|
80
103
|
/**
|
|
81
104
|
* Everything the table reads from the catalog, hashed.
|
|
82
105
|
* @param {any[]} all
|
|
@@ -89,20 +112,15 @@ function fingerprint(all, cards) {
|
|
|
89
112
|
h.update(String(cardIds.get(cards)));
|
|
90
113
|
for (const c of all) {
|
|
91
114
|
h.update(
|
|
92
|
-
JSON.stringify(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
c.aliases,
|
|
102
|
-
c.titles,
|
|
103
|
-
(c.guidance ?? []).slice(0, 10),
|
|
104
|
-
(c.prose ?? []).slice(0, 4),
|
|
105
|
-
]),
|
|
115
|
+
JSON.stringify(
|
|
116
|
+
HASHED_FIELDS.map(f =>
|
|
117
|
+
f === 'guidance'
|
|
118
|
+
? (c.guidance ?? []).slice(0, GUIDANCE_LINES)
|
|
119
|
+
: f === 'prose'
|
|
120
|
+
? (c.prose ?? []).slice(0, PROSE_PARAGRAPHS)
|
|
121
|
+
: c[f],
|
|
122
|
+
),
|
|
123
|
+
),
|
|
106
124
|
);
|
|
107
125
|
}
|
|
108
126
|
return h.digest('hex');
|
|
@@ -113,7 +131,7 @@ function fingerprint(all, cards) {
|
|
|
113
131
|
* @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
|
|
114
132
|
* @returns {EntryTable}
|
|
115
133
|
*/
|
|
116
|
-
function buildTable(all, cards) {
|
|
134
|
+
export function buildTable(all, cards) {
|
|
117
135
|
/** @type {Map<string, any[]>} */
|
|
118
136
|
const by = new Map();
|
|
119
137
|
/** @type {Map<string, string>} each id's first package */
|
|
@@ -164,8 +182,8 @@ function buildTable(all, cards) {
|
|
|
164
182
|
...(c.titles ?? []),
|
|
165
183
|
);
|
|
166
184
|
text.push(
|
|
167
|
-
...(c.guidance ?? []).slice(0,
|
|
168
|
-
...(c.prose ?? []).slice(0,
|
|
185
|
+
...(c.guidance ?? []).slice(0, GUIDANCE_LINES),
|
|
186
|
+
...(c.prose ?? []).slice(0, PROSE_PARAGRAPHS),
|
|
169
187
|
);
|
|
170
188
|
}
|
|
171
189
|
const card =
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The entry index is reused while the catalog's text is unchanged, so
|
|
5
|
+
* every field it reads must be part of the hash that decides reuse.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {describe, it, expect} from 'vitest';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import {fileURLToPath} from 'node:url';
|
|
11
|
+
import {gatherCandidates, loadSearchData} from './_adapter.mjs';
|
|
12
|
+
import {HASHED_FIELDS, buildTable, entryTable} from './_entries.mjs';
|
|
13
|
+
|
|
14
|
+
const cwd = path.resolve(
|
|
15
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
16
|
+
'../../../..',
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
describe('entry index cache', () => {
|
|
20
|
+
it('hashes every candidate field the index reads', async () => {
|
|
21
|
+
const {all} = await gatherCandidates({cwd});
|
|
22
|
+
/** @type {Set<string>} */
|
|
23
|
+
const read = new Set();
|
|
24
|
+
const watched = all.map(
|
|
25
|
+
c =>
|
|
26
|
+
new Proxy(c, {
|
|
27
|
+
get(target, key, receiver) {
|
|
28
|
+
if (typeof key === 'string') read.add(key);
|
|
29
|
+
return Reflect.get(target, key, receiver);
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
buildTable(watched, loadSearchData().cards);
|
|
34
|
+
const unhashed = [...read].filter(k => !HASHED_FIELDS.includes(k));
|
|
35
|
+
expect(unhashed).toEqual([]);
|
|
36
|
+
}, 60_000);
|
|
37
|
+
|
|
38
|
+
it('rebuilds when a candidate text changes and reuses it otherwise', async () => {
|
|
39
|
+
const {all} = await gatherCandidates({cwd});
|
|
40
|
+
const {cards} = loadSearchData();
|
|
41
|
+
const first = entryTable([...all], cards);
|
|
42
|
+
expect(entryTable([...all], cards)).toBe(first);
|
|
43
|
+
const changed = all.map((c, i) =>
|
|
44
|
+
i === 0 ? {...c, description: `${c.description ?? ''} changed`} : c,
|
|
45
|
+
);
|
|
46
|
+
expect(entryTable(changed, cards)).not.toBe(first);
|
|
47
|
+
}, 60_000);
|
|
48
|
+
});
|
|
@@ -63,7 +63,7 @@ export async function gatherDocs(cwd) {
|
|
|
63
63
|
// integration issues; search just cannot index it.
|
|
64
64
|
}
|
|
65
65
|
const doc = lowered?.doc ?? null;
|
|
66
|
-
// A flat topic lives in
|
|
66
|
+
// A flat topic lives in its topic level; its hits say so, and name
|
|
67
67
|
// the package each section came from.
|
|
68
68
|
const home = tree?.get(entry.name);
|
|
69
69
|
const placed = home?.ref?.flatTopic === entry.name ? home : null;
|
|
@@ -176,7 +176,7 @@ export async function gatherDocs(cwd) {
|
|
|
176
176
|
* @param {string} [path] - where the topic lives in the docs tree, as titles
|
|
177
177
|
* joined by ` › `; a flat topic is its own title
|
|
178
178
|
* @param {string} [parent] - the command that opens the level above the
|
|
179
|
-
* topic: its namespace, or the
|
|
179
|
+
* topic: its namespace, or the topic level for a flat topic
|
|
180
180
|
* @param {string} [pkg] - the npm package that authored the topic
|
|
181
181
|
* @param {(key: string) => string} [sectionPackage] - the npm package a
|
|
182
182
|
* section came from: an extension's section names the extension's package
|
|
@@ -197,7 +197,7 @@ function topicCandidates(
|
|
|
197
197
|
const docTitle = path || doc?.title || title || name;
|
|
198
198
|
const split = sections.length > 1;
|
|
199
199
|
// A placed guide also answers to its last route segment's words:
|
|
200
|
-
// `quick start` is
|
|
200
|
+
// `quick start` is authoring/quick-start.
|
|
201
201
|
const leaf = name.slice(name.lastIndexOf('/') + 1);
|
|
202
202
|
/** @type {Candidate[]} */
|
|
203
203
|
const out = [
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
-
/** @typedef {import('./_lexical.mjs').Candidate} Candidate */
|
|
5
4
|
/**
|
|
6
5
|
* Build template candidates (page + block) from the template discovery API.
|
|
7
6
|
* @param {string} cwd
|
|
@@ -8,9 +8,31 @@ import {CORE_PACKAGE} from '../../foundation/discovery/component-discovery.mjs';
|
|
|
8
8
|
import {discoverTemplates, extractComponents} from '../template/template.mjs';
|
|
9
9
|
import {listAvailableThemes} from '../theme/_adapter.mjs';
|
|
10
10
|
import {templateLookupIds} from '../../foundation/discovery/template-adapter.mjs';
|
|
11
|
+
import {sameWord, wordsOf} from './_words.mjs';
|
|
11
12
|
|
|
12
13
|
/** @typedef {import('./_lexical.mjs').Candidate} Candidate */
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* A template's authored display name as another name and title of it, when the
|
|
17
|
+
* name stands for the template: two words or more that hold every word of the
|
|
18
|
+
* component the block shows (`exampleFor`), as "Rich Text Editor" does for
|
|
19
|
+
* RichTextEditor. A query that is the name then names the entry whole, and one
|
|
20
|
+
* that holds it as a phrase ("rich text") reaches search's title tier, above
|
|
21
|
+
* entries that match one of its words. A label of the variant alone ("Inside a
|
|
22
|
+
* card" for a Comments block) does not name the block, so it stays out.
|
|
23
|
+
* @param {{displayName?: string, exampleFor?: string}} t
|
|
24
|
+
* @returns {{aliases?: string[], titles?: string[]}}
|
|
25
|
+
*/
|
|
26
|
+
function subjectName(t) {
|
|
27
|
+
const name = String(t.displayName ?? '').trim();
|
|
28
|
+
const words = wordsOf(name);
|
|
29
|
+
const subject = wordsOf(String(t.exampleFor ?? ''));
|
|
30
|
+
if (words.length < 2 || subject.length === 0) return {};
|
|
31
|
+
return subject.every(s => words.some(w => sameWord(s, w)))
|
|
32
|
+
? {aliases: [name], titles: [name]}
|
|
33
|
+
: {};
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
/**
|
|
15
37
|
* Build template candidates (page + block) from the template discovery API.
|
|
16
38
|
* @param {string} cwd
|
|
@@ -67,6 +89,9 @@ export async function gatherTemplates(cwd) {
|
|
|
67
89
|
// as its prose does, not as a name: one of them matching one word of a
|
|
68
90
|
// short idea is not a direct match.
|
|
69
91
|
prose: t.keywords ?? [],
|
|
92
|
+
// A display name that names the block's subject is another name of it
|
|
93
|
+
// and its title (subjectName).
|
|
94
|
+
...subjectName(t),
|
|
70
95
|
_displayName: t.name,
|
|
71
96
|
_package: t.package ?? CORE_PACKAGE,
|
|
72
97
|
_kind: t.type, // 'page' | 'block'
|
|
@@ -58,7 +58,7 @@ export const doc = {
|
|
|
58
58
|
{
|
|
59
59
|
type: 'search',
|
|
60
60
|
description:
|
|
61
|
-
'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit`: each has domain, name, score, reason, description, and follow-up command, plus `import` for components and hooks, `title` for docs, `displayName` and `kind` for templates, and `displayName` for themes. A doc result is the smallest part that answers: one section (with `section`, and a command that reads only it), one docs-tree route, or a topic, whose command lists its sections. `parent` is the command that opens the level above it: the section list of its topic, the namespace a tree node sits in, the
|
|
61
|
+
'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit`: each has domain, name, score, reason, description, and follow-up command, plus `import` for components and hooks, `title` for docs, `displayName` and `kind` for templates, and `displayName` for themes. A doc result is the smallest part that answers: one section (with `section`, and a command that reads only it), one docs-tree route, or a topic, whose command lists its sections. `parent` is the command that opens the level above it: the section list of its topic, the namespace a tree node sits in, the topic level (Guides or Foundations) for a flat topic, or the topic list for a top-level namespace. Every doc result also carries `package`, the npm package that authored it (for a section, the package its file came from). A theme result is one theme you can import: `name` is its slug, its command is `astryx theme add <slug>` (outside a project, where there is no app to add it to, `astryx theme eject <slug>`), and `package` is the npm package that ships it (`@astryxdesign/cli` for the CLI\'s own themes). When a search with no `type` could not obtain @astryxdesign/core, `meta.partial` is `{skipped, reason}`: the domains it skipped (`component`, `hook`, `template`) and why; the results are the docs and themes, and text mode prints one line on standard error.',
|
|
62
62
|
},
|
|
63
63
|
],
|
|
64
64
|
throws: [
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file An integration's own block answers a query that names it, though no
|
|
5
|
+
* learned table lists it: its authored display name is a title search reads,
|
|
6
|
+
* so "rich text editor" finds the rich text package's block first and build
|
|
7
|
+
* offers it, while a variant label that does not name the block (Lab's "Inside
|
|
8
|
+
* a card") captures nothing.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import {fileURLToPath} from 'node:url';
|
|
15
|
+
import {afterAll, beforeAll, describe, expect, it} from 'vitest';
|
|
16
|
+
import {search} from './search.mjs';
|
|
17
|
+
import {build} from '../build/build.mjs';
|
|
18
|
+
|
|
19
|
+
const SLOW = 60_000;
|
|
20
|
+
const packages = path.resolve(
|
|
21
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
22
|
+
'../../..',
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
describe('an integration block found by its display name', () => {
|
|
26
|
+
/** @type {string} */
|
|
27
|
+
let dir;
|
|
28
|
+
beforeAll(() => {
|
|
29
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-integration-block-'));
|
|
30
|
+
fs.writeFileSync(
|
|
31
|
+
path.join(dir, 'package.json'),
|
|
32
|
+
JSON.stringify({
|
|
33
|
+
name: 'consumer',
|
|
34
|
+
dependencies: {
|
|
35
|
+
'@astryxdesign/core': '*',
|
|
36
|
+
'@astryxdesign/richtext': '*',
|
|
37
|
+
'@astryxdesign/lab': '*',
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
const scope = path.join(dir, 'node_modules', '@astryxdesign');
|
|
42
|
+
fs.mkdirSync(scope, {recursive: true});
|
|
43
|
+
for (const name of ['core', 'richtext', 'lab'])
|
|
44
|
+
fs.symlinkSync(path.join(packages, name), path.join(scope, name), 'dir');
|
|
45
|
+
});
|
|
46
|
+
afterAll(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
47
|
+
|
|
48
|
+
it.each(['rich text editor', 'rich text', 'text editor'])(
|
|
49
|
+
'`%s` ranks the rich text block first among templates',
|
|
50
|
+
async query => {
|
|
51
|
+
const {results} = (await search(query, {cwd: dir, type: 'template'}))
|
|
52
|
+
.data;
|
|
53
|
+
expect(results[0], JSON.stringify(results.slice(0, 3))).toMatchObject({
|
|
54
|
+
name: 'RichTextEditorShowcase',
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
SLOW,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
it(
|
|
61
|
+
'a whole display name names the block outright',
|
|
62
|
+
async () => {
|
|
63
|
+
const {results} = (
|
|
64
|
+
await search('rich text editor', {cwd: dir, type: 'template'})
|
|
65
|
+
).data;
|
|
66
|
+
expect(results[0]).toMatchObject({
|
|
67
|
+
name: 'RichTextEditorShowcase',
|
|
68
|
+
reason: 'exact name',
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
SLOW,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
it(
|
|
75
|
+
"a variant label that does not name the block's subject is no title",
|
|
76
|
+
async () => {
|
|
77
|
+
const {results} = (
|
|
78
|
+
await search('table inside a card', {cwd: dir, type: 'template'})
|
|
79
|
+
).data;
|
|
80
|
+
expect(results[0], JSON.stringify(results.slice(0, 3))).toMatchObject({
|
|
81
|
+
name: 'TableInCard',
|
|
82
|
+
});
|
|
83
|
+
const kit = (await build('a settings form inside a card', {cwd: dir}))
|
|
84
|
+
.data;
|
|
85
|
+
expect(kit.blocks[0]?.name).not.toBe('CommentsInCard');
|
|
86
|
+
},
|
|
87
|
+
SLOW,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
it(
|
|
91
|
+
'build offers the rich text block for a request that names it',
|
|
92
|
+
async () => {
|
|
93
|
+
const kit = (
|
|
94
|
+
await build('a comment box with a rich text editor', {cwd: dir})
|
|
95
|
+
).data;
|
|
96
|
+
expect(kit.blocks.map(b => b.name)).toContain('RichTextEditorShowcase');
|
|
97
|
+
},
|
|
98
|
+
SLOW,
|
|
99
|
+
);
|
|
100
|
+
});
|
package/api/search/search.mjs
CHANGED
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
gatherCandidates,
|
|
20
|
+
gatherCandidatesReused,
|
|
21
|
+
loadSearchData,
|
|
22
|
+
} from './_adapter.mjs';
|
|
19
23
|
import {rankLexical} from './_lexical.mjs';
|
|
20
24
|
import {checkSearchArgs} from './_result.mjs';
|
|
21
25
|
import {runTree} from '../../foundation/route/route.mjs';
|
|
@@ -56,7 +60,7 @@ export async function search(query, options = {}) {
|
|
|
56
60
|
await runTree(
|
|
57
61
|
SEARCH_TREE,
|
|
58
62
|
{query, options},
|
|
59
|
-
{...(await
|
|
63
|
+
{...(await gatherCandidatesReused(options)), data: loadSearchData()},
|
|
60
64
|
)
|
|
61
65
|
),
|
|
62
66
|
options.cwd ?? process.cwd(),
|
|
@@ -117,16 +117,16 @@ describe('search leaf — docs at the grain a reader reads them', () => {
|
|
|
117
117
|
.find(result => result.section === 'which-codemods-run');
|
|
118
118
|
expect(hit).toMatchObject({
|
|
119
119
|
domain: 'doc',
|
|
120
|
-
name: expect.stringMatching(/^
|
|
120
|
+
name: expect.stringMatching(/^authoring\/(?:.+\/)?codemods$/),
|
|
121
121
|
title: expect.stringMatching(/ › Codemods › Choose when a codemod runs$/),
|
|
122
122
|
});
|
|
123
123
|
expect(hit.parent).toBe(`astryx docs ${hit.name} --index`);
|
|
124
124
|
expect(hit.command).toBe(`astryx docs ${hit.name} which-codemods-run`);
|
|
125
125
|
const block = await search('token-ref', {cwd});
|
|
126
126
|
expect(block.data.results[0]).toMatchObject({
|
|
127
|
-
name: 'authoring',
|
|
127
|
+
name: 'authoring/field-reference',
|
|
128
128
|
section: 'reference-doc',
|
|
129
|
-
command: 'astryx docs authoring reference-doc',
|
|
129
|
+
command: 'astryx docs authoring/field-reference reference-doc',
|
|
130
130
|
});
|
|
131
131
|
const fn = await search('assertResponse', {cwd, type: 'doc'});
|
|
132
132
|
expect(fn.data.results[0]).toMatchObject({
|
|
@@ -148,13 +148,13 @@ describe('search leaf — docs at the grain a reader reads them', () => {
|
|
|
148
148
|
// keywords and the title the guides declare. A namespace's own
|
|
149
149
|
// keywords count, and a plural name is the name.
|
|
150
150
|
for (const [query, route] of [
|
|
151
|
-
['make an integration', /^
|
|
152
|
-
['build an integration', /^
|
|
153
|
-
['create an integration', /^
|
|
154
|
-
['integration', /^
|
|
155
|
-
['publish an integration', /^
|
|
151
|
+
['make an integration', /^authoring$/],
|
|
152
|
+
['build an integration', /^authoring$/],
|
|
153
|
+
['create an integration', /^authoring$/],
|
|
154
|
+
['integration', /^authoring$/],
|
|
155
|
+
['publish an integration', /^authoring$/],
|
|
156
156
|
// The troubleshooting guide, wherever the tree places it.
|
|
157
|
-
['troubleshoot integration', /^
|
|
157
|
+
['troubleshoot integration', /^authoring\/(?:.+\/)?troubleshooting$/],
|
|
158
158
|
]) {
|
|
159
159
|
const r = await search(query, {cwd, type: 'doc'});
|
|
160
160
|
const names = r.data.results.slice(0, 3).map(result => result.name);
|
|
@@ -167,7 +167,7 @@ describe('search leaf — docs at the grain a reader reads them', () => {
|
|
|
167
167
|
it(
|
|
168
168
|
'gives a top-level namespace hit the topic list as its parent',
|
|
169
169
|
async () => {
|
|
170
|
-
for (const [query, route] of [['
|
|
170
|
+
for (const [query, route] of [['foundations', 'foundations'], ['Astryx CLI', 'cli']]) {
|
|
171
171
|
const r = await search(query, {cwd, type: 'doc'});
|
|
172
172
|
expect(r.data.results).toContainEqual(
|
|
173
173
|
expect.objectContaining({
|
|
@@ -185,7 +185,7 @@ describe('search leaf — docs at the grain a reader reads them', () => {
|
|
|
185
185
|
'points a topic hit at its index, never a whole-topic read',
|
|
186
186
|
async () => {
|
|
187
187
|
// A guide the tree places, read from the tree rather than named.
|
|
188
|
-
const {data: integrations} = await docs('
|
|
188
|
+
const {data: integrations} = await docs('authoring');
|
|
189
189
|
const guide = integrations.slots
|
|
190
190
|
.flatMap(slot => slot.children)
|
|
191
191
|
.find(child => child.kind === 'generic').route;
|
|
@@ -440,9 +440,9 @@ describe('search leaf — a candidate that matches every word outranks a partial
|
|
|
440
440
|
const tokens = await search('tokens', {cwd});
|
|
441
441
|
expect(tokens.data.results[0]).toMatchObject({domain: 'doc', name: 'tokens'});
|
|
442
442
|
for (const [query, route] of [
|
|
443
|
-
['codemods', /^
|
|
444
|
-
['quick start', /^
|
|
445
|
-
['test in an app', /^
|
|
443
|
+
['codemods', /^authoring\/(?:.+\/)?codemods$/],
|
|
444
|
+
['quick start', /^authoring\/(?:.+\/)?quick-start$/],
|
|
445
|
+
['test in an app', /^authoring\/(?:.+\/)?test-in-an-app$/],
|
|
446
446
|
]) {
|
|
447
447
|
const r = await search(query, {cwd, type: 'doc'});
|
|
448
448
|
// The guide is among the hits that share the top score: two guides
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from '../../foundation/discovery/template-adapter.mjs';
|
|
25
25
|
import {AstryxError} from '../error.mjs';
|
|
26
26
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
27
|
+
import {orderByAffinity} from '../../foundation/text/suggest-order.mjs';
|
|
27
28
|
import {templateList} from './list/list.mjs';
|
|
28
29
|
import {templateShow} from './show/show.mjs';
|
|
29
30
|
import {templateSkeleton} from './skeleton/skeleton.mjs';
|
|
@@ -188,7 +189,10 @@ export async function template(name, options = {}) {
|
|
|
188
189
|
if (name && candidates.length === 0) {
|
|
189
190
|
throw new AstryxError(
|
|
190
191
|
`Unknown template "${name}"`,
|
|
191
|
-
templates
|
|
192
|
+
orderByAffinity(name, templates, t => [t.dirName, t.name]).map(t => ({
|
|
193
|
+
name: t.dirName,
|
|
194
|
+
reason: `${t.type} template`,
|
|
195
|
+
})),
|
|
192
196
|
ERROR_CODES.ERR_UNKNOWN_TEMPLATE,
|
|
193
197
|
);
|
|
194
198
|
}
|
|
@@ -28,7 +28,7 @@ export const docs = {
|
|
|
28
28
|
{type: 'code', lang: 'json', label: 'Minimal palette config (palette.config.json)', code: '{"families": [{"id": "ocean", "seed": "#0074e2"}]}'},
|
|
29
29
|
{type: 'code', lang: 'bash', label: 'Generate and preview', code: '# Print the palette without writing files\nastryx theme palette generate palette.config.json\n\n# Write palette + receipt, and open a visual preview\nastryx theme palette generate palette.config.json \\\n --out src/themes/ocean/tokens/ocean.palette.ts \\\n --preview preview.html'},
|
|
30
30
|
{type: 'prose', text: "The command writes a `.ts` file exporting 21 shades (stops 0–100) for both light and dark, plus a `.receipt.json` to regenerate later. Point your theme's tokens at the palette, then run defineTheme (see below)."},
|
|
31
|
-
{type: 'prose', text: 'For the full palette config fields and CLI flags, run `astryx docs cli/commands/theme-palette-generate`. For the integration-authoring walkthrough of connecting a palette to theme tokens, run `astryx docs
|
|
31
|
+
{type: 'prose', text: 'For the full palette config fields and CLI flags, run `astryx docs cli/commands/theme-palette-generate`. For the integration-authoring walkthrough of connecting a palette to theme tokens, run `astryx docs authoring/building-blocks/themes/generate-a-palette`.'},
|
|
32
32
|
],
|
|
33
33
|
},
|
|
34
34
|
{
|
|
@@ -61,7 +61,7 @@ export const docs = {
|
|
|
61
61
|
['adaptations', 'Width-breakpoint overrides merge by fixed name. Inherited ordered rules keep their relative order; child rules append and re-resolve against the child root axes.'],
|
|
62
62
|
]},
|
|
63
63
|
{type: 'prose', text: "Inheritance is resolved when the theme is defined, so an extended theme is flat: `astryx theme build` emits one self-contained stylesheet holding everything the child inherited, and the base theme's CSS does not need to be loaded next to it. A base that is not a theme (most often an import that missed) throws when `defineTheme` runs, rather than producing a theme that silently inherits nothing."},
|
|
64
|
-
{type: 'prose', text: 'For the integration-specific guidance on mapping a palette to tokens when extending, see `astryx docs
|
|
64
|
+
{type: 'prose', text: 'For the integration-specific guidance on mapping a palette to tokens when extending, see `astryx docs authoring/building-blocks/themes/define-the-theme`.'},
|
|
65
65
|
],
|
|
66
66
|
},
|
|
67
67
|
{
|