@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,383 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import * as os from 'node:os';
|
|
7
|
+
import {Command} from 'commander';
|
|
8
|
+
import {formatBlock, registerDocs} from './docs.mjs';
|
|
9
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
10
|
+
import {displayWidth} from '../formatters/index.mjs';
|
|
11
|
+
|
|
12
|
+
let tmpDir;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-docs-test-'));
|
|
16
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
17
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
22
|
+
vi.restoreAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function createProgram() {
|
|
26
|
+
const program = new Command();
|
|
27
|
+
program.exitOverride(); // Throw instead of calling process.exit
|
|
28
|
+
registerDocs(program);
|
|
29
|
+
return program;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('registerDocs', () => {
|
|
33
|
+
it('lists available topics when no topic given', async () => {
|
|
34
|
+
const program = createProgram();
|
|
35
|
+
await program.parseAsync(['node', 'astryx', 'docs']);
|
|
36
|
+
|
|
37
|
+
const output = console.log.mock.calls.map(c => c[0]).join('\n');
|
|
38
|
+
expect(output).toContain('principles');
|
|
39
|
+
expect(output).toContain('tokens');
|
|
40
|
+
expect(output).not.toContain('shadcn-compatibility');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('errors for unknown topic', async () => {
|
|
44
|
+
const program = createProgram();
|
|
45
|
+
vi.spyOn(process, 'exit').mockImplementation(code => {
|
|
46
|
+
throw new Error(`exit ${code}`);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await expect(
|
|
50
|
+
program.parseAsync(['node', 'astryx', 'docs', 'nonexistent']),
|
|
51
|
+
).rejects.toThrow('exit 1');
|
|
52
|
+
|
|
53
|
+
const errorOutput = console.error.mock.calls.map(c => c[0]).join('\n');
|
|
54
|
+
expect(errorOutput).toContain('Unknown topic');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('hyphenated doc filenames', () => {
|
|
59
|
+
it('lists hyphenated topics like getting-started', async () => {
|
|
60
|
+
const program = createProgram();
|
|
61
|
+
await program.parseAsync(['node', 'astryx', 'docs']);
|
|
62
|
+
|
|
63
|
+
const output = console.log.mock.calls.map(c => c[0]).join('\n');
|
|
64
|
+
expect(output).toContain('getting-started');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('loads a hyphenated topic by name', async () => {
|
|
68
|
+
const program = createProgram();
|
|
69
|
+
await program.parseAsync(['node', 'astryx', 'docs', 'getting-started']);
|
|
70
|
+
|
|
71
|
+
const output = console.log.mock.calls.map(c => c[0]).join('\n');
|
|
72
|
+
expect(output.length).toBeGreaterThan(0);
|
|
73
|
+
expect(console.error).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('returns docs.detail via API for hyphenated topic', async () => {
|
|
77
|
+
const {docs: docsApi} = await import('../../../api/docs/docs.mjs');
|
|
78
|
+
const result = await docsApi('getting-started', undefined, {full: true});
|
|
79
|
+
expect(result.type).toBe('docs.detail');
|
|
80
|
+
expect(result.data).toBeDefined();
|
|
81
|
+
expect(result.data.description).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('migration docs', () => {
|
|
86
|
+
it('lists the migration topic', async () => {
|
|
87
|
+
const program = createProgram();
|
|
88
|
+
await program.parseAsync(['node', 'astryx', 'docs']);
|
|
89
|
+
|
|
90
|
+
const output = console.log.mock.calls.map(c => c[0]).join('\n');
|
|
91
|
+
expect(output).toContain('migration');
|
|
92
|
+
expect(output).toContain('Tailwind');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('loads migration docs by topic name', async () => {
|
|
96
|
+
const program = createProgram();
|
|
97
|
+
await program.parseAsync(['node', 'astryx', 'docs', 'migration']);
|
|
98
|
+
|
|
99
|
+
const output = console.log.mock.calls.map(c => c[0]).join('\n');
|
|
100
|
+
expect(output).toContain('Migration Guide');
|
|
101
|
+
expect(output).toContain('Recommended Order');
|
|
102
|
+
expect(output).toContain('Map shadcn and Radix Primitives');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('progressive reads', () => {
|
|
107
|
+
const SLOW = 60_000;
|
|
108
|
+
/** @param {string} out */
|
|
109
|
+
const widest = out => Math.max(...out.split('\n').map(line => line.length));
|
|
110
|
+
|
|
111
|
+
it('lists every topic on one line each', async () => {
|
|
112
|
+
const {status, stdout} = await runCli(['docs']);
|
|
113
|
+
expect(status).toBe(0);
|
|
114
|
+
expect(stdout).toMatch(/^principles +\S/m);
|
|
115
|
+
expect(widest(stdout)).toBeLessThanOrEqual(120);
|
|
116
|
+
expect(stdout).toContain('Usage: pnpm exec astryx docs <topic>');
|
|
117
|
+
}, SLOW);
|
|
118
|
+
|
|
119
|
+
it("prints a topic's section index with the keys to read by", async () => {
|
|
120
|
+
const {status, stdout} = await runCli(['docs', 'theme', '--index']);
|
|
121
|
+
expect(status).toBe(0);
|
|
122
|
+
expect(stdout).toMatch(/^quick-start +Wrap your app in a theme/m);
|
|
123
|
+
expect(stdout).toContain('docs theme <section>');
|
|
124
|
+
expect(stdout).toMatch(/Read everything: +\S.* docs theme --full$/m);
|
|
125
|
+
expect(widest(stdout)).toBeLessThanOrEqual(120);
|
|
126
|
+
}, SLOW);
|
|
127
|
+
|
|
128
|
+
it('prints one section by its key', async () => {
|
|
129
|
+
const {status, stdout} = await runCli(['docs', 'theme', 'quick-start']);
|
|
130
|
+
expect(status).toBe(0);
|
|
131
|
+
expect(stdout).toMatch(/^## Wrap your app in a theme/m);
|
|
132
|
+
}, SLOW);
|
|
133
|
+
|
|
134
|
+
it("lists a topic's sections by default; --full prints the whole topic", async () => {
|
|
135
|
+
const index = await runCli(['docs', 'theme', '--index']);
|
|
136
|
+
expect((await runCli(['docs', 'theme'])).stdout).toBe(index.stdout);
|
|
137
|
+
const full = await runCli(['docs', 'theme', '--full']);
|
|
138
|
+
expect(full.status).toBe(0);
|
|
139
|
+
expect(full.stdout).toMatch(/^## Wrap your app in a theme/m);
|
|
140
|
+
expect(full.stdout.length).toBeGreaterThan(index.stdout.length * 3);
|
|
141
|
+
expect((await runCli(['--detail', 'full', 'docs', 'theme', '--full'])).stdout).toBe(
|
|
142
|
+
full.stdout,
|
|
143
|
+
);
|
|
144
|
+
}, SLOW);
|
|
145
|
+
|
|
146
|
+
it('returns the matching envelopes as JSON', async () => {
|
|
147
|
+
const envelope = async args => JSON.parse((await runCli([...args, '--json'])).stdout);
|
|
148
|
+
// JSON keeps docs(): a bare read is the whole topic.
|
|
149
|
+
expect((await envelope(['docs', 'theme'])).type).toBe('docs.detail');
|
|
150
|
+
expect((await envelope(['docs', 'theme', '--full'])).type).toBe('docs.detail');
|
|
151
|
+
expect((await envelope(['docs', 'theme', '--index'])).type).toBe(
|
|
152
|
+
'docs.index',
|
|
153
|
+
);
|
|
154
|
+
expect((await envelope(['docs', 'theme', 'quick-start'])).type).toBe(
|
|
155
|
+
'docs.detail.section',
|
|
156
|
+
);
|
|
157
|
+
}, SLOW);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('blocks as text', () => {
|
|
161
|
+
const SLOW = 60_000;
|
|
162
|
+
|
|
163
|
+
it('prints a code label above the fence, never inside it', () => {
|
|
164
|
+
for (const lang of ['bash', 'css', 'json', 'html', 'text', 'tsx']) {
|
|
165
|
+
expect(
|
|
166
|
+
formatBlock({type: 'code', lang, label: 'Terminal', code: 'x'}, 'full'),
|
|
167
|
+
).toBe(`Terminal:\n\`\`\`${lang}\nx\n\`\`\``);
|
|
168
|
+
}
|
|
169
|
+
expect(formatBlock({type: 'code', lang: 'bash', code: 'x'}, 'full')).toBe(
|
|
170
|
+
'```bash\nx\n```',
|
|
171
|
+
);
|
|
172
|
+
// A label that already ends in a colon does not get a second one.
|
|
173
|
+
expect(
|
|
174
|
+
formatBlock({type: 'code', lang: 'css', label: 'globals.css:', code: 'x'}, 'full'),
|
|
175
|
+
).toBe('globals.css:\n```css\nx\n```');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('escapes pipes in table cells, so a union type stays one column', () => {
|
|
179
|
+
const table = {
|
|
180
|
+
type: /** @type {const} */ ('table'),
|
|
181
|
+
headers: ['Prop', 'Type', 'Default'],
|
|
182
|
+
rows: [
|
|
183
|
+
['mode', "'system' | 'light' | 'dark'", "'system'"],
|
|
184
|
+
['theme', 'DefinedTheme', '-'],
|
|
185
|
+
],
|
|
186
|
+
};
|
|
187
|
+
const lines = /** @type {string} */ (formatBlock(table, 'full')).split('\n');
|
|
188
|
+
expect(lines).toHaveLength(4);
|
|
189
|
+
// Every line has exactly two column separators, all at the same place.
|
|
190
|
+
for (const line of lines) expect(line.split(' | ')).toHaveLength(3);
|
|
191
|
+
expect(new Set(lines.map(line => line.indexOf(' | '))).size).toBe(1);
|
|
192
|
+
expect(lines[2]).toContain("'system' \\| 'light' \\| 'dark'");
|
|
193
|
+
expect(formatBlock(table, 'brief')).toBe(
|
|
194
|
+
"mode='system' \\| 'light' \\| 'dark' | theme=DefinedTheme",
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('prints the labels of a real section above their fences', async () => {
|
|
199
|
+
const {status, stdout} = await runCli(['docs', 'theme', 'quick-start']);
|
|
200
|
+
expect(status).toBe(0);
|
|
201
|
+
expect(stdout).toContain('Install a theme package:\n```bash\nnpm install');
|
|
202
|
+
expect(stdout).not.toContain('// Install a theme package');
|
|
203
|
+
}, SLOW);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('the docs tree, one level at a time', () => {
|
|
207
|
+
const SLOW = 60_000;
|
|
208
|
+
/** @param {string} out */
|
|
209
|
+
const widest = out => Math.max(...out.split('\n').map(line => line.length));
|
|
210
|
+
|
|
211
|
+
it('lists the docs tree first, under its own heading, then the topics', async () => {
|
|
212
|
+
const {status, stdout} = await runCli(['docs']);
|
|
213
|
+
expect(status).toBe(0);
|
|
214
|
+
expect(stdout).toMatch(/^Docs tree$/m);
|
|
215
|
+
expect(stdout).toMatch(/^Topics$/m);
|
|
216
|
+
expect(stdout).toMatch(/^cli +Commands, programmatic APIs/m);
|
|
217
|
+
expect(stdout.indexOf('\ncli ')).toBeLessThan(stdout.indexOf('\nprinciples '));
|
|
218
|
+
expect(stdout).not.toMatch(/^cli-integrations /m);
|
|
219
|
+
}, SLOW);
|
|
220
|
+
|
|
221
|
+
it("shows a child's own name when its route name does not spell it", async () => {
|
|
222
|
+
const {status, stdout} = await runCli(['docs', 'cli/api/functions']);
|
|
223
|
+
expect(status).toBe(0);
|
|
224
|
+
expect(stdout).toMatch(/^assert-response +assertResponse\(\): \S/m);
|
|
225
|
+
expect(stdout).toMatch(/^search +search\(\): Unified ranked search/m);
|
|
226
|
+
}, SLOW);
|
|
227
|
+
|
|
228
|
+
it('wraps namespace summaries without discarding searchable words', async () => {
|
|
229
|
+
const {status, stdout} = await runCli([
|
|
230
|
+
'docs',
|
|
231
|
+
'cli/integrations/building-blocks/templates',
|
|
232
|
+
]);
|
|
233
|
+
expect(status).toBe(0);
|
|
234
|
+
expect(stdout).toMatch(/^start-a-template +Help others build apps faster/m);
|
|
235
|
+
expect(stdout).not.toMatch(/^start-a-template +Start a template:/m);
|
|
236
|
+
expect(stdout).toMatch(/full page or page\s+section\./);
|
|
237
|
+
expect(widest(stdout)).toBeLessThanOrEqual(120);
|
|
238
|
+
}, SLOW);
|
|
239
|
+
|
|
240
|
+
it('prints a namespace: each slot, its children, and how to go down and up', async () => {
|
|
241
|
+
const {status, stdout} = await runCli(['docs', 'cli/api']);
|
|
242
|
+
expect(status).toBe(0);
|
|
243
|
+
expect(stdout).toMatch(/^API$/m);
|
|
244
|
+
expect(stdout).toMatch(/^Reference$/m);
|
|
245
|
+
expect(stdout).toMatch(/^functions +Every function/m);
|
|
246
|
+
expect(stdout).toMatch(/^schemas +/m);
|
|
247
|
+
expect(stdout).toMatch(/^enums +/m);
|
|
248
|
+
// One level only: no function is listed on the api page.
|
|
249
|
+
expect(stdout).not.toMatch(/^search +/m);
|
|
250
|
+
expect(stdout).toMatch(/Open one: .*docs cli\/api\/<name>$/m);
|
|
251
|
+
expect(stdout).toMatch(/Up: .*docs cli$/m);
|
|
252
|
+
expect(widest(stdout)).toBeLessThanOrEqual(120);
|
|
253
|
+
}, SLOW);
|
|
254
|
+
|
|
255
|
+
it('prints a typed doc and the way back up', async () => {
|
|
256
|
+
const {status, stdout} = await runCli(['docs', 'cli/api/functions/search']);
|
|
257
|
+
expect(status).toBe(0);
|
|
258
|
+
expect(stdout).toMatch(/^## search\(\)/m);
|
|
259
|
+
expect(stdout).toContain('Read it with `astryx docs cli/commands/search`.');
|
|
260
|
+
expect(stdout).toMatch(/Up: .*docs cli\/api\/functions$/m);
|
|
261
|
+
}, SLOW);
|
|
262
|
+
|
|
263
|
+
it('reads the dense variant whole, asked with --dense or with --lang dense', async () => {
|
|
264
|
+
for (const args of [['--dense', 'docs', 'theme'], ['--lang', 'dense', 'docs', 'theme']]) {
|
|
265
|
+
const {status, stdout} = await runCli(args);
|
|
266
|
+
expect(status).toBe(0);
|
|
267
|
+
expect(stdout).not.toContain('Read one section:');
|
|
268
|
+
}
|
|
269
|
+
}, SLOW);
|
|
270
|
+
|
|
271
|
+
it('refuses --index with --full', async () => {
|
|
272
|
+
const both = await runCli(['docs', 'theme', '--index', '--full', '--json']);
|
|
273
|
+
expect(both.status).toBe(1);
|
|
274
|
+
expect(JSON.parse(both.stdout).code).toBe('ERR_INVALID_ARGUMENT');
|
|
275
|
+
}, SLOW);
|
|
276
|
+
|
|
277
|
+
it('reads the integration guides by their routes, and not by the old name', async () => {
|
|
278
|
+
// cli/integrations is a namespace: one level, its guides by slot.
|
|
279
|
+
const level = await runCli(['docs', 'cli/integrations']);
|
|
280
|
+
expect(level.status).toBe(0);
|
|
281
|
+
expect(level.stdout).toMatch(
|
|
282
|
+
/^quick-start +Create a new integration package/m,
|
|
283
|
+
);
|
|
284
|
+
expect(level.stdout).toMatch(/^building-blocks +/m);
|
|
285
|
+
const guide = await runCli([
|
|
286
|
+
'docs',
|
|
287
|
+
'cli/integrations/building-blocks/codemods',
|
|
288
|
+
'--index',
|
|
289
|
+
]);
|
|
290
|
+
expect(guide.status).toBe(0);
|
|
291
|
+
expect(guide.stdout).toMatch(
|
|
292
|
+
/Read one section: .*docs cli\/integrations\/building-blocks\/codemods <section>/,
|
|
293
|
+
);
|
|
294
|
+
// A bare read is one level too: the sections, and how to read it all.
|
|
295
|
+
const bare = await runCli([
|
|
296
|
+
'docs',
|
|
297
|
+
'cli/integrations/building-blocks/codemods',
|
|
298
|
+
]);
|
|
299
|
+
expect(bare.status).toBe(0);
|
|
300
|
+
expect(bare.stdout).toBe(guide.stdout);
|
|
301
|
+
expect(bare.stdout).toMatch(
|
|
302
|
+
/Read everything: +.*docs cli\/integrations\/building-blocks\/codemods --full$/m,
|
|
303
|
+
);
|
|
304
|
+
const one = await runCli([
|
|
305
|
+
'docs',
|
|
306
|
+
'cli/integrations/building-blocks/codemods',
|
|
307
|
+
'which-codemods-run',
|
|
308
|
+
]);
|
|
309
|
+
expect(one.status).toBe(0);
|
|
310
|
+
expect(one.stdout).toMatch(/^## Choose when a codemod runs$/m);
|
|
311
|
+
expect(one.stdout).toMatch(
|
|
312
|
+
/^Up: .*docs cli\/integrations\/building-blocks\/codemods --index$/m,
|
|
313
|
+
);
|
|
314
|
+
expect(one.stdout).toMatch(
|
|
315
|
+
/^Previous: .*docs cli\/integrations\/building-blocks\/codemods write-the-transform$/m,
|
|
316
|
+
);
|
|
317
|
+
expect(one.stdout).toMatch(
|
|
318
|
+
/^Next: .*docs cli\/integrations\/building-blocks\/codemods run-codemods-in-an-app$/m,
|
|
319
|
+
);
|
|
320
|
+
const full = await runCli([
|
|
321
|
+
'docs',
|
|
322
|
+
'cli/integrations/building-blocks/codemods',
|
|
323
|
+
'--full',
|
|
324
|
+
]);
|
|
325
|
+
expect(full.status).toBe(0);
|
|
326
|
+
expect(full.stdout).toMatch(/^## Add a codemod$/m);
|
|
327
|
+
expect(full.stdout.length).toBeGreaterThan(bare.stdout.length * 2);
|
|
328
|
+
const old = await runCli(['docs', 'cli-integrations']);
|
|
329
|
+
expect(old.status).toBe(1);
|
|
330
|
+
expect(old.stderr).toContain('Unknown topic "cli-integrations"');
|
|
331
|
+
}, SLOW);
|
|
332
|
+
|
|
333
|
+
it('returns docs.node as JSON, and fails a section of a namespace', async () => {
|
|
334
|
+
const node = JSON.parse((await runCli(['docs', 'cli', '--json'])).stdout);
|
|
335
|
+
expect(node).toMatchObject({
|
|
336
|
+
type: 'docs.node',
|
|
337
|
+
data: {route: 'cli', kind: 'namespace', breadcrumb: []},
|
|
338
|
+
});
|
|
339
|
+
expect(node.data.slots.map(slot => slot.name)).toEqual(['guides', 'reference']);
|
|
340
|
+
const section = await runCli(['docs', 'cli', 'commands', '--json']);
|
|
341
|
+
expect(section.status).toBe(1);
|
|
342
|
+
const error = JSON.parse(section.stdout);
|
|
343
|
+
expect(error).toMatchObject({code: 'ERR_UNKNOWN_SECTION'});
|
|
344
|
+
// It names the namespace's children, in the order its slots list them.
|
|
345
|
+
expect(error.suggestions.map(s => s.name)).toEqual(
|
|
346
|
+
node.data.slots.flatMap(slot => slot.children.map(child => child.route)),
|
|
347
|
+
);
|
|
348
|
+
expect(error.suggestions.map(s => s.name)).toContain('cli/commands');
|
|
349
|
+
}, SLOW);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
describe('text width in every language', () => {
|
|
353
|
+
const SLOW = 60_000;
|
|
354
|
+
/** Widest line outside code blocks, in terminal columns. */
|
|
355
|
+
const widest = out => {
|
|
356
|
+
let inCode = false;
|
|
357
|
+
let max = 0;
|
|
358
|
+
for (const line of out.split('\n')) {
|
|
359
|
+
if (/^\s*```/.test(line)) {
|
|
360
|
+
inCode = !inCode;
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
// A single unbreakable token (a long URL) cannot wrap without breaking it.
|
|
364
|
+
const oneToken = !/\s/.test(line.trim());
|
|
365
|
+
if (!inCode && !line.startsWith('#') && !oneToken) {
|
|
366
|
+
max = Math.max(max, displayWidth(line));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return max;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
it('keeps the additive section index within 120 columns', async () => {
|
|
373
|
+
const {status, stdout} = await runCli([
|
|
374
|
+
'docs',
|
|
375
|
+
'theme',
|
|
376
|
+
'--index',
|
|
377
|
+
'--lang',
|
|
378
|
+
'zh',
|
|
379
|
+
]);
|
|
380
|
+
expect(status).toBe(0);
|
|
381
|
+
expect(widest(stdout)).toBeLessThanOrEqual(120);
|
|
382
|
+
}, SLOW);
|
|
383
|
+
});
|
|
@@ -258,10 +258,10 @@ async function runProjectDoctor(program) {
|
|
|
258
258
|
async function runIntegrationValidation(program, pkg) {
|
|
259
259
|
const result = await validateIntegration(pkg);
|
|
260
260
|
if (program.opts().json) jsonOut(result);
|
|
261
|
-
else if (result.data.
|
|
261
|
+
else if (!result.data.validated) {
|
|
262
262
|
emit(
|
|
263
263
|
text(
|
|
264
|
-
'
|
|
264
|
+
'Nothing was validated: no astryx.integration.* found next to package.json. ' +
|
|
265
265
|
'To validate an installed integration: astryx doctor integration validate <package>',
|
|
266
266
|
),
|
|
267
267
|
);
|
|
@@ -284,10 +284,10 @@ async function runAuthoringCheck(program, pkg, kind) {
|
|
|
284
284
|
: await integrationDocConflicts(pkg);
|
|
285
285
|
|
|
286
286
|
if (program.opts().json) jsonOut(result);
|
|
287
|
-
else if (result.data.
|
|
287
|
+
else if (!result.data.validated) {
|
|
288
288
|
emit(
|
|
289
289
|
text(
|
|
290
|
-
'
|
|
290
|
+
'Nothing was checked: no astryx.integration.* found next to package.json. ' +
|
|
291
291
|
`To check an installed integration: astryx doctor integration ${kind} <package>`,
|
|
292
292
|
),
|
|
293
293
|
);
|
|
@@ -55,6 +55,18 @@ export function registerGapReport(program) {
|
|
|
55
55
|
result.type === 'gap-report.file' &&
|
|
56
56
|
(result.data.status === 'failed' || result.data.status === 'partial');
|
|
57
57
|
|
|
58
|
+
// stderr in both modes, so a caller that reads only the exit code or the
|
|
59
|
+
// JSON envelope still sees which delivery failed and why.
|
|
60
|
+
if (isFailure && result.type === 'gap-report.file') {
|
|
61
|
+
for (const delivery of result.data.deliveries) {
|
|
62
|
+
if (delivery.status === 'failed') {
|
|
63
|
+
console.error(
|
|
64
|
+
`gap-report: delivery to ${delivery.handler} failed: ${delivery.message ?? 'no message'}`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
58
70
|
if (program.opts().json) {
|
|
59
71
|
jsonOut(result);
|
|
60
72
|
if (isFailure) process.exitCode = 1;
|
|
@@ -172,6 +172,69 @@ export default {};\n`,
|
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
+
it('exits nonzero and names the integration on stderr when one fails to load', async () => {
|
|
176
|
+
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-gap-broken-'));
|
|
177
|
+
try {
|
|
178
|
+
fs.writeFileSync(
|
|
179
|
+
path.join(cwd, 'package.json'),
|
|
180
|
+
JSON.stringify({name: 'fixture-app'}),
|
|
181
|
+
);
|
|
182
|
+
fs.writeFileSync(
|
|
183
|
+
path.join(cwd, 'astryx.config.mjs'),
|
|
184
|
+
"export default {integrations: ['@test/broken']};\n",
|
|
185
|
+
);
|
|
186
|
+
const integrationDir = path.join(cwd, 'node_modules', '@test', 'broken');
|
|
187
|
+
fs.mkdirSync(integrationDir, {recursive: true});
|
|
188
|
+
fs.writeFileSync(
|
|
189
|
+
path.join(integrationDir, 'package.json'),
|
|
190
|
+
JSON.stringify({
|
|
191
|
+
name: '@test/broken',
|
|
192
|
+
version: '1.0.0',
|
|
193
|
+
type: 'module',
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
fs.writeFileSync(
|
|
197
|
+
path.join(integrationDir, 'astryx.integration.mjs'),
|
|
198
|
+
"throw new Error('intentional integration load failure');\n",
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const cli = await runCli(
|
|
202
|
+
[
|
|
203
|
+
'gap-report',
|
|
204
|
+
'General',
|
|
205
|
+
'--category',
|
|
206
|
+
'docs_gap',
|
|
207
|
+
'--reason',
|
|
208
|
+
'Need a keyboard example',
|
|
209
|
+
'--json',
|
|
210
|
+
],
|
|
211
|
+
{cwd},
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
expect(cli.status).toBe(1);
|
|
215
|
+
expect(JSON.parse(cli.stdout)).toMatchObject({
|
|
216
|
+
type: 'gap-report.file',
|
|
217
|
+
data: {
|
|
218
|
+
status: 'failed',
|
|
219
|
+
filedCount: 0,
|
|
220
|
+
deliveries: [
|
|
221
|
+
{
|
|
222
|
+
handlerType: 'integration',
|
|
223
|
+
handler: '@test/broken',
|
|
224
|
+
status: 'failed',
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
expect(cli.stderr).toContain(
|
|
230
|
+
'gap-report: delivery to @test/broken failed:',
|
|
231
|
+
);
|
|
232
|
+
expect(cli.stderr).toContain('intentional integration load failure');
|
|
233
|
+
} finally {
|
|
234
|
+
fs.rmSync(cwd, {recursive: true, force: true});
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
175
238
|
it('reports missing required fields through the JSON error contract', async () => {
|
|
176
239
|
const cli = await runCli(['gap-report', 'Button', '--json']);
|
|
177
240
|
expect(cli.status).toBe(1);
|
|
@@ -56,6 +56,12 @@ export const doc = {
|
|
|
56
56
|
description:
|
|
57
57
|
"Namespace of this package to place the doc in, as a guide in its `guides` slot; writes the namespace doc when it is missing, and declares the CLI that reads it as an optional `@astryxdesign/cli` peer. Only valid for doc, and not with --replaces or --extends",
|
|
58
58
|
},
|
|
59
|
+
{
|
|
60
|
+
flag: '--from <theme>',
|
|
61
|
+
param: 'options.from',
|
|
62
|
+
description:
|
|
63
|
+
'Existing theme slug to fork as a starting point instead of a blank scaffold; the new theme copies the base and has no link back, and package.json `dependencies` gains the npm packages the copied files import (other than Core and React). Only valid for theme',
|
|
64
|
+
},
|
|
59
65
|
{
|
|
60
66
|
flag: '--to <version>',
|
|
61
67
|
param: 'options.to',
|
|
@@ -102,6 +108,10 @@ export const doc = {
|
|
|
102
108
|
cli: "astryx integration add agent-doc 'Run acme verify before finishing.'",
|
|
103
109
|
},
|
|
104
110
|
{label: 'Add a source theme', cli: 'astryx integration add theme ocean'},
|
|
111
|
+
{
|
|
112
|
+
label: 'Fork an existing theme',
|
|
113
|
+
cli: 'astryx integration add theme ocean --from neutral',
|
|
114
|
+
},
|
|
105
115
|
],
|
|
106
116
|
exitCodes: [
|
|
107
117
|
{code: 0, when: 'the contribution is written or the dry run succeeds'},
|
|
@@ -174,11 +174,21 @@ describe('integration authoring CLI', () => {
|
|
|
174
174
|
expect(text.stdout).toBe(verifyText.stdout);
|
|
175
175
|
expect(text.stderr).toContain('`integration pack --check` is deprecated');
|
|
176
176
|
expect(text.stderr).toContain('astryx integration verify');
|
|
177
|
-
// Without --check it fails, as it did, and
|
|
177
|
+
// Without --check it fails, as it did, and points only at the new name:
|
|
178
|
+
// suggesting `--check` would send people to the deprecated spelling.
|
|
178
179
|
const bare = await runCli(['integration', 'pack'], tmpDir);
|
|
179
180
|
expect(bare.status).not.toBe(0);
|
|
180
|
-
expect(bare.stderr).toContain(
|
|
181
|
+
expect(bare.stderr).toContain(
|
|
182
|
+
'`integration pack` is now `integration verify`',
|
|
183
|
+
);
|
|
181
184
|
expect(bare.stderr).toContain('astryx integration verify');
|
|
185
|
+
expect(bare.stderr).toContain('npm pack');
|
|
186
|
+
expect(bare.stderr).not.toContain('--check');
|
|
187
|
+
const bareJson = await runCli(['--json', 'integration', 'pack'], tmpDir);
|
|
188
|
+
expect(parseEnvelope(bareJson.stdout)).toMatchObject({
|
|
189
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
190
|
+
error: expect.stringContaining('astryx integration verify'),
|
|
191
|
+
});
|
|
182
192
|
// Help lists it, marked deprecated: nothing is hidden.
|
|
183
193
|
const help = await runCli(['integration', '--help'], tmpDir);
|
|
184
194
|
expect(help.stdout).toMatch(
|
|
@@ -115,6 +115,7 @@ export function registerIntegration(program) {
|
|
|
115
115
|
extends: options.extends,
|
|
116
116
|
parent: options.parent,
|
|
117
117
|
to: options.to,
|
|
118
|
+
from: options.from,
|
|
118
119
|
});
|
|
119
120
|
} catch (error) {
|
|
120
121
|
const err =
|
|
@@ -168,8 +169,9 @@ export function registerIntegration(program) {
|
|
|
168
169
|
fn: integrationPackCheckFn,
|
|
169
170
|
action: async options => {
|
|
170
171
|
if (!options.check) {
|
|
172
|
+
// One way forward: the new name. `npm pack` is what builds a tarball.
|
|
171
173
|
return cliError(
|
|
172
|
-
'
|
|
174
|
+
'`integration pack` is now `integration verify`: run `astryx integration verify` to check the package the way npm will publish it. To build the tarball, run `npm pack`.',
|
|
173
175
|
{code: ERROR_CODES.ERR_INVALID_ARGUMENT},
|
|
174
176
|
);
|
|
175
177
|
}
|
|
@@ -18,7 +18,9 @@ export const doc = {
|
|
|
18
18
|
description:
|
|
19
19
|
'Parses and validates a compressed XLE/XLO expression, then expands it into ' +
|
|
20
20
|
'ready-to-use XDS TSX, routing children into slots, scaffolding typed useState for ' +
|
|
21
|
-
'interactive controls, and splicing referenced blocks. Writes to a path, or returns the code.'
|
|
21
|
+
'interactive controls, and splicing referenced blocks. Writes to a path, or returns the code. ' +
|
|
22
|
+
'Astryx demo media in a spliced block becomes a placeholder, and the output says how many ' +
|
|
23
|
+
'references were replaced (as a closing line comment when it prints the code).',
|
|
22
24
|
fn: 'layoutExpand',
|
|
23
25
|
args: [
|
|
24
26
|
{
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx layout expand` tells the caller, in JSON and in text, when demo
|
|
5
|
+
* media in a spliced template block was replaced with placeholders. Printed
|
|
6
|
+
* code stays verbatim and valid TSX: the disclosure follows it as a comment.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import ts from 'typescript';
|
|
13
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
14
|
+
import {discoverTemplates} from '../../../api/template/template.mjs';
|
|
15
|
+
|
|
16
|
+
const SLOW = 60_000;
|
|
17
|
+
const DISCLOSURE = /demo media/i;
|
|
18
|
+
|
|
19
|
+
/** @param {string} name */
|
|
20
|
+
const hintKey = name => name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
21
|
+
|
|
22
|
+
/** @param {string} source */
|
|
23
|
+
const tsxErrors = source =>
|
|
24
|
+
/** @type {any} */ (
|
|
25
|
+
ts.createSourceFile('out.tsx', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX)
|
|
26
|
+
).parseDiagnostics.map((/** @type {ts.Diagnostic} */ d) =>
|
|
27
|
+
ts.flattenDiagnosticMessageText(d.messageText, ' '),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
/** A `{hint}` for a template block whose source carries demo media. */
|
|
31
|
+
async function mediaBlockHint() {
|
|
32
|
+
const blocks = /** @type {Array<{dirName: string, type: string, filePath: string}>} */ (
|
|
33
|
+
await discoverTemplates()
|
|
34
|
+
).filter(t => t.type === 'block' && t.filePath && fs.existsSync(t.filePath));
|
|
35
|
+
const seen = new Map();
|
|
36
|
+
for (const t of blocks) seen.set(hintKey(t.dirName), (seen.get(hintKey(t.dirName)) ?? 0) + 1);
|
|
37
|
+
const found = blocks.find(
|
|
38
|
+
t =>
|
|
39
|
+
seen.get(hintKey(t.dirName)) === 1 &&
|
|
40
|
+
/\/template-assets\/[\w.-]+\.\w+/.test(fs.readFileSync(t.filePath, 'utf-8')),
|
|
41
|
+
);
|
|
42
|
+
if (!found) throw new Error('no template block carries demo media');
|
|
43
|
+
return hintKey(found.dirName);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('layout expand discloses replaced demo media', () => {
|
|
47
|
+
let cwd;
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
// Inside the workspace so @astryxdesign/core resolves.
|
|
50
|
+
cwd = fs.mkdtempSync(path.join(process.cwd(), '.xle-media-receipt-'));
|
|
51
|
+
});
|
|
52
|
+
afterEach(() => fs.rmSync(cwd, {recursive: true, force: true}));
|
|
53
|
+
|
|
54
|
+
it('--json carries demoMediaReplaced; the text receipt states it for the written file', async () => {
|
|
55
|
+
const expr = `V > {${await mediaBlockHint()}}`;
|
|
56
|
+
const json = await runCli(['layout', 'expand', expr, './a', '--json'], cwd);
|
|
57
|
+
expect(json.status).toBe(0);
|
|
58
|
+
const {data} = JSON.parse(json.stdout);
|
|
59
|
+
expect(data.demoMediaReplaced).toBeGreaterThan(0);
|
|
60
|
+
|
|
61
|
+
const human = await runCli(['layout', 'expand', expr, './b'], cwd);
|
|
62
|
+
expect(human.status).toBe(0);
|
|
63
|
+
expect(human.stdout).toContain(
|
|
64
|
+
`Replaced ${data.demoMediaReplaced} Astryx demo media reference`,
|
|
65
|
+
);
|
|
66
|
+
expect(human.stdout).toContain(path.join('b', 'GeneratedLayout.tsx'));
|
|
67
|
+
}, SLOW);
|
|
68
|
+
|
|
69
|
+
it('prints the code verbatim, then states the count in a comment that keeps it valid TSX', async () => {
|
|
70
|
+
const expr = `V > {${await mediaBlockHint()}}`;
|
|
71
|
+
const {data} = JSON.parse((await runCli(['layout', 'expand', expr, '--json'], cwd)).stdout);
|
|
72
|
+
|
|
73
|
+
const human = await runCli(['layout', 'expand', expr], cwd);
|
|
74
|
+
expect(human.status).toBe(0);
|
|
75
|
+
expect(human.stdout.startsWith(data.code)).toBe(true);
|
|
76
|
+
expect(human.stdout.slice(data.code.length).trim()).toMatch(
|
|
77
|
+
new RegExp(`^// Replaced ${data.demoMediaReplaced} Astryx demo media references? in the code above: [^\\n]+$`),
|
|
78
|
+
);
|
|
79
|
+
expect(tsxErrors(human.stdout)).toEqual([]);
|
|
80
|
+
}, SLOW);
|
|
81
|
+
|
|
82
|
+
it('says nothing about demo media when none was replaced', async () => {
|
|
83
|
+
const json = await runCli(['layout', 'expand', 'V > B"Save"', '--json'], cwd);
|
|
84
|
+
const {data} = JSON.parse(json.stdout);
|
|
85
|
+
expect(data.demoMediaReplaced).toBe(0);
|
|
86
|
+
|
|
87
|
+
const written = await runCli(['layout', 'expand', 'V > B"Save"', './a'], cwd);
|
|
88
|
+
expect(written.status).toBe(0);
|
|
89
|
+
expect(written.stdout).not.toMatch(DISCLOSURE);
|
|
90
|
+
const printed = await runCli(['layout', 'expand', 'V > B"Save"'], cwd);
|
|
91
|
+
expect(printed.status).toBe(0);
|
|
92
|
+
expect(printed.stdout).toBe(`${data.code}\n`);
|
|
93
|
+
}, SLOW);
|
|
94
|
+
});
|