@astryxdesign/cli 0.6.5-canary.b421f01 → 0.6.5-canary.b65e45f
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/api/build/_adapter.d.mts +14 -0
- package/api/build/_adapter.mjs +58 -1
- package/api/build/build.test.mjs +74 -1
- package/api/build/kit/kit.mjs +39 -7
- package/api/build/kit/rank.d.mts +8 -0
- package/api/build/kit/rank.mjs +14 -0
- 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.type.d.mts +38 -1
- package/api/docs/docs.type.mjs +18 -1
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +146 -23
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-theme.mjs +93 -3
- package/api/integration/add-theme.test.mjs +100 -0
- package/api/integration/integrationAddTheme.doc.mjs +1 -1
- package/api/search/search.d.mts +8 -1
- package/api/search/search.mjs +48 -37
- package/api/search/search.test.mjs +114 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +4 -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/integration-add.doc.mjs +1 -1
- package/clients/cli/commands/search.test.mjs +22 -13
- package/foundation/discovery/theme-discovery.d.mts +6 -0
- package/foundation/discovery/theme-discovery.mjs +9 -0
- package/package.json +9 -9
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
4
|
+
import {execFileSync} from 'node:child_process';
|
|
4
5
|
import * as fs from 'node:fs';
|
|
5
6
|
import * as path from 'node:path';
|
|
7
|
+
import {CLI_ROOT, findInstalledPackage} from '../../foundation/fs/paths.mjs';
|
|
6
8
|
import {integrationAddTheme} from './add-theme.mjs';
|
|
7
9
|
import {validateLocalIntegration} from './validate-integration.mjs';
|
|
8
10
|
|
|
@@ -473,6 +475,104 @@ describe('integrationAddTheme --from', () => {
|
|
|
473
475
|
).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
|
|
474
476
|
});
|
|
475
477
|
|
|
478
|
+
it('declares the npm packages the forked files import, at the range the bundled themes use', async () => {
|
|
479
|
+
setup({includeFiles: false});
|
|
480
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
481
|
+
const pkg = JSON.parse(
|
|
482
|
+
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
483
|
+
);
|
|
484
|
+
const cli = JSON.parse(
|
|
485
|
+
fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
|
|
486
|
+
);
|
|
487
|
+
// The copied icons.tsx imports lucide-react; Core and React are every
|
|
488
|
+
// app's own, so the fork does not declare them.
|
|
489
|
+
expect(pkg.dependencies).toEqual({
|
|
490
|
+
'lucide-react': cli.devDependencies['lucide-react'],
|
|
491
|
+
});
|
|
492
|
+
expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('keeps a dependency the package already declares', async () => {
|
|
496
|
+
setup({includeFiles: false});
|
|
497
|
+
const file = path.join(tmpDir, 'package.json');
|
|
498
|
+
const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
499
|
+
fs.writeFileSync(
|
|
500
|
+
file,
|
|
501
|
+
`${JSON.stringify({...pkg, dependencies: {'lucide-react': '^1.0.0'}}, null, 2)}\n`,
|
|
502
|
+
);
|
|
503
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
504
|
+
expect(JSON.parse(fs.readFileSync(file, 'utf-8')).dependencies).toEqual({
|
|
505
|
+
'lucide-react': '^1.0.0',
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it('declares nothing for a fork of a theme the package owns', async () => {
|
|
510
|
+
setup({includeFiles: false});
|
|
511
|
+
await integrationAddTheme('base', {cwd: tmpDir});
|
|
512
|
+
await integrationAddTheme('variant', {cwd: tmpDir, from: 'base'});
|
|
513
|
+
const pkg = JSON.parse(
|
|
514
|
+
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
515
|
+
);
|
|
516
|
+
expect(pkg.dependencies).toBeUndefined();
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it('builds a forked neutral theme once the package installs what --from declared', async () => {
|
|
520
|
+
setup({includeFiles: false});
|
|
521
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
522
|
+
const pkg = JSON.parse(
|
|
523
|
+
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
524
|
+
);
|
|
525
|
+
// Install exactly what the package declares, plus what every Astryx
|
|
526
|
+
// project has: Core and React.
|
|
527
|
+
for (const name of [
|
|
528
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
529
|
+
'@astryxdesign/core',
|
|
530
|
+
'react',
|
|
531
|
+
]) {
|
|
532
|
+
const installed = findInstalledPackage(CLI_ROOT, name);
|
|
533
|
+
expect(installed, name).not.toBeNull();
|
|
534
|
+
const link = path.join(tmpDir, 'node_modules', ...name.split('/'));
|
|
535
|
+
fs.mkdirSync(path.dirname(link), {recursive: true});
|
|
536
|
+
fs.symlinkSync(
|
|
537
|
+
fs.realpathSync(/** @type {string} */ (installed)),
|
|
538
|
+
link,
|
|
539
|
+
'dir',
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
// A separate process without NODE_PATH, so only what the package
|
|
543
|
+
// installed can resolve.
|
|
544
|
+
let status = 0;
|
|
545
|
+
let output = '';
|
|
546
|
+
try {
|
|
547
|
+
execFileSync(
|
|
548
|
+
process.execPath,
|
|
549
|
+
[
|
|
550
|
+
path.join(CLI_ROOT, 'clients/cli/bin/astryx.mjs'),
|
|
551
|
+
'theme',
|
|
552
|
+
'build',
|
|
553
|
+
'themes/ocean/oceanTheme.ts',
|
|
554
|
+
],
|
|
555
|
+
{
|
|
556
|
+
cwd: tmpDir,
|
|
557
|
+
env: {...process.env, NODE_PATH: ''},
|
|
558
|
+
encoding: 'utf-8',
|
|
559
|
+
stdio: 'pipe',
|
|
560
|
+
},
|
|
561
|
+
);
|
|
562
|
+
} catch (error) {
|
|
563
|
+
const failure = /** @type {any} */ (error);
|
|
564
|
+
status = failure.status ?? 1;
|
|
565
|
+
output = `${failure.stdout ?? ''}${failure.stderr ?? ''}`;
|
|
566
|
+
}
|
|
567
|
+
expect({status, output: status === 0 ? '' : output}).toEqual({
|
|
568
|
+
status: 0,
|
|
569
|
+
output: '',
|
|
570
|
+
});
|
|
571
|
+
expect(fs.existsSync(path.join(tmpDir, 'themes/ocean/ocean.css'))).toBe(
|
|
572
|
+
true,
|
|
573
|
+
);
|
|
574
|
+
});
|
|
575
|
+
|
|
476
576
|
it('works with different bundled themes', async () => {
|
|
477
577
|
setup();
|
|
478
578
|
const result = await integrationAddTheme('dusk', {
|
|
@@ -37,7 +37,7 @@ export const doc = {
|
|
|
37
37
|
name: 'options.from',
|
|
38
38
|
type: 'string',
|
|
39
39
|
description:
|
|
40
|
-
'Slug of an existing theme to fork as the starting point. The new theme copies the base and has no link back.',
|
|
40
|
+
'Slug of an existing theme to fork as the starting point. The new theme copies the base and has no link back, and package.json `dependencies` gains the npm packages the copied files import (other than Core and React).',
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
returns: [
|
package/api/search/search.d.mts
CHANGED
|
@@ -66,6 +66,7 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
66
66
|
* @param {string} term - Lowercased search term.
|
|
67
67
|
* @param {object} candidate
|
|
68
68
|
* @param {string} candidate.name - Primary identifier (component/hook name, topic, template name).
|
|
69
|
+
* @param {string[]} [candidate.aliases] - Other names, scored like the name (a theme's display name).
|
|
69
70
|
* @param {string} [candidate.domain] - A component, hook, or template name
|
|
70
71
|
* also matches typed as words: `command palette` is CommandPalette.
|
|
71
72
|
* @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
|
|
@@ -76,8 +77,9 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
76
77
|
* @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
|
|
77
78
|
* @returns {{score: number, reason: string} | null}
|
|
78
79
|
*/
|
|
79
|
-
export function scoreCandidate(term: string, { name, domain, keywords, weakKeywords, description, prose, guidance, }: {
|
|
80
|
+
export function scoreCandidate(term: string, { name, aliases, domain, keywords, weakKeywords, description, prose, guidance, }: {
|
|
80
81
|
name: string;
|
|
82
|
+
aliases?: string[] | undefined;
|
|
81
83
|
domain?: string | undefined;
|
|
82
84
|
keywords?: string[] | undefined;
|
|
83
85
|
weakKeywords?: string[] | undefined;
|
|
@@ -161,6 +163,11 @@ export const STOPWORDS: Set<string>;
|
|
|
161
163
|
export type Candidate = {
|
|
162
164
|
domain: "component" | "hook" | "doc" | "template" | "theme";
|
|
163
165
|
name: string;
|
|
166
|
+
/**
|
|
167
|
+
* - Other names the candidate answers to, scored
|
|
168
|
+
* with the same name signals: a theme's display name.
|
|
169
|
+
*/
|
|
170
|
+
aliases?: string[] | undefined;
|
|
164
171
|
keywords?: string[] | undefined;
|
|
165
172
|
weakKeywords?: string[] | undefined;
|
|
166
173
|
description?: string | undefined;
|
package/api/search/search.mjs
CHANGED
|
@@ -113,6 +113,8 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
113
113
|
* @typedef {object} Candidate
|
|
114
114
|
* @property {'component'|'hook'|'doc'|'template'|'theme'} domain
|
|
115
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.
|
|
116
118
|
* @property {string[]} [keywords]
|
|
117
119
|
* @property {string[]} [weakKeywords]
|
|
118
120
|
* @property {string} [description]
|
|
@@ -717,6 +719,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
717
719
|
* @param {string} term - Lowercased search term.
|
|
718
720
|
* @param {object} candidate
|
|
719
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).
|
|
720
723
|
* @param {string} [candidate.domain] - A component, hook, or template name
|
|
721
724
|
* also matches typed as words: `command palette` is CommandPalette.
|
|
722
725
|
* @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
|
|
@@ -731,6 +734,7 @@ export function scoreCandidate(
|
|
|
731
734
|
term,
|
|
732
735
|
{
|
|
733
736
|
name,
|
|
737
|
+
aliases = [],
|
|
734
738
|
domain,
|
|
735
739
|
keywords = [],
|
|
736
740
|
weakKeywords = [],
|
|
@@ -753,40 +757,44 @@ export function scoreCandidate(
|
|
|
753
757
|
}
|
|
754
758
|
};
|
|
755
759
|
|
|
756
|
-
const nameLower = name.toLowerCase();
|
|
757
|
-
// A placed guide's name is its route, and the route's last segment is its
|
|
758
|
-
// name too, as a flat topic's is: `codemods` is cli/integrations/codemods.
|
|
759
|
-
const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
|
|
760
|
-
|
|
761
760
|
// ── Name signals ────────────────────────────────────────────────
|
|
762
|
-
//
|
|
763
|
-
//
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
//
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
);
|
|
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
|
+
}
|
|
790
798
|
}
|
|
791
799
|
}
|
|
792
800
|
}
|
|
@@ -1487,6 +1495,12 @@ async function gatherTemplates(cwd) {
|
|
|
1487
1495
|
* Build theme candidates from bundled and integration-provided themes. Without
|
|
1488
1496
|
* this, an integration's themes are invisible to `search` even though
|
|
1489
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.
|
|
1490
1504
|
* @param {string} cwd
|
|
1491
1505
|
* @returns {Promise<Candidate[]>}
|
|
1492
1506
|
*/
|
|
@@ -1500,10 +1514,7 @@ async function gatherThemes(cwd) {
|
|
|
1500
1514
|
return themes.map(t => ({
|
|
1501
1515
|
domain: 'theme',
|
|
1502
1516
|
name: t.slug,
|
|
1503
|
-
|
|
1504
|
-
t.displayName,
|
|
1505
|
-
...(t.description ? t.description.split(/[^A-Za-z0-9]+/).filter(w => w.length > 3) : []),
|
|
1506
|
-
],
|
|
1517
|
+
aliases: t.displayName ? [t.displayName] : [],
|
|
1507
1518
|
description: t.description || '',
|
|
1508
1519
|
_displayName: t.displayName,
|
|
1509
1520
|
_package: t.package,
|
|
@@ -25,6 +25,8 @@ import * as os from 'node:os';
|
|
|
25
25
|
import * as path from 'node:path';
|
|
26
26
|
import {fileURLToPath} from 'node:url';
|
|
27
27
|
import {docs} from '../docs/docs.mjs';
|
|
28
|
+
import {listAvailableThemes} from '../theme/_adapter.mjs';
|
|
29
|
+
import {doc as themeAddCommandDoc} from '../../clients/cli/commands/theme-add.doc.mjs';
|
|
28
30
|
import {
|
|
29
31
|
headingWithPhrase,
|
|
30
32
|
titleInQuery,
|
|
@@ -76,7 +78,10 @@ describe('search leaf — envelope + ranking', () => {
|
|
|
76
78
|
|
|
77
79
|
describe('search leaf — per-domain result fields', () => {
|
|
78
80
|
it('carries import for components and hooks, title for docs, displayName and kind for templates, displayName for themes', async () => {
|
|
79
|
-
|
|
81
|
+
// `theme` reaches every domain, but a theme matches it only through its
|
|
82
|
+
// description, a prose mention below every name and keyword hit, so read
|
|
83
|
+
// the whole result list.
|
|
84
|
+
const r = await search('theme', {cwd, limit: 400});
|
|
80
85
|
expect(new Set(r.data.results.map(res => res.domain))).toEqual(
|
|
81
86
|
new Set(SEARCH_DOMAINS),
|
|
82
87
|
);
|
|
@@ -499,6 +504,114 @@ describe('search leaf — limit validation (API matches the CLI contract)', () =
|
|
|
499
504
|
}, SLOW);
|
|
500
505
|
});
|
|
501
506
|
|
|
507
|
+
describe('search leaf — a theme is found by its names; its description is prose (AST-050 FR14)', () => {
|
|
508
|
+
/** A result that answers the query by a name or a declared keyword, not a typo or a mention. */
|
|
509
|
+
const matchesByNameOrKeyword = (/** @type {{reason: string}} */ result) =>
|
|
510
|
+
/^(exact name|plural of the name|name "|name contains ")/.test(result.reason) ||
|
|
511
|
+
/^keyword "[^"]*"$/.test(result.reason);
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* The `theme add` command AST-050 FR12 and FR13 name for the stage that
|
|
515
|
+
* `theme add` itself declares: no `--import` yet, a deprecated copy default
|
|
516
|
+
* beside `--import`, or the cleanup, which keeps `--import` and drops the
|
|
517
|
+
* copy's `--overwrite`.
|
|
518
|
+
* @param {string} slug
|
|
519
|
+
*/
|
|
520
|
+
function themeAddCommandForStage(slug) {
|
|
521
|
+
const flags = themeAddCommandDoc.options.flatMap(option => option.flag.split(/[\s,]+/));
|
|
522
|
+
if (!flags.includes('--import')) return `astryx theme add ${slug}`;
|
|
523
|
+
if (flags.includes('--overwrite')) return `astryx theme add --import ${slug}`;
|
|
524
|
+
return `astryx theme add ${slug}`;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
it(
|
|
528
|
+
'ranks a theme found only through its description below every name and keyword match',
|
|
529
|
+
async () => {
|
|
530
|
+
for (const [query, slugs] of [
|
|
531
|
+
['focus', ['neutral']],
|
|
532
|
+
['content', ['matcha', 'neutral']],
|
|
533
|
+
]) {
|
|
534
|
+
const {results} = (await search(query, {cwd, limit: 400})).data;
|
|
535
|
+
const strong = results.filter(
|
|
536
|
+
result => result.domain !== 'theme' && matchesByNameOrKeyword(result),
|
|
537
|
+
);
|
|
538
|
+
expect(strong.length).toBeGreaterThan(0);
|
|
539
|
+
const lastStrong = Math.max(...strong.map(result => results.indexOf(result)));
|
|
540
|
+
for (const slug of slugs) {
|
|
541
|
+
const at = results.findIndex(result => result.domain === 'theme' && result.name === slug);
|
|
542
|
+
expect(at).toBeGreaterThan(-1);
|
|
543
|
+
expect(results[at].reason).toMatch(/^description mentions /);
|
|
544
|
+
expect(at).toBeGreaterThan(lastStrong);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
SLOW,
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
it(
|
|
552
|
+
'scores a word in a theme description the same as a word in a component description',
|
|
553
|
+
async () => {
|
|
554
|
+
const {results} = (await search('minimal', {cwd, limit: 400})).data;
|
|
555
|
+
const neutral = results.find(result => result.domain === 'theme' && result.name === 'neutral');
|
|
556
|
+
const topNav = results.find(result => result.domain === 'component' && result.name === 'TopNav');
|
|
557
|
+
expect(neutral?.reason).toMatch(/^description mentions /);
|
|
558
|
+
expect(topNav?.reason).toMatch(/^description mentions /);
|
|
559
|
+
expect(neutral?.score).toBe(topNav?.score);
|
|
560
|
+
},
|
|
561
|
+
SLOW,
|
|
562
|
+
);
|
|
563
|
+
|
|
564
|
+
it(
|
|
565
|
+
'keeps a theme that matches every word only in its description below results with a keyword hit',
|
|
566
|
+
async () => {
|
|
567
|
+
// Overlay and Dialog declare `focus` and mention `content`; neutral only
|
|
568
|
+
// mentions both, in "so the content stays the focus".
|
|
569
|
+
const {results} = (await search('content focus', {cwd, limit: 400})).data;
|
|
570
|
+
const neutral = results.findIndex(result => result.domain === 'theme' && result.name === 'neutral');
|
|
571
|
+
expect(neutral).toBeGreaterThan(-1);
|
|
572
|
+
for (const name of ['Overlay', 'Dialog']) {
|
|
573
|
+
const at = results.findIndex(result => result.domain === 'component' && result.name === name);
|
|
574
|
+
expect(at).toBeGreaterThan(-1);
|
|
575
|
+
expect(at).toBeLessThan(neutral);
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
SLOW,
|
|
579
|
+
);
|
|
580
|
+
|
|
581
|
+
it(
|
|
582
|
+
'still finds a theme first by its slug or its display name',
|
|
583
|
+
async () => {
|
|
584
|
+
for (const query of ['neutral', 'Matcha', 'Y2K']) {
|
|
585
|
+
const [first] = (await search(query, {cwd})).data.results;
|
|
586
|
+
expect(first).toMatchObject({domain: 'theme', name: query.toLowerCase(), reason: 'exact name'});
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
SLOW,
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
it('scores a display name with the same name signals as the slug', () => {
|
|
593
|
+
const theme = {name: 'ocean', aliases: ['Ocean Blue'], description: 'Deep blues for calm reading.'};
|
|
594
|
+
expect(scoreCandidate('ocean blue', theme)).toEqual(scoreCandidate('ocean', theme));
|
|
595
|
+
expect(scoreCandidate('ocean blue', {...theme, aliases: []})?.score ?? 0).toBeLessThan(
|
|
596
|
+
scoreCandidate('ocean', theme).score,
|
|
597
|
+
);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it(
|
|
601
|
+
'names the theme add command for the stage theme add declares',
|
|
602
|
+
async () => {
|
|
603
|
+
const themes = await listAvailableThemes(cwd);
|
|
604
|
+
expect(themes.length).toBeGreaterThan(0);
|
|
605
|
+
for (const {slug} of themes) {
|
|
606
|
+
const {results} = (await search(slug, {cwd, type: 'theme'})).data;
|
|
607
|
+
const result = results.find(entry => entry.name === slug);
|
|
608
|
+
expect(result?.command).toBe(themeAddCommandForStage(slug));
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
SLOW,
|
|
612
|
+
);
|
|
613
|
+
});
|
|
614
|
+
|
|
502
615
|
describe('search leaf — integration components', () => {
|
|
503
616
|
/**
|
|
504
617
|
* A minimal consumer project: a stub `@astryxdesign/core` (so `findCoreDir`
|
|
@@ -65,6 +65,10 @@ Declare theme root ./themes in astryx.integration.mjs.
|
|
|
65
65
|
lang: 'bash',
|
|
66
66
|
code: 'npx astryx integration add theme ocean --from neutral',
|
|
67
67
|
},
|
|
68
|
+
{
|
|
69
|
+
type: 'prose',
|
|
70
|
+
text: 'The copy keeps the packages the base theme uses, such as `lucide-react` for its icons: `--from` adds them to your `dependencies`, so an app that installs your package gets them too. Install your dependencies again before you build the theme.',
|
|
71
|
+
},
|
|
68
72
|
{
|
|
69
73
|
type: 'prose',
|
|
70
74
|
text: 'Use `--from` when you want to change a lot. For a small change that should stay linked to a base theme, use `extends` instead ({@link generic:define-the-theme}).',
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
6
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
7
|
+
|
|
8
|
+
const SLOW = 60_000;
|
|
9
|
+
|
|
10
|
+
/** @type {string} */
|
|
11
|
+
let tmpDir;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-docs-depth-test-'));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/** An app with an integration that places one guide under its namespace. */
|
|
22
|
+
function scaffoldGuide() {
|
|
23
|
+
fs.writeFileSync(
|
|
24
|
+
path.join(tmpDir, 'package.json'),
|
|
25
|
+
JSON.stringify({name: 'consumer'}),
|
|
26
|
+
);
|
|
27
|
+
fs.writeFileSync(
|
|
28
|
+
path.join(tmpDir, 'astryx.config.mjs'),
|
|
29
|
+
"export default {integrations: ['@acme/kit']};\n",
|
|
30
|
+
);
|
|
31
|
+
const packageDir = path.join(tmpDir, 'node_modules', '@acme', 'kit');
|
|
32
|
+
fs.mkdirSync(path.join(packageDir, 'docs'), {recursive: true});
|
|
33
|
+
fs.writeFileSync(
|
|
34
|
+
path.join(packageDir, 'package.json'),
|
|
35
|
+
JSON.stringify({name: '@acme/kit', version: '1.0.0'}),
|
|
36
|
+
);
|
|
37
|
+
fs.writeFileSync(
|
|
38
|
+
path.join(packageDir, 'astryx.integration.mjs'),
|
|
39
|
+
"export default {docs: './docs'};\n",
|
|
40
|
+
);
|
|
41
|
+
const namespace = {
|
|
42
|
+
type: 'namespace',
|
|
43
|
+
name: 'acme',
|
|
44
|
+
title: 'Acme docs',
|
|
45
|
+
summary: 'Build with the Acme kit.',
|
|
46
|
+
slots: {guides: {title: 'Guides', accepts: {kinds: ['generic']}}},
|
|
47
|
+
};
|
|
48
|
+
const guide = {
|
|
49
|
+
type: 'generic',
|
|
50
|
+
name: 'themes',
|
|
51
|
+
title: 'Theme building',
|
|
52
|
+
description: 'Build an Acme theme.',
|
|
53
|
+
placement: {parent: 'namespace:acme', slot: 'guides'},
|
|
54
|
+
sections: [
|
|
55
|
+
{
|
|
56
|
+
title: 'Create the theme',
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: 'prose',
|
|
60
|
+
text: 'Child guide body marker: compile the ocean palette.',
|
|
61
|
+
},
|
|
62
|
+
{type: 'code', lang: 'bash', code: 'npx acme theme build ocean'},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
for (const [file, doc] of [
|
|
68
|
+
['acme.doc.mjs', namespace],
|
|
69
|
+
['themes.doc.mjs', guide],
|
|
70
|
+
]) {
|
|
71
|
+
fs.writeFileSync(
|
|
72
|
+
path.join(packageDir, 'docs', file),
|
|
73
|
+
`export const docs = ${JSON.stringify(doc, null, 2)};\n`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
describe('astryx docs --depth', () => {
|
|
79
|
+
it(
|
|
80
|
+
'lists every doc below a namespace, one line each, by where it sits',
|
|
81
|
+
async () => {
|
|
82
|
+
const result = await runCli(['docs', 'cli/api', '--depth', 'all']);
|
|
83
|
+
expect(result.status).toBe(0);
|
|
84
|
+
expect(result.stdout).toMatch(/^functions\s+\S/m);
|
|
85
|
+
expect(result.stdout).toMatch(/^functions\/search\s+search\(\): /m);
|
|
86
|
+
expect(result.stdout).toContain('Open one: ');
|
|
87
|
+
expect(result.stdout).toContain('docs cli/api/<name>');
|
|
88
|
+
// One line each: no doc's body.
|
|
89
|
+
expect(result.stdout).not.toContain('`astryx search` runs it.');
|
|
90
|
+
},
|
|
91
|
+
SLOW,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
it(
|
|
95
|
+
'says how many docs sit below where the read stops',
|
|
96
|
+
async () => {
|
|
97
|
+
const zero = await runCli(['docs', 'cli/api', '--depth', '0']);
|
|
98
|
+
expect(zero.status).toBe(0);
|
|
99
|
+
expect(zero.stdout).toMatch(
|
|
100
|
+
/^\d+ docs below\. Read them: .*docs cli\/api --depth 1$/m,
|
|
101
|
+
);
|
|
102
|
+
expect(zero.stdout).not.toMatch(/^functions\s/m);
|
|
103
|
+
|
|
104
|
+
const one = await runCli(['docs', 'cli/api', '--depth', '1']);
|
|
105
|
+
expect(one.status).toBe(0);
|
|
106
|
+
expect(one.stdout).toMatch(/^functions\s+.*\(\d+ docs below\)$/m);
|
|
107
|
+
expect(one.stdout).not.toMatch(/^functions\/search\s/m);
|
|
108
|
+
},
|
|
109
|
+
SLOW,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
it(
|
|
113
|
+
'prints each doc below whole with --detail full, and drops code at compact',
|
|
114
|
+
async () => {
|
|
115
|
+
scaffoldGuide();
|
|
116
|
+
const full = await runCli(
|
|
117
|
+
['docs', 'acme', '--depth', 'all', '--detail', 'full'],
|
|
118
|
+
tmpDir,
|
|
119
|
+
);
|
|
120
|
+
expect(full.status).toBe(0);
|
|
121
|
+
expect(full.stdout).toMatch(/^## Theme building \(themes\)$/m);
|
|
122
|
+
expect(full.stdout).toMatch(/^### Create the theme$/m);
|
|
123
|
+
expect(full.stdout).toContain(
|
|
124
|
+
'Child guide body marker: compile the ocean palette.',
|
|
125
|
+
);
|
|
126
|
+
expect(full.stdout).toContain('npx acme theme build ocean');
|
|
127
|
+
|
|
128
|
+
const compact = await runCli(
|
|
129
|
+
['docs', 'acme', '--depth', '1', '--detail', 'compact'],
|
|
130
|
+
tmpDir,
|
|
131
|
+
);
|
|
132
|
+
expect(compact.status).toBe(0);
|
|
133
|
+
expect(compact.stdout).toContain('Child guide body marker');
|
|
134
|
+
expect(compact.stdout).not.toContain('npx acme theme build ocean');
|
|
135
|
+
|
|
136
|
+
// Without --depth, the namespace still lists the guide by one line.
|
|
137
|
+
const plain = await runCli(['docs', 'acme'], tmpDir);
|
|
138
|
+
expect(plain.status).toBe(0);
|
|
139
|
+
expect(plain.stdout).toMatch(/^themes\s+Build an Acme theme\./m);
|
|
140
|
+
expect(plain.stdout).not.toContain('Child guide body marker');
|
|
141
|
+
},
|
|
142
|
+
SLOW,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
it(
|
|
146
|
+
'returns the same tree as JSON, with text only when --detail asks',
|
|
147
|
+
async () => {
|
|
148
|
+
const brief = await runCli(['--json', 'docs', 'cli/api', '--depth', '2']);
|
|
149
|
+
expect(brief.status).toBe(0);
|
|
150
|
+
const briefData = JSON.parse(brief.stdout);
|
|
151
|
+
expect(briefData.type).toBe('docs.node');
|
|
152
|
+
const functions = briefData.data.slots
|
|
153
|
+
.flatMap((/** @type {any} */ slot) => slot.children)
|
|
154
|
+
.find(
|
|
155
|
+
(/** @type {any} */ child) => child.route === 'cli/api/functions',
|
|
156
|
+
);
|
|
157
|
+
const search = functions.slots
|
|
158
|
+
.flatMap((/** @type {any} */ slot) => slot.children)
|
|
159
|
+
.find(
|
|
160
|
+
(/** @type {any} */ child) =>
|
|
161
|
+
child.route === 'cli/api/functions/search',
|
|
162
|
+
);
|
|
163
|
+
expect(search).not.toHaveProperty('content');
|
|
164
|
+
|
|
165
|
+
const full = await runCli([
|
|
166
|
+
'--json',
|
|
167
|
+
'docs',
|
|
168
|
+
'cli/api',
|
|
169
|
+
'--depth',
|
|
170
|
+
'2',
|
|
171
|
+
'--detail',
|
|
172
|
+
'full',
|
|
173
|
+
]);
|
|
174
|
+
expect(full.status).toBe(0);
|
|
175
|
+
expect(full.stdout).toContain('`astryx search` runs it.');
|
|
176
|
+
},
|
|
177
|
+
SLOW,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
it(
|
|
181
|
+
'composes with --index and --full, and leaves a topic read as it was',
|
|
182
|
+
async () => {
|
|
183
|
+
const depth = await runCli(['docs', 'cli/api', '--depth', '1']);
|
|
184
|
+
expect(depth.status).toBe(0);
|
|
185
|
+
for (const flag of ['--index', '--full']) {
|
|
186
|
+
const both = await runCli(['docs', 'cli/api', '--depth', '1', flag]);
|
|
187
|
+
expect(both.status).toBe(0);
|
|
188
|
+
expect(both.stdout).toBe(depth.stdout);
|
|
189
|
+
}
|
|
190
|
+
for (const args of [
|
|
191
|
+
['docs', 'theme'],
|
|
192
|
+
['docs', 'theme', '--index'],
|
|
193
|
+
['docs', 'theme', '--full'],
|
|
194
|
+
]) {
|
|
195
|
+
const plain = await runCli(args);
|
|
196
|
+
const withDepth = await runCli([...args, '--depth', '2']);
|
|
197
|
+
expect(withDepth.status).toBe(plain.status);
|
|
198
|
+
expect(withDepth.stdout).toBe(plain.stdout);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
SLOW,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
it(
|
|
205
|
+
'refuses a depth that is not a number of levels',
|
|
206
|
+
async () => {
|
|
207
|
+
const result = await runCli([
|
|
208
|
+
'--json',
|
|
209
|
+
'docs',
|
|
210
|
+
'cli/api',
|
|
211
|
+
'--depth',
|
|
212
|
+
'deep',
|
|
213
|
+
]);
|
|
214
|
+
expect(result.status).toBe(1);
|
|
215
|
+
expect(JSON.parse(result.stdout).code).toBe('ERR_INVALID_ARGUMENT');
|
|
216
|
+
},
|
|
217
|
+
SLOW,
|
|
218
|
+
);
|
|
219
|
+
});
|