@astryxdesign/cli 0.6.3-canary.db4e378 → 0.6.3-canary.db7b338
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 +22 -1
- package/api/blog/blog.doc.mjs +1 -0
- package/api/build/build.doc.mjs +1 -0
- package/api/component/component.doc.mjs +1 -0
- package/api/discover/discover.doc.mjs +1 -0
- package/api/docs/_adapter.d.mts +3 -8
- package/api/docs/_adapter.mjs +13 -105
- package/api/docs/detail/section/section.mjs +9 -15
- package/api/docs/detail/section/section.test.mjs +15 -6
- package/api/docs/docs.doc.mjs +1 -0
- package/api/docs/list/list.mjs +3 -7
- package/api/doctor/doctor.d.mts +25 -3
- package/api/doctor/doctor.doc.mjs +1 -0
- package/api/doctor/doctor.mjs +186 -14
- package/api/doctor/doctor.test.mjs +332 -7
- package/api/gap-report/gap-report.doc.mjs +1 -0
- package/api/hook/_adapter.mjs +19 -5
- package/api/hook/hook.doc.mjs +1 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/hook/list/list.mjs +69 -17
- package/api/init/init.doc.mjs +1 -0
- package/api/integration/add-contribution.mjs +7 -7
- package/api/integration/add-contribution.test.mjs +37 -3
- package/api/integration/add-theme.mjs +34 -64
- package/api/integration/add-theme.test.mjs +105 -21
- package/api/integration/authoring-checks.test.mjs +8 -4
- package/api/integration/integration-block-exports.test.mjs +10 -6
- package/api/integration/integrationAdd.doc.mjs +1 -0
- package/api/integration/integrationAddAgentDoc.doc.mjs +1 -0
- package/api/integration/integrationAddCodemod.doc.mjs +1 -0
- package/api/integration/integrationAddComponent.doc.mjs +1 -0
- package/api/integration/integrationAddDoc.doc.mjs +1 -0
- package/api/integration/integrationAddTemplate.doc.mjs +1 -0
- package/api/integration/integrationAddTheme.doc.mjs +6 -5
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -0
- package/api/integration/integrationDocConflicts.doc.mjs +1 -0
- package/api/integration/integrationPackCheck.doc.mjs +1 -0
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -0
- package/api/integration/pack-check.test.mjs +17 -47
- package/api/integration/summarizeIssues.doc.mjs +1 -0
- package/api/integration/validate-integration-fixes.test.mjs +1389 -0
- package/api/integration/validate-integration.mjs +50 -102
- package/api/integration/validate-integration.test.mjs +85 -23
- package/api/integration/validate-unread-theme-folders.test.mjs +110 -0
- package/api/integration/validateIntegration.doc.mjs +1 -0
- package/api/json/assertResponse.doc.mjs +1 -0
- package/api/json/isError.doc.mjs +1 -0
- package/api/json/parseResponse.doc.mjs +1 -0
- package/api/layout/layoutCheck.doc.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -0
- package/api/layout/layoutGrammar.doc.mjs +1 -0
- package/api/search/search.doc.mjs +1 -0
- package/api/search/search.mjs +16 -6
- package/api/swizzle/swizzle.doc.mjs +1 -0
- package/api/template/template-suffix.test.mjs +41 -21
- package/api/template/template.doc.mjs +1 -0
- package/api/theme/_adapter.d.mts +2 -3
- package/api/theme/_adapter.mjs +4 -5
- package/api/theme/add/add.binary.test.mjs +10 -17
- package/api/theme/add/add.test.mjs +14 -1
- package/api/theme/generateTonalPalette.doc.mjs +1 -0
- package/api/theme/integration-themes.test.mjs +39 -28
- package/api/theme/list/list.test.mjs +19 -20
- package/api/theme/listThemes.doc.mjs +6 -5
- package/api/theme/themeAdd.doc.mjs +4 -3
- package/api/theme/themeBuild.doc.mjs +1 -0
- package/api/theme/themeList.doc.mjs +6 -3
- package/api/theme/themeListAvailable.doc.mjs +5 -3
- package/api/theme/themePaletteGenerate.doc.mjs +1 -0
- package/api/theme/themeTargets.doc.mjs +1 -0
- package/api/theme/themeTemplate.doc.mjs +1 -0
- package/api/upgrade/_adapter.d.mts +32 -5
- package/api/upgrade/_adapter.mjs +97 -69
- package/api/upgrade/provider-agreement.test.mjs +152 -0
- package/api/upgrade/run/run.mjs +356 -59
- package/api/upgrade/upgrade.doc.mjs +6 -1
- package/api/upgrade/upgrade.type.d.mts +34 -0
- package/api/upgrade/upgrade.type.mjs +15 -0
- package/assets/codemods/__tests__/runner.test.mjs +330 -8
- package/assets/codemods/integration-discovery.mjs +8 -2
- package/assets/codemods/integration-discovery.test.mjs +15 -0
- package/assets/codemods/integration-runner.mjs +56 -4
- package/assets/codemods/integration-runner.protection.test.mjs +153 -0
- package/assets/codemods/run-codemod.mjs +177 -34
- package/assets/codemods/runner.mjs +350 -102
- package/assets/codemods/transforms/next/__tests__/migrate-native-picker-to-presentation.test.mjs +63 -0
- package/assets/codemods/transforms/next/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +220 -0
- package/assets/codemods/transforms/next/index.mjs +19 -1
- package/assets/codemods/transforms/next/migrate-native-picker-to-presentation.mjs +148 -0
- package/assets/codemods/transforms/next/migrate-theme-catalog-to-descriptors.mjs +141 -0
- package/assets/docs/cli-integrations.doc.mjs +30 -30
- package/assets/docs/cli.doc.mjs +15 -0
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/templates/blocks/components/DateInput/DateInputDateRange.tsx +1 -1
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +14 -0
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +100 -0
- package/assets/templates/blocks/components/TimeInput/TimeInputConstrained.tsx +1 -0
- package/assets/templates/themes/butter/butterTheme.doc.mjs +11 -0
- package/assets/templates/themes/chocolate/chocolateTheme.doc.mjs +11 -0
- package/assets/templates/themes/gothic/gothicTheme.doc.mjs +11 -0
- package/assets/templates/themes/matcha/matchaTheme.doc.mjs +11 -0
- package/assets/templates/themes/neutral/neutralTheme.doc.mjs +11 -0
- package/assets/templates/themes/stone/stoneTheme.doc.mjs +11 -0
- package/assets/templates/themes/y2k/y2kTheme.doc.mjs +11 -0
- package/authoring/codemod/codemod.doc.mjs +1 -1
- package/authoring/codemod/type.ts +12 -0
- package/authoring/config/config.doc.mjs +1 -1
- package/authoring/debug/debug.doc.d.mts +11 -0
- package/authoring/debug/debug.doc.mjs +182 -0
- package/authoring/doctypes/_schema.d.mts +71 -141
- package/authoring/doctypes/_schema.mjs +29 -2
- package/authoring/doctypes/base/graph-fields.doc.mjs +1 -1
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/command/type.ts +1 -1
- package/authoring/doctypes/component/type.ts +2 -2
- package/authoring/doctypes/doctypes-new.test.mjs +48 -6
- package/authoring/doctypes/enum/enum.doc.mjs +1 -1
- package/authoring/doctypes/enum/type.ts +1 -1
- package/authoring/doctypes/function/function.doc.mjs +1 -1
- package/authoring/doctypes/function/type.ts +1 -1
- package/authoring/doctypes/hook/type.ts +2 -2
- package/authoring/doctypes/load-contract.test.mjs +3 -2
- package/authoring/doctypes/namespace/namespace.doc.mjs +2 -2
- package/authoring/doctypes/namespace/parse.test.mjs +23 -25
- package/authoring/doctypes/namespace/type.ts +5 -2
- package/authoring/doctypes/parse.d.mts +4 -2
- package/authoring/doctypes/parse.mjs +10 -5
- package/authoring/doctypes/reference/reference.doc.mjs +6 -4
- package/authoring/doctypes/reference/type.ts +9 -10
- package/authoring/doctypes/schema/schema.doc.mjs +1 -1
- package/authoring/doctypes/schema/type.ts +1 -2
- package/authoring/doctypes/template/template.doc.mjs +3 -3
- package/authoring/doctypes/theme/parse.d.mts +35 -0
- package/authoring/doctypes/theme/parse.mjs +76 -0
- package/authoring/doctypes/theme/theme.doc.d.mts +9 -0
- package/authoring/doctypes/theme/theme.doc.mjs +79 -0
- package/authoring/doctypes/theme/type.ts +42 -0
- package/authoring/doctypes/types.ts +2 -1
- package/authoring/gap-report/gap-report.doc.d.mts +12 -0
- package/authoring/gap-report/gap-report.doc.mjs +183 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +7 -4
- package/authoring/index.mjs +2 -1
- package/authoring/integration/integration.doc.mjs +2 -2
- package/authoring/integration/type.ts +3 -9
- package/clients/cli/__tests__/cliManifest.test.ts +27 -29
- package/clients/cli/commands/blog.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +100 -1
- package/clients/cli/commands/build-theme.mjs +10 -44
- package/clients/cli/commands/build.doc.mjs +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/discover.doc.mjs +1 -1
- package/clients/cli/commands/docs.doc.mjs +1 -1
- package/clients/cli/commands/docs.mjs +15 -58
- package/clients/cli/commands/docs.test.mjs +11 -14
- package/clients/cli/commands/doctor-integration-components.doc.mjs +1 -1
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
- package/clients/cli/commands/doctor-integration-templates.doc.mjs +1 -1
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +1 -1
- package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
- package/clients/cli/commands/doctor-integration.test.mjs +15 -7
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/gap-report.doc.mjs +1 -1
- package/clients/cli/commands/hook.doc.mjs +1 -1
- package/clients/cli/commands/init.doc.mjs +1 -1
- package/clients/cli/commands/integration-add.controls.test.mjs +1 -1
- package/clients/cli/commands/integration-add.doc.mjs +1 -1
- package/clients/cli/commands/integration-pack.doc.mjs +1 -1
- package/clients/cli/commands/integration-real-world.test.mjs +3 -9
- package/clients/cli/commands/integration.doc.mjs +1 -1
- package/clients/cli/commands/layout-check.doc.mjs +1 -1
- package/clients/cli/commands/layout-expand.doc.mjs +1 -1
- package/clients/cli/commands/layout-grammar.doc.mjs +1 -1
- package/clients/cli/commands/layout.doc.mjs +1 -1
- package/clients/cli/commands/manifest.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +1 -1
- package/clients/cli/commands/swizzle.doc.mjs +1 -1
- package/clients/cli/commands/template.doc.mjs +1 -1
- package/clients/cli/commands/text-json-parity.test.mjs +718 -0
- package/clients/cli/commands/theme-add.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/commands/theme-list.doc.mjs +2 -2
- package/clients/cli/commands/theme-palette-generate.doc.mjs +3 -3
- package/clients/cli/commands/theme-palette.doc.mjs +1 -1
- package/clients/cli/commands/theme-targets.behavior.test.mjs +4 -3
- package/clients/cli/commands/theme-targets.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/upgrade.doc.mjs +3 -2
- package/clients/cli/commands/upgrade.file-protection.test.mjs +228 -0
- package/clients/cli/commands/upgrade.mjs +29 -7
- package/clients/cli/formatters/index.mjs +2 -0
- package/clients/cli/formatters/index.test.mjs +6 -0
- package/clients/cli/lib/hook-format.mjs +14 -5
- package/foundation/config/project-themes.test.mjs +11 -19
- package/foundation/config/project.d.mts +8 -0
- package/foundation/config/project.mjs +50 -21
- package/foundation/config/project.test.mjs +3 -16
- package/foundation/discovery/authoring-self-docs.d.mts +6 -0
- package/foundation/discovery/authoring-self-docs.mjs +17 -7
- package/foundation/discovery/authoring-self-docs.test.mjs +3 -2
- package/foundation/discovery/authoring-surface.d.mts +74 -0
- package/foundation/discovery/authoring-surface.mjs +525 -0
- package/foundation/discovery/authoring-surface.test.mjs +392 -0
- package/foundation/discovery/cli-self-docs.d.mts +113 -0
- package/foundation/discovery/cli-self-docs.mjs +514 -0
- package/foundation/discovery/cli-self-docs.test.mjs +437 -0
- package/foundation/discovery/component-loader.d.mts +35 -38
- package/foundation/discovery/component-loader.mjs +53 -222
- package/foundation/discovery/docs-discovery.d.mts +3 -2
- package/foundation/discovery/docs-discovery.mjs +14 -17
- package/foundation/discovery/docs-discovery.test.mjs +15 -15
- package/foundation/discovery/docs-section-key.d.mts +19 -8
- package/foundation/discovery/docs-section-key.mjs +119 -32
- package/foundation/discovery/docs-section-key.test.mjs +41 -19
- package/foundation/discovery/template-adapter.d.mts +7 -0
- package/foundation/discovery/template-adapter.mjs +27 -40
- package/foundation/discovery/template-adapter.test.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +67 -7
- package/foundation/discovery/theme-discovery.mjs +916 -186
- package/foundation/discovery/theme-discovery.test.mjs +613 -219
- package/foundation/doc-compiler/bundle.d.mts +47 -0
- package/foundation/doc-compiler/bundle.mjs +218 -0
- package/foundation/doc-compiler/bundle.test.mjs +255 -0
- package/foundation/doc-compiler/compile.d.mts +200 -0
- package/foundation/doc-compiler/compile.mjs +259 -9
- package/foundation/doc-compiler/diagnostics.d.mts +126 -0
- package/foundation/doc-compiler/diagnostics.mjs +277 -0
- package/foundation/doc-compiler/doc-compiler.test.mjs +28 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +1642 -0
- package/foundation/doc-compiler/import.d.mts +24 -0
- package/foundation/doc-compiler/import.mjs +59 -0
- package/foundation/doc-compiler/inputs.d.mts +102 -0
- package/foundation/doc-compiler/inputs.mjs +286 -0
- package/foundation/doc-compiler/inputs.test.mjs +299 -0
- package/foundation/doc-compiler/ir.d.mts +13 -0
- package/foundation/doc-compiler/ir.mjs +189 -12
- package/foundation/doc-compiler/lower-doc.test.mjs +492 -0
- package/foundation/doc-compiler/overlays.d.mts +37 -0
- package/foundation/doc-compiler/overlays.mjs +206 -0
- package/foundation/doc-compiler/parse-readable.d.mts +9 -0
- package/foundation/doc-compiler/parse-readable.mjs +29 -0
- package/foundation/doc-compiler/read.d.mts +126 -0
- package/foundation/doc-compiler/read.mjs +320 -0
- package/foundation/doc-compiler/read.test.mjs +313 -0
- package/foundation/doc-compiler/source.d.mts +33 -0
- package/foundation/doc-compiler/source.mjs +128 -0
- package/foundation/fs/file-protection.d.mts +33 -0
- package/foundation/fs/file-protection.mjs +825 -0
- package/foundation/fs/file-protection.test.mjs +250 -0
- package/foundation/integrations/autolink.d.mts +58 -1
- package/foundation/integrations/autolink.mjs +143 -57
- package/foundation/integrations/contribution-fixes.d.mts +145 -0
- package/foundation/integrations/contribution-fixes.mjs +1284 -0
- package/foundation/integrations/contribution-inventory.d.mts +1 -1
- package/foundation/integrations/contribution-inventory.mjs +17 -20
- package/foundation/integrations/contribution-inventory.test.mjs +67 -27
- package/foundation/integrations/integrations.d.mts +3 -0
- package/foundation/integrations/integrations.mjs +11 -97
- package/foundation/integrations/provider-ledger.test.mjs +275 -0
- package/foundation/integrations/provider-resolution.d.mts +152 -0
- package/foundation/integrations/provider-resolution.mjs +576 -0
- package/foundation/integrations/provider-resolution.test.mjs +369 -0
- package/foundation/integrations/theme-descriptor.d.mts +8 -0
- package/foundation/integrations/theme-descriptor.mjs +44 -0
- package/foundation/integrations/validate-contributions.mjs +104 -10
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +2 -0
- package/foundation/response/error-codes.doc.mjs +12 -2
- package/foundation/response/error-codes.mjs +7 -1
- package/foundation/response/error-codes.test.mjs +55 -11
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/response/response.doc.mjs +1 -1
- package/foundation/text/string-utils.mjs +22 -10
- package/package.json +10 -9
- package/assets/templates/themes/manifest.json +0 -95
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Tests for the CLI docs reader. Every command, API function, schema, and
|
|
5
|
+
* enum doc this package ships is readable in the topic its namespace names.
|
|
6
|
+
* Each way one can fail to be is reported: no namespace, a namespace no topic
|
|
7
|
+
* reads, a clash with the authoring topic's list, a doc that does not load, and
|
|
8
|
+
* two `cli` sections with one key.
|
|
9
|
+
*
|
|
10
|
+
* @input This package's own docs, and fixture doc trees written under the
|
|
11
|
+
* working directory.
|
|
12
|
+
* @output Assertions on the audit, the `cli` topic, and reads through `docs()`.
|
|
13
|
+
* @position packages/cli/foundation/discovery — tests for cli-self-docs.mjs.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as path from 'node:path';
|
|
18
|
+
import {afterAll, describe, expect, it} from 'vitest';
|
|
19
|
+
import {
|
|
20
|
+
CLI_DOC_NAMESPACES,
|
|
21
|
+
auditCliSelfDocs,
|
|
22
|
+
buildCliReferenceDoc,
|
|
23
|
+
buildCliTopic,
|
|
24
|
+
cliSectionKey,
|
|
25
|
+
discoverCliSelfDocSources,
|
|
26
|
+
keySegment,
|
|
27
|
+
loadCliSelfDocs,
|
|
28
|
+
} from './cli-self-docs.mjs';
|
|
29
|
+
import * as api from '../../api/index.mjs';
|
|
30
|
+
|
|
31
|
+
const SLOW = 60_000;
|
|
32
|
+
|
|
33
|
+
/** @type {string[]} */
|
|
34
|
+
const tmpRoots = [];
|
|
35
|
+
afterAll(() => {
|
|
36
|
+
for (const root of tmpRoots) fs.rmSync(root, {recursive: true, force: true});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/** Write `files` (relative path -> content) under a fresh directory. */
|
|
40
|
+
function writeTree(/** @type {Record<string, string>} */ files) {
|
|
41
|
+
const root = fs.mkdtempSync(path.join(process.cwd(), '.astryx-cli-docs-'));
|
|
42
|
+
tmpRoots.push(root);
|
|
43
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
44
|
+
const file = path.join(root, rel);
|
|
45
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
46
|
+
fs.writeFileSync(file, content);
|
|
47
|
+
}
|
|
48
|
+
return root;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const docModule = (/** @type {any} */ doc) =>
|
|
52
|
+
`export const doc = ${JSON.stringify(doc, null, 2)};\n`;
|
|
53
|
+
|
|
54
|
+
const command = (/** @type {string} */ name, extra = {}) => ({
|
|
55
|
+
type: 'command',
|
|
56
|
+
name,
|
|
57
|
+
displayName: `astryx ${name}`,
|
|
58
|
+
namespace: 'cli/commands',
|
|
59
|
+
summary: `Do ${name}`,
|
|
60
|
+
...extra,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const fn = (/** @type {string} */ name, extra = {}) => ({
|
|
64
|
+
type: 'function',
|
|
65
|
+
kind: 'api',
|
|
66
|
+
name,
|
|
67
|
+
displayName: `${name}()`,
|
|
68
|
+
namespace: 'cli/api',
|
|
69
|
+
summary: `The ${name} function.`,
|
|
70
|
+
importPath: '@astryxdesign/cli/api',
|
|
71
|
+
params: [],
|
|
72
|
+
returns: [{type: name, description: 'The result.'}],
|
|
73
|
+
...extra,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const enumDoc = (/** @type {string} */ name, extra = {}) => ({
|
|
77
|
+
type: 'enum',
|
|
78
|
+
name,
|
|
79
|
+
displayName: name,
|
|
80
|
+
namespace: 'cli/api',
|
|
81
|
+
description: `The ${name}.`,
|
|
82
|
+
members: [{value: 'A', description: 'The a.'}],
|
|
83
|
+
...extra,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const schema = (/** @type {string} */ name, extra = {}) => ({
|
|
87
|
+
type: 'schema',
|
|
88
|
+
name,
|
|
89
|
+
displayName: name,
|
|
90
|
+
namespace: 'authoring',
|
|
91
|
+
description: `The ${name} file.`,
|
|
92
|
+
fields: [{name: 'x', type: 'string', description: 'The x.'}],
|
|
93
|
+
...extra,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/** Audit a fixture tree with nothing in the authoring topic's list. */
|
|
97
|
+
const audit = (/** @type {string} */ root, authoringSources = []) =>
|
|
98
|
+
auditCliSelfDocs({root, authoringSources});
|
|
99
|
+
|
|
100
|
+
describe('the CLI docs this package ships', () => {
|
|
101
|
+
it(
|
|
102
|
+
'each declare a namespace a topic reads, and none fails, clashes, or overflows',
|
|
103
|
+
async () => {
|
|
104
|
+
const result = await auditCliSelfDocs();
|
|
105
|
+
expect({
|
|
106
|
+
missing: result.missing,
|
|
107
|
+
unknown: result.unknown,
|
|
108
|
+
misfiled: result.misfiled,
|
|
109
|
+
failed: result.failed,
|
|
110
|
+
keyProblems: result.keyProblems,
|
|
111
|
+
oversized: result.oversized,
|
|
112
|
+
}).toEqual({
|
|
113
|
+
missing: [],
|
|
114
|
+
unknown: [],
|
|
115
|
+
misfiled: [],
|
|
116
|
+
failed: [],
|
|
117
|
+
keyProblems: [],
|
|
118
|
+
oversized: [],
|
|
119
|
+
});
|
|
120
|
+
expect(result.docs).toBeGreaterThan(0);
|
|
121
|
+
expect(result.sections + result.authoring).toBe(result.docs);
|
|
122
|
+
},
|
|
123
|
+
SLOW,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
it(
|
|
127
|
+
'give every function @astryxdesign/cli/api exports a section of astryx docs cli',
|
|
128
|
+
async () => {
|
|
129
|
+
const topic = await buildCliTopic();
|
|
130
|
+
const keys = new Set(topic.sections.map(section => section.id));
|
|
131
|
+
const exported = Object.entries(api)
|
|
132
|
+
.filter(
|
|
133
|
+
([, value]) =>
|
|
134
|
+
typeof value === 'function' &&
|
|
135
|
+
Object.getOwnPropertyDescriptor(value, 'prototype')?.writable !==
|
|
136
|
+
false,
|
|
137
|
+
)
|
|
138
|
+
.map(([name]) => `api-${keySegment(name)}`);
|
|
139
|
+
expect(exported.length).toBeGreaterThan(0);
|
|
140
|
+
expect(exported.filter(key => !keys.has(key))).toEqual([]);
|
|
141
|
+
},
|
|
142
|
+
SLOW,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
it(
|
|
146
|
+
'give every command doc a section, keyed commands-<name>',
|
|
147
|
+
async () => {
|
|
148
|
+
const {loaded} = await loadCliSelfDocs();
|
|
149
|
+
const commands = loaded.filter(({doc}) => doc.type === 'command');
|
|
150
|
+
expect(commands.length).toBeGreaterThan(0);
|
|
151
|
+
const keys = new Set(
|
|
152
|
+
(await buildCliTopic()).sections.map(section => section.id),
|
|
153
|
+
);
|
|
154
|
+
expect(
|
|
155
|
+
commands
|
|
156
|
+
.map(({doc}) => `commands-${keySegment(doc.name)}`)
|
|
157
|
+
.filter(key => !keys.has(key)),
|
|
158
|
+
).toEqual([]);
|
|
159
|
+
},
|
|
160
|
+
SLOW,
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
it(
|
|
164
|
+
'are read one section at a time through docs()',
|
|
165
|
+
async () => {
|
|
166
|
+
const search = await api.docs('cli', 'api-search');
|
|
167
|
+
expect(search).toMatchObject({type: 'docs.detail.section'});
|
|
168
|
+
expect(JSON.stringify(search.data)).toContain('search()');
|
|
169
|
+
const command = await api.docs('cli', 'commands-integration-add');
|
|
170
|
+
expect(JSON.stringify(command.data)).toContain(
|
|
171
|
+
'astryx integration add <kind> <name>',
|
|
172
|
+
);
|
|
173
|
+
const codes = await api.docs('cli', 'api-error-codes');
|
|
174
|
+
expect(JSON.stringify(codes.data)).toContain('ERR_UNKNOWN_SECTION');
|
|
175
|
+
const index = await api.docs('cli', undefined, {index: true});
|
|
176
|
+
expect(index.type).toBe('docs.index');
|
|
177
|
+
expect(index.data.sections.length).toBe(
|
|
178
|
+
(await buildCliTopic()).sections.length,
|
|
179
|
+
);
|
|
180
|
+
},
|
|
181
|
+
SLOW,
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('auditCliSelfDocs', () => {
|
|
186
|
+
it('reports a doc with no namespace, and one no topic reads', async () => {
|
|
187
|
+
const root = writeTree({
|
|
188
|
+
'api/alpha/alpha.doc.mjs': docModule(fn('alpha', {namespace: undefined})),
|
|
189
|
+
'clients/cli/commands/beta.doc.mjs': docModule(
|
|
190
|
+
command('beta', {namespace: 'cli'}),
|
|
191
|
+
),
|
|
192
|
+
'api/gamma/gamma.doc.mjs': docModule(fn('gamma')),
|
|
193
|
+
});
|
|
194
|
+
const result = await audit(root);
|
|
195
|
+
expect(result.missing).toEqual(['api/alpha/alpha.doc.mjs']);
|
|
196
|
+
expect(result.unknown).toEqual([
|
|
197
|
+
{source: 'clients/cli/commands/beta.doc.mjs', namespace: 'cli'},
|
|
198
|
+
]);
|
|
199
|
+
expect(result.sections).toBe(1);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('holds the authoring namespace to the authoring topic list', async () => {
|
|
203
|
+
const root = writeTree({
|
|
204
|
+
'authoring/x/x.doc.mjs': docModule(schema('x')),
|
|
205
|
+
'authoring/y/y.doc.mjs': docModule(schema('y', {namespace: 'cli/api'})),
|
|
206
|
+
'authoring/z/z.doc.mjs': docModule(schema('z')),
|
|
207
|
+
});
|
|
208
|
+
const result = await audit(root, ['y/y.doc.mjs', 'z/z.doc.mjs']);
|
|
209
|
+
expect(result.misfiled.map(entry => entry.message)).toEqual([
|
|
210
|
+
'authoring/x/x.doc.mjs has namespace "authoring", but `astryx docs authoring` does not list it',
|
|
211
|
+
'authoring/y/y.doc.mjs is read in `astryx docs authoring`, but its namespace is "cli/api"',
|
|
212
|
+
]);
|
|
213
|
+
expect(result.authoring).toBe(1);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('reports a doc that fails to load, and skips fixture directories', async () => {
|
|
217
|
+
const root = writeTree({
|
|
218
|
+
'api/bad/bad.doc.mjs': 'throw new Error("boom");\n',
|
|
219
|
+
'api/__fixtures__/ghost.doc.mjs': docModule(fn('ghost')),
|
|
220
|
+
'foundation/.hidden/hidden.doc.mjs': docModule(fn('hidden')),
|
|
221
|
+
'foundation/codes.doc.mjs': docModule(enumDoc('codes')),
|
|
222
|
+
});
|
|
223
|
+
expect(discoverCliSelfDocSources(root)).toEqual([
|
|
224
|
+
'api/bad/bad.doc.mjs',
|
|
225
|
+
'foundation/codes.doc.mjs',
|
|
226
|
+
]);
|
|
227
|
+
const result = await audit(root);
|
|
228
|
+
expect(result.failed).toEqual([
|
|
229
|
+
expect.objectContaining({
|
|
230
|
+
source: 'api/bad/bad.doc.mjs',
|
|
231
|
+
error: expect.stringContaining('boom'),
|
|
232
|
+
}),
|
|
233
|
+
]);
|
|
234
|
+
expect(result.sections).toBe(1);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('reports two cli sections that share a key', async () => {
|
|
238
|
+
const root = writeTree({
|
|
239
|
+
'api/a/fooBar.doc.mjs': docModule(fn('fooBar')),
|
|
240
|
+
'api/b/foo_bar.doc.mjs': docModule(fn('foo_bar')),
|
|
241
|
+
});
|
|
242
|
+
const result = await audit(root);
|
|
243
|
+
expect(result.keyProblems).toHaveLength(1);
|
|
244
|
+
expect(result.keyProblems[0]).toContain('api-foo-bar');
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('buildCliReferenceDoc', () => {
|
|
249
|
+
it('keeps a command and the function it runs apart, and links them', () => {
|
|
250
|
+
const topic = buildCliReferenceDoc([
|
|
251
|
+
fn('docs', {command: 'docs'}),
|
|
252
|
+
command('docs', {fn: 'docs'}),
|
|
253
|
+
]);
|
|
254
|
+
expect(topic.sections.map(s => s.id)).toEqual([
|
|
255
|
+
'commands-docs',
|
|
256
|
+
'api-docs',
|
|
257
|
+
]);
|
|
258
|
+
expect(JSON.stringify(topic.sections[0].content)).toContain(
|
|
259
|
+
'It runs `docs()` from `@astryxdesign/cli/api`. Read it with `astryx docs cli api-docs`.',
|
|
260
|
+
);
|
|
261
|
+
expect(JSON.stringify(topic.sections[1].content)).toContain(
|
|
262
|
+
'`astryx docs` runs it. Read it with `astryx docs cli commands-docs`.',
|
|
263
|
+
);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('renders a command: usage, arguments, options, examples, exit codes, subcommands', () => {
|
|
267
|
+
const topic = buildCliReferenceDoc([
|
|
268
|
+
command('grp', {subcommands: ['sub', 'gone']}),
|
|
269
|
+
command('grp sub', {
|
|
270
|
+
description: 'The long form.',
|
|
271
|
+
fn: 'grpSub',
|
|
272
|
+
args: [
|
|
273
|
+
{name: 'files', required: true, variadic: true, description: 'Files.'},
|
|
274
|
+
],
|
|
275
|
+
options: [
|
|
276
|
+
{flag: '--fast', description: 'Go fast'},
|
|
277
|
+
{
|
|
278
|
+
flag: '--mode <m>',
|
|
279
|
+
description: 'Mode',
|
|
280
|
+
choices: ['a', 'b'],
|
|
281
|
+
default: 'a',
|
|
282
|
+
},
|
|
283
|
+
{flag: '--limit <n>', param: 'options.limit'},
|
|
284
|
+
{flag: '--dry', description: 'Dry run.', default: false},
|
|
285
|
+
],
|
|
286
|
+
examples: [
|
|
287
|
+
{label: 'Run it', cli: 'astryx grp sub x'},
|
|
288
|
+
{cli: 'astryx grp sub y'},
|
|
289
|
+
],
|
|
290
|
+
exitCodes: [{code: 1, when: 'it fails'}],
|
|
291
|
+
}),
|
|
292
|
+
fn('grpSub', {
|
|
293
|
+
params: [{name: 'options.limit', type: 'number', description: 'Max.'}],
|
|
294
|
+
}),
|
|
295
|
+
]);
|
|
296
|
+
const [group, sub] = topic.sections;
|
|
297
|
+
expect(group.content).toContainEqual({
|
|
298
|
+
type: 'list',
|
|
299
|
+
style: 'unordered',
|
|
300
|
+
items: ['`astryx grp sub`: `astryx docs cli commands-grp-sub`'],
|
|
301
|
+
});
|
|
302
|
+
expect(sub).toMatchObject({id: 'commands-grp-sub', title: 'astryx grp sub'});
|
|
303
|
+
expect(sub.content).toEqual([
|
|
304
|
+
{type: 'prose', text: 'Do grp sub'},
|
|
305
|
+
{type: 'prose', text: 'The long form.'},
|
|
306
|
+
{type: 'code', lang: 'bash', code: 'astryx grp sub <files...>'},
|
|
307
|
+
{
|
|
308
|
+
type: 'table',
|
|
309
|
+
headers: ['Argument', 'Description'],
|
|
310
|
+
rows: [['`files`', 'Files.']],
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
type: 'table',
|
|
314
|
+
headers: ['Option', 'Description'],
|
|
315
|
+
rows: [
|
|
316
|
+
['`--fast`', 'Go fast'],
|
|
317
|
+
['`--mode <m>`', 'Mode. One of: `a`, `b`. Default: `a`.'],
|
|
318
|
+
['`--limit <n>`', 'Max.'],
|
|
319
|
+
['`--dry`', 'Dry run.'],
|
|
320
|
+
],
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
type: 'code',
|
|
324
|
+
lang: 'bash',
|
|
325
|
+
code: '# Run it\nastryx grp sub x\nastryx grp sub y',
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
type: 'table',
|
|
329
|
+
headers: ['Exit code', 'When'],
|
|
330
|
+
rows: [['1', 'it fails']],
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
type: 'prose',
|
|
334
|
+
text: 'It runs `grpSub()` from `@astryxdesign/cli/api`. Read it with `astryx docs cli api-grp-sub`.',
|
|
335
|
+
},
|
|
336
|
+
]);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('renders an API function and an enum', () => {
|
|
340
|
+
const topic = buildCliReferenceDoc([
|
|
341
|
+
fn('alpha', {
|
|
342
|
+
description: 'Longer.',
|
|
343
|
+
signature: 'alpha(x: string): Promise<Alpha>',
|
|
344
|
+
params: [{name: 'x', type: 'string', description: 'The x.'}],
|
|
345
|
+
throws: [{code: 'ERR_X', when: 'x is bad'}],
|
|
346
|
+
examples: [{label: 'Call it', code: "await alpha('x');"}],
|
|
347
|
+
}),
|
|
348
|
+
enumDoc('codes', {
|
|
349
|
+
members: [
|
|
350
|
+
{value: 'A', description: 'The a.'},
|
|
351
|
+
{value: 'B', description: 'The b.', deprecated: 'Use A.'},
|
|
352
|
+
],
|
|
353
|
+
}),
|
|
354
|
+
]);
|
|
355
|
+
expect(topic.sections[0].content).toEqual([
|
|
356
|
+
{type: 'prose', text: 'The alpha function.'},
|
|
357
|
+
{type: 'prose', text: 'Longer.'},
|
|
358
|
+
{type: 'code', lang: 'ts', code: 'alpha(x: string): Promise<Alpha>'},
|
|
359
|
+
{type: 'prose', text: 'Import it from `@astryxdesign/cli/api`.'},
|
|
360
|
+
{
|
|
361
|
+
type: 'table',
|
|
362
|
+
headers: ['Parameter', 'Type', 'Description'],
|
|
363
|
+
rows: [['`x`', '`string`', 'The x.']],
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
type: 'table',
|
|
367
|
+
headers: ['Returns', 'Description'],
|
|
368
|
+
rows: [['`alpha`', 'The result.']],
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
type: 'table',
|
|
372
|
+
headers: ['Throws', 'When'],
|
|
373
|
+
rows: [['`ERR_X`', 'x is bad']],
|
|
374
|
+
},
|
|
375
|
+
{type: 'code', lang: 'ts', label: 'Call it', code: "await alpha('x');"},
|
|
376
|
+
]);
|
|
377
|
+
expect(topic.sections[1]).toEqual({
|
|
378
|
+
id: 'api-codes',
|
|
379
|
+
title: 'codes',
|
|
380
|
+
content: [
|
|
381
|
+
{type: 'prose', text: 'The codes.'},
|
|
382
|
+
{
|
|
383
|
+
type: 'table',
|
|
384
|
+
headers: ['Value', 'Meaning'],
|
|
385
|
+
rows: [
|
|
386
|
+
['`A`', 'The a.'],
|
|
387
|
+
['`B`', 'The b. Deprecated: Use A.'],
|
|
388
|
+
],
|
|
389
|
+
},
|
|
390
|
+
],
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('orders commands, then functions, schemas, and enums, and leaves other namespaces out', () => {
|
|
395
|
+
const topic = buildCliReferenceDoc([
|
|
396
|
+
enumDoc('codes'),
|
|
397
|
+
schema('output', {namespace: 'cli/api'}),
|
|
398
|
+
fn('beta'),
|
|
399
|
+
schema('config'),
|
|
400
|
+
command('zed'),
|
|
401
|
+
fn('alpha'),
|
|
402
|
+
command('abc'),
|
|
403
|
+
fn('gone', {namespace: 'somewhere'}),
|
|
404
|
+
]);
|
|
405
|
+
expect(topic.sections.map(s => s.id)).toEqual([
|
|
406
|
+
'commands-abc',
|
|
407
|
+
'commands-zed',
|
|
408
|
+
'api-alpha',
|
|
409
|
+
'api-beta',
|
|
410
|
+
'api-output',
|
|
411
|
+
'api-codes',
|
|
412
|
+
]);
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
describe('section keys', () => {
|
|
417
|
+
it('join lowercase words with hyphens, whatever the name looks like', () => {
|
|
418
|
+
expect(keySegment('integrationPackCheck')).toBe('integration-pack-check');
|
|
419
|
+
expect(keySegment('doctor integration validate')).toBe(
|
|
420
|
+
'doctor-integration-validate',
|
|
421
|
+
);
|
|
422
|
+
expect(keySegment('error-codes')).toBe('error-codes');
|
|
423
|
+
expect(keySegment('isError')).toBe('is-error');
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it('come from the namespace a doc declares, and only a cli one', () => {
|
|
427
|
+
expect(cliSectionKey(fn('search'))).toBe('api-search');
|
|
428
|
+
expect(cliSectionKey(command('theme add'))).toBe('commands-theme-add');
|
|
429
|
+
expect(cliSectionKey(schema('config'))).toBeNull();
|
|
430
|
+
expect(cliSectionKey(fn('x', {namespace: 'cli'}))).toBeNull();
|
|
431
|
+
expect(Object.keys(CLI_DOC_NAMESPACES)).toEqual([
|
|
432
|
+
'cli/commands',
|
|
433
|
+
'cli/api',
|
|
434
|
+
'authoring',
|
|
435
|
+
]);
|
|
436
|
+
});
|
|
437
|
+
});
|
|
@@ -2,49 +2,46 @@
|
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Load a component doc
|
|
5
|
+
* Load a component or hook doc and check it against its kind's parser.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* / `'function'` / `'generic'`) — the same single-export convention the
|
|
13
|
-
* other authoring parsers use for config/integration/template. These carry
|
|
14
|
-
* a stamped `type` and validate against the matching per-kind parser.
|
|
15
|
-
* - OLD: the legacy loose `export const docs = {...}` (no `type`), validated
|
|
16
|
-
* against the permissive legacy union.
|
|
17
|
-
* The default export wins when both are present. Throws a readable
|
|
18
|
-
* `formatZodError`-style message on failure. Translations (`docsZh`/
|
|
19
|
-
* `docsDense`) are merged exactly as {@link loadDocs} does so callers see
|
|
20
|
-
* identical output.
|
|
7
|
+
* Reads `.doc.ts` through jiti and `.doc.mjs`/`.doc.js` natively. Both formats
|
|
8
|
+
* load: a stamped default export (`export default {type: 'component', ...}`)
|
|
9
|
+
* checked against its kind, and the legacy `export const docs = {...}` checked
|
|
10
|
+
* against the permissive legacy union. The default export wins when both are
|
|
11
|
+
* present. Throws the parser's readable message when the doc fails.
|
|
21
12
|
*
|
|
22
13
|
* @param {string} docPath absolute path to a `.doc.{ts,mjs,js}` file
|
|
23
|
-
* @param {
|
|
24
|
-
* @returns {Promise<
|
|
14
|
+
* @param {LoadDocOptions} [opts]
|
|
15
|
+
* @returns {Promise<any>} the checked (and optionally translated) doc
|
|
25
16
|
*/
|
|
26
|
-
export function loadComponentDoc(docPath: string,
|
|
27
|
-
zh?: boolean;
|
|
28
|
-
dense?: boolean;
|
|
29
|
-
lang?: string;
|
|
30
|
-
}): Promise<object>;
|
|
17
|
+
export function loadComponentDoc(docPath: string, opts?: LoadDocOptions): Promise<any>;
|
|
31
18
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
export function mergeTranslation(docs: any, translation: any): any;
|
|
37
|
-
/**
|
|
38
|
-
* Load the typed docs object from a .doc.mjs file.
|
|
39
|
-
* Supports --lang flag: 'zh' for Chinese, 'dense' for compressed format.
|
|
40
|
-
* Also supports legacy --zh and --dense flags.
|
|
41
|
-
* Translations are merged onto the base docs, keeping structure intact.
|
|
19
|
+
* Load a component or hook doc without checking it. Supports `lang` ('zh' for
|
|
20
|
+
* Chinese, 'dense' for compressed) and the legacy `zh`/`dense` flags; the
|
|
21
|
+
* translation is laid over the doc, keeping its structure. A file that exports
|
|
22
|
+
* no doc reads as `undefined`.
|
|
42
23
|
* @param {string} readmePath
|
|
43
|
-
* @param {
|
|
24
|
+
* @param {LoadDocOptions} [opts]
|
|
44
25
|
* @returns {Promise<any>}
|
|
45
26
|
*/
|
|
46
|
-
export function loadDocs(readmePath: string,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
27
|
+
export function loadDocs(readmePath: string, opts?: LoadDocOptions): Promise<any>;
|
|
28
|
+
export { mergeTranslation } from "../doc-compiler/overlays.mjs";
|
|
29
|
+
export type LoadDocOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* legacy flag for `lang: 'zh'`
|
|
32
|
+
*/
|
|
33
|
+
zh?: boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* legacy flag for `lang: 'dense'`
|
|
36
|
+
*/
|
|
37
|
+
dense?: boolean | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* wins over the legacy flags
|
|
40
|
+
*/
|
|
41
|
+
lang?: string | null | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* which root reads the doc
|
|
44
|
+
* (default: components)
|
|
45
|
+
*/
|
|
46
|
+
root?: "hooks" | "components" | undefined;
|
|
47
|
+
};
|