@astryxdesign/cli 0.7.0-canary.9eb7c76 → 0.7.0-canary.de3959f
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 +19 -23
- package/api/build/build.mjs +9 -0
- package/api/component/_adapter.d.mts +2 -0
- package/api/component/_adapter.mjs +3 -1
- package/api/component/component.doc.mjs +5 -1
- package/api/docs/compiled-topics.test.mjs +16 -0
- package/api/gap-report/gap-report.doc.mjs +1 -1
- package/api/gap-report/gap-report.mjs +15 -0
- package/api/index.d.mts +0 -2
- package/api/index.mjs +0 -2
- package/api/init/init.mjs +22 -0
- package/api/integration/validate-integration.d.mts +4 -0
- package/api/integration/validate-integration.mjs +5 -2
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/json/index.ts +0 -1
- package/api/template/list/list.mjs +23 -2
- package/api/template/list/list.test.mjs +52 -0
- package/api/template/template-integration.test.mjs +37 -100
- package/api/template/template.doc.mjs +7 -2
- package/api/template/template.mjs +45 -0
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.mjs +19 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -3
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
- package/clients/cli/command-result-coverage.test.mjs +1 -1
- package/clients/cli/commands/build.doc.mjs +1 -1
- package/clients/cli/commands/build.mjs +1 -1
- package/clients/cli/commands/component-ownership.test.mjs +2 -2
- package/clients/cli/commands/debug-result-summary.test.mjs +0 -16
- package/clients/cli/commands/doctor.mjs +5 -2
- package/clients/cli/commands/gap-report.doc.mjs +1 -1
- package/clients/cli/commands/gap-report.test.mjs +2 -2
- package/clients/cli/commands/init.doc.mjs +4 -4
- package/clients/cli/commands/init.flag-help.test.mjs +7 -10
- package/clients/cli/commands/integration.mjs +2 -1
- package/clients/cli/commands/option-pair-refusals.test.mjs +37 -0
- package/clients/cli/commands/silent-success-refusals.test.mjs +15 -0
- package/clients/cli/commands/template.doc.mjs +4 -4
- package/clients/cli/commands/template.flag-help.test.mjs +18 -11
- package/clients/cli/commands/text-json-parity.test.mjs +0 -17
- package/clients/cli/commands/upgrade.doc.mjs +1 -1
- package/clients/cli/commands/upgrade.flag-help.test.mjs +7 -11
- package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +67 -0
- package/clients/cli/index.mjs +0 -4
- package/clients/cli/lib/exit-codes.test.mjs +0 -7
- package/clients/cli/lib/json-shim.test.mjs +0 -24
- package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +1 -17
- package/foundation/response/response.doc.mjs +1 -1
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/browser.mjs +2 -2
- package/foundation/xle/expand.mjs +1 -1
- package/foundation/xle/print.mjs +1 -1
- package/package.json +9 -9
- package/api/layout/_adapter.d.mts +0 -34
- package/api/layout/_adapter.mjs +0 -148
- package/api/layout/check/check.d.mts +0 -17
- package/api/layout/check/check.mjs +0 -41
- package/api/layout/expand/expand.d.mts +0 -23
- package/api/layout/expand/expand.mjs +0 -161
- package/api/layout/expand/expand.path-safety.test.mjs +0 -53
- package/api/layout/expand/expand.receipt.test.mjs +0 -74
- package/api/layout/grammar/grammar.d.mts +0 -14
- package/api/layout/grammar/grammar.mjs +0 -88
- package/api/layout/layout.d.mts +0 -6
- package/api/layout/layout.mjs +0 -17
- package/api/layout/layout.test.mjs +0 -297
- package/api/layout/layout.type.d.mts +0 -90
- package/api/layout/layout.type.mjs +0 -104
- package/api/layout/layoutCheck.doc.d.mts +0 -11
- package/api/layout/layoutCheck.doc.mjs +0 -85
- package/api/layout/layoutExpand.doc.d.mts +0 -11
- package/api/layout/layoutExpand.doc.mjs +0 -107
- package/api/layout/layoutGrammar.doc.d.mts +0 -11
- package/api/layout/layoutGrammar.doc.mjs +0 -57
- package/clients/cli/commands/layout-check.doc.mjs +0 -67
- package/clients/cli/commands/layout-expand.doc.mjs +0 -87
- package/clients/cli/commands/layout-grammar.doc.mjs +0 -32
- package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +0 -140
- package/clients/cli/commands/layout.doc.mjs +0 -36
- package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
- package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
- package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
- package/clients/cli/commands/layout.mjs +0 -327
- package/clients/cli/commands/layout.path-help.test.mjs +0 -33
- package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
- package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
package/README.md
CHANGED
|
@@ -78,24 +78,23 @@ Options:
|
|
|
78
78
|
|
|
79
79
|
<!-- BEGIN GENERATED: commands -->
|
|
80
80
|
|
|
81
|
-
| Command | Description
|
|
82
|
-
| ------------- |
|
|
83
|
-
| `blog` | Read the Astryx blog from the published feed
|
|
84
|
-
| `build` | Build a page: the template to start from, or the workflow playbook (no query)
|
|
85
|
-
| `component` | List components or print component docs
|
|
86
|
-
| `discover` | Browse and search integrations: the ones you have and the ones you could add
|
|
87
|
-
| `docs` | Print reference docs
|
|
88
|
-
| `doctor` | Diagnose Astryx projects and integration packages
|
|
89
|
-
| `gap-report` | Report a missing component or feature to the package that owns it
|
|
90
|
-
| `hook` | List hooks or print hook docs
|
|
91
|
-
| `init` | Initialize the design system in your project
|
|
92
|
-
| `integration` | Author and verify an Astryx integration package
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
98
|
-
| `upgrade` | Update your code after upgrading Astryx, and refresh ShadCN-copied components |
|
|
81
|
+
| Command | Description |
|
|
82
|
+
| ------------- | ----------------------------------------------------------------------------- |
|
|
83
|
+
| `blog` | Read the Astryx blog from the published feed |
|
|
84
|
+
| `build` | Build a page: the template to start from, or the workflow playbook (no query) |
|
|
85
|
+
| `component` | List components or print component docs |
|
|
86
|
+
| `discover` | Browse and search integrations: the ones you have and the ones you could add |
|
|
87
|
+
| `docs` | Print reference docs |
|
|
88
|
+
| `doctor` | Diagnose Astryx projects and integration packages |
|
|
89
|
+
| `gap-report` | Report a missing component or feature to the package that owns it |
|
|
90
|
+
| `hook` | List hooks or print hook docs |
|
|
91
|
+
| `init` | Initialize the design system in your project |
|
|
92
|
+
| `integration` | Author and verify an Astryx integration package |
|
|
93
|
+
| `search` | Search components, hooks, docs, templates, and themes in one ranked list |
|
|
94
|
+
| `swizzle` | Copy component source for customization |
|
|
95
|
+
| `template` | List, show, or scaffold page and block templates |
|
|
96
|
+
| `theme` | Add, switch, build, and author themes |
|
|
97
|
+
| `upgrade` | Update your code after upgrading Astryx, and refresh ShadCN-copied components |
|
|
99
98
|
|
|
100
99
|
<!-- END GENERATED: commands -->
|
|
101
100
|
<!-- Generated by scripts/generate-cli-readme.mjs from `astryx manifest`. Run `pnpm -F @astryxdesign/cli readme`. -->
|
|
@@ -165,7 +164,7 @@ if (isError(result)) {
|
|
|
165
164
|
| `ERR_UNKNOWN` | Fallback for any error without a more specific code. |
|
|
166
165
|
| `ERR_UNKNOWN_COMMAND` | A top-level command name was not recognized (e.g. `astryx bogus`). |
|
|
167
166
|
| `ERR_UNKNOWN_SUBCOMMAND` | A subcommand under a command group was not recognized (e.g. `astryx theme bogus`). |
|
|
168
|
-
| `ERR_INVALID_OPTION` | An unknown option was passed, --json was given to a command without JSON output
|
|
167
|
+
| `ERR_INVALID_OPTION` | An unknown option was passed, --json was given to a command without JSON output. |
|
|
169
168
|
| `ERR_INVALID_ARGUMENT` | An argument or option value is invalid: wrong type, out of range, an unknown choice, an extra argument, or a conflicting combination. |
|
|
170
169
|
| `ERR_MISSING_ARGUMENT` | A required argument or option value was omitted. |
|
|
171
170
|
| `ERR_INVALID_LANG` | `--lang` was given a value outside its choices (en, zh, dense). |
|
|
@@ -477,13 +476,10 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
477
476
|
| `doctor` | The health-check report: `checks` (each with id, label, status: pass \| warn \| fail \| info, a message, and an optional fix, always present on warn and fail) plus a `summary` of counts per status. |
|
|
478
477
|
| `integration.add` | A contribution-writer receipt: kind, name, optional root {path, created}, integration-manifest path, every affected project-relative path, written, and dryRun. |
|
|
479
478
|
| `integration.pack-check` | The packed-package check: name, version, packable, tarball {filename, fileCount, size, unpackedSize} or null, inventory {manifest, roots [{kind, path, expectedFiles, missingFiles, complete}], expectedFiles, packedFiles}, contributions {local, packed}, each null or {themes [{slug, exportName}], components, templates [{id, type, name}], codemods [{version, id}], docs, agentDocsAppend}, and issues [{code, severity, message}]. |
|
|
480
|
-
| `integration.validate` | The validation result: validated (false when no
|
|
479
|
+
| `integration.validate` | The validation result: validated (false when nothing was validated: with no package.json the issues list carries one no_package error so the command exits 1, and with a package.json but no integration manifest the issues list is empty and proves nothing), the package name and version (both null when validated is false) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning \| error, message}. |
|
|
481
480
|
| `integration.template-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and non-blocking Core template-id conflicts as {id, severity: warning, integrationPackage, integrationType, integrationName, coreMatches, message, command}. |
|
|
482
481
|
| `integration.component-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and non-blocking conflicts where an integration component name is also owned by Core; each conflict includes the exact package-qualified command. |
|
|
483
482
|
| `integration.doc-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and Core doc overlaps. Each finding includes `severity` (`info` \| `error`) and `relationship` (`replaces` \| `extends` \| `accidental`). |
|
|
484
|
-
| `layout.expand` | The expansion: parsed form, generated TSX code, componentsUsed, states (count of useState hooks scaffolded), todos, blocksReferenced (each {name, mode}), warnings, written (the output path, or null when nothing was written), and demoMediaReplaced (count of demo media placeholders). Carries `meta.deprecations` with DEP-0006 and its replacement commands. |
|
|
485
|
-
| `layout.check` | The validation result: a valid flag, the detected form, errors (each with line/col, message, formatted text, and suggestions), warnings, and the expression re-printed in both canonical surfaces (compact and outline). Carries `meta.deprecations` with DEP-0006 and its replacement commands. |
|
|
486
|
-
| `layout.grammar` | The XLE/XLO grammar cheatsheet: a text field with the full reference plus an aliases map (short name → canonical component) generated from this install's registry. Carries `meta.deprecations` with DEP-0006 and its replacement commands. |
|
|
487
483
|
|
|
488
484
|
<!-- END GENERATED: response-types -->
|
|
489
485
|
<!-- Generated by scripts/generate-cli-readme.mjs from the response-types EnumDoc. Run `pnpm -F @astryxdesign/cli readme`. -->
|
package/api/build/build.mjs
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* a query → build.kit (api/build/kit/kit.mjs)
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
import {AstryxError} from '../error.mjs';
|
|
17
|
+
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
16
18
|
import {buildHelp} from './help/help.mjs';
|
|
17
19
|
import {buildKit} from './kit/kit.mjs';
|
|
18
20
|
|
|
@@ -31,5 +33,12 @@ export async function build(query, options = {}) {
|
|
|
31
33
|
if (!query || !String(query).trim()) {
|
|
32
34
|
return buildHelp();
|
|
33
35
|
}
|
|
36
|
+
if (options.limit != null && (!Number.isInteger(options.limit) || options.limit <= 0)) {
|
|
37
|
+
throw new AstryxError(
|
|
38
|
+
`Invalid limit "${options.limit}". Must be a positive integer.`,
|
|
39
|
+
undefined,
|
|
40
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
34
43
|
return buildKit(query, options);
|
|
35
44
|
}
|
|
@@ -149,6 +149,8 @@ export function resolveCoreSourcePath(coreDir: string, dirName: string): string
|
|
|
149
149
|
/**
|
|
150
150
|
* Resolve a bare (unscoped) name to a `.doc.mjs`: core first, then back-compat
|
|
151
151
|
* externals, then a conservative fuzzy search. Throws ERR_UNKNOWN_COMPONENT
|
|
152
|
+
* for a genuinely unknown name, and ERR_AMBIGUOUS_COMPONENT when multiple
|
|
153
|
+
* packages provide the same name
|
|
152
154
|
* (with candidate suggestions when close) or ERR_NO_DOC.
|
|
153
155
|
* @param {string} dirName - bare component name (no `XDS` prefix)
|
|
154
156
|
* @param {{coreDir: string, cwd: string, name: string}} ctx - `name` is the caller's original (prefixed) input, used in error text
|
|
@@ -324,7 +324,7 @@ export class ComponentAmbiguityError extends AstryxError {
|
|
|
324
324
|
super(
|
|
325
325
|
`Component "${dirName}" is provided by multiple packages. Re-run with --package <pkg> to choose one.`,
|
|
326
326
|
owners.map(o => ({name: o.package, reason: 'provides this component'})),
|
|
327
|
-
ERROR_CODES.
|
|
327
|
+
ERROR_CODES.ERR_AMBIGUOUS_COMPONENT,
|
|
328
328
|
);
|
|
329
329
|
this.candidates = owners.map(owner => ({
|
|
330
330
|
package: owner.package,
|
|
@@ -375,6 +375,8 @@ export function resolveCoreSourcePath(coreDir, dirName) {
|
|
|
375
375
|
/**
|
|
376
376
|
* Resolve a bare (unscoped) name to a `.doc.mjs`: core first, then back-compat
|
|
377
377
|
* externals, then a conservative fuzzy search. Throws ERR_UNKNOWN_COMPONENT
|
|
378
|
+
* for a genuinely unknown name, and ERR_AMBIGUOUS_COMPONENT when multiple
|
|
379
|
+
* packages provide the same name
|
|
378
380
|
* (with candidate suggestions when close) or ERR_NO_DOC.
|
|
379
381
|
* @param {string} dirName - bare component name (no `XDS` prefix)
|
|
380
382
|
* @param {{coreDir: string, cwd: string, name: string}} ctx - `name` is the caller's original (prefixed) input, used in error text
|
|
@@ -170,7 +170,11 @@ export const doc = {
|
|
|
170
170
|
},
|
|
171
171
|
{
|
|
172
172
|
code: 'ERR_UNKNOWN_COMPONENT',
|
|
173
|
-
when: 'name is not a string, resolves to no known component,
|
|
173
|
+
when: 'name is not a string, resolves to no known component, or is absent from the requested options.package',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
code: 'ERR_AMBIGUOUS_COMPONENT',
|
|
177
|
+
when: 'the component is provided by multiple packages (pass options.package to disambiguate)',
|
|
174
178
|
},
|
|
175
179
|
{
|
|
176
180
|
code: 'ERR_UNKNOWN_PACKAGE',
|
|
@@ -48,6 +48,22 @@ describe('every shipped topic compiles to plain JSON', () => {
|
|
|
48
48
|
);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
describe('author-a-theme color guidance', () => {
|
|
52
|
+
it('teaches committed generated palette references as the main example', async () => {
|
|
53
|
+
const catalog = await loadDocsCatalog();
|
|
54
|
+
const topic = detailView(
|
|
55
|
+
await compileTopic(catalog, catalog.resolve('author-a-theme')),
|
|
56
|
+
);
|
|
57
|
+
const rendered = JSON.stringify(topic);
|
|
58
|
+
|
|
59
|
+
expect(rendered).toContain("import {palette} from './palette.generated';");
|
|
60
|
+
expect(rendered).toContain('palette.neutral.light[100]');
|
|
61
|
+
expect(rendered).toContain('palette.neutral.dark[15]');
|
|
62
|
+
expect(rendered).toContain('color (existing themes)');
|
|
63
|
+
expect(rendered).not.toContain("color: { accent: ['#7B61FF'");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
51
67
|
describe('reads that share a catalog', () => {
|
|
52
68
|
it(
|
|
53
69
|
'never let one read change another',
|
|
@@ -74,7 +74,7 @@ export const doc = {
|
|
|
74
74
|
name: 'options.listCategories',
|
|
75
75
|
type: 'boolean',
|
|
76
76
|
description:
|
|
77
|
-
'Return categories without resolving a route or writing; the component and every other option are
|
|
77
|
+
'Return categories without resolving a route or writing; the component and every other option are refused with ERR_INVALID_ARGUMENT.',
|
|
78
78
|
default: 'false',
|
|
79
79
|
},
|
|
80
80
|
{
|
|
@@ -595,6 +595,21 @@ function aggregateStatus(deliveries) {
|
|
|
595
595
|
*/
|
|
596
596
|
export async function gapReport(component, options = {}) {
|
|
597
597
|
if (options.listCategories) {
|
|
598
|
+
const ignored = [
|
|
599
|
+
component ? 'component' : null,
|
|
600
|
+
options.category ? '--category' : null,
|
|
601
|
+
options.reason ? '--reason' : null,
|
|
602
|
+
options.detail ? '--additional-context' : null,
|
|
603
|
+
options.package ? '--package' : null,
|
|
604
|
+
options.confirmPublic ? '--confirm-public' : null,
|
|
605
|
+
].filter(Boolean);
|
|
606
|
+
if (ignored.length > 0) {
|
|
607
|
+
throw new AstryxError(
|
|
608
|
+
`\`--list-categories\` cannot be combined with ${ignored.join(', ')}: it lists categories and ignores submission options.`,
|
|
609
|
+
undefined,
|
|
610
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
611
|
+
);
|
|
612
|
+
}
|
|
598
613
|
return {
|
|
599
614
|
type: 'gap-report.categories',
|
|
600
615
|
data: GAP_REPORT_CATEGORIES.map(category => ({...category})),
|
package/api/index.d.mts
CHANGED
|
@@ -33,14 +33,12 @@ export * from "./gap-report/gap-report.type.mjs";
|
|
|
33
33
|
export * from "./upgrade/upgrade.type.mjs";
|
|
34
34
|
export * from "./init/init.type.mjs";
|
|
35
35
|
export * from "./doctor/doctor.type.mjs";
|
|
36
|
-
export * from "./layout/layout.type.mjs";
|
|
37
36
|
export * from "./integration/integration-authoring.type.mjs";
|
|
38
37
|
export * from "./integration/pack-check.type.mjs";
|
|
39
38
|
export * from "./integration/validate-integration.type.mjs";
|
|
40
39
|
export * from "./integration/authoring-checks.type.mjs";
|
|
41
40
|
export type Logger = import("./logger.mjs").Logger;
|
|
42
41
|
export { themeBuild, themeAdd, themeRemove, themeUse, themeEject, themeTemplate, themeList, themeListAvailable, themeListCopySources, themeTargets, themePaletteGenerate, generateTonalPalette, listThemes } from "./theme/theme.mjs";
|
|
43
|
-
export { layoutExpand, layoutCheck, layoutGrammar } from "./layout/layout.mjs";
|
|
44
42
|
export { integrationAdd, integrationAddAgentDoc, integrationAddCodemod, integrationAddComponent, integrationAddDoc, integrationAddTemplate } from "./integration/add-contribution.mjs";
|
|
45
43
|
export { validateIntegration, summarizeIssues } from "./integration/validate-integration.mjs";
|
|
46
44
|
export { integrationTemplateConflicts, integrationComponentConflicts, integrationDocConflicts } from "./integration/authoring-checks.mjs";
|
package/api/index.mjs
CHANGED
|
@@ -48,7 +48,6 @@ export {gapReport} from './gap-report/gap-report.mjs';
|
|
|
48
48
|
export {upgrade} from './upgrade/upgrade.mjs';
|
|
49
49
|
export {init} from './init/init.mjs';
|
|
50
50
|
export {doctor} from './doctor/doctor.mjs';
|
|
51
|
-
export {layoutExpand, layoutCheck, layoutGrammar} from './layout/layout.mjs';
|
|
52
51
|
export {
|
|
53
52
|
integrationAdd,
|
|
54
53
|
integrationAddAgentDoc,
|
|
@@ -97,7 +96,6 @@ export * from './gap-report/gap-report.type.mjs';
|
|
|
97
96
|
export * from './upgrade/upgrade.type.mjs';
|
|
98
97
|
export * from './init/init.type.mjs';
|
|
99
98
|
export * from './doctor/doctor.type.mjs';
|
|
100
|
-
export * from './layout/layout.type.mjs';
|
|
101
99
|
export * from './integration/integration-authoring.type.mjs';
|
|
102
100
|
export * from './integration/pack-check.type.mjs';
|
|
103
101
|
export * from './integration/validate-integration.type.mjs';
|
package/api/init/init.mjs
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
|
|
19
19
|
import {run} from './run/run.mjs';
|
|
20
20
|
import {remove} from './remove/remove.mjs';
|
|
21
|
+
import {AstryxError} from '../error.mjs';
|
|
22
|
+
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
21
23
|
|
|
22
24
|
export {getNextSteps} from './run/run.mjs';
|
|
23
25
|
|
|
@@ -42,7 +44,27 @@ export {getNextSteps} from './run/run.mjs';
|
|
|
42
44
|
*/
|
|
43
45
|
export async function init(options = {}, {cwd = process.cwd()} = {}) {
|
|
44
46
|
if (options.removeAgents) {
|
|
47
|
+
const ignored = [
|
|
48
|
+
options.features ? '--features' : null,
|
|
49
|
+
options.all ? '--all' : null,
|
|
50
|
+
options.agent ? '--agent' : null,
|
|
51
|
+
options.agentDocsPath ? '--agent-docs-path' : null,
|
|
52
|
+
].filter(Boolean);
|
|
53
|
+
if (ignored.length > 0) {
|
|
54
|
+
throw new AstryxError(
|
|
55
|
+
`\`--remove-agents\` cannot be combined with ${ignored.join(', ')}: it removes the managed block and ignores install options.`,
|
|
56
|
+
undefined,
|
|
57
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
45
60
|
return remove({cwd});
|
|
46
61
|
}
|
|
62
|
+
if (options.all && options.features) {
|
|
63
|
+
throw new AstryxError(
|
|
64
|
+
'`--all` and `--features` cannot be used together: `--all` installs every feature, so a feature list is redundant.',
|
|
65
|
+
undefined,
|
|
66
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
47
69
|
return run(options, {cwd});
|
|
48
70
|
}
|
|
@@ -62,6 +62,10 @@ export type ValidateResult = {
|
|
|
62
62
|
* Absolute path to the loaded manifest.
|
|
63
63
|
*/
|
|
64
64
|
manifestFile?: string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Why nothing was validated (internal).
|
|
67
|
+
*/
|
|
68
|
+
reason?: "no_package_json" | undefined;
|
|
65
69
|
issues: Issue[];
|
|
66
70
|
integration?: import("../../foundation/integrations/integrations.mjs").LoadedIntegration | undefined;
|
|
67
71
|
};
|
|
@@ -72,6 +72,7 @@ export {validateLoadedIntegration};
|
|
|
72
72
|
* @property {string} [name] Integration package name (from package.json).
|
|
73
73
|
* @property {string} [version] Integration package version.
|
|
74
74
|
* @property {string} [manifestFile] Absolute path to the loaded manifest.
|
|
75
|
+
* @property {'no_package_json'} [reason] Why nothing was validated (internal).
|
|
75
76
|
* @property {Issue[]} issues
|
|
76
77
|
* @property {import('../../foundation/integrations/integrations.mjs').LoadedIntegration} [integration]
|
|
77
78
|
*/
|
|
@@ -349,7 +350,7 @@ async function validateAtPackageDir(
|
|
|
349
350
|
export async function validateLocalIntegration(cwd = process.cwd()) {
|
|
350
351
|
const pkgJsonPath = findNearestPackageJson(cwd);
|
|
351
352
|
if (!pkgJsonPath) {
|
|
352
|
-
return {found: false, issues: []};
|
|
353
|
+
return {found: false, reason: 'no_package_json', issues: []};
|
|
353
354
|
}
|
|
354
355
|
const packageDir = path.dirname(pkgJsonPath);
|
|
355
356
|
|
|
@@ -468,7 +469,9 @@ export async function validateIntegration(pkg, options = {}) {
|
|
|
468
469
|
validated: result.found,
|
|
469
470
|
name: result.found ? (result.name ?? null) : null,
|
|
470
471
|
version: result.found ? (result.version ?? null) : null,
|
|
471
|
-
issues: result.
|
|
472
|
+
issues: result.reason === 'no_package_json'
|
|
473
|
+
? [{code: 'no_package', severity: 'error', message: 'No package.json found. Run this command inside a package directory.'}]
|
|
474
|
+
: result.issues,
|
|
472
475
|
},
|
|
473
476
|
};
|
|
474
477
|
}
|
|
@@ -46,7 +46,7 @@ export const doc = {
|
|
|
46
46
|
{
|
|
47
47
|
type: 'integration.validate',
|
|
48
48
|
description:
|
|
49
|
-
'The result envelope: `data.validated`, false
|
|
49
|
+
'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',
|
|
50
50
|
},
|
|
51
51
|
],
|
|
52
52
|
examples: [
|
package/api/json/index.ts
CHANGED
|
@@ -26,7 +26,6 @@ export type * from '../gap-report/gap-report.type.mjs';
|
|
|
26
26
|
export type * from '../upgrade/upgrade.type.mjs';
|
|
27
27
|
export type * from '../init/init.type.mjs';
|
|
28
28
|
export type * from '../doctor/doctor.type.mjs';
|
|
29
|
-
export type * from '../layout/layout.type.mjs';
|
|
30
29
|
export type * from '../integration/validate-integration.type.mjs';
|
|
31
30
|
export type * from '../integration/authoring-checks.type.mjs';
|
|
32
31
|
export type * from '../integration/pack-check.type.mjs';
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import {pkgOf} from '../../../foundation/discovery/template-adapter.mjs';
|
|
13
|
+
import {AstryxError} from '../../error.mjs';
|
|
14
|
+
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Project a discovered template set into the `template.list` envelope.
|
|
@@ -19,10 +21,29 @@ import {pkgOf} from '../../../foundation/discovery/template-adapter.mjs';
|
|
|
19
21
|
*/
|
|
20
22
|
export function templateList(templates, options = {}) {
|
|
21
23
|
const {type, package: packageFilter} = options;
|
|
24
|
+
const VALID_TYPES = ['page', 'block'];
|
|
22
25
|
let filtered = templates;
|
|
23
|
-
if (type)
|
|
24
|
-
|
|
26
|
+
if (type) {
|
|
27
|
+
if (!VALID_TYPES.includes(type)) {
|
|
28
|
+
throw new AstryxError(
|
|
29
|
+
`Unknown template type "${type}". Valid types: ${VALID_TYPES.join(', ')}.`,
|
|
30
|
+
VALID_TYPES.map(t => ({name: t, reason: 'valid type'})),
|
|
31
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
filtered = filtered.filter(t => t.type === type);
|
|
35
|
+
}
|
|
36
|
+
if (packageFilter) {
|
|
37
|
+
const allPackages = [...new Set(templates.map(t => pkgOf(t)))];
|
|
38
|
+
if (!allPackages.includes(packageFilter)) {
|
|
39
|
+
throw new AstryxError(
|
|
40
|
+
`No templates found in package "${packageFilter}".`,
|
|
41
|
+
allPackages.sort().map(p => ({name: p, reason: 'has templates'})),
|
|
42
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
25
45
|
filtered = filtered.filter(t => pkgOf(t) === packageFilter);
|
|
46
|
+
}
|
|
26
47
|
return {
|
|
27
48
|
type: 'template.list',
|
|
28
49
|
data: filtered.map(t => ({
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
import {describe, expect, it} from 'vitest';
|
|
3
|
+
import {templateList} from './list.mjs';
|
|
4
|
+
|
|
5
|
+
const t = (type, dirName, pkg) => ({
|
|
6
|
+
type,
|
|
7
|
+
dirName,
|
|
8
|
+
name: dirName,
|
|
9
|
+
description: dirName,
|
|
10
|
+
...(pkg ? {package: pkg} : {}),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const templates = [
|
|
14
|
+
t('page', 'dashboard'),
|
|
15
|
+
t('block', 'hero'),
|
|
16
|
+
t('block', 'promo', '@acme/blocks'),
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
describe('templateList filters', () => {
|
|
20
|
+
it('returns an empty list for a valid filter that matches nothing', () => {
|
|
21
|
+
// @acme/blocks ships only blocks, so asking it for pages is a valid
|
|
22
|
+
// filter with no match: an empty list, not an error.
|
|
23
|
+
const response = templateList(templates, {
|
|
24
|
+
type: 'page',
|
|
25
|
+
package: '@acme/blocks',
|
|
26
|
+
});
|
|
27
|
+
expect(response.type).toBe('template.list');
|
|
28
|
+
expect(response.data).toEqual([]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('refuses a type outside page or block', () => {
|
|
32
|
+
expect(() => templateList(templates, {type: 'bogus'})).toThrow(
|
|
33
|
+
/Unknown template type "bogus"/,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('refuses a package that provides no templates', () => {
|
|
38
|
+
expect(() => templateList(templates, {package: '@nope/x'})).toThrow(
|
|
39
|
+
/No templates found in package "@nope\/x"/,
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('keeps a matching type and package filter', () => {
|
|
44
|
+
const response = templateList(templates, {
|
|
45
|
+
type: 'block',
|
|
46
|
+
package: '@acme/blocks',
|
|
47
|
+
});
|
|
48
|
+
expect(response.data.map(item => item.id ?? item.dirName)).toEqual([
|
|
49
|
+
'promo',
|
|
50
|
+
]);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
} from './template.mjs';
|
|
20
20
|
import {search} from '../search/search.mjs';
|
|
21
21
|
import {build} from '../build/build.mjs';
|
|
22
|
-
import {layoutExpand} from '../layout/layout.mjs';
|
|
23
22
|
import {runCli} from '../../test-utils/run-cli.mjs';
|
|
24
23
|
|
|
25
24
|
let tmpDir;
|
|
@@ -532,105 +531,6 @@ describe('integration template discovery', () => {
|
|
|
532
531
|
});
|
|
533
532
|
});
|
|
534
533
|
|
|
535
|
-
it('resolves a replacement block through the layout alias', async () => {
|
|
536
|
-
const pkgDir = installWidgets(tmpDir);
|
|
537
|
-
writeTemplate(pkgDir, 'acme-card-callout', {
|
|
538
|
-
kind: 'block',
|
|
539
|
-
source:
|
|
540
|
-
'export default function AcmeCardCallout() { return <span>Acme replacement block</span>; }\n',
|
|
541
|
-
});
|
|
542
|
-
declareReplaces(pkgDir, {
|
|
543
|
-
'acme-card-callout': 'CardCallout',
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
const accidental = path.join(tmpDir, 'node_modules', '@acme', 'extra');
|
|
547
|
-
fs.mkdirSync(path.join(accidental, 'templates'), {recursive: true});
|
|
548
|
-
fs.writeFileSync(
|
|
549
|
-
path.join(accidental, 'package.json'),
|
|
550
|
-
JSON.stringify({name: '@acme/extra', version: '1.0.0'}),
|
|
551
|
-
);
|
|
552
|
-
fs.writeFileSync(
|
|
553
|
-
path.join(accidental, 'astryx.integration.mjs'),
|
|
554
|
-
`export default {templates: './templates'};\n`,
|
|
555
|
-
);
|
|
556
|
-
writeTemplate(accidental, 'CardCallout', {
|
|
557
|
-
kind: 'block',
|
|
558
|
-
body: `export default {type: 'block', name: 'ZZZ accidental block', description: 'collision'};\n`,
|
|
559
|
-
source:
|
|
560
|
-
'export default function Accidental() { return <span>Accidental block</span>; }\n',
|
|
561
|
-
});
|
|
562
|
-
fs.writeFileSync(
|
|
563
|
-
path.join(tmpDir, 'astryx.config.mjs'),
|
|
564
|
-
`export default { integrations: ['@acme/widgets', '@acme/extra'] };\n`,
|
|
565
|
-
);
|
|
566
|
-
|
|
567
|
-
const result = await layoutExpand('C{card-callout}', {
|
|
568
|
-
name: 'ReplacementLayout',
|
|
569
|
-
cwd: tmpDir,
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
expect(result.data.code).toContain('Acme replacement block');
|
|
573
|
-
expect(result.data.code).not.toContain('Accidental block');
|
|
574
|
-
expect(result.data.blocksReferenced).toEqual(
|
|
575
|
-
expect.arrayContaining([
|
|
576
|
-
expect.objectContaining({name: 'CardCallout', mode: 'splice'}),
|
|
577
|
-
]),
|
|
578
|
-
);
|
|
579
|
-
}, 30_000);
|
|
580
|
-
|
|
581
|
-
it('resolves chained block aliases consistently in template and layout', async () => {
|
|
582
|
-
const [firstTarget, secondTarget] = (await discoverCoreTemplates()).filter(
|
|
583
|
-
candidate => candidate.type === 'block',
|
|
584
|
-
);
|
|
585
|
-
expect(firstTarget).toBeDefined();
|
|
586
|
-
expect(secondTarget).toBeDefined();
|
|
587
|
-
|
|
588
|
-
const pkgDir = installWidgets(tmpDir);
|
|
589
|
-
writeTemplate(pkgDir, secondTarget.dirName, {
|
|
590
|
-
kind: 'block',
|
|
591
|
-
source:
|
|
592
|
-
'export default function FirstReplacement() { return <span>First chain replacement</span>; }\n',
|
|
593
|
-
});
|
|
594
|
-
writeTemplate(pkgDir, 'acme-final-block', {
|
|
595
|
-
kind: 'block',
|
|
596
|
-
source:
|
|
597
|
-
'export default function FinalReplacement() { return <span>Final chain replacement</span>; }\n',
|
|
598
|
-
});
|
|
599
|
-
declareReplaces(pkgDir, {
|
|
600
|
-
[secondTarget.dirName]: firstTarget.dirName,
|
|
601
|
-
'acme-final-block': secondTarget.dirName,
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
const firstTemplate = await template(firstTarget.dirName, {
|
|
605
|
-
show: true,
|
|
606
|
-
cwd: tmpDir,
|
|
607
|
-
});
|
|
608
|
-
expect(firstTemplate.data.source).toContain('First chain replacement');
|
|
609
|
-
const layoutId = id =>
|
|
610
|
-
id.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();
|
|
611
|
-
const firstLayout = await layoutExpand(
|
|
612
|
-
`C{${layoutId(firstTarget.dirName)}}`,
|
|
613
|
-
{
|
|
614
|
-
cwd: tmpDir,
|
|
615
|
-
},
|
|
616
|
-
);
|
|
617
|
-
expect(firstLayout.data.code).toContain('First chain replacement');
|
|
618
|
-
expect(firstLayout.data.code).not.toContain('Final chain replacement');
|
|
619
|
-
|
|
620
|
-
const secondTemplate = await template(secondTarget.dirName, {
|
|
621
|
-
show: true,
|
|
622
|
-
cwd: tmpDir,
|
|
623
|
-
});
|
|
624
|
-
expect(secondTemplate.data.source).toContain('Final chain replacement');
|
|
625
|
-
const secondLayout = await layoutExpand(
|
|
626
|
-
`C{${layoutId(secondTarget.dirName)}}`,
|
|
627
|
-
{
|
|
628
|
-
cwd: tmpDir,
|
|
629
|
-
},
|
|
630
|
-
);
|
|
631
|
-
expect(secondLayout.data.code).toContain('Final chain replacement');
|
|
632
|
-
}, 30_000);
|
|
633
|
-
|
|
634
534
|
it('keeps the old discovery behavior when no replacement is declared', async () => {
|
|
635
535
|
const pkgDir = installWidgets(tmpDir);
|
|
636
536
|
writeTemplate(pkgDir, 'acme-app-shell', {kind: 'page'});
|
|
@@ -1334,4 +1234,41 @@ describe('build names a start its command selects', () => {
|
|
|
1334
1234
|
template('contact-form', {show: true, cwd: tmpDir}),
|
|
1335
1235
|
).rejects.toMatchObject({code: 'ERR_AMBIGUOUS_TEMPLATE'});
|
|
1336
1236
|
});
|
|
1237
|
+
|
|
1238
|
+
it('resolves chained template aliases without the layout command', async () => {
|
|
1239
|
+
const [firstTarget, secondTarget] = (await discoverCoreTemplates()).filter(
|
|
1240
|
+
candidate => candidate.type === 'block',
|
|
1241
|
+
);
|
|
1242
|
+
expect(firstTarget).toBeDefined();
|
|
1243
|
+
expect(secondTarget).toBeDefined();
|
|
1244
|
+
|
|
1245
|
+
const pkgDir = installWidgets(tmpDir);
|
|
1246
|
+
writeTemplate(pkgDir, secondTarget.dirName, {
|
|
1247
|
+
kind: 'block',
|
|
1248
|
+
source:
|
|
1249
|
+
'export default function FirstReplacement() { return <span>First chain replacement</span>; }\n',
|
|
1250
|
+
});
|
|
1251
|
+
writeTemplate(pkgDir, 'acme-final-block', {
|
|
1252
|
+
kind: 'block',
|
|
1253
|
+
source:
|
|
1254
|
+
'export default function FinalReplacement() { return <span>Final chain replacement</span>; }\n',
|
|
1255
|
+
});
|
|
1256
|
+
declareReplaces(pkgDir, {
|
|
1257
|
+
[secondTarget.dirName]: firstTarget.dirName,
|
|
1258
|
+
'acme-final-block': secondTarget.dirName,
|
|
1259
|
+
});
|
|
1260
|
+
|
|
1261
|
+
const firstTemplate = await template(firstTarget.dirName, {
|
|
1262
|
+
show: true,
|
|
1263
|
+
cwd: tmpDir,
|
|
1264
|
+
});
|
|
1265
|
+
expect(firstTemplate.data.source).toContain('First chain replacement');
|
|
1266
|
+
|
|
1267
|
+
const secondTemplate = await template(secondTarget.dirName, {
|
|
1268
|
+
show: true,
|
|
1269
|
+
cwd: tmpDir,
|
|
1270
|
+
});
|
|
1271
|
+
expect(secondTemplate.data.source).toContain('Final chain replacement');
|
|
1272
|
+
}, 30_000);
|
|
1273
|
+
|
|
1337
1274
|
});
|
|
@@ -48,7 +48,8 @@ export const doc = {
|
|
|
48
48
|
{
|
|
49
49
|
name: 'options.list',
|
|
50
50
|
type: 'boolean',
|
|
51
|
-
description:
|
|
51
|
+
description:
|
|
52
|
+
'List templates instead of scaffolding; refused with ERR_INVALID_ARGUMENT when a name or path is also given.',
|
|
52
53
|
default: 'false',
|
|
53
54
|
},
|
|
54
55
|
{
|
|
@@ -89,7 +90,7 @@ export const doc = {
|
|
|
89
90
|
type: 'string',
|
|
90
91
|
description:
|
|
91
92
|
'Destination (relative to cwd) to scaffold the template into. Its presence switches a named lookup into a copy. ' +
|
|
92
|
-
|
|
93
|
+
"A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is the file to write; any other path is a directory, which receives page.tsx for a page template or the block's own file name for a block.",
|
|
93
94
|
},
|
|
94
95
|
{
|
|
95
96
|
name: 'options.overwrite',
|
|
@@ -133,6 +134,10 @@ export const doc = {
|
|
|
133
134
|
},
|
|
134
135
|
],
|
|
135
136
|
throws: [
|
|
137
|
+
{
|
|
138
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
139
|
+
when: '--cdn is combined with <name>, --list, --skeleton, --type, or --package; --list is combined with <name>, <path>, --skeleton, or --overwrite; --skeleton is combined with <path> or --overwrite; or options.list is set with a type outside page or block, or with a package that provides no templates (a valid filter that matches nothing returns an empty list instead)',
|
|
140
|
+
},
|
|
136
141
|
{
|
|
137
142
|
code: 'ERR_UNKNOWN_TEMPLATE',
|
|
138
143
|
when: 'the named template does not exist, or options.skeleton is set without a name',
|