@astryxdesign/cli 0.7.0-canary.21875fc → 0.7.0-canary.291c4e9

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.
Files changed (224) hide show
  1. package/README.md +79 -84
  2. package/api/build/build.mjs +9 -0
  3. package/api/component/_adapter.d.mts +2 -0
  4. package/api/component/_adapter.mjs +3 -1
  5. package/api/component/component.doc.mjs +5 -1
  6. package/api/docs/compiled-topics.test.mjs +16 -0
  7. package/api/doctor/doctor.doc.mjs +1 -1
  8. package/api/doctor/doctor.test.mjs +28 -0
  9. package/api/doctor/theme-checks.mjs +10 -10
  10. package/api/doctor/theme-checks.test.mjs +5 -4
  11. package/api/gap-report/gap-report.doc.mjs +1 -1
  12. package/api/gap-report/gap-report.mjs +15 -0
  13. package/api/gap-report/gap-report.test.mjs +1 -1
  14. package/api/index.d.mts +0 -2
  15. package/api/index.mjs +0 -2
  16. package/api/init/init.doc.mjs +5 -1
  17. package/api/init/init.mjs +22 -0
  18. package/api/init/init.type.d.mts +4 -1
  19. package/api/init/init.type.mjs +1 -1
  20. package/api/init/remove/remove.mjs +8 -3
  21. package/api/init/remove/remove.test.mjs +12 -0
  22. package/api/init/run/run.d.mts +1 -1
  23. package/api/init/run/run.mjs +3 -3
  24. package/api/integration/pack-check.test.mjs +8 -0
  25. package/api/integration/validate-integration.d.mts +4 -0
  26. package/api/integration/validate-integration.mjs +5 -2
  27. package/api/integration/validateIntegration.doc.mjs +1 -1
  28. package/api/json/index.ts +0 -1
  29. package/api/search/search.doc.mjs +1 -1
  30. package/api/search/search.mjs +1 -1
  31. package/api/search/search.test.mjs +1 -1
  32. package/api/search/search.type.d.mts +1 -1
  33. package/api/search/search.type.mjs +1 -1
  34. package/api/template/list/list.mjs +23 -2
  35. package/api/template/list/list.test.mjs +52 -0
  36. package/api/template/template-integration.test.mjs +37 -100
  37. package/api/template/template.doc.mjs +8 -3
  38. package/api/template/template.mjs +45 -0
  39. package/api/template/template.type.mjs +1 -1
  40. package/api/theme/_adapter.mjs +3 -3
  41. package/api/theme/add/add.d.mts +11 -5
  42. package/api/theme/add/add.mjs +19 -192
  43. package/api/theme/add/add.test.mjs +68 -258
  44. package/api/theme/add/add.types.test.mjs +0 -1
  45. package/api/theme/build/build.d.mts +3 -4
  46. package/api/theme/build/build.mjs +26 -65
  47. package/api/theme/build/build.test.mjs +11 -24
  48. package/api/theme/build/family.mjs +1 -1
  49. package/api/theme/eject/eject.copy-compat.test.mjs +168 -0
  50. package/api/theme/integration-themes.test.mjs +3 -3
  51. package/api/theme/remove/remove.test.mjs +1 -1
  52. package/api/theme/targets/targets.test.mjs +0 -4
  53. package/api/theme/template/template.mjs +1 -1
  54. package/api/theme/theme.type.d.mts +1 -30
  55. package/api/theme/theme.type.mjs +3 -13
  56. package/api/theme/themeAdd.doc.mjs +19 -27
  57. package/api/theme/themeTargets.doc.mjs +3 -4
  58. package/api/theme/themeTemplate.doc.mjs +1 -1
  59. package/api/theme/use/use.test.mjs +1 -1
  60. package/api/upgrade/upgrade.doc.mjs +1 -1
  61. package/api/upgrade/upgrade.mjs +19 -0
  62. package/assets/codemods/transforms/next/__tests__/migrate-deprecated-theme-surface.test.mjs +322 -0
  63. package/assets/codemods/transforms/next/__tests__/migrate-field-input-styling.test.mjs +108 -0
  64. package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
  65. package/assets/codemods/transforms/next/index.mjs +27 -1
  66. package/assets/codemods/transforms/next/migrate-deprecated-theme-surface-v0.6-data.mjs +229 -0
  67. package/assets/codemods/transforms/next/migrate-deprecated-theme-surface.mjs +624 -0
  68. package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
  69. package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
  70. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +38 -18
  71. package/assets/docs/author-a-theme.doc.mjs +5 -5
  72. package/assets/docs/getting-started.doc.mjs +2 -2
  73. package/assets/docs/theme.doc.dense.mjs +1 -1
  74. package/assets/docs/theme.doc.mjs +2 -2
  75. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  76. package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
  77. package/assets/docs/tree/fonts-and-assets.doc.mjs +3 -3
  78. package/assets/docs/tree/styling-advanced.doc.mjs +21 -14
  79. package/assets/docs/tree/themes.doc.mjs +1 -1
  80. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  81. package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
  82. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +2 -2
  83. package/assets/docs/tree/versioning.doc.mjs +1 -4
  84. package/assets/docs/use-a-theme.doc.mjs +16 -16
  85. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
  86. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
  87. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
  88. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
  89. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
  90. package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
  91. package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
  92. package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
  93. package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
  94. package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
  95. package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
  96. package/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx +1 -1
  97. package/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx +1 -1
  98. package/assets/templates/blocks/components/Slider/SliderShowcase.tsx +1 -1
  99. package/assets/templates/blocks/components/Slider/SliderWithMarks.tsx +1 -1
  100. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -1
  101. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -2
  102. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -1
  103. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -1
  104. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -1
  105. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -2
  106. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -1
  107. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -4
  108. package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
  109. package/assets/templates/pages/canvas-editor/page.tsx +2 -2
  110. package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
  111. package/assets/templates/pages/payment-form/page.tsx +1 -1
  112. package/assets/templates/pages/table-filter/page.tsx +3 -3
  113. package/assets/templates/pages/theme-showcase/page.tsx +2 -2
  114. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
  115. package/authoring/debug/type.ts +2 -2
  116. package/authoring/doctypes/base/type.ts +0 -9
  117. package/authoring/integration/integration.doc.mjs +1 -1
  118. package/clients/cli/command-result-coverage.test.mjs +1 -1
  119. package/clients/cli/commands/build-theme.adaptations.test.mjs +4 -0
  120. package/clients/cli/commands/build-theme.ascii-output.test.mjs +35 -8
  121. package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
  122. package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
  123. package/clients/cli/commands/build-theme.mjs +31 -67
  124. package/clients/cli/commands/build-theme.registry.test.mjs +0 -10
  125. package/clients/cli/commands/build.doc.mjs +1 -1
  126. package/clients/cli/commands/build.mjs +1 -1
  127. package/clients/cli/commands/component-ownership.test.mjs +2 -2
  128. package/clients/cli/commands/debug-result-summary.test.mjs +0 -16
  129. package/clients/cli/commands/discover.mjs +2 -1
  130. package/clients/cli/commands/doctor.mjs +5 -2
  131. package/clients/cli/commands/empty-argument.test.mjs +16 -0
  132. package/clients/cli/commands/gap-report.doc.mjs +1 -1
  133. package/clients/cli/commands/gap-report.test.mjs +2 -2
  134. package/clients/cli/commands/init.doc.mjs +4 -4
  135. package/clients/cli/commands/init.flag-help.test.mjs +7 -10
  136. package/clients/cli/commands/init.next-steps.test.mjs +1 -1
  137. package/clients/cli/commands/integration.mjs +2 -1
  138. package/clients/cli/commands/option-pair-refusals.test.mjs +37 -0
  139. package/clients/cli/commands/search.test.mjs +1 -1
  140. package/clients/cli/commands/silent-success-refusals.test.mjs +15 -0
  141. package/clients/cli/commands/swizzle.mjs +4 -1
  142. package/clients/cli/commands/template.doc.mjs +4 -4
  143. package/clients/cli/commands/template.flag-help.test.mjs +18 -11
  144. package/clients/cli/commands/template.mjs +7 -1
  145. package/clients/cli/commands/text-json-parity.test.mjs +0 -17
  146. package/clients/cli/commands/theme-add-lifecycle.test.mjs +142 -49
  147. package/clients/cli/commands/theme-add.doc.mjs +10 -17
  148. package/clients/cli/commands/theme-list.behavior.test.mjs +2 -1
  149. package/clients/cli/commands/theme-targets.behavior.test.mjs +8 -6
  150. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  151. package/clients/cli/commands/theme.doc.mjs +2 -2
  152. package/clients/cli/commands/upgrade.doc.mjs +1 -1
  153. package/clients/cli/commands/upgrade.flag-help.test.mjs +7 -11
  154. package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +67 -0
  155. package/clients/cli/index.mjs +0 -4
  156. package/clients/cli/lib/cli-error.mjs +19 -0
  157. package/clients/cli/lib/component-format.mjs +111 -57
  158. package/clients/cli/lib/component-format.test.mjs +28 -39
  159. package/clients/cli/lib/doc-text-ascii.test.mjs +5 -2
  160. package/clients/cli/lib/exit-codes.test.mjs +0 -7
  161. package/clients/cli/lib/json-shim.test.mjs +0 -24
  162. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  163. package/foundation/agent-docs/agent-docs.mjs +6 -1
  164. package/foundation/agent-docs/app-theme-workflow.test.mjs +3 -0
  165. package/foundation/config/theme-state.mjs +3 -3
  166. package/foundation/debug/debug-fields.test.mjs +13 -35
  167. package/foundation/debug/event.mjs +13 -78
  168. package/foundation/debug/privacy-contract.test.mjs +20 -12
  169. package/foundation/debug/redact.d.mts +2 -2
  170. package/foundation/debug/redact.mjs +2 -2
  171. package/foundation/discovery/template-needs.mjs +93 -11
  172. package/foundation/discovery/template-needs.test.mjs +106 -3
  173. package/foundation/discovery/theme-imports.mjs +1 -1
  174. package/foundation/discovery/theming-targets.d.mts +1 -20
  175. package/foundation/discovery/theming-targets.mjs +1 -38
  176. package/foundation/discovery/theming-targets.test.mjs +9 -175
  177. package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
  178. package/foundation/env/package-manager.d.mts +13 -0
  179. package/foundation/env/package-manager.mjs +106 -63
  180. package/foundation/response/error-codes.doc.mjs +1 -1
  181. package/foundation/response/response-types.doc.mjs +11 -31
  182. package/foundation/response/response-types.doc.test.mjs +36 -14
  183. package/foundation/response/response.doc.mjs +1 -1
  184. package/foundation/xle/browser.d.mts +2 -2
  185. package/foundation/xle/browser.mjs +2 -2
  186. package/foundation/xle/expand.mjs +1 -1
  187. package/foundation/xle/print.mjs +1 -1
  188. package/package.json +9 -9
  189. package/api/layout/_adapter.d.mts +0 -34
  190. package/api/layout/_adapter.mjs +0 -148
  191. package/api/layout/check/check.d.mts +0 -17
  192. package/api/layout/check/check.mjs +0 -41
  193. package/api/layout/expand/expand.d.mts +0 -23
  194. package/api/layout/expand/expand.mjs +0 -161
  195. package/api/layout/expand/expand.path-safety.test.mjs +0 -53
  196. package/api/layout/expand/expand.receipt.test.mjs +0 -74
  197. package/api/layout/grammar/grammar.d.mts +0 -14
  198. package/api/layout/grammar/grammar.mjs +0 -88
  199. package/api/layout/layout.d.mts +0 -6
  200. package/api/layout/layout.mjs +0 -17
  201. package/api/layout/layout.test.mjs +0 -297
  202. package/api/layout/layout.type.d.mts +0 -90
  203. package/api/layout/layout.type.mjs +0 -104
  204. package/api/layout/layoutCheck.doc.d.mts +0 -11
  205. package/api/layout/layoutCheck.doc.mjs +0 -85
  206. package/api/layout/layoutExpand.doc.d.mts +0 -11
  207. package/api/layout/layoutExpand.doc.mjs +0 -107
  208. package/api/layout/layoutGrammar.doc.d.mts +0 -11
  209. package/api/layout/layoutGrammar.doc.mjs +0 -57
  210. package/api/theme/add/add.binary.test.mjs +0 -157
  211. package/api/theme/add/add.rollback.test.mjs +0 -158
  212. package/api/theme/add/add.staging.test.mjs +0 -83
  213. package/clients/cli/commands/layout-check.doc.mjs +0 -67
  214. package/clients/cli/commands/layout-expand.doc.mjs +0 -87
  215. package/clients/cli/commands/layout-grammar.doc.mjs +0 -32
  216. package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +0 -140
  217. package/clients/cli/commands/layout.doc.mjs +0 -36
  218. package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
  219. package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
  220. package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
  221. package/clients/cli/commands/layout.mjs +0 -327
  222. package/clients/cli/commands/layout.path-help.test.mjs +0 -33
  223. package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
  224. package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
@@ -1,327 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file layout command — thin CLI wrapper around api/layout.mjs.
5
- *
6
- * Subcommands:
7
- * astryx layout expand "<expr>" [path] compressed expression → validated TSX
8
- * astryx layout check "<expr>" validate + echo both canonical surfaces
9
- * astryx layout grammar agent cheatsheet (alias table is branch-generated)
10
- *
11
- * The expression argument may also come from --file or stdin (`-`),
12
- * which is how multi-line outline (XLO) input usually arrives.
13
- *
14
- * The command surface (group + subcommand descriptions, args, flags) is sourced
15
- * from the colocated CommandDocs via `defineCommand`; this file supplies only the
16
- * actions.
17
- */
18
-
19
- import * as fs from 'node:fs';
20
- import * as path from 'node:path';
21
- import {jsonOut, isJsonMode} from '../../../foundation/response/json.mjs';
22
- import {emit, section, text, list, record, code, WARN} from '../formatters/index.mjs';
23
- import {cliError} from '../lib/cli-error.mjs';
24
- import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
25
- import {layoutExpand, layoutCheck, layoutGrammar} from '../../../api/layout/layout.mjs';
26
- import {defineCommand} from '../lib/define-command.mjs';
27
- import {doc as layoutGroup} from './layout.doc.mjs';
28
- import {doc as layoutExpandCommand} from './layout-expand.doc.mjs';
29
- import {doc as layoutCheckCommand} from './layout-check.doc.mjs';
30
- import {doc as layoutGrammarCommand} from './layout-grammar.doc.mjs';
31
- import {doc as layoutExpandFn} from '../../../api/layout/layoutExpand.doc.mjs';
32
- import {doc as layoutCheckFn} from '../../../api/layout/layoutCheck.doc.mjs';
33
- import {doc as layoutGrammarFn} from '../../../api/layout/layoutGrammar.doc.mjs';
34
- import {NO_RESULT_SET, resultSet} from '../../../foundation/debug/index.mjs';
35
-
36
- /**
37
- * The api layer's @returns for these functions widen the `type` discriminator
38
- * to `string`, so annotate the command-local result with the precise response
39
- * shapes from the colocated api/layout/layout.type.mjs so narrowing + jsonOut
40
- * typecheck.
41
- *
42
- * @typedef {import('../../../api/layout/layout.type.mjs').LayoutExpandResponse} LayoutExpandResponse
43
- * @typedef {import('../../../api/layout/layout.type.mjs').LayoutCheckResponse} LayoutCheckResponse
44
- * @typedef {import('../../../api/layout/layout.type.mjs').LayoutGrammarResponse} LayoutGrammarResponse
45
- */
46
-
47
- /**
48
- * @typedef {object} LayoutExpandOptions
49
- * @property {string} [file]
50
- * @property {'compact'|'outline'|'auto'} [form]
51
- * @property {string} [name]
52
- * @property {boolean} [loose]
53
- */
54
-
55
- /**
56
- * @typedef {object} LayoutCheckOptions
57
- * @property {string} [file]
58
- * @property {'compact'|'outline'|'auto'} [form]
59
- * @property {boolean} [loose]
60
- */
61
-
62
- /**
63
- * DEP-0006: the `astryx layout` command group is deprecated.
64
- *
65
- * Human mode: one stderr warning per invocation.
66
- * JSON mode: `meta.deprecations` array in the response envelope.
67
- */
68
- const LAYOUT_DEPRECATION = Object.freeze({
69
- id: 'DEP-0006',
70
- replacements: ['build', 'template', 'docs layout'],
71
- });
72
-
73
- function warnDeprecated() {
74
- if (!isJsonMode()) {
75
- console.error(
76
- '[DEP-0006] astryx layout is deprecated and will be removed in a future minor release.\n' +
77
- ' Use instead:\n' +
78
- ' astryx build "<idea>" choose the template to start from\n' +
79
- ' astryx template <name> scaffold it\n' +
80
- ' astryx docs layout layout guidance\n',
81
- );
82
- }
83
- }
84
-
85
- /**
86
- * Add deprecation metadata to a JSON response before output.
87
- * Canonical stdout (type, data) is unchanged; the metadata sits in `meta`.
88
- * @param {{type: string, data: unknown}} result
89
- * @returns {{type: string, data: unknown, meta: {deprecations: [typeof LAYOUT_DEPRECATION]}}}
90
- */
91
- function withDeprecation(result) {
92
- return {...result, meta: {deprecations: [LAYOUT_DEPRECATION]}};
93
- }
94
-
95
- /** The largest layout expression read from --file or stdin. */
96
- const MAX_EXPRESSION_BYTES = 5 * 1024 * 1024; // 5 MB
97
-
98
- /**
99
- * Resolve the expression from arg, --file, or stdin ('-').
100
- * @param {string} [expr]
101
- * @param {{file?: string}} [options]
102
- * @returns {Promise<string>}
103
- */
104
- async function readExpression(expr, options = {}) {
105
- if (options.file) {
106
- // Validate the file exists + is a regular file + is reasonably sized.
107
- // We intentionally do NOT confine the read path (the user running the CLI
108
- // controls --file; this is a read, not a write). The size cap prevents OOM
109
- // from infinite streams like /dev/zero.
110
- const filePath = path.resolve(process.cwd(), options.file);
111
- const stat = fs.statSync(filePath, {throwIfNoEntry: false});
112
- if (!stat || !stat.isFile()) {
113
- cliError(`File not found: ${options.file}`, {
114
- code: ERROR_CODES.ERR_FILE_NOT_FOUND,
115
- });
116
- }
117
- if (stat.size > MAX_EXPRESSION_BYTES) {
118
- cliError(
119
- `File "${options.file}" is too large (${(stat.size / 1024 / 1024).toFixed(1)} MB, max 5 MB)`,
120
- {code: ERROR_CODES.ERR_FILE_NOT_FOUND},
121
- );
122
- }
123
- try {
124
- return fs.readFileSync(filePath, 'utf-8');
125
- } catch (e) {
126
- const errno = /** @type {NodeJS.ErrnoException} */ (e);
127
- if (errno && errno.code === 'ENOENT') {
128
- // A --file pointing at a missing file is foreseeable — surface a
129
- // stable code, not the raw ENOENT errno (and no stack in human mode).
130
- cliError(`File not found: ${options.file}`, {
131
- code: ERROR_CODES.ERR_FILE_NOT_FOUND,
132
- });
133
- }
134
- throw e;
135
- }
136
- }
137
- if (expr === '-') {
138
- // Capped like --file: an endless stream must not be buffered whole.
139
- /** @type {Buffer[]} */
140
- const chunks = [];
141
- let size = 0;
142
- for await (const chunk of process.stdin) {
143
- size += /** @type {Buffer} */ (chunk).length;
144
- if (size > MAX_EXPRESSION_BYTES) {
145
- cliError('The layout expression on stdin is too large (max 5 MB)', {
146
- code: ERROR_CODES.ERR_INVALID_ARGUMENT,
147
- });
148
- }
149
- chunks.push(/** @type {Buffer} */ (chunk));
150
- }
151
- return Buffer.concat(chunks).toString('utf-8');
152
- }
153
- return expr ?? '';
154
- }
155
-
156
- /**
157
- * The disclosure for demo media replaced in spliced template blocks, or '' when
158
- * none was. After printed code it is a line comment, so piped output stays TSX.
159
- * @param {LayoutExpandResponse['data']} data
160
- * @returns {string}
161
- */
162
- function demoMediaNotice({demoMediaReplaced, written}) {
163
- if (demoMediaReplaced === 0) return '';
164
- const notice =
165
- `Replaced ${demoMediaReplaced} Astryx demo media reference${demoMediaReplaced === 1 ? '' : 's'} in ${written ?? 'the code above'}: ` +
166
- 'images now show a neutral placeholder and videos have an empty source. Supply your own media there.';
167
- return written ? notice : `// ${notice}`;
168
- }
169
-
170
- /**
171
- * @param {import('commander').Command} program
172
- */
173
- export function registerLayout(program) {
174
- const layoutCmd = defineCommand(program, layoutGroup);
175
-
176
- defineCommand(layoutCmd, layoutExpandCommand, {
177
- fn: layoutExpandFn,
178
- action: async (/** @type {string} */ expression, /** @type {string} */ targetPath, /** @type {LayoutExpandOptions} */ options) => {
179
- warnDeprecated();
180
- const json = program.opts().json || false;
181
- const source = await readExpression(expression, options);
182
- if (!source || source.trim() === '') {
183
- return cliError(
184
- 'No layout expression given — pass it as an argument, via --file, or on stdin',
185
- {code: ERROR_CODES.ERR_MISSING_ARGUMENT},
186
- );
187
- }
188
- /** @type {LayoutExpandResponse} */
189
- let result;
190
- try {
191
- result = /** @type {LayoutExpandResponse} */ (await layoutExpand(source, {
192
- targetPath,
193
- form: options.form,
194
- loose: options.loose || false,
195
- name: options.name,
196
- cwd: process.cwd(),
197
- }));
198
- } catch (e) {
199
- const err = /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
200
- return cliError(err.message, {suggestions: err.suggestions || [], code: err.code});
201
- }
202
- // Expanding turns an expression into TSX — a transformation, not a
203
- // lookup. What it produced is in the output; there is no set to count.
204
- if (json) {
205
- jsonOut(withDeprecation(result));
206
- return NO_RESULT_SET;
207
- }
208
-
209
- /** @type {import('../formatters/index.mjs').Block[]} */
210
- const out = [];
211
- if (result.data.warnings.length > 0) {
212
- out.push(text(result.data.warnings.map(w => `${WARN} ${w}`).join('\n')));
213
- }
214
- if (result.data.written) {
215
- out.push(
216
- text(`[ok] Expanded to ${result.data.written}`),
217
- // Field names are the JSON keys; todos are summarised, not listed.
218
- record(
219
- {componentsUsed: result.data.componentsUsed, todos: result.data.todos},
220
- {
221
- format: {
222
- todos: (/** @type {string[]} */ todos) =>
223
- `${todos.length} (search for "TODO(xle)")`,
224
- },
225
- },
226
- ),
227
- );
228
- } else {
229
- // Raw expanded TSX (no target path) — preformatted, emitted verbatim.
230
- out.push(code(result.data.code));
231
- }
232
- const mediaNotice = demoMediaNotice(result.data);
233
- if (mediaNotice) out.push(text(mediaNotice));
234
- emit(...out);
235
- return NO_RESULT_SET;
236
- },
237
- });
238
-
239
- defineCommand(layoutCmd, layoutCheckCommand, {
240
- fn: layoutCheckFn,
241
- action: async (/** @type {string} */ expression, /** @type {LayoutCheckOptions} */ options) => {
242
- warnDeprecated();
243
- const json = program.opts().json || false;
244
- const source = await readExpression(expression, options);
245
- if (!source || source.trim() === '') {
246
- return cliError(
247
- 'No layout expression given — pass it as an argument, via --file, or on stdin',
248
- {code: ERROR_CODES.ERR_MISSING_ARGUMENT},
249
- );
250
- }
251
- /** @type {LayoutCheckResponse} */
252
- let result;
253
- try {
254
- result = /** @type {LayoutCheckResponse} */ (await layoutCheck(source, {
255
- form: options.form,
256
- loose: options.loose || false,
257
- cwd: process.cwd(),
258
- }));
259
- } catch (e) {
260
- const err = /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
261
- return cliError(err.message, {suggestions: err.suggestions || [], code: err.code});
262
- }
263
- // Exit code is the contract and must NOT depend on --json vs human: an
264
- // invalid (but parseable) layout exits 1 in BOTH modes so `layout check`
265
- // works as a CI gate / agent check without parsing stdout. Decide it
266
- // before the JSON return (parity with doctor integration validate).
267
- if (!result.data.valid) process.exitCode = 1;
268
-
269
- // A verdict on one expression: valid or not, with the errors that made
270
- // it so. Nothing was looked up.
271
- if (json) {
272
- jsonOut(withDeprecation(result));
273
- return NO_RESULT_SET;
274
- }
275
-
276
- const {valid, form, errors, warnings, compact, outline} = result.data;
277
- if (!valid) {
278
- // Each error: the formatted issue, with a hanging "did you mean" line.
279
- const items = errors.map(e =>
280
- e.suggestions && e.suggestions.length > 0
281
- ? [e.formatted, `did you mean: ${e.suggestions.join(', ')}?`]
282
- : [e.formatted],
283
- );
284
- emit(
285
- text(`[fail] Invalid (${errors.length} error${errors.length === 1 ? '' : 's'}):`),
286
- list(items),
287
- );
288
- return NO_RESULT_SET;
289
- }
290
-
291
- /** @type {import('../formatters/index.mjs').Block[]} */
292
- const out = [text(`[ok] Valid (parsed as ${form})`)];
293
- if (warnings.length > 0) {
294
- out.push(text(warnings.map(w => `${WARN} ${w}`).join('\n')));
295
- }
296
- // The canonical compact/outline surfaces are preformatted — emit verbatim.
297
- out.push(section('compact'), code(compact), section('outline'), code(outline));
298
- emit(...out);
299
- return NO_RESULT_SET;
300
- },
301
- });
302
-
303
- defineCommand(layoutCmd, layoutGrammarCommand, {
304
- fn: layoutGrammarFn,
305
- action: async () => {
306
- warnDeprecated();
307
- const json = program.opts().json || false;
308
- /** @type {LayoutGrammarResponse} */
309
- let result;
310
- try {
311
- result = /** @type {LayoutGrammarResponse} */ (await layoutGrammar({cwd: process.cwd()}));
312
- } catch (e) {
313
- const err = /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
314
- return cliError(err.message, {suggestions: err.suggestions || [], code: err.code});
315
- }
316
- // One document, the same one every time: the grammar cheatsheet.
317
- const answered = resultSet({count: 1, resultKind: 'doc'});
318
- if (json) {
319
- jsonOut(withDeprecation(result));
320
- return answered;
321
- }
322
- // The cheatsheet is a preformatted document — emit verbatim.
323
- emit(code(result.data.text));
324
- return answered;
325
- },
326
- });
327
- }
@@ -1,33 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file `layout expand` and `layout check` document their input modes (the
5
- * argument, `-` for stdin, --file) and where `layout expand` writes.
6
- */
7
-
8
- import {describe, it, expect} from 'vitest';
9
- import {runCli} from '../../../test-utils/run-cli.mjs';
10
- import {isFilePathArg} from '../../../foundation/fs/path-safety.mjs';
11
-
12
- const SLOW = 30_000;
13
-
14
- describe('layout argument behavior is documented', () => {
15
- it('layout expand help covers stdin, --file precedence and the output path rule', async () => {
16
- const {status, stdout} = await runCli(['layout', 'expand', '--help']);
17
- expect(status).toBe(0);
18
- expect(stdout).toMatch(/Pass - to read it from stdin/);
19
- expect(stdout).toMatch(/instead of the argument/);
20
- expect(stdout).toContain('<Name>.tsx');
21
- expect(stdout).toMatch(/existing file there is replaced/);
22
- const exts = [...(stdout.match(/ends in ([.\w, ]+ or \.\w+)/)?.[1] ?? '').matchAll(/\.\w+/g)];
23
- expect(exts.length).toBeGreaterThan(0);
24
- for (const [ext] of exts) expect(isFilePathArg(`src/Page${ext}`)).toBe(true);
25
- }, SLOW);
26
-
27
- it('layout check help covers stdin and --file precedence', async () => {
28
- const {status, stdout} = await runCli(['layout', 'check', '--help']);
29
- expect(status).toBe(0);
30
- expect(stdout).toMatch(/Pass - to read it from stdin/);
31
- expect(stdout).toMatch(/instead of the argument/);
32
- }, SLOW);
33
- });
@@ -1,47 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file `layout check -` reads the expression from stdin under the same 5 MB
5
- * cap as --file, instead of buffering whatever the pipe delivers. Spawns the
6
- * real bin, since the in-process harness has no stdin.
7
- */
8
-
9
- import {describe, it, expect} from 'vitest';
10
- import {spawnSync} from 'node:child_process';
11
- import * as path from 'node:path';
12
- import {fileURLToPath} from 'node:url';
13
-
14
- const HERE = path.dirname(fileURLToPath(import.meta.url));
15
- const BIN = path.resolve(HERE, '../bin/astryx.mjs');
16
- // Run against the monorepo root so @astryxdesign/core is discoverable.
17
- const REPO = path.resolve(HERE, '../../../..');
18
- const SLOW = 60_000;
19
-
20
- /** @param {string} input @param {string[]} [extra] */
21
- function checkFromStdin(input, extra = []) {
22
- return spawnSync(process.execPath, [BIN, 'layout', 'check', '-', ...extra], {
23
- cwd: REPO,
24
- input,
25
- encoding: 'utf-8',
26
- maxBuffer: 16 * 1024 * 1024,
27
- });
28
- }
29
-
30
- describe('layout check - (stdin)', () => {
31
- it('refuses more than 5 MB with ERR_INVALID_ARGUMENT, in both modes', () => {
32
- // Valid once trimmed, so only the cap can reject it.
33
- const big = ' '.repeat(5 * 1024 * 1024 + 1) + 'V';
34
- const json = checkFromStdin(big, ['--json']);
35
- expect(json.status).toBe(1);
36
- expect(JSON.parse(json.stdout).code).toBe('ERR_INVALID_ARGUMENT');
37
- const human = checkFromStdin(big);
38
- expect(human.status).toBe(1);
39
- expect(human.stderr + human.stdout).toMatch(/too large/);
40
- }, SLOW);
41
-
42
- it('still reads a normal expression', () => {
43
- const r = checkFromStdin('V > B', ['--json']);
44
- expect(r.status).toBe(0);
45
- expect(JSON.parse(r.stdout).data.valid).toBe(true);
46
- }, SLOW);
47
- });
@@ -1,39 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file `layout expand` text output names its fields after the JSON keys, so
5
- * the two views stay greppable against each other.
6
- */
7
-
8
- import {describe, it, expect, beforeEach, afterEach} from 'vitest';
9
- import * as fs from 'node:fs';
10
- import * as path from 'node:path';
11
- import {runCli} from '../../../test-utils/run-cli.mjs';
12
-
13
- const SLOW = 60_000;
14
-
15
- describe('layout expand text fields mirror the JSON keys', () => {
16
- let cwd;
17
- beforeEach(() => {
18
- // Inside the workspace so @astryxdesign/core resolves.
19
- cwd = fs.mkdtempSync(path.join(process.cwd(), '.xle-text-fields-'));
20
- });
21
- afterEach(() => fs.rmSync(cwd, {recursive: true, force: true}));
22
-
23
- it('labels every record field with a key of the layout.expand data', async () => {
24
- const expr = 'V > B + {not-a-real-block}';
25
- const json = await runCli(['layout', 'expand', expr, './a', '--loose', '--json'], cwd);
26
- expect(json.status).toBe(0);
27
- const {data} = JSON.parse(json.stdout);
28
- expect(data.todos.length).toBeGreaterThan(0);
29
-
30
- const human = await runCli(['layout', 'expand', expr, './b', '--loose'], cwd);
31
- expect(human.status).toBe(0);
32
- const fields = human.stdout
33
- .split('\n')
34
- .map(line => /^([A-Za-z]+):\s/.exec(line)?.[1])
35
- .filter(Boolean);
36
- expect(fields).toEqual(['componentsUsed', 'todos']);
37
- for (const field of fields) expect(Object.keys(data)).toContain(field);
38
- }, SLOW);
39
- });