@astryxdesign/cli 0.6.3-canary.1b199ad → 0.6.3-canary.1f30d4e
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/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
|
@@ -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);
|