Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

docs(cli): build --type lists every domain it accepts (#10361)

Joey1a348eefad7f
diff --git a/.changeset/build-type-choices.md b/.changeset/build-type-choices.md
new file mode 100644
index 0000000000..4463c3d003
--- /dev/null
+++ b/.changeset/build-type-choices.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[docs] `astryx build --help` lists every value `--type` accepts (component, hook, doc, template, theme), matching the invalid-type error and what build actually runs, and says that `doc` and `theme` give an empty kit, since the kit has no doc or theme group. A test keeps the help text, the choices, the API doc and the error message on build and search naming the same set, and checks what each value returns.
+
+@josephfarina
diff --git a/packages/cli/api/build/build.doc.mjs b/packages/cli/api/build/build.doc.mjs
index d11ba5de40..70a46910a2 100644
--- a/packages/cli/api/build/build.doc.mjs
+++ b/packages/cli/api/build/build.doc.mjs
@@ -44,7 +44,7 @@ export const doc = {
},
{
name: 'options.type',
- type: "'component' | 'hook' | 'doc' | 'template'",
+ type: "'component' | 'hook' | 'doc' | 'template' | 'theme'",
description: 'Restrict the underlying search to a single domain.',
},
{
diff --git a/packages/cli/clients/cli/commands/build.doc.mjs b/packages/cli/clients/cli/commands/build.doc.mjs
index a534477ef1..eaa044a3ea 100644
--- a/packages/cli/clients/cli/commands/build.doc.mjs
+++ b/packages/cli/clients/cli/commands/build.doc.mjs
@@ -26,8 +26,9 @@ export const doc = {
{
flag: '--type <domain>',
param: 'options.type',
- choices: ['component', 'hook', 'template'],
- description: 'Filter the kit to one domain (component|hook|template)',
+ choices: ['component', 'hook', 'doc', 'template', 'theme'],
+ description:
+ 'Filter the kit to one domain (component|hook|doc|template|theme); doc and theme give an empty kit',
},
{
flag: '--limit <n>',
diff --git a/packages/cli/clients/cli/commands/type-choices.test.mjs b/packages/cli/clients/cli/commands/type-choices.test.mjs
new file mode 100644
index 0000000000..1292ee2172
--- /dev/null
+++ b/packages/cli/clients/cli/commands/type-choices.test.mjs
@@ -0,0 +1,95 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file `--type` on build and search accepts exactly search's domains, and
+ * the help text, the CLI choices, the API doc and the invalid-type error all
+ * name that same set, so the four cannot drift apart.
+ */
+
+import {describe, expect, it} from 'vitest';
+import {SEARCH_DOMAINS} from '../../../api/search/_query.mjs';
+import {doc as buildCommand} from './build.doc.mjs';
+import {doc as searchCommand} from './search.doc.mjs';
+import {doc as buildFn} from '../../../api/build/build.doc.mjs';
+import {doc as searchFn} from '../../../api/search/search.doc.mjs';
+import {build} from '../../../api/build/build.mjs';
+import {search} from '../../../api/search/search.mjs';
+
+/** @param {any} d */
+const typeOption = d =>
+ d.options.find((/** @type {any} */ o) => o.flag.startsWith('--type'));
+/** @param {any} d */
+const typeParam = d =>
+ d.params.find((/** @type {any} */ p) => p.name === 'options.type');
+
+/**
+ * What build returns for each domain: template names a start; component and
+ * hook list only that domain; the kit has no doc or theme group, so doc and
+ * theme return an empty kit.
+ * @param {string} type
+ * @param {any} data
+ */
+const checkBuild = (type, data) => {
+ if (type === 'template') {
+ expect(data.start).not.toBeNull();
+ return;
+ }
+ expect(data.start).toBeNull();
+ expect(data.pages).toEqual([]);
+ expect(data.blocks).toEqual([]);
+ if (type === 'doc' || type === 'theme') expect(data.domain).toEqual([]);
+ else for (const entry of data.domain) expect(entry.domain).toBe(type);
+};
+
+/**
+ * Search returns only entries of the requested domain.
+ * @param {string} type
+ * @param {any} data
+ */
+const checkSearch = (type, data) => {
+ for (const entry of data.results) expect(entry.domain).toBe(type);
+};
+
+describe.each([
+ [
+ 'build',
+ buildCommand,
+ buildFn,
+ (/** @type {string} */ t) =>
+ build('settings page', {type: /** @type {any} */ (t)}),
+ checkBuild,
+ ],
+ [
+ 'search',
+ searchCommand,
+ searchFn,
+ (/** @type {string} */ t) =>
+ search('button', {type: /** @type {any} */ (t)}),
+ checkSearch,
+ ],
+])('%s --type', (_name, command, fn, run, check) => {
+ it('lists exactly the accepted domains in the CLI choices and help text', () => {
+ const option = typeOption(command);
+ expect(option.choices).toEqual(SEARCH_DOMAINS);
+ expect(option.description).toContain(`(${SEARCH_DOMAINS.join('|')})`);
+ });
+
+ it('lists exactly the accepted domains in the API doc', () => {
+ const named = [...typeParam(fn).type.matchAll(/'([a-z]+)'/g)].map(
+ m => m[1],
+ );
+ expect(named).toEqual(SEARCH_DOMAINS);
+ });
+
+ it('names the same domains in the invalid-type error', async () => {
+ await expect(run('bogus')).rejects.toMatchObject({
+ suggestions: SEARCH_DOMAINS.map(d => ({name: d, reason: 'valid type'})),
+ });
+ });
+
+ it.each(SEARCH_DOMAINS)('accepts %s', async type => {
+ const response = /** @type {any} */ (await run(type));
+ expect(response).toBeTruthy();
+ check(type, response.data);
+ });
+});