An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): document how template and layout read their path arguments (#6571)
Joey9b7e2d0ecc74
diff --git a/.changeset/cli-spec-document-target-paths.md b/.changeset/cli-spec-document-target-paths.mdnew file mode 100644index 0000000000..6f591c7dde--- /dev/null+++ b/.changeset/cli-spec-document-target-paths.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] `astryx template --help` and `astryx layout expand --help` now explain how the path argument is read: a path ending in a source-file extension is the file to write, anything else is a directory that gets `page.tsx`, the block's file name, or `<Name>.tsx`. `layout expand` and `layout check` also document `-` for stdin and that `--file` wins over the argument, and `--overwrite` no longer mentions a prompt the CLI never shows.++@josephfarinadiff --git a/packages/cli/api/layout/layoutExpand.doc.mjs b/packages/cli/api/layout/layoutExpand.doc.mjsindex ea481a203f..da55852bb9 100644--- a/packages/cli/api/layout/layoutExpand.doc.mjs+++ b/packages/cli/api/layout/layoutExpand.doc.mjs@@ -36,7 +36,7 @@ export const doc = {name: 'options.targetPath',type: 'string',description:- 'Write the generated TSX here (validated to stay within cwd). A directory gets <name>.tsx; a file path is used as-is. Omit to return the code without writing.',+ 'Write the generated TSX here (validated to stay within cwd). A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is used as-is; any other path is a directory that gets <name>.tsx. An existing file is replaced. Omit to return the code without writing.',},{name: 'options.form',diff --git a/packages/cli/api/template/template.doc.mjs b/packages/cli/api/template/template.doc.mjsindex e2ba07ebfc..3ca91bee76 100644--- a/packages/cli/api/template/template.doc.mjs+++ b/packages/cli/api/template/template.doc.mjs@@ -75,7 +75,8 @@ export const doc = {name: 'options.targetPath',type: 'string',description:- 'Destination (relative to cwd) to scaffold the template into. Its presence switches a named lookup into a copy.',+ 'Destination (relative to cwd) to scaffold the template into. Its presence switches a named lookup into a copy. ' ++ '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.',},{name: 'options.overwrite',diff --git a/packages/cli/clients/cli/commands/layout-check.doc.mjs b/packages/cli/clients/cli/commands/layout-check.doc.mjsindex 3db63db5dd..30e7072e19 100644--- a/packages/cli/clients/cli/commands/layout-check.doc.mjs+++ b/packages/cli/clients/cli/commands/layout-check.doc.mjs@@ -21,9 +21,20 @@ export const doc = {'echoes it back in both canonical surfaces (compact and outline). An invalid but ' +'parseable expression is reported with line/col and suggestions, and exits non-zero.',fn: 'layoutCheck',- args: [{name: 'expression', param: 'expression', required: false}],+ args: [+ {+ name: 'expression',+ param: 'expression',+ required: false,+ description:+ 'The XLE/XLO expression. Pass - to read it from stdin; --file reads it from a file instead.',+ },+ ],options: [- {flag: '--file <file>', description: 'Read the expression from a file'},+ {+ flag: '--file <file>',+ description: 'Read the expression from a file (used instead of the argument when both are given)',+ },{flag: '--form <form>',param: 'options.form',diff --git a/packages/cli/clients/cli/commands/layout-expand.doc.mjs b/packages/cli/clients/cli/commands/layout-expand.doc.mjsindex 44bdec8780..9d9ec1d409 100644--- a/packages/cli/clients/cli/commands/layout-expand.doc.mjs+++ b/packages/cli/clients/cli/commands/layout-expand.doc.mjs@@ -21,11 +21,28 @@ export const doc = {'interactive controls, and splicing referenced blocks. Writes to a path, or returns the code.',fn: 'layoutExpand',args: [- {name: 'expression', param: 'expression', required: false},- {name: 'path', param: 'options.targetPath', required: false},+ {+ name: 'expression',+ param: 'expression',+ required: false,+ description:+ 'The XLE/XLO expression. Pass - to read it from stdin; --file reads it from a file instead.',+ },+ {+ name: 'path',+ param: 'options.targetPath',+ required: false,+ description:+ 'Where to write the TSX, relative to the project root. 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 <Name>.tsx (see --name). An existing file there is replaced. ' ++ 'Omit it to print the code.',+ },],options: [- {flag: '--file <file>', description: 'Read the expression from a file'},+ {+ flag: '--file <file>',+ description: 'Read the expression from a file (used instead of the argument when both are given)',+ },{flag: '--form <form>',param: 'options.form',diff --git a/packages/cli/clients/cli/commands/layout.path-help.test.mjs b/packages/cli/clients/cli/commands/layout.path-help.test.mjsnew file mode 100644index 0000000000..d0c782e8a7--- /dev/null+++ b/packages/cli/clients/cli/commands/layout.path-help.test.mjs@@ -0,0 +1,33 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file `layout expand` and `layout check` document their input modes (the+ * argument, `-` for stdin, --file) and where `layout expand` writes.+ */++import {describe, it, expect} from 'vitest';+import {runCli} from '../../../test-utils/run-cli.mjs';+import {isFilePathArg} from '../../../foundation/fs/path-safety.mjs';++const SLOW = 30_000;++describe('layout argument behavior is documented', () => {+ it('layout expand help covers stdin, --file precedence and the output path rule', async () => {+ const {status, stdout} = await runCli(['layout', 'expand', '--help']);+ expect(status).toBe(0);+ expect(stdout).toMatch(/Pass - to read it from stdin/);+ expect(stdout).toMatch(/instead of the argument/);+ expect(stdout).toContain('<Name>.tsx');+ expect(stdout).toMatch(/existing file there is replaced/);+ const exts = [...(stdout.match(/ends in ([.\w, ]+ or \.\w+)/)?.[1] ?? '').matchAll(/\.\w+/g)];+ expect(exts.length).toBeGreaterThan(0);+ for (const [ext] of exts) expect(isFilePathArg(`src/Page${ext}`)).toBe(true);+ }, SLOW);++ it('layout check help covers stdin and --file precedence', async () => {+ const {status, stdout} = await runCli(['layout', 'check', '--help']);+ expect(status).toBe(0);+ expect(stdout).toMatch(/Pass - to read it from stdin/);+ expect(stdout).toMatch(/instead of the argument/);+ }, SLOW);+});diff --git a/packages/cli/clients/cli/commands/template.doc.mjs b/packages/cli/clients/cli/commands/template.doc.mjsindex 0aa7ac5b44..4ee6c4fd2e 100644--- a/packages/cli/clients/cli/commands/template.doc.mjs+++ b/packages/cli/clients/cli/commands/template.doc.mjs@@ -23,8 +23,21 @@ export const doc = {'a discovered template.',fn: 'template',args: [- {name: 'name', param: 'name', required: false},- {name: 'path', param: 'options.targetPath', required: false},+ {+ name: 'name',+ param: 'name',+ required: false,+ description: 'Template id (see --list). Omit it to list the templates.',+ },+ {+ name: 'path',+ param: 'options.targetPath',+ required: false,+ description:+ 'Where to scaffold the template, relative to the project root. 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. " ++ 'Omit it to print the source.',+ },],options: [{flag: '--list', param: 'options.list', description: 'List available templates'},@@ -54,7 +67,8 @@ export const doc = {{flag: '-f, --overwrite',param: 'options.overwrite',- description: 'Overwrite existing files without prompting',+ description:+ 'Replace an existing target file. Without it an existing file is refused (ERR_FILE_EXISTS) and an existing CDN page is left as is',},],examples: [diff --git a/packages/cli/clients/cli/commands/template.path-help.test.mjs b/packages/cli/clients/cli/commands/template.path-help.test.mjsnew file mode 100644index 0000000000..b381678ab6--- /dev/null+++ b/packages/cli/clients/cli/commands/template.path-help.test.mjs@@ -0,0 +1,40 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file `template <name> <path>` decides by extension whether <path> is the+ * file to write or a directory to write into. Help and the manifest say so,+ * and every extension they list is one the resolver treats as a file.+ */++import {describe, it, expect} from 'vitest';+import {runCli} from '../../../test-utils/run-cli.mjs';+import {isFilePathArg} from '../../../foundation/fs/path-safety.mjs';++const SLOW = 30_000;++/** @param {string} text */+const listedExtensions = text =>+ [...(text.match(/ends in ([.\w, ]+ or \.\w+)/)?.[1] ?? '').matchAll(/\.\w+/g)].map(m => m[0]);++describe('template path resolution is documented', () => {+ it('help explains the file-or-directory rule and the default file names', async () => {+ const {status, stdout} = await runCli(['template', '--help']);+ expect(status).toBe(0);+ expect(stdout).toMatch(/Arguments:/);+ expect(stdout).toContain('page.tsx');+ expect(stdout).toMatch(/block's own file name/);+ }, SLOW);++ it('the manifest carries the same description, and its extensions are the resolver\'s', async () => {+ const {stdout} = await runCli(['manifest', '--json']);+ const {data} = JSON.parse(stdout);+ const template = data.commands.find((/** @type {any} */ c) => c.name === 'template');+ const pathArg = template.arguments.find((/** @type {any} */ a) => a.name === 'path');+ expect(pathArg.description).toContain('page.tsx');++ const exts = listedExtensions(pathArg.description);+ expect(exts.length).toBeGreaterThan(0);+ for (const ext of exts) expect(isFilePathArg(`out/page${ext}`)).toBe(true);+ expect(isFilePathArg('out/page')).toBe(false);+ }, SLOW);+});