@astryxdesign/cli 0.6.5 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/README.md +16 -15
- package/api/build/_adapter.d.mts +50 -2
- package/api/build/_adapter.mjs +98 -10
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +111 -2
- package/api/build/kit/kit.mjs +98 -22
- package/api/build/kit/rank.d.mts +32 -8
- package/api/build/kit/rank.mjs +291 -97
- package/api/build/kit/rank.test.mjs +231 -48
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +132 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +44 -1
- package/api/docs/docs.test.mjs +279 -0
- package/api/docs/docs.type.d.mts +38 -1
- package/api/docs/docs.type.mjs +18 -1
- package/api/docs/integration-tree.test.mjs +572 -0
- package/api/docs/integrationDocs.test.mjs +336 -0
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +146 -23
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/gap-report/gap-report.d.mts +3 -1
- package/api/gap-report/gap-report.mjs +12 -2
- package/api/gap-report/gap-report.test.mjs +106 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-theme.mjs +338 -26
- package/api/integration/add-theme.test.mjs +314 -1
- package/api/integration/authoring-checks.mjs +10 -7
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +12 -3
- package/api/integration/pack-check.test.mjs +52 -3
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +36 -5
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +194 -54
- package/api/search/search.test.mjs +825 -0
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/api/swizzle/copy/copy.mjs +66 -3
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/template/copy/copy.mjs +14 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +15 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/template-integration.test.mjs +14 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +381 -77
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +1 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/docs/theme.doc.mjs +3 -2
- package/assets/docs/tokens.doc.mjs +3 -3
- package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
- package/assets/docs/tree/versioning.doc.mjs +7 -6
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
- package/assets/templates/pages/blank/template.doc.mjs +3 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
- package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
- package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
- package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
- package/assets/templates/pages/documentation/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
- package/assets/templates/pages/editor/template.doc.mjs +9 -1
- package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
- package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
- package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
- package/assets/templates/pages/ide/template.doc.mjs +9 -1
- package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
- package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
- package/assets/templates/pages/library/template.doc.mjs +15 -1
- package/assets/templates/pages/login/template.doc.mjs +10 -1
- package/assets/templates/pages/login-card/template.doc.mjs +11 -1
- package/assets/templates/pages/login-split/template.doc.mjs +10 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
- package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
- package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/settings/template.doc.mjs +3 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/table/template.doc.mjs +11 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
- package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
- package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
- package/assets/templates/pages/table-page/template.doc.mjs +20 -1
- package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
- package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +1 -0
- package/authoring/doctypes/template/parse.test.mjs +21 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +10 -0
- package/clients/cli/commands/build-theme.mjs +8 -2
- package/clients/cli/commands/discover.mjs +29 -1
- package/clients/cli/commands/discover.no-source.test.mjs +75 -0
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +222 -5
- package/clients/cli/commands/docs.test.mjs +383 -0
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/gap-report.mjs +12 -0
- package/clients/cli/commands/gap-report.test.mjs +63 -0
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/search.doc.mjs +5 -4
- package/clients/cli/commands/search.mjs +30 -6
- package/clients/cli/commands/search.test.mjs +60 -16
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +19 -5
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +41 -0
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/foundation/agent-docs/agent-docs.mjs +2 -1
- package/foundation/agent-docs/agent-docs.test.mjs +1168 -0
- package/foundation/discovery/template-adapter.d.mts +14 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +21 -1
- package/foundation/discovery/theme-discovery.d.mts +6 -0
- package/foundation/discovery/theme-discovery.mjs +9 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/foundation/integrations/cli-requirement.d.mts +57 -13
- package/foundation/integrations/cli-requirement.mjs +84 -22
- package/foundation/integrations/cli-requirement.test.mjs +135 -8
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx discover` when no discover source is configured and no
|
|
5
|
+
* integration provides one.
|
|
6
|
+
*
|
|
7
|
+
* In a fresh public app with no integrations, `discover --available` used to
|
|
8
|
+
* print "No integrations configured. Add integration package names..." — a
|
|
9
|
+
* message that told users to add names they had no way to find. These tests
|
|
10
|
+
* pin the honest replacement.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
14
|
+
import * as fs from 'node:fs';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import * as os from 'node:os';
|
|
17
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
18
|
+
|
|
19
|
+
let tmpDir;
|
|
20
|
+
let project;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-discover-nosource-'));
|
|
24
|
+
project = path.join(tmpDir, 'project');
|
|
25
|
+
fs.mkdirSync(project, {recursive: true});
|
|
26
|
+
fs.writeFileSync(
|
|
27
|
+
path.join(project, 'package.json'),
|
|
28
|
+
JSON.stringify({name: 'my-app', version: '1.0.0'}),
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('astryx discover --available with no source', () => {
|
|
37
|
+
it('explains what discover sources are and where to find packages', async () => {
|
|
38
|
+
const {status, stdout} = await runCli(['discover', '--available'], {
|
|
39
|
+
cwd: project,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(status).toBe(0);
|
|
43
|
+
expect(stdout).toContain('No discover source is configured.');
|
|
44
|
+
expect(stdout).toContain('discover sources');
|
|
45
|
+
expect(stdout).toContain('npm search @astryxdesign');
|
|
46
|
+
expect(stdout).toContain('docs cli/integrations');
|
|
47
|
+
// Must not show the old misleading message
|
|
48
|
+
expect(stdout).not.toContain('Add integration package names');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('returns an empty list with configured=false in --json', async () => {
|
|
52
|
+
const {status, stdout} = await runCli(
|
|
53
|
+
['discover', '--available', '--json'],
|
|
54
|
+
{cwd: project},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(status).toBe(0);
|
|
58
|
+
const result = JSON.parse(stdout);
|
|
59
|
+
expect(result.type).toBe('discover.list');
|
|
60
|
+
expect(result.data).toEqual([]);
|
|
61
|
+
expect(result.meta).toEqual({configured: false});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('astryx discover with nothing configured', () => {
|
|
66
|
+
it('shows the config snippet and a pointer to npm and docs', async () => {
|
|
67
|
+
const {status, stdout} = await runCli(['discover'], {cwd: project});
|
|
68
|
+
|
|
69
|
+
expect(status).toBe(0);
|
|
70
|
+
expect(stdout).toContain('No integrations configured.');
|
|
71
|
+
expect(stdout).toContain("integrations: ['@scope/your-integration']");
|
|
72
|
+
expect(stdout).toContain('npm search @astryxdesign');
|
|
73
|
+
expect(stdout).toContain('docs cli/integrations');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -22,7 +22,9 @@ export const doc = {
|
|
|
22
22
|
'does, and `--index` its section index. A route ' +
|
|
23
23
|
'opens a node of the docs tree: `cli` lists its guides and reference, ' +
|
|
24
24
|
'`cli/api/functions` lists every API function, and `cli/api/functions/search` prints ' +
|
|
25
|
-
'one.'
|
|
25
|
+
'one. `--depth` reads as far down the tree as you ask, from the doc alone (0) to ' +
|
|
26
|
+
'everything below it (all), and with it `--detail` sets how much of each doc below ' +
|
|
27
|
+
'shows: one line (brief, the default), its sections (compact), or all of it (full).',
|
|
26
28
|
fn: 'docs',
|
|
27
29
|
args: [
|
|
28
30
|
{name: 'topic', param: 'topic', required: false},
|
|
@@ -39,6 +41,12 @@ export const doc = {
|
|
|
39
41
|
description:
|
|
40
42
|
'Print the whole topic instead of its sections (text; `--json` returns the whole topic unless --index). Cannot be set with --index',
|
|
41
43
|
},
|
|
44
|
+
{
|
|
45
|
+
flag: '--depth <levels>',
|
|
46
|
+
param: 'options.depth',
|
|
47
|
+
description:
|
|
48
|
+
'How many levels of the docs tree to read below a namespace: 0 for the namespace alone, 1 for its children (what a read without --depth shows), all for everything below it. With it, --detail sets how much of each doc below shows: brief (one line each, the default), compact (with its sections), or full',
|
|
49
|
+
},
|
|
42
50
|
],
|
|
43
51
|
examples: [
|
|
44
52
|
{label: 'List topics', cli: 'astryx docs'},
|
|
@@ -46,6 +54,11 @@ export const doc = {
|
|
|
46
54
|
{label: 'A whole topic as JSON', cli: 'astryx docs spacing --json'},
|
|
47
55
|
{label: 'One section', cli: 'astryx docs theme quick-start'},
|
|
48
56
|
{label: 'The CLI docs tree', cli: 'astryx docs cli'},
|
|
57
|
+
{label: 'Every CLI doc, one line each', cli: 'astryx docs cli --depth all'},
|
|
58
|
+
{
|
|
59
|
+
label: 'The integration guides as one read',
|
|
60
|
+
cli: 'astryx docs cli/integrations --depth all --detail full',
|
|
61
|
+
},
|
|
49
62
|
{label: 'One API function', cli: 'astryx docs cli/api/functions/search'},
|
|
50
63
|
{label: 'A whole guide', cli: 'astryx docs cli/integrations/quick-start --full'},
|
|
51
64
|
],
|
|
@@ -53,7 +66,7 @@ export const doc = {
|
|
|
53
66
|
{code: 0, when: 'success'},
|
|
54
67
|
{
|
|
55
68
|
code: 1,
|
|
56
|
-
when: 'unknown topic or route,
|
|
69
|
+
when: 'unknown topic or route, a section that matches no section or more than one, or a --depth that is not a number of levels or all',
|
|
57
70
|
},
|
|
58
71
|
],
|
|
59
72
|
related: ['search', 'component', 'hook', 'template'],
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* @file docs command — Print Astryx reference docs
|
|
5
5
|
*
|
|
6
6
|
* In text, every read is one level: a topic lists its sections, so a reader can
|
|
7
|
-
* open one section by its key, and `--full` prints the whole topic. `--
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* open one section by its key, and `--full` prints the whole topic. `--depth`
|
|
8
|
+
* reads a docs-tree namespace as many levels down as asked, each doc below it
|
|
9
|
+
* at --detail (brief by default: one line each). `--json` keeps the docs()
|
|
10
|
+
* contract: a topic returns its whole doc, and `--index` its sections.
|
|
10
11
|
* Supports --detail (full|compact|brief) and --lang (en|zh|dense). A code
|
|
11
12
|
* block's label prints above its fence, and table cells escape their pipes.
|
|
12
13
|
*
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
* astryx docs <topic> --full Print the whole topic
|
|
19
20
|
* astryx docs <route> Open a node of the docs tree, such as
|
|
20
21
|
* cli, cli/api, or cli/api/functions/search
|
|
22
|
+
* astryx docs <route> --depth <n|all> Read that many levels below it
|
|
21
23
|
*/
|
|
22
24
|
|
|
23
25
|
import {
|
|
@@ -181,6 +183,202 @@ function formatReferenceFull(docs, detail) {
|
|
|
181
183
|
return `${header}\n\n${sections.join(sep)}`;
|
|
182
184
|
}
|
|
183
185
|
|
|
186
|
+
/**
|
|
187
|
+
* @param {string} title
|
|
188
|
+
* @param {number} level
|
|
189
|
+
* @returns {string}
|
|
190
|
+
*/
|
|
191
|
+
function treeHeading(title, level) {
|
|
192
|
+
return `${'#'.repeat(Math.max(1, Math.min(6, level)))} ${title}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* A doc's blocks at one depth: its headings move down with it.
|
|
197
|
+
* @param {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} blocks
|
|
198
|
+
* @param {'full' | 'compact' | 'brief'} detail
|
|
199
|
+
* @param {number} headingOffset
|
|
200
|
+
* @returns {string[]}
|
|
201
|
+
*/
|
|
202
|
+
function formatTreeBlocks(blocks, detail, headingOffset) {
|
|
203
|
+
/** @type {string[]} */
|
|
204
|
+
const formatted = [];
|
|
205
|
+
for (const block of blocks) {
|
|
206
|
+
const value =
|
|
207
|
+
block.type === 'heading'
|
|
208
|
+
? treeHeading(block.text, (block.level || 3) + headingOffset)
|
|
209
|
+
: formatBlock(block, detail);
|
|
210
|
+
if (value) formatted.push(value);
|
|
211
|
+
}
|
|
212
|
+
return formatted;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @param {import('../../../api/docs/docs.type.mjs').DocsReadSection} docSection
|
|
217
|
+
* @param {'full' | 'compact' | 'brief'} detail
|
|
218
|
+
* @param {number} headingLevel
|
|
219
|
+
* @returns {string}
|
|
220
|
+
*/
|
|
221
|
+
function formatTreeSection(docSection, detail, headingLevel) {
|
|
222
|
+
const heading = treeHeading(docSection.title, headingLevel);
|
|
223
|
+
const blocks = formatTreeBlocks(docSection.content, detail, headingLevel - 2);
|
|
224
|
+
return blocks.length > 0 ? `${heading}\n\n${blocks.join('\n\n')}` : heading;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Where a route sits below the namespace a read names.
|
|
229
|
+
* @param {string} route
|
|
230
|
+
* @param {string} root
|
|
231
|
+
* @returns {string}
|
|
232
|
+
*/
|
|
233
|
+
function belowRoot(route, root) {
|
|
234
|
+
return route.startsWith(`${root}/`) ? route.slice(root.length + 1) : route;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @param {number} count
|
|
239
|
+
* @returns {string}
|
|
240
|
+
*/
|
|
241
|
+
function docsBelow(count) {
|
|
242
|
+
return `${count} ${count === 1 ? 'doc' : 'docs'} below`;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Every child of a depth read, one row each in reading order, named by where
|
|
247
|
+
* it sits below the read's namespace.
|
|
248
|
+
* @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild[]} children
|
|
249
|
+
* @param {string} root
|
|
250
|
+
* @returns {{name: string, summary: string}[]}
|
|
251
|
+
*/
|
|
252
|
+
function treeRows(children, root) {
|
|
253
|
+
return children.flatMap(child => [
|
|
254
|
+
{
|
|
255
|
+
name: belowRoot(child.route, root),
|
|
256
|
+
summary: child.childCount
|
|
257
|
+
? `${childRow(child).summary} (${docsBelow(child.childCount)})`
|
|
258
|
+
: childRow(child).summary,
|
|
259
|
+
},
|
|
260
|
+
...(child.slots ?? []).flatMap(slot => treeRows(slot.children, root)),
|
|
261
|
+
]);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* One child of a depth read with its text, under a heading for its level, and
|
|
266
|
+
* its own children below it.
|
|
267
|
+
* @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild} child
|
|
268
|
+
* @param {'full' | 'compact'} detail
|
|
269
|
+
* @param {number} level
|
|
270
|
+
* @param {string} root
|
|
271
|
+
* @param {string} run
|
|
272
|
+
* @returns {string}
|
|
273
|
+
*/
|
|
274
|
+
function formatTreeChild(child, detail, level, root, run) {
|
|
275
|
+
const parts = [
|
|
276
|
+
`${treeHeading(child.title, level)} (${belowRoot(child.route, root)})`,
|
|
277
|
+
];
|
|
278
|
+
if (
|
|
279
|
+
child.summary &&
|
|
280
|
+
(child.kind === 'namespace' || child.kind === 'generic')
|
|
281
|
+
) {
|
|
282
|
+
parts.push(child.summary);
|
|
283
|
+
}
|
|
284
|
+
const content = formatTreeBlocks(child.content ?? [], detail, level - 2);
|
|
285
|
+
if (content.length > 0) parts.push(content.join('\n\n'));
|
|
286
|
+
parts.push(
|
|
287
|
+
...(child.sections ?? []).map(docSection =>
|
|
288
|
+
formatTreeSection(docSection, detail, level + 1),
|
|
289
|
+
),
|
|
290
|
+
);
|
|
291
|
+
if (child.childCount) {
|
|
292
|
+
parts.push(
|
|
293
|
+
`${docsBelow(child.childCount)}: ${run} docs ${child.route} --depth 1`,
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
for (const slot of child.slots ?? []) {
|
|
297
|
+
parts.push(
|
|
298
|
+
...slot.children.map(each =>
|
|
299
|
+
formatTreeChild(each, detail, level + 1, root, run),
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return parts.join('\n\n');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* A depth read of a namespace: its intro, then each slot's docs as deep as
|
|
308
|
+
* asked, one line each (brief) or with their text (compact, full). A typed doc
|
|
309
|
+
* has nothing below it, so it reads as it always does.
|
|
310
|
+
* @param {import('../../../api/docs/docs.type.mjs').DocsNode} node
|
|
311
|
+
* @param {'full' | 'compact' | 'brief'} detail how the named node reads
|
|
312
|
+
* @param {'full' | 'compact' | 'brief'} childDetail how each doc below reads
|
|
313
|
+
* @param {string} run
|
|
314
|
+
*/
|
|
315
|
+
function emitTree(node, detail, childDetail, run) {
|
|
316
|
+
if (node.kind !== 'namespace') {
|
|
317
|
+
emitNode(node, detail, run);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild[]} children
|
|
322
|
+
* @returns {string[]}
|
|
323
|
+
*/
|
|
324
|
+
const routes = children =>
|
|
325
|
+
children.flatMap(child => [
|
|
326
|
+
child.route,
|
|
327
|
+
...(child.slots ?? []).flatMap(slot => routes(slot.children)),
|
|
328
|
+
]);
|
|
329
|
+
const allBelow = node.slots
|
|
330
|
+
.flatMap(slot => routes(slot.children))
|
|
331
|
+
.every(route => route.startsWith(`${node.route}/`));
|
|
332
|
+
const root = allBelow ? node.route : '';
|
|
333
|
+
emit(
|
|
334
|
+
section(node.title, wrapText(node.summary)),
|
|
335
|
+
...(node.content?.length
|
|
336
|
+
? [
|
|
337
|
+
text(
|
|
338
|
+
node.content
|
|
339
|
+
.map(b => formatBlock(b, detail))
|
|
340
|
+
.filter(Boolean)
|
|
341
|
+
.join('\n\n'),
|
|
342
|
+
),
|
|
343
|
+
]
|
|
344
|
+
: []),
|
|
345
|
+
...(node.childCount
|
|
346
|
+
? [
|
|
347
|
+
text(
|
|
348
|
+
`${docsBelow(node.childCount)}. Read them: ${run} docs ${node.route} --depth 1`,
|
|
349
|
+
),
|
|
350
|
+
]
|
|
351
|
+
: []),
|
|
352
|
+
...node.slots.flatMap(slot => [
|
|
353
|
+
...(node.slots.length === 1 && slot.title === node.title
|
|
354
|
+
? []
|
|
355
|
+
: [section(slot.title)]),
|
|
356
|
+
childDetail === 'brief'
|
|
357
|
+
? records(treeRows(slot.children, root), {
|
|
358
|
+
fields: ['name', 'summary'],
|
|
359
|
+
layout: 'inline',
|
|
360
|
+
})
|
|
361
|
+
: code(
|
|
362
|
+
slot.children
|
|
363
|
+
.map(child => formatTreeChild(child, childDetail, 2, root, run))
|
|
364
|
+
.join('\n\n'),
|
|
365
|
+
),
|
|
366
|
+
]),
|
|
367
|
+
text(
|
|
368
|
+
[
|
|
369
|
+
...(node.slots.length > 0
|
|
370
|
+
? [
|
|
371
|
+
allBelow
|
|
372
|
+
? `Open one: ${run} docs ${node.route}/<name>`
|
|
373
|
+
: `Open one: ${run} docs <name>`,
|
|
374
|
+
]
|
|
375
|
+
: []),
|
|
376
|
+
...linkLines(node.links),
|
|
377
|
+
].join('\n'),
|
|
378
|
+
),
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
184
382
|
/**
|
|
185
383
|
* The moves a read offers (spec:AST-047), one runnable command per line: up to
|
|
186
384
|
* the level it sits in, the item before and after it, and the docs it names.
|
|
@@ -331,7 +529,7 @@ export function registerDocs(program) {
|
|
|
331
529
|
action: async (
|
|
332
530
|
/** @type {string | undefined} */ topic,
|
|
333
531
|
/** @type {string | undefined} */ sectionName,
|
|
334
|
-
/** @type {{index?: boolean, full?: boolean}} */ options = {},
|
|
532
|
+
/** @type {{index?: boolean, full?: boolean, depth?: string}} */ options = {},
|
|
335
533
|
) => {
|
|
336
534
|
const run = getCliInvocation();
|
|
337
535
|
const lang = program.opts().lang || null;
|
|
@@ -346,6 +544,22 @@ export function registerDocs(program) {
|
|
|
346
544
|
{code: ERROR_CODES.ERR_INVALID_ARGUMENT},
|
|
347
545
|
);
|
|
348
546
|
}
|
|
547
|
+
/** @type {number | 'all' | undefined} */
|
|
548
|
+
let depth;
|
|
549
|
+
if (options.depth != null) {
|
|
550
|
+
if (options.depth === 'all') depth = 'all';
|
|
551
|
+
else if (/^\d+$/.test(options.depth)) depth = Number(options.depth);
|
|
552
|
+
else {
|
|
553
|
+
return cliError(
|
|
554
|
+
`--depth takes a number of levels (0, 1, 2, ...) or all, not "${options.depth}".`,
|
|
555
|
+
{code: ERROR_CODES.ERR_INVALID_ARGUMENT},
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
// With --depth, --detail is how much of each doc below shows; left at
|
|
560
|
+
// its default, each is one line.
|
|
561
|
+
const childDetail =
|
|
562
|
+
program.getOptionValueSource('detail') === 'default' ? 'brief' : detail;
|
|
349
563
|
// Text reads one level: a topic lists its sections (one with a single
|
|
350
564
|
// section prints whole). JSON keeps docs(): the whole topic unless
|
|
351
565
|
// --index. The dense variant is written to be read whole.
|
|
@@ -363,6 +577,7 @@ export function registerDocs(program) {
|
|
|
363
577
|
zh,
|
|
364
578
|
dense,
|
|
365
579
|
index: listSections,
|
|
580
|
+
...(depth != null ? {depth, detail: childDetail} : {}),
|
|
366
581
|
});
|
|
367
582
|
if (
|
|
368
583
|
!options.index &&
|
|
@@ -417,6 +632,7 @@ export function registerDocs(program) {
|
|
|
417
632
|
` ${run} docs <topic> <section> read one section`,
|
|
418
633
|
` ${run} docs <topic> --full read the whole topic`,
|
|
419
634
|
` ${run} docs cli/api go down the docs tree one level at a time`,
|
|
635
|
+
` ${run} docs cli --depth all every doc below cli, one line each`,
|
|
420
636
|
`With --json, a topic returns its whole doc; add --index for its section list.`,
|
|
421
637
|
].join('\n'),
|
|
422
638
|
),
|
|
@@ -462,7 +678,8 @@ export function registerDocs(program) {
|
|
|
462
678
|
}
|
|
463
679
|
|
|
464
680
|
case 'docs.node': {
|
|
465
|
-
|
|
681
|
+
if (depth != null) emitTree(result.data, detail, childDetail, run);
|
|
682
|
+
else emitNode(result.data, detail, run);
|
|
466
683
|
break;
|
|
467
684
|
}
|
|
468
685
|
}
|