@astryxdesign/cli 0.6.3-canary.e59d786 → 0.6.3-canary.e78c3ce
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/docs/detail/section/section.mjs +9 -15
- package/api/docs/detail/section/section.test.mjs +15 -6
- package/api/doctor/doctor.mjs +1 -1
- package/api/doctor/doctor.test.mjs +6 -6
- 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 +4 -0
- package/assets/codemods/transforms/next/index.mjs +8 -0
- package/assets/codemods/transforms/next/migrate-native-picker-to-presentation.mjs +148 -0
- package/assets/templates/blocks/components/DateInput/DateInputDateRange.tsx +1 -1
- package/assets/templates/blocks/components/TimeInput/TimeInputConstrained.tsx +1 -0
- package/authoring/doctypes/_schema.d.mts +71 -141
- package/authoring/doctypes/_schema.mjs +29 -2
- package/authoring/doctypes/load-contract.test.mjs +1 -1
- 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.mjs +3 -2
- package/authoring/doctypes/reference/reference.doc.mjs +5 -3
- package/authoring/doctypes/reference/type.ts +7 -8
- package/authoring/index.d.ts +1 -0
- package/clients/cli/commands/build-theme.adaptations.test.mjs +100 -1
- package/clients/cli/commands/build-theme.mjs +10 -44
- package/clients/cli/commands/docs.mjs +15 -58
- package/clients/cli/commands/docs.test.mjs +11 -14
- package/clients/cli/commands/text-json-parity.test.mjs +718 -0
- package/clients/cli/commands/theme-targets.behavior.test.mjs +4 -3
- package/clients/cli/commands/upgrade.mjs +26 -7
- package/clients/cli/formatters/index.mjs +2 -0
- package/clients/cli/formatters/index.test.mjs +6 -0
- package/foundation/discovery/authoring-self-docs.test.mjs +3 -2
- package/foundation/discovery/docs-discovery.mjs +6 -5
- package/foundation/discovery/docs-discovery.test.mjs +7 -10
- 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/doc-compiler/compile.mjs +5 -4
- package/package.json +9 -9
|
@@ -15,6 +15,7 @@ import {z} from 'zod';
|
|
|
15
15
|
/** @typedef {import('./base/type.js').AuthoredDocKind} AuthoredDocKind */
|
|
16
16
|
/** @typedef {import('./namespace/type.js').NamespaceDoc} NamespaceDoc */
|
|
17
17
|
/** @typedef {import('./reference/type.js').ReferenceContentBlock} ReferenceContentBlock */
|
|
18
|
+
/** @typedef {import('./reference/type.js').GraphContentBlock} GraphContentBlock */
|
|
18
19
|
/** @typedef {import('./reference/type.js').ReferenceDoc} ReferenceDoc */
|
|
19
20
|
/** @typedef {import('./component/type.js').SingleComponentDoc} SingleComponentDoc */
|
|
20
21
|
/** @typedef {import('./base/type.js').ComponentPropDoc} ComponentPropDoc */
|
|
@@ -161,7 +162,7 @@ const ReferenceBlockSchema = z
|
|
|
161
162
|
})
|
|
162
163
|
.strict();
|
|
163
164
|
|
|
164
|
-
/** Runtime schema for
|
|
165
|
+
/** Runtime schema for the stable content-block union published in 0.6.x. */
|
|
165
166
|
export const ReferenceContentBlockSchema = z.discriminatedUnion('type', [
|
|
166
167
|
ProseBlockSchema,
|
|
167
168
|
HeadingBlockSchema,
|
|
@@ -169,6 +170,23 @@ export const ReferenceContentBlockSchema = z.discriminatedUnion('type', [
|
|
|
169
170
|
TableBlockSchema,
|
|
170
171
|
ListBlockSchema,
|
|
171
172
|
TokenReferenceBlockSchema,
|
|
173
|
+
]);
|
|
174
|
+
|
|
175
|
+
/** Runtime schema for graph-only blocks used by NamespaceDoc. */
|
|
176
|
+
export const GraphContentBlockSchema = z.discriminatedUnion('type', [
|
|
177
|
+
WorkflowBlockSchema,
|
|
178
|
+
CollectionBlockSchema,
|
|
179
|
+
ReferenceBlockSchema,
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
/** Namespace content accepts both stable reference blocks and graph-only blocks. */
|
|
183
|
+
export const NamespaceContentBlockSchema = z.discriminatedUnion('type', [
|
|
184
|
+
ProseBlockSchema,
|
|
185
|
+
HeadingBlockSchema,
|
|
186
|
+
CodeBlockSchema,
|
|
187
|
+
TableBlockSchema,
|
|
188
|
+
ListBlockSchema,
|
|
189
|
+
TokenReferenceBlockSchema,
|
|
172
190
|
WorkflowBlockSchema,
|
|
173
191
|
CollectionBlockSchema,
|
|
174
192
|
ReferenceBlockSchema,
|
|
@@ -183,6 +201,15 @@ export const ReferenceContentBlockSchema = z.discriminatedUnion('type', [
|
|
|
183
201
|
* >} _ReferenceContentBlockDriftLock
|
|
184
202
|
*/
|
|
185
203
|
|
|
204
|
+
/**
|
|
205
|
+
* @typedef {import('../_shared/contract.js').Expect<
|
|
206
|
+
* import('../_shared/contract.js').Equal<
|
|
207
|
+
* z.infer<typeof GraphContentBlockSchema>,
|
|
208
|
+
* GraphContentBlock
|
|
209
|
+
* >
|
|
210
|
+
* >} _GraphContentBlockDriftLock
|
|
211
|
+
*/
|
|
212
|
+
|
|
186
213
|
const ReferenceSectionSchema = z
|
|
187
214
|
.object({
|
|
188
215
|
id: nonEmptyString.optional(),
|
|
@@ -605,7 +632,7 @@ export const NamespaceDocKindSchema = z
|
|
|
605
632
|
.strict(),
|
|
606
633
|
)
|
|
607
634
|
.optional(),
|
|
608
|
-
blocks: z.array(
|
|
635
|
+
blocks: z.array(NamespaceContentBlockSchema).optional(),
|
|
609
636
|
})
|
|
610
637
|
.strict()
|
|
611
638
|
.superRefine((doc, context) => {
|
|
@@ -71,7 +71,7 @@ describe('load check vs published type', () => {
|
|
|
71
71
|
expect(() => parseDoc(EXAMPLES[kind], `${kind}.doc.mjs`)).not.toThrow();
|
|
72
72
|
}
|
|
73
73
|
expect(() => parseDoc({type: 'widget', name: 'x'}, 'x.doc.mjs')).toThrow(
|
|
74
|
-
/
|
|
74
|
+
/x\.doc\.mjs is invalid/u,
|
|
75
75
|
);
|
|
76
76
|
});
|
|
77
77
|
});
|
|
@@ -78,9 +78,9 @@ export const doc = {
|
|
|
78
78
|
},
|
|
79
79
|
{
|
|
80
80
|
name: 'blocks',
|
|
81
|
-
type: 'ReferenceContentBlock[]',
|
|
81
|
+
type: '(ReferenceContentBlock | GraphContentBlock)[]',
|
|
82
82
|
description:
|
|
83
|
-
'Ordered layout content.
|
|
83
|
+
'Ordered layout content. Graph-only workflow, collection, and reference blocks are available here without widening the stable ReferenceContentBlock union used by existing topic renderers.',
|
|
84
84
|
},
|
|
85
85
|
],
|
|
86
86
|
examples: [
|
|
@@ -134,32 +134,30 @@ describe('NamespaceDoc', () => {
|
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
describe('semantic blocks
|
|
138
|
-
it('
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
'workflow',
|
|
155
|
-
'collection',
|
|
156
|
-
'reference',
|
|
157
|
-
]);
|
|
137
|
+
describe('semantic graph blocks', () => {
|
|
138
|
+
it('keeps graph-only blocks out of the stable ReferenceDoc section union', () => {
|
|
139
|
+
expect(() =>
|
|
140
|
+
parseReference({
|
|
141
|
+
type: 'generic',
|
|
142
|
+
name: 'publishing',
|
|
143
|
+
title: 'Publishing',
|
|
144
|
+
description: 'Publish an integration.',
|
|
145
|
+
sections: [
|
|
146
|
+
{
|
|
147
|
+
id: 'start',
|
|
148
|
+
title: 'Start',
|
|
149
|
+
content: namespaceDoc.blocks,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
}),
|
|
153
|
+
).toThrow(/Invalid discriminator value/u);
|
|
158
154
|
});
|
|
159
155
|
|
|
160
|
-
it('
|
|
161
|
-
expect(
|
|
162
|
-
|
|
163
|
-
|
|
156
|
+
it('keeps shape-sniffing an unknown stamp for 0.6.x compatibility', () => {
|
|
157
|
+
expect(parseDoc({type: 'choice', name: 'x', props: []})).toMatchObject({
|
|
158
|
+
type: 'choice',
|
|
159
|
+
name: 'x',
|
|
160
|
+
props: [],
|
|
161
|
+
});
|
|
164
162
|
});
|
|
165
163
|
});
|
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type {AuthoredDocGraphFields, AuthoredDocKind} from '../base/type.js';
|
|
10
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
GraphContentBlock,
|
|
12
|
+
ReferenceContentBlock,
|
|
13
|
+
} from '../reference/type.js';
|
|
11
14
|
|
|
12
15
|
/** Which providers may contribute appearances to a namespace slot. */
|
|
13
16
|
export type NamespaceProviderScope = 'same' | 'configured';
|
|
@@ -67,5 +70,5 @@ export interface NamespaceDoc extends AuthoredDocGraphFields {
|
|
|
67
70
|
/** Optional source-adoption rules for otherwise-unplaced docs. */
|
|
68
71
|
adopts?: NamespaceAdoptionRule[];
|
|
69
72
|
/** Ordered renderer-neutral content and collection blocks. */
|
|
70
|
-
blocks?: ReferenceContentBlock[];
|
|
73
|
+
blocks?: (ReferenceContentBlock | GraphContentBlock)[];
|
|
71
74
|
}
|
|
@@ -67,8 +67,9 @@ export function parseDoc(input, label = 'doc') {
|
|
|
67
67
|
case 'theme':
|
|
68
68
|
return parseTheme(input, label);
|
|
69
69
|
case undefined:
|
|
70
|
-
return parseLegacyDoc(input, label);
|
|
71
70
|
default:
|
|
72
|
-
|
|
71
|
+
// 0.6.x shape-sniffed unknown stamps. Keep accepting them through the
|
|
72
|
+
// patch compatibility window; canonical writers emit a known stamp.
|
|
73
|
+
return parseLegacyDoc(input, label);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
@@ -95,7 +95,7 @@ export const doc = {
|
|
|
95
95
|
name: 'sections[].content',
|
|
96
96
|
type: 'ReferenceContentBlock[]',
|
|
97
97
|
description:
|
|
98
|
-
'Ordered content blocks: prose, heading, code, table, list, and token-ref. workflow, collection, and reference are
|
|
98
|
+
'Ordered content blocks: prose, heading, code, table, list, and token-ref. Graph-only workflow, collection, and reference blocks are available through GraphContentBlock on NamespaceDoc, without widening this stable union.',
|
|
99
99
|
required: true,
|
|
100
100
|
},
|
|
101
101
|
{
|
|
@@ -144,7 +144,7 @@ export const docs = {
|
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
146
|
type: 'prose',
|
|
147
|
-
text: 'Each `sections[].content` is an ordered array of ReferenceContentBlock,
|
|
147
|
+
text: 'Each `sections[].content` is an ordered array of ReferenceContentBlock, the stable discriminated union of prose, heading, code, table, list, and token-ref. Docs-graph-only workflow, collection, and reference blocks are exported separately as GraphContentBlock and accepted by NamespaceDoc. choice, callout, and checklist remain invalid. ReferenceContentBlock is also reused by the `notes` field on SchemaDoc and CommandDoc.',
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
150
|
type: 'code',
|
|
@@ -156,7 +156,9 @@ export const docs = {
|
|
|
156
156
|
| { type: 'code'; lang: string; code: string; label?: string }
|
|
157
157
|
| { type: 'table'; headers: string[]; rows: string[][] }
|
|
158
158
|
| { type: 'list'; style: 'ordered' | 'unordered' | 'do' | 'dont'; items: string[] }
|
|
159
|
-
| { type: 'token-ref'; topic: string; section: string }
|
|
159
|
+
| { type: 'token-ref'; topic: string; section: string };
|
|
160
|
+
|
|
161
|
+
type GraphContentBlock =
|
|
160
162
|
| { type: 'workflow'; title?: string; steps: WorkflowStep[] }
|
|
161
163
|
| { type: 'collection'; source: {slot: string}; presentation?: 'list' | 'cards' | 'compact'; whenEmpty?: 'show' | 'omit' }
|
|
162
164
|
| { type: 'reference'; target: string; projection?: {fields?: string[]; sections?: string[]} };`,
|
|
@@ -41,8 +41,13 @@ export interface ReferenceDocBlock {
|
|
|
41
41
|
presentation?: 'summary' | 'compact' | 'full';
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/** Graph-only content blocks. These are additive and do not widen the stable
|
|
45
|
+
* {@link ReferenceContentBlock} union consumed by existing exhaustive renderers. */
|
|
46
|
+
export type GraphContentBlock =
|
|
47
|
+
WorkflowDocBlock | CollectionDocBlock | ReferenceDocBlock;
|
|
48
|
+
|
|
44
49
|
/**
|
|
45
|
-
* A content block within a reference doc section
|
|
50
|
+
* A content block within a reference doc section.
|
|
46
51
|
* Ordered arrays of these blocks form renderer-neutral documentation content.
|
|
47
52
|
* A new semantic kind must ship with every renderer or fail visibly at a legacy
|
|
48
53
|
* reader boundary until that renderer is available.
|
|
@@ -55,9 +60,6 @@ export interface ReferenceDocBlock {
|
|
|
55
60
|
* { type: 'table', headers: ['Token', 'Value'], rows: [['--spacing-4', '16px']] }
|
|
56
61
|
* { type: 'list', style: 'do', items: ['Use semantic tokens'] }
|
|
57
62
|
* { type: 'token-ref', topic: 'tokens', section: 'Color Tokens' }
|
|
58
|
-
* { type: 'workflow', steps: [{title: 'Validate', references: ['command:doctor']}] }
|
|
59
|
-
* { type: 'collection', source: {slot: 'guides'}, presentation: 'cards' }
|
|
60
|
-
* { type: 'reference', target: 'schema:integration', projection: {fields: ['docs']} }
|
|
61
63
|
* ```
|
|
62
64
|
*/
|
|
63
65
|
export type ReferenceContentBlock =
|
|
@@ -80,10 +82,7 @@ export type ReferenceContentBlock =
|
|
|
80
82
|
topic: string;
|
|
81
83
|
/** Section title to pull from that topic. e.g. `'Color Tokens'` */
|
|
82
84
|
section: string;
|
|
83
|
-
}
|
|
84
|
-
| WorkflowDocBlock
|
|
85
|
-
| CollectionDocBlock
|
|
86
|
-
| ReferenceDocBlock;
|
|
85
|
+
};
|
|
87
86
|
|
|
88
87
|
/**
|
|
89
88
|
* A reference documentation file (.doc.mjs).
|
package/authoring/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file Ensures `astryx theme build` preserves AST-012 adaptation semantics.
|
|
5
5
|
* Runtime and static output share core's compiler; this suite guards the CLI
|
|
6
|
-
* loading, diagnostics, serialization, and extension boundaries around it
|
|
6
|
+
* loading, diagnostics, serialization, and extension boundaries around it,
|
|
7
|
+
* including root component overrides underneath adapted typography scales.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import {afterEach, beforeAll, beforeEach, describe, expect, it} from 'vitest';
|
|
@@ -94,6 +95,104 @@ describe('theme build adaptations', () => {
|
|
|
94
95
|
);
|
|
95
96
|
});
|
|
96
97
|
|
|
98
|
+
it.each([
|
|
99
|
+
['defined', writeTheme],
|
|
100
|
+
['plain', writePlainTheme],
|
|
101
|
+
])(
|
|
102
|
+
'preserves component pins in %s themes and built extensions',
|
|
103
|
+
async (_kind, write) => {
|
|
104
|
+
const {defineTheme, generateAdaptationCSS, generateThemeCSS} =
|
|
105
|
+
await import('@astryxdesign/core/theme');
|
|
106
|
+
const project = path.join(tmpDir, 'project');
|
|
107
|
+
const themesDir = path.join(project, 'themes');
|
|
108
|
+
const displayFamily =
|
|
109
|
+
'Sarina, "Brush Script MT", "Snell Roundhand", cursive';
|
|
110
|
+
const input = {
|
|
111
|
+
name: 'adaptive-display',
|
|
112
|
+
typography: {
|
|
113
|
+
scale: {base: 16, ratio: 1.25},
|
|
114
|
+
body: {family: 'Outfit', fallbacks: 'sans-serif'},
|
|
115
|
+
},
|
|
116
|
+
components: {
|
|
117
|
+
text: Object.fromEntries(
|
|
118
|
+
['display-1', 'display-2', 'display-3'].map(type => [
|
|
119
|
+
`type:${type}`,
|
|
120
|
+
{fontFamily: displayFamily},
|
|
121
|
+
]),
|
|
122
|
+
),
|
|
123
|
+
button: {base: {borderRadius: '12px'}},
|
|
124
|
+
},
|
|
125
|
+
adaptations: {
|
|
126
|
+
rules: [
|
|
127
|
+
{
|
|
128
|
+
when: {width: {below: 'md'}, pointer: 'coarse'},
|
|
129
|
+
value: {typography: {scale: {base: 14, ratio: 1.2}}},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
when: {contrast: 'more'},
|
|
133
|
+
value: {
|
|
134
|
+
typography: {scale: {base: 15}},
|
|
135
|
+
components: {
|
|
136
|
+
text: {'type:display-1': {fontFamily: 'monospace'}},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
const themeFile = write(themesDir, input.name, JSON.stringify(input));
|
|
144
|
+
const result = await build(project, themeFile);
|
|
145
|
+
expect(result.code, result.stderr).toBe(0);
|
|
146
|
+
const css = fs.readFileSync(
|
|
147
|
+
path.join(themesDir, 'adaptive-display.css'),
|
|
148
|
+
'utf8',
|
|
149
|
+
);
|
|
150
|
+
const compact = value => value.replace(/\s+/g, ' ').trim();
|
|
151
|
+
const source = defineTheme(input);
|
|
152
|
+
const runtime = generateThemeCSS(source);
|
|
153
|
+
// The CLI wraps root, adaptation, and surface CSS in separate @layer
|
|
154
|
+
// blocks; their contents and order must still match runtime output.
|
|
155
|
+
const adaptationCSS = generateAdaptationCSS(source).component;
|
|
156
|
+
const [rootCSS, surfaceCSS] = runtime.component.split(adaptationCSS);
|
|
157
|
+
const blocks = [rootCSS, adaptationCSS, surfaceCSS].map(compact);
|
|
158
|
+
let previousIndex = -1;
|
|
159
|
+
for (const block of blocks) {
|
|
160
|
+
expect(compact(css)).toContain(block);
|
|
161
|
+
const index = compact(css).indexOf(block);
|
|
162
|
+
expect(index).toBeGreaterThan(previousIndex);
|
|
163
|
+
previousIndex = index;
|
|
164
|
+
}
|
|
165
|
+
expect(compact(css)).toContain(compact(runtime.prose));
|
|
166
|
+
const scaleBlock = css.slice(
|
|
167
|
+
css.indexOf('@media (width < 768px) and (pointer: coarse)'),
|
|
168
|
+
css.indexOf('@media (prefers-contrast: more)'),
|
|
169
|
+
);
|
|
170
|
+
expect(scaleBlock).toContain('--font-size-base: 0.875rem');
|
|
171
|
+
expect(scaleBlock).not.toContain('.astryx-text');
|
|
172
|
+
expect(scaleBlock).not.toContain('.astryx-heading');
|
|
173
|
+
expect(scaleBlock).not.toContain('.astryx-button');
|
|
174
|
+
expect(css).toContain(`font-family: ${displayFamily};`);
|
|
175
|
+
expect(css).toContain('font-family: monospace;');
|
|
176
|
+
|
|
177
|
+
const {adaptiveDisplayTheme: builtTheme} = await import(
|
|
178
|
+
pathToFileURL(path.join(themesDir, 'adaptive-display.js')).href
|
|
179
|
+
);
|
|
180
|
+
expect(builtTheme.__adaptationRules).toBeUndefined();
|
|
181
|
+
expect(generateThemeCSS(builtTheme)).toEqual(runtime);
|
|
182
|
+
const childInput = {
|
|
183
|
+
name: 'display-child',
|
|
184
|
+
components: {text: {'type:display-2': {fontFamily: 'serif'}}},
|
|
185
|
+
};
|
|
186
|
+
const fromSource = defineTheme({...childInput, extends: source});
|
|
187
|
+
const fromBuilt = defineTheme({...childInput, extends: builtTheme});
|
|
188
|
+
expect(generateThemeCSS(fromBuilt)).toEqual(generateThemeCSS(fromSource));
|
|
189
|
+
expect(fromBuilt.__adaptationRules[0].components).toBeUndefined();
|
|
190
|
+
expect(fromBuilt.components.text['type:display-2'].fontFamily).toBe(
|
|
191
|
+
'serif',
|
|
192
|
+
);
|
|
193
|
+
},
|
|
194
|
+
);
|
|
195
|
+
|
|
97
196
|
it('resolves a plain object whose only input-only field is adaptations', async () => {
|
|
98
197
|
const project = path.join(tmpDir, 'project');
|
|
99
198
|
const themesDir = path.join(project, 'themes');
|
|
@@ -33,7 +33,7 @@ import {fileURLToPath} from 'node:url';
|
|
|
33
33
|
import {spawn} from 'node:child_process';
|
|
34
34
|
import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
|
|
35
35
|
import {jsonOut} from '../../../foundation/response/json.mjs';
|
|
36
|
-
import {emit, section, text, list, code} from '../formatters/index.mjs';
|
|
36
|
+
import {emit, section, text, list, records, code} from '../formatters/index.mjs';
|
|
37
37
|
import {logger} from '../../../api/logger.mjs';
|
|
38
38
|
import {cliError} from '../lib/cli-error.mjs';
|
|
39
39
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
@@ -229,47 +229,6 @@ function printThemeList(themes) {
|
|
|
229
229
|
);
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
/**
|
|
233
|
-
* Render the targets as one greppable line each, under an aligned header. A
|
|
234
|
-
* `records()` block would be five lines per target — over a thousand for the
|
|
235
|
-
* full surface, which is the view this command exists to make readable.
|
|
236
|
-
* @param {import('../../../api/theme/theme.type.mjs').ThemeTargetEntry[]} targets
|
|
237
|
-
* @returns {string}
|
|
238
|
-
*/
|
|
239
|
-
function formatTargetsTable(targets) {
|
|
240
|
-
const rows = targets.map(t => ({
|
|
241
|
-
key: t.deprecatedFor
|
|
242
|
-
? `${t.key} [deprecated; use ${t.deprecatedFor}]`
|
|
243
|
-
: t.key,
|
|
244
|
-
component: t.component,
|
|
245
|
-
props: t.props.join(', ') || '-',
|
|
246
|
-
states: t.states.join(', ') || '-',
|
|
247
|
-
}));
|
|
248
|
-
const head = {
|
|
249
|
-
key: 'key',
|
|
250
|
-
component: 'component',
|
|
251
|
-
props: 'props',
|
|
252
|
-
states: 'states',
|
|
253
|
-
};
|
|
254
|
-
const width = (/** @type {'key'|'component'|'props'} */ field) =>
|
|
255
|
-
[head, ...rows].reduce((max, r) => Math.max(max, r[field].length), 0);
|
|
256
|
-
const w = {
|
|
257
|
-
key: width('key'),
|
|
258
|
-
component: width('component'),
|
|
259
|
-
props: width('props'),
|
|
260
|
-
};
|
|
261
|
-
const line = (/** @type {typeof head} */ r) =>
|
|
262
|
-
[
|
|
263
|
-
r.key.padEnd(w.key),
|
|
264
|
-
r.component.padEnd(w.component),
|
|
265
|
-
r.props.padEnd(w.props),
|
|
266
|
-
r.states,
|
|
267
|
-
]
|
|
268
|
-
.join(' ')
|
|
269
|
-
.trimEnd();
|
|
270
|
-
return [line(head), ...rows.map(line)].join('\n');
|
|
271
|
-
}
|
|
272
|
-
|
|
273
232
|
/**
|
|
274
233
|
* @param {import('commander').Command} program
|
|
275
234
|
*/
|
|
@@ -811,9 +770,16 @@ export function registerTheme(program) {
|
|
|
811
770
|
emit(
|
|
812
771
|
section(
|
|
813
772
|
'Theming targets',
|
|
814
|
-
`${targets.length} across ${componentCount} component${componentCount === 1 ? '' : 's'}`,
|
|
773
|
+
`${targets.length} across ${componentCount} component${componentCount === 1 ? '' : 's'}\n(key - component - props - states - className - deprecatedFor)`,
|
|
815
774
|
),
|
|
816
|
-
|
|
775
|
+
records(targets, {
|
|
776
|
+
fields: ['key', 'component', 'props', 'states', 'className', 'deprecatedFor'],
|
|
777
|
+
layout: 'inline',
|
|
778
|
+
format: {
|
|
779
|
+
deprecatedFor: (/** @type {string|null} */ v) =>
|
|
780
|
+
v ? `deprecated; use ${v}` : '',
|
|
781
|
+
},
|
|
782
|
+
}),
|
|
817
783
|
text(
|
|
818
784
|
[
|
|
819
785
|
`Each key goes under \`components\` in defineTheme; it paints \`.astryx-<key>\`.`,
|
|
@@ -23,8 +23,6 @@ import {
|
|
|
23
23
|
text,
|
|
24
24
|
code,
|
|
25
25
|
wrapText,
|
|
26
|
-
displayWidth,
|
|
27
|
-
WRAP_WIDTH,
|
|
28
26
|
} from '../formatters/index.mjs';
|
|
29
27
|
import {cliError} from '../lib/cli-error.mjs';
|
|
30
28
|
import {defineCommand} from '../lib/define-command.mjs';
|
|
@@ -52,28 +50,6 @@ function formatTable(headers, rows) {
|
|
|
52
50
|
return `${head}\n${sep}\n${body}`;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
/**
|
|
56
|
-
* A table too wide for {@link WRAP_WIDTH}: one `header: cell` line per cell and
|
|
57
|
-
* a blank line between rows, so nothing runs off the side of a terminal.
|
|
58
|
-
* @param {string[]} headers
|
|
59
|
-
* @param {string[][]} rows
|
|
60
|
-
* @returns {string}
|
|
61
|
-
*/
|
|
62
|
-
function formatTableVertical(headers, rows) {
|
|
63
|
-
const width = Math.max(...headers.map(h => h.length)) + 2;
|
|
64
|
-
return rows
|
|
65
|
-
.map(row =>
|
|
66
|
-
headers
|
|
67
|
-
.map((h, i) =>
|
|
68
|
-
wrapText(`${`${h}:`.padEnd(width)}${row[i] ?? ''}`, {
|
|
69
|
-
indent: ' '.repeat(width),
|
|
70
|
-
}),
|
|
71
|
-
)
|
|
72
|
-
.join('\n'),
|
|
73
|
-
)
|
|
74
|
-
.join('\n\n');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
53
|
/**
|
|
78
54
|
* @param {string[]} headers
|
|
79
55
|
* @param {string[][]} rows
|
|
@@ -91,7 +67,7 @@ function formatTableCompact(headers, rows) {
|
|
|
91
67
|
function formatBlock(block, detail) {
|
|
92
68
|
switch (block.type) {
|
|
93
69
|
case 'prose':
|
|
94
|
-
return
|
|
70
|
+
return block.text;
|
|
95
71
|
|
|
96
72
|
case 'heading':
|
|
97
73
|
return `${'#'.repeat(block.level || 3)} ${block.text}`;
|
|
@@ -110,12 +86,7 @@ function formatBlock(block, detail) {
|
|
|
110
86
|
if (detail === 'compact') {
|
|
111
87
|
return formatTableCompact(block.headers, block.rows);
|
|
112
88
|
}
|
|
113
|
-
|
|
114
|
-
const table = formatTable(block.headers, block.rows);
|
|
115
|
-
return table.split('\n').some(line => displayWidth(line) > WRAP_WIDTH)
|
|
116
|
-
? formatTableVertical(block.headers, block.rows)
|
|
117
|
-
: table;
|
|
118
|
-
}
|
|
89
|
+
return formatTable(block.headers, block.rows);
|
|
119
90
|
|
|
120
91
|
case 'list': {
|
|
121
92
|
const prefix =
|
|
@@ -126,21 +97,9 @@ function formatBlock(block, detail) {
|
|
|
126
97
|
: block.style === 'do'
|
|
127
98
|
? () => '+ '
|
|
128
99
|
: () => '- ';
|
|
129
|
-
return block.items
|
|
130
|
-
.map((item, i) => {
|
|
131
|
-
const head = prefix(i);
|
|
132
|
-
return wrapText(`${head}${item}`, {indent: ' '.repeat(head.length)});
|
|
133
|
-
})
|
|
134
|
-
.join('\n');
|
|
100
|
+
return block.items.map((item, i) => `${prefix(i)}${item}`).join('\n');
|
|
135
101
|
}
|
|
136
102
|
|
|
137
|
-
case 'workflow':
|
|
138
|
-
case 'collection':
|
|
139
|
-
case 'reference':
|
|
140
|
-
throw new Error(
|
|
141
|
-
`Documentation block "${block.type}" requires the compiled graph renderer.`,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
103
|
default:
|
|
145
104
|
return null;
|
|
146
105
|
}
|
|
@@ -173,16 +132,15 @@ function formatSection(section, detail) {
|
|
|
173
132
|
*/
|
|
174
133
|
function formatReferenceFull(docs, detail) {
|
|
175
134
|
if (detail === 'brief') {
|
|
176
|
-
const header =
|
|
135
|
+
const header = `${docs.title}: ${docs.description}`;
|
|
177
136
|
const sections = docs.sections.map(s => formatSection(s, detail));
|
|
178
137
|
return `${header}\n${sections.join('\n')}`;
|
|
179
138
|
}
|
|
180
139
|
|
|
181
|
-
const description = wrapText(docs.description);
|
|
182
140
|
const header =
|
|
183
141
|
detail === 'compact'
|
|
184
|
-
? `# ${docs.title}\n${description}`
|
|
185
|
-
: `# ${docs.title}\n\n${description}`;
|
|
142
|
+
? `# ${docs.title}\n${docs.description}`
|
|
143
|
+
: `# ${docs.title}\n\n${docs.description}`;
|
|
186
144
|
const sections = docs.sections.map(s => formatSection(s, detail));
|
|
187
145
|
const sep = detail === 'compact' ? '\n\n' : '\n\n';
|
|
188
146
|
return `${header}\n\n${sections.join(sep)}`;
|
|
@@ -196,7 +154,10 @@ function formatReferenceFull(docs, detail) {
|
|
|
196
154
|
*/
|
|
197
155
|
function emitIndex(index, run) {
|
|
198
156
|
emit(
|
|
199
|
-
section(
|
|
157
|
+
section(
|
|
158
|
+
index.title,
|
|
159
|
+
index.description ? wrapText(index.description) : undefined,
|
|
160
|
+
),
|
|
200
161
|
records(index.sections, {
|
|
201
162
|
fields: ['id', 'title', 'summary'],
|
|
202
163
|
layout: 'inline',
|
|
@@ -275,19 +236,15 @@ export function registerDocs(program) {
|
|
|
275
236
|
|
|
276
237
|
switch (result.type) {
|
|
277
238
|
case 'docs.list': {
|
|
278
|
-
//
|
|
279
|
-
// description
|
|
239
|
+
// Keep the published 0.6 text projection: stacked topic and
|
|
240
|
+
// description fields, followed by the two original usage lines.
|
|
280
241
|
emit(
|
|
281
242
|
section('Available docs'),
|
|
282
|
-
records(result.data, {
|
|
283
|
-
fields: ['topic', 'description'],
|
|
284
|
-
layout: 'inline',
|
|
285
|
-
}),
|
|
243
|
+
records(result.data, {fields: ['topic', 'description']}),
|
|
286
244
|
text(
|
|
287
245
|
[
|
|
288
|
-
`Usage: ${run} docs <topic
|
|
289
|
-
` ${run} docs <topic>
|
|
290
|
-
` ${run} docs <topic> <section> read one section`,
|
|
246
|
+
`Usage: ${run} docs <topic>`,
|
|
247
|
+
` ${run} docs <topic> <section>`,
|
|
291
248
|
].join('\n'),
|
|
292
249
|
),
|
|
293
250
|
);
|
|
@@ -108,11 +108,11 @@ describe('progressive reads', () => {
|
|
|
108
108
|
/** @param {string} out */
|
|
109
109
|
const widest = out => Math.max(...out.split('\n').map(line => line.length));
|
|
110
110
|
|
|
111
|
-
it('
|
|
111
|
+
it('keeps the 0.6.x stacked topic list', async () => {
|
|
112
112
|
const {status, stdout} = await runCli(['docs']);
|
|
113
113
|
expect(status).toBe(0);
|
|
114
|
-
expect(stdout).toMatch(/^principles
|
|
115
|
-
expect(
|
|
114
|
+
expect(stdout).toMatch(/^topic: +principles$/m);
|
|
115
|
+
expect(stdout).toContain('Usage: pnpm exec astryx docs <topic>');
|
|
116
116
|
}, SLOW);
|
|
117
117
|
|
|
118
118
|
it("prints a topic's section index with the keys to read by", async () => {
|
|
@@ -139,9 +139,6 @@ describe('progressive reads', () => {
|
|
|
139
139
|
expect((await runCli(['--detail', 'full', 'docs', 'theme'])).stdout).toBe(
|
|
140
140
|
full.stdout,
|
|
141
141
|
);
|
|
142
|
-
expect(widest(full.stdout.replace(/```[\s\S]*?```/g, ''))).toBeLessThanOrEqual(
|
|
143
|
-
120,
|
|
144
|
-
);
|
|
145
142
|
}, SLOW);
|
|
146
143
|
|
|
147
144
|
it('returns the matching envelopes as JSON', async () => {
|
|
@@ -176,14 +173,14 @@ describe('text width in every language', () => {
|
|
|
176
173
|
return max;
|
|
177
174
|
};
|
|
178
175
|
|
|
179
|
-
it
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
176
|
+
it('keeps the additive section index within 120 columns', async () => {
|
|
177
|
+
const {status, stdout} = await runCli([
|
|
178
|
+
'docs',
|
|
179
|
+
'theme',
|
|
180
|
+
'--index',
|
|
181
|
+
'--lang',
|
|
182
|
+
'zh',
|
|
183
|
+
]);
|
|
187
184
|
expect(status).toBe(0);
|
|
188
185
|
expect(widest(stdout)).toBeLessThanOrEqual(120);
|
|
189
186
|
}, SLOW);
|