@astryxdesign/cli 0.1.6-canary.eb549c8 → 0.1.6-canary.eba4f34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.1.6-canary.eb549c8",
3
+ "version": "0.1.6-canary.eba4f34",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -75,10 +75,10 @@
75
75
  "zod": "^4.4.3"
76
76
  },
77
77
  "peerDependencies": {
78
- "@astryxdesign/charts": "0.1.6-canary.eb549c8",
79
- "@astryxdesign/core": "0.1.6-canary.eb549c8",
80
- "@astryxdesign/lab": "0.1.6-canary.eb549c8",
81
- "@astryxdesign/theme-neutral": "0.1.6-canary.eb549c8",
78
+ "@astryxdesign/charts": "0.1.6-canary.eba4f34",
79
+ "@astryxdesign/core": "0.1.6-canary.eba4f34",
80
+ "@astryxdesign/lab": "0.1.6-canary.eba4f34",
81
+ "@astryxdesign/theme-neutral": "0.1.6-canary.eba4f34",
82
82
  "gpt-tokenizer": "^3.4.0"
83
83
  },
84
84
  "peerDependenciesMeta": {
@@ -96,10 +96,10 @@
96
96
  }
97
97
  },
98
98
  "devDependencies": {
99
- "@astryxdesign/charts": "0.1.6-canary.eb549c8",
100
- "@astryxdesign/core": "0.1.6-canary.eb549c8",
101
- "@astryxdesign/lab": "0.1.6-canary.eb549c8",
102
- "@astryxdesign/theme-neutral": "0.1.6-canary.eb549c8",
99
+ "@astryxdesign/charts": "0.1.6-canary.eba4f34",
100
+ "@astryxdesign/core": "0.1.6-canary.eba4f34",
101
+ "@astryxdesign/lab": "0.1.6-canary.eba4f34",
102
+ "@astryxdesign/theme-neutral": "0.1.6-canary.eba4f34",
103
103
  "gpt-tokenizer": "^3.4.0"
104
104
  },
105
105
  "scripts": {
@@ -6,7 +6,6 @@
6
6
 
7
7
  import * as fs from 'node:fs';
8
8
  import * as path from 'node:path';
9
- import {createJiti} from 'jiti';
10
9
  import {loadModuleWithSchema} from '../lib/module-loader.mjs';
11
10
  import {TemplateEnvelopeSchema} from '../template.mjs';
12
11
  import {CLI_ROOT, discoverExternalPackages} from '../utils/paths.mjs';
@@ -22,54 +21,9 @@ import {Project} from '../lib/project.mjs';
22
21
  /** Identity used for core (built-in) templates in package-scoped listings. */
23
22
  const CORE_PACKAGE = '@astryxdesign/core';
24
23
 
25
- /**
26
- * Canonical basename suffixes for template-spec files, in precedence order.
27
- * A template spec exports a `createBlockTemplate`/`createPageTemplate` result
28
- * (a scaffoldable TEMPLATE), so `.template.*` is the descriptive family name.
29
- */
30
- const TEMPLATE_SUFFIXES = ['.template.ts', '.template.mjs', '.template.js'];
31
-
32
- /**
33
- * Legacy basename suffixes for template-spec files, in precedence order.
34
- * `.doc.*` was inherited from the component-doc convention before templates
35
- * had their own name; it is still accepted during the transition window.
36
- */
24
+ /** Doc-file basename suffixes for integration templates, in precedence order. */
37
25
  const DOC_SUFFIXES = ['.doc.ts', '.doc.mjs', '.doc.js'];
38
26
 
39
- /**
40
- * The union of canonical + legacy template-spec suffixes, canonical first so
41
- * `.template.*` wins over `.doc.*` when both stems exist. All template
42
- * discovery matches this union so a `Foo.template.ts` file is treated exactly
43
- * like a legacy `Foo.doc.mjs`.
44
- */
45
- const ALL_TEMPLATE_SUFFIXES = [...TEMPLATE_SUFFIXES, ...DOC_SUFFIXES];
46
-
47
- /**
48
- * The template-spec suffix present on `file`, or null if none matches.
49
- * Recognizes both the canonical `.template.*` and legacy `.doc.*` families.
50
- * @param {string} file
51
- * @returns {string | null}
52
- */
53
- function matchedTemplateSuffix(file) {
54
- return ALL_TEMPLATE_SUFFIXES.find(suffix => file.endsWith(suffix)) ?? null;
55
- }
56
-
57
- /**
58
- * RegExp matching either template-spec suffix family at end of a basename.
59
- * Used where a per-file regex is convenient (e.g. block discovery walks).
60
- */
61
- const TEMPLATE_SUFFIX_RE = /\.(template|doc)\.(ts|mjs|js)$/;
62
-
63
- let jitiInstance;
64
- /** Lazily-created jiti for loading `.ts` template specs (JSX-capable). */
65
- function getJiti() {
66
- if (!jitiInstance) {
67
- jitiInstance = createJiti(import.meta.url, {jsx: true});
68
- }
69
- return jitiInstance;
70
- }
71
-
72
-
73
27
  /**
74
28
  * Load an integration template doc module and validate it against the template
75
29
  * envelope at the load boundary. Default export only — `.ts` via jiti,
@@ -133,29 +87,12 @@ export function stripTemplateAssetRefs(source) {
133
87
  source,
134
88
  );
135
89
  }
136
- /**
137
- * Load a template-spec module and return its metadata object. Supports both
138
- * families of suffix:
139
- * - Legacy `.doc.*` core/external specs export `export const doc = {...}`.
140
- * - Specs authored with `createPageTemplate`/`createBlockTemplate` export the
141
- * stamped object as the default export.
142
- * Prefers the default export, falling back to the named `doc` export, so a
143
- * `Foo.template.ts` (default export) is read identically to a legacy
144
- * `Foo.doc.mjs` (`doc` export). `.ts` is loaded via jiti; `.mjs`/`.js` via a
145
- * native dynamic import. Returns null if the file does not exist.
146
- *
147
- * @param {string} docPath absolute path to the spec file
148
- * @returns {Promise<Record<string, unknown> | undefined | null>}
149
- */
150
90
  async function loadDocModule(docPath) {
151
91
  if (!fs.existsSync(docPath)) return null;
152
- const docModule = docPath.endsWith('.ts')
153
- ? await getJiti().import(docPath)
154
- : await import(`file://${docPath}`);
155
- return docModule.default ?? docModule.doc;
92
+ const docModule = await import(`file://${docPath}`);
93
+ return docModule.doc;
156
94
  }
157
95
 
158
-
159
96
  export {discoverAll as discoverTemplates};
160
97
 
161
98
  export function listTemplates() {
@@ -185,20 +122,6 @@ function findDocFiles(dir, pattern) {
185
122
  return results;
186
123
  }
187
124
 
188
- /**
189
- * Resolve the template-spec file for a core page directory: the first existing
190
- * `template.<suffix>` in canonical-then-legacy precedence, or null.
191
- * @param {string} dirPath
192
- * @returns {string | null}
193
- */
194
- function findPageDocFile(dirPath) {
195
- for (const suffix of ALL_TEMPLATE_SUFFIXES) {
196
- const candidate = path.join(dirPath, `template${suffix}`);
197
- if (fs.existsSync(candidate)) return candidate;
198
- }
199
- return null;
200
- }
201
-
202
125
  async function discoverPages() {
203
126
  if (!fs.existsSync(PAGES_DIR)) return [];
204
127
  const dirs = fs
@@ -208,9 +131,7 @@ async function discoverPages() {
208
131
  const templates = [];
209
132
  for (const dir of dirs) {
210
133
  const dirPath = path.join(PAGES_DIR, dir.name);
211
- const docPath =
212
- findPageDocFile(dirPath) ?? path.join(dirPath, 'template.doc.mjs');
213
- const doc = await loadDocModule(docPath);
134
+ const doc = await loadDocModule(path.join(dirPath, 'template.doc.mjs'));
214
135
  templates.push({
215
136
  type: 'page',
216
137
  dirName: dir.name,
@@ -220,18 +141,17 @@ async function discoverPages() {
220
141
  isReady: doc?.isReady ?? true,
221
142
  scaffold: doc?.scaffold ?? false,
222
143
  filePath: path.join(dirPath, 'page.tsx'),
223
- docPath,
144
+ docPath: path.join(dirPath, 'template.doc.mjs'),
224
145
  });
225
146
  }
226
147
  return templates;
227
148
  }
228
149
 
229
150
  async function discoverBlocks() {
230
- const docFiles = findDocFiles(BLOCKS_DIR, TEMPLATE_SUFFIX_RE);
151
+ const docFiles = findDocFiles(BLOCKS_DIR, /\.doc\.mjs$/);
231
152
  const blocks = [];
232
153
  for (const docPath of docFiles) {
233
- const suffix = matchedTemplateSuffix(docPath);
234
- const basename = path.basename(docPath, suffix);
154
+ const basename = path.basename(docPath, '.doc.mjs');
235
155
  const tsxPath = path.join(path.dirname(docPath), basename + '.tsx');
236
156
  if (!fs.existsSync(tsxPath)) continue;
237
157
  const doc = await loadDocModule(docPath);
@@ -253,7 +173,6 @@ async function discoverBlocks() {
253
173
  return blocks;
254
174
  }
255
175
 
256
-
257
176
  /**
258
177
  * Discover blocks from external packages that declare `astryx.blocks` in
259
178
  * their package.json. Same shape as discoverBlocks() output.
@@ -266,10 +185,9 @@ async function discoverExternalBlocks(cwd = process.cwd()) {
266
185
 
267
186
  for (const ext of externals) {
268
187
  if (!ext.blocksDir || !fs.existsSync(ext.blocksDir)) continue;
269
- const docFiles = findDocFiles(ext.blocksDir, TEMPLATE_SUFFIX_RE);
188
+ const docFiles = findDocFiles(ext.blocksDir, /\.doc\.mjs$/);
270
189
  for (const docPath of docFiles) {
271
- const suffix = matchedTemplateSuffix(docPath);
272
- const basename = path.basename(docPath, suffix);
190
+ const basename = path.basename(docPath, '.doc.mjs');
273
191
  const tsxPath = path.join(path.dirname(docPath), basename + '.tsx');
274
192
  if (!fs.existsSync(tsxPath)) continue;
275
193
  const doc = await loadDocModule(docPath);
@@ -340,9 +258,8 @@ async function discoverAllWithErrors(cwd = process.cwd()) {
340
258
  export {discoverAllWithErrors};
341
259
 
342
260
  /**
343
- * Recursively collect integration template-spec files under `root`.
344
- * Returns absolute paths to files ending in one of ALL_TEMPLATE_SUFFIXES
345
- * (canonical `.template.*` or legacy `.doc.*`).
261
+ * Recursively collect integration template doc files under `root`.
262
+ * Returns absolute paths to files ending in one of DOC_SUFFIXES.
346
263
  *
347
264
  * @param {string} root
348
265
  * @returns {string[]}
@@ -355,7 +272,7 @@ function findIntegrationDocFiles(root) {
355
272
  const full = path.join(dir, entry.name);
356
273
  if (entry.isDirectory()) {
357
274
  walk(full);
358
- } else if (ALL_TEMPLATE_SUFFIXES.some(suffix => entry.name.endsWith(suffix))) {
275
+ } else if (DOC_SUFFIXES.some(suffix => entry.name.endsWith(suffix))) {
359
276
  results.push(full);
360
277
  }
361
278
  }
@@ -364,17 +281,24 @@ function findIntegrationDocFiles(root) {
364
281
  return results;
365
282
  }
366
283
 
284
+ /**
285
+ * The doc-file suffix present on `file`, or null if none matches.
286
+ * @param {string} file
287
+ */
288
+ function matchedDocSuffix(file) {
289
+ return DOC_SUFFIXES.find(suffix => file.endsWith(suffix)) ?? null;
290
+ }
291
+
367
292
  /**
368
293
  * Discover templates contributed by configured integrations.
369
294
  *
370
295
  * For each integration with a resolved `templates` root, every
371
- * `<id>.template.{ts,mjs,js}` (or legacy `<id>.doc.{ts,mjs,js}`) file is a
372
- * template whose id is its path relative to the templates root with the
373
- * matched suffix stripped (kebab-case, may be nested). The doc's `type`
374
- * (page|block) decides scaffolding — there is no `/pages` vs `/blocks`
375
- * requirement. A same-stem sibling source file (`<id>.tsx`) is required; a doc
376
- * missing its source, or missing `type`, is an integration error and that
377
- * template is skipped (recorded in `errors`).
296
+ * `<id>.doc.{ts,mjs,js}` file is a template whose id is its path relative to
297
+ * the templates root with the `.doc.*` suffix stripped (kebab-case, may be
298
+ * nested). The doc's `type` (page|block) decides scaffolding — there is no
299
+ * `/pages` vs `/blocks` requirement. A same-stem sibling source file
300
+ * (`<id>.tsx`) is required; a doc missing its source, or missing `type`, is
301
+ * an integration error and that template is skipped (recorded in `errors`).
378
302
  *
379
303
  * @param {string} [cwd]
380
304
  * @returns {Promise<{templates: object[], errors: {package: string, template?: string, message: string}[]}>}
@@ -420,7 +344,7 @@ export async function discoverIntegrationTemplatesForOne(integration) {
420
344
  if (!root || !fs.existsSync(root)) return {templates, errors};
421
345
 
422
346
  for (const docPath of findIntegrationDocFiles(root)) {
423
- const suffix = matchedTemplateSuffix(docPath);
347
+ const suffix = matchedDocSuffix(docPath);
424
348
  const id = path
425
349
  .relative(root, docPath)
426
350
  .slice(0, -suffix.length)
@@ -7,26 +7,28 @@ import {AvatarGroup, AvatarGroupOverflow} from '@astryxdesign/core/AvatarGroup';
7
7
  import {Stack} from '@astryxdesign/core/Layout';
8
8
  import {Text} from '@astryxdesign/core/Text';
9
9
 
10
+ const CDN = 'https://lookaside.facebook.com/assets/astryx';
11
+
10
12
  const USERS = [
11
13
  {
12
14
  name: 'Ami Pena',
13
- src: 'https://lookaside.facebook.com/assets/astryx/DATA-Ami-Pena.png',
15
+ src: `${CDN}/DATA-Ami-Pena.png`,
14
16
  },
15
17
  {
16
18
  name: 'Drew Young',
17
- src: 'https://lookaside.facebook.com/assets/astryx/DATA-Drew-Young.png',
19
+ src: `${CDN}/DATA-Drew-Young.png`,
18
20
  },
19
21
  {
20
22
  name: 'Gabriela Fernandez',
21
- src: 'https://lookaside.facebook.com/assets/astryx/DATA-Gabriela-Fernandez.png',
23
+ src: `${CDN}/DATA-Gabriela-Fernandez.png`,
22
24
  },
23
25
  {
24
26
  name: 'Jihoo Song',
25
- src: 'https://lookaside.facebook.com/assets/astryx/DATA-Jihoo-Song.png',
27
+ src: `${CDN}/DATA-Jihoo-Song.png`,
26
28
  },
27
29
  {
28
30
  name: 'Nam Tran',
29
- src: 'https://lookaside.facebook.com/assets/astryx/DATA-Nam-Tran.png',
31
+ src: `${CDN}/DATA-Nam-Tran.png`,
30
32
  },
31
33
  ];
32
34
 
@@ -5,27 +5,29 @@
5
5
  import {Avatar, AvatarStatusDot} from '@astryxdesign/core/Avatar';
6
6
  import {Stack} from '@astryxdesign/core/Layout';
7
7
 
8
+ const CDN = 'https://lookaside.facebook.com/assets/astryx';
9
+
8
10
  export default function AvatarShowcase() {
9
11
  return (
10
12
  <Stack direction="horizontal" gap={4} vAlign="center">
11
13
  <Avatar
12
- src="https://lookaside.facebook.com/assets/astryx/DATA-Ana-Thomas.png"
14
+ src={`${CDN}/DATA-Ana-Thomas.png`}
13
15
  name="Ana Thomas"
14
16
  size="large"
15
17
  status={<AvatarStatusDot variant="success" label="Online" />}
16
18
  />
17
19
  <Avatar
18
- src="https://lookaside.facebook.com/assets/astryx/DATA-Drew-Young.png"
20
+ src={`${CDN}/DATA-Drew-Young.png`}
19
21
  name="Drew Young"
20
22
  size="large"
21
23
  />
22
24
  <Avatar
23
- src="https://lookaside.facebook.com/assets/astryx/DATA-Jihoo-Song.png"
25
+ src={`${CDN}/DATA-Jihoo-Song.png`}
24
26
  name="Jihoo Song"
25
27
  size="large"
26
28
  />
27
29
  <Avatar
28
- src="https://lookaside.facebook.com/assets/astryx/DATA-Nam-Tran.png"
30
+ src={`${CDN}/DATA-Nam-Tran.png`}
29
31
  name="Nam Tran"
30
32
  size="large"
31
33
  status={<AvatarStatusDot variant="error" label="Online" />}
@@ -6,22 +6,24 @@ import {Avatar, AvatarStatusDot} from '@astryxdesign/core/Avatar';
6
6
  import {Stack} from '@astryxdesign/core/Layout';
7
7
  import {Text} from '@astryxdesign/core/Text';
8
8
 
9
+ const CDN = 'https://lookaside.facebook.com/assets/astryx';
10
+
9
11
  const USERS = [
10
12
  {
11
13
  name: 'Itai Jordaan',
12
- src: 'https://lookaside.facebook.com/assets/astryx/DATA-Itai-Jordaan.png',
14
+ src: `${CDN}/DATA-Itai-Jordaan.png`,
13
15
  role: 'Engineering Lead',
14
16
  variant: 'success' as const,
15
17
  },
16
18
  {
17
19
  name: 'Margot Schroder',
18
- src: 'https://lookaside.facebook.com/assets/astryx/DATA-Margot-Schroder.png',
20
+ src: `${CDN}/DATA-Margot-Schroder.png`,
19
21
  role: 'Product Designer',
20
22
  variant: 'neutral' as const,
21
23
  },
22
24
  {
23
25
  name: 'Daniela Gimenez',
24
- src: 'https://lookaside.facebook.com/assets/astryx/DATA-Daniela-Gimenez.png',
26
+ src: `${CDN}/DATA-Daniela-Gimenez.png`,
25
27
  role: 'Engineering Manager',
26
28
  variant: 'error' as const,
27
29
  },
@@ -5,26 +5,24 @@
5
5
  import {Avatar} from '@astryxdesign/core/Avatar';
6
6
  import {Stack} from '@astryxdesign/core/Layout';
7
7
 
8
+ const CDN = 'https://lookaside.facebook.com/assets/astryx';
9
+
8
10
  export default function AvatarWithImage() {
9
11
  return (
10
12
  <Stack direction="horizontal" gap={4} vAlign="center">
13
+ <Avatar src={`${CDN}/DATA-Ami-Pena.png`} name="Ami Pena" size="tiny" />
11
14
  <Avatar
12
- src="https://lookaside.facebook.com/assets/astryx/DATA-Ami-Pena.png"
13
- name="Ami Pena"
14
- size="tiny"
15
- />
16
- <Avatar
17
- src="https://lookaside.facebook.com/assets/astryx/DATA-Ana-Thomas.png"
15
+ src={`${CDN}/DATA-Ana-Thomas.png`}
18
16
  name="Ana Thomas"
19
17
  size="small"
20
18
  />
21
19
  <Avatar
22
- src="https://lookaside.facebook.com/assets/astryx/DATA-Daniela-Gimenez.png"
20
+ src={`${CDN}/DATA-Daniela-Gimenez.png`}
23
21
  name="Daniela Gimenez"
24
22
  size="medium"
25
23
  />
26
24
  <Avatar
27
- src="https://lookaside.facebook.com/assets/astryx/DATA-Gabriela-Fernandez.png"
25
+ src={`${CDN}/DATA-Gabriela-Fernandez.png`}
28
26
  name="Gabriela Fernandez"
29
27
  size="large"
30
28
  />
@@ -5,23 +5,25 @@
5
5
  import {Avatar, AvatarStatusDot} from '@astryxdesign/core/Avatar';
6
6
  import {Stack} from '@astryxdesign/core/Layout';
7
7
 
8
+ const CDN = 'https://lookaside.facebook.com/assets/astryx';
9
+
8
10
  export default function AvatarWithStatus() {
9
11
  return (
10
12
  <Stack direction="horizontal" gap={4} vAlign="center">
11
13
  <Avatar
12
- src="https://lookaside.facebook.com/assets/astryx/DATA-Itai-Jordaan.png"
14
+ src={`${CDN}/DATA-Itai-Jordaan.png`}
13
15
  name="Itai Jordaan"
14
16
  size="large"
15
17
  status={<AvatarStatusDot variant="success" label="Online" />}
16
18
  />
17
19
  <Avatar
18
- src="https://lookaside.facebook.com/assets/astryx/DATA-Margot-Schroder.png"
20
+ src={`${CDN}/DATA-Margot-Schroder.png`}
19
21
  name="Margot Schroder"
20
22
  size="large"
21
23
  status={<AvatarStatusDot variant="neutral" label="Offline" />}
22
24
  />
23
25
  <Avatar
24
- src="https://lookaside.facebook.com/assets/astryx/DATA-Pablo-Morales.png"
26
+ src={`${CDN}/DATA-Pablo-Morales.png`}
25
27
  name="Pablo Morales"
26
28
  size="large"
27
29
  status={<AvatarStatusDot variant="error" label="Busy" />}
@@ -10,7 +10,7 @@ import {Text} from '@astryxdesign/core/Text';
10
10
  export default function ChatComposerInputControlledInput() {
11
11
  const [value, setValue] = useState('');
12
12
  return (
13
- <Stack direction="vertical" gap={3} style={{width: 450, maxWidth: '100%'}}>
13
+ <Stack direction="vertical" gap={3} style={{width: '100%', maxWidth: 450}}>
14
14
  <ChatComposer
15
15
  onSubmit={() => setValue('')}
16
16
  value={value}
@@ -7,7 +7,7 @@ import {Stack} from '@astryxdesign/core/Layout';
7
7
 
8
8
  export default function ChatComposerInputDisabled() {
9
9
  return (
10
- <Stack direction="vertical" style={{width: 450, maxWidth: '100%'}}>
10
+ <Stack direction="vertical" style={{width: '100%', maxWidth: 450}}>
11
11
  <ChatComposer
12
12
  onSubmit={() => {}}
13
13
  isDisabled
@@ -43,7 +43,7 @@ export default function ChatComposerInputMentionTrigger() {
43
43
  };
44
44
 
45
45
  return (
46
- <Stack direction="vertical" gap={3} style={{width: 450, maxWidth: '100%'}}>
46
+ <Stack direction="vertical" gap={3} style={{width: '100%', maxWidth: 450}}>
47
47
  <ChatComposer
48
48
  onSubmit={() => setValue('')}
49
49
  input={
@@ -54,7 +54,7 @@ export default function ChatComposerInputMultipleTriggers() {
54
54
  };
55
55
 
56
56
  return (
57
- <Stack direction="vertical" gap={3} style={{width: 450, maxWidth: '100%'}}>
57
+ <Stack direction="vertical" gap={3} style={{width: '100%', maxWidth: 450}}>
58
58
  <Text type="supporting" color="secondary">
59
59
  Type @ for mentions (blue) or / for commands (yellow)
60
60
  </Text>
@@ -7,7 +7,7 @@ import {Stack} from '@astryxdesign/core/Layout';
7
7
 
8
8
  export default function ChatComposerInputShowcase() {
9
9
  return (
10
- <Stack direction="vertical" style={{width: 450, maxWidth: '100%'}}>
10
+ <Stack direction="vertical" style={{width: '100%', maxWidth: 450}}>
11
11
  <ChatComposer
12
12
  onSubmit={() => {}}
13
13
  input={
@@ -40,7 +40,7 @@ export default function ChatComposerInputSlashCommands() {
40
40
  };
41
41
 
42
42
  return (
43
- <Stack direction="vertical" style={{width: 450, maxWidth: '100%'}}>
43
+ <Stack direction="vertical" style={{width: '100%', maxWidth: 450}}>
44
44
  <ChatComposer
45
45
  onSubmit={() => {}}
46
46
  input={
@@ -282,14 +282,14 @@ const DEFAULT_PRODUCTS: ProductSpec[] = [
282
282
 
283
283
  // Neutral product photos, served from the shared astryx asset CDN so the
284
284
  // scaffolded template renders real imagery without needing local public assets.
285
+ const NEUTRAL_CDN = 'https://lookaside.facebook.com/assets/astryx';
285
286
  const DEFAULT_IMAGES: Record<string, string> = {
286
- watch: 'https://lookaside.facebook.com/assets/astryx/Neutral-Watch.png',
287
- headphones:
288
- 'https://lookaside.facebook.com/assets/astryx/Neutral-Headphones.png',
289
- backpack: 'https://lookaside.facebook.com/assets/astryx/Neutral-Backpack.png',
290
- wallet: 'https://lookaside.facebook.com/assets/astryx/Neutral-Wallet.png',
291
- tumbler: 'https://lookaside.facebook.com/assets/astryx/Neutral-Tumbler.png',
292
- throw_: 'https://lookaside.facebook.com/assets/astryx/Neutral-Blanket.png',
287
+ watch: `${NEUTRAL_CDN}/Neutral-Watch.png`,
288
+ headphones: `${NEUTRAL_CDN}/Neutral-Headphones.png`,
289
+ backpack: `${NEUTRAL_CDN}/Neutral-Backpack.png`,
290
+ wallet: `${NEUTRAL_CDN}/Neutral-Wallet.png`,
291
+ tumbler: `${NEUTRAL_CDN}/Neutral-Tumbler.png`,
292
+ throw_: `${NEUTRAL_CDN}/Neutral-Blanket.png`,
293
293
  };
294
294
 
295
295
  export interface ThemeShowcaseProps {
@@ -1,105 +0,0 @@
1
- # Authoring an Astryx Integration
2
-
3
- > **Status:** working notes. This should eventually move to the public wiki
4
- > alongside the rest of the integration-authoring guidance; it lives here for
5
- > now so it ships and is versioned with the CLI.
6
-
7
- An **Integration** is an npm package that contributes components, templates, and/or
8
- codemods to a consumer's design-system workflow. Consumers install the 3rd party
9
- package, add a line to their astryx.config file:
10
-
11
- ```js
12
- import {createConfig} from '@astryxdesign/cli/config';
13
-
14
- export default createConfig({
15
- integrations: ['@acme/astryx-widgets'],
16
- ...
17
- });
18
- ```
19
-
20
- Then the integration's components and templates will be surfaced alongside Astryx
21
- components in the Astryx CLI.
22
-
23
- ```sh
24
- astryx component AcmeCarousel --props
25
- astryx component --list --package @acme/astryx-widgets
26
- ```
27
-
28
- ## The Integration File
29
-
30
- In order to register your package as an Astryx Integration, create an
31
- `astryx.integration.{ts,mjs,js}` file as a sibling to your `package.json`. This file
32
- tells Astryx where to find your components, templates, codemods, etc.
33
-
34
- ```js
35
- // astryx.integration.{ts,mjs,js}
36
- import {createIntegration} from '@astryxdesign/cli/integration';
37
-
38
- export default createIntegration({
39
- components: './components',
40
- templates: './templates',
41
- codemods: './codemods',
42
- issuesUrl: 'https://github.com/acme/widgets/issues',
43
- });
44
- ```
45
-
46
- ## Components
47
-
48
- Your components themselves may be exported from your library as you see fit (consumers
49
- will still import them from your package) but Astryx CLI will look for a .doc.{ts,mjs,js}
50
- file with the same stem e.g. `AcmeCarousel.tsx` and `AcmeCarousel.doc.ts`.
51
-
52
- ```js
53
- // AcmeCarousel.doc.ts
54
- import {createComponentDoc} from '@astryxdesign/cli/doc';
55
-
56
- export default createComponentDoc({
57
- name: 'AcmeCarousel',
58
- description: '...',
59
- ...
60
- });
61
- ```
62
-
63
- ## Templates
64
-
65
- Templates are typically not exported from the package directly, but instead accessed
66
- via the Astryx CLI. Consumers can look through your templates and materialize them
67
- into their apps.
68
-
69
- You define a template with the `createPageTemplate` (for full pages) or `createBlockTemplate`
70
- (for smaller chunks). e.g. `AcmeLandingPage.tsx`, `AcmeLandingPage.template.ts`
71
-
72
- ```js
73
- // AcmeLandingPage.template.ts
74
- import {createPageTemplate} from '@astryxdesign/cli/template';
75
-
76
- export default createPageTemplate({
77
- ...
78
- });
79
- ```
80
-
81
- Note that, since the CLI needs access to the template source code, you need to make sure
82
- that it is included in your published package. This will also allow us to render previews
83
- of templates in the future by bundling your template into a doc site build.
84
-
85
- Typically, this is done via the package.json `exports` key.
86
-
87
- ```jsonc
88
- {
89
- "exports": {
90
- // ...
91
- "./templates/*.tsx": "./templates/*.tsx",
92
- },
93
- }
94
- ```
95
-
96
- In order to verify that it's working, you can test importing the template component like this:
97
-
98
- ```ts
99
- import('@acme/astryx-widgets/templates/AcmeLandingPage.tsx');
100
- ```
101
-
102
- Import **with the `.tsx` extension** — an extensionless specifier won't resolve
103
- under `moduleResolution: bundler`. The extensionful `"./templates/*.tsx"` export
104
- above is what lets that import type-check without consumers enabling
105
- `allowImportingTsExtensions`.
@@ -1,240 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Proves the minimal `exports` recipe an integration package needs so a
5
- * bundler-resolution consumer can `import()` its block templates AND type-check
6
- * them under `moduleResolution: bundler`.
7
- *
8
- * Integration packages in this ecosystem ship TypeScript SOURCE — their block
9
- * templates are `.tsx` files with no compiled `.d.ts`. A later feature renders
10
- * showcase previews by a REAL dynamic `import()` of a block's `.tsx` source
11
- * (e.g. `import('@acme/widgets/templates/Gauge/GaugeShowcase.tsx')`) instead of
12
- * eval'ing source text. For that import to resolve, the integration's
13
- * `package.json#exports` map must GATE the deep path.
14
- *
15
- * These tests stand up a throwaway `@acme/widgets` fixture and drive the two
16
- * gates that matter with the repo's own toolchain:
17
- * 1. `tsc --noEmit` under `moduleResolution: bundler` (the consumer profile
18
- * used by the Next.js example apps — NO `allowImportingTsExtensions`).
19
- * 2. `esbuild --bundle` (a real bundler resolving + loading the deep import).
20
- *
21
- * CANONICAL RECIPE (see integration-authoring.md):
22
- * exports: { "./templates/*.tsx": "./templates/*.tsx" }
23
- * import: import('@acme/widgets/templates/<Name>/<Name>Showcase.tsx') // WITH .tsx
24
- *
25
- * The negative controls lock in WHY the extension is required: a bare
26
- * `./templates/*` export with an extensionless import fails to type-check under
27
- * bundler resolution (TS cannot infer the `.tsx` extension for a deep
28
- * specifier), and an extensionless import fails to bundle.
29
- */
30
-
31
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
32
- import * as fs from 'node:fs';
33
- import * as os from 'node:os';
34
- import * as path from 'node:path';
35
- import {createRequire} from 'node:module';
36
- import {execFileSync} from 'node:child_process';
37
-
38
- const require = createRequire(import.meta.url);
39
-
40
- /** Resolve the workspace tsc/esbuild binaries; null if unavailable. */
41
- function resolveBin(spec) {
42
- try {
43
- return require.resolve(spec);
44
- } catch {
45
- return null;
46
- }
47
- }
48
- const TSC_BIN = resolveBin('typescript/bin/tsc');
49
- const ESBUILD_BIN = resolveBin('esbuild/bin/esbuild');
50
-
51
- let tmpDir;
52
-
53
- /**
54
- * Build an @acme/widgets fixture: a block template (`.template.ts` doc +
55
- * same-stem `.tsx` source) under `templates/`, plus an astryx.integration
56
- * manifest, plus a caller-supplied `exports` map.
57
- * @param {Record<string, string> | undefined} exportsMap
58
- */
59
- function makeWidgets(exportsMap) {
60
- const pkgDir = path.join(tmpDir, 'node_modules', '@acme', 'widgets');
61
- const blockDir = path.join(pkgDir, 'templates', 'Gauge');
62
- fs.mkdirSync(blockDir, {recursive: true});
63
-
64
- const pkg = {name: '@acme/widgets', version: '2.0.0', type: 'module'};
65
- if (exportsMap) pkg.exports = exportsMap;
66
- fs.writeFileSync(
67
- path.join(pkgDir, 'package.json'),
68
- JSON.stringify(pkg, null, 2),
69
- );
70
- fs.writeFileSync(
71
- path.join(pkgDir, 'astryx.integration.mjs'),
72
- `export default { templates: './templates' };\n`,
73
- );
74
- // The template-spec doc (canonical `.template.*` family).
75
- fs.writeFileSync(
76
- path.join(blockDir, 'GaugeShowcase.template.ts'),
77
- `export default { name: 'Gauge showcase', description: 'A gauge.' };\n`,
78
- );
79
- // The same-stem `.tsx` SOURCE that a preview will dynamically import().
80
- // Returns a plain value so the fixture type-checks without React types.
81
- fs.writeFileSync(
82
- path.join(blockDir, 'GaugeShowcase.tsx'),
83
- `const GaugeShowcase = (): string => 'gauge-showcase';\n` +
84
- `export default GaugeShowcase;\n`,
85
- );
86
- return pkgDir;
87
- }
88
-
89
- /** Write a consumer that dynamically imports the given specifier. */
90
- function writeConsumer(specifier) {
91
- fs.writeFileSync(
92
- path.join(tmpDir, 'consumer.ts'),
93
- `const load = () => import('${specifier}');\nexport default load;\n`,
94
- );
95
- }
96
-
97
- /**
98
- * The realistic consumer tsconfig: matches the repo's Next.js example apps
99
- * (`moduleResolution: bundler`, `noEmit`, and deliberately NO
100
- * `allowImportingTsExtensions`).
101
- */
102
- function writeTsconfig() {
103
- fs.writeFileSync(
104
- path.join(tmpDir, 'tsconfig.json'),
105
- JSON.stringify(
106
- {
107
- compilerOptions: {
108
- target: 'ES2022',
109
- lib: ['ES2022', 'DOM', 'DOM.Iterable'],
110
- module: 'ESNext',
111
- moduleResolution: 'bundler',
112
- jsx: 'react-jsx',
113
- strict: true,
114
- skipLibCheck: true,
115
- esModuleInterop: true,
116
- noEmit: true,
117
- isolatedModules: true,
118
- },
119
- include: ['consumer.ts'],
120
- },
121
- null,
122
- 2,
123
- ),
124
- );
125
- }
126
-
127
- /** @returns {{ok: boolean, out: string}} */
128
- function runTsc() {
129
- try {
130
- execFileSync(process.execPath, [TSC_BIN, '--noEmit', '-p', 'tsconfig.json'], {
131
- cwd: tmpDir,
132
- stdio: 'pipe',
133
- });
134
- return {ok: true, out: ''};
135
- } catch (e) {
136
- return {ok: false, out: `${e.stdout ?? ''}${e.stderr ?? ''}`};
137
- }
138
- }
139
-
140
- /** @returns {{ok: boolean, out: string}} */
141
- function runEsbuild() {
142
- try {
143
- // esbuild's bin is a native executable (not a node script), so invoke it
144
- // directly rather than through process.execPath.
145
- execFileSync(
146
- ESBUILD_BIN,
147
- [
148
- 'consumer.ts',
149
- '--bundle',
150
- '--format=esm',
151
- '--loader:.tsx=tsx',
152
- '--outfile=/dev/null',
153
- '--log-level=error',
154
- ],
155
- {cwd: tmpDir, stdio: 'pipe'},
156
- );
157
- return {ok: true, out: ''};
158
- } catch (e) {
159
- return {ok: false, out: `${e.stdout ?? ''}${e.stderr ?? ''}`};
160
- }
161
- }
162
-
163
- beforeEach(() => {
164
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-block-exports-'));
165
- fs.writeFileSync(
166
- path.join(tmpDir, 'package.json'),
167
- JSON.stringify({name: 'consumer', private: true, type: 'module'}),
168
- );
169
- writeTsconfig();
170
- });
171
-
172
- afterEach(() => {
173
- fs.rmSync(tmpDir, {recursive: true, force: true});
174
- });
175
-
176
- const CANONICAL = 'import(@acme/widgets/templates/Gauge/GaugeShowcase.tsx)';
177
- const SPEC = '@acme/widgets/templates/Gauge/GaugeShowcase.tsx';
178
-
179
- describe('integration block-template exports recipe', () => {
180
- it.runIf(TSC_BIN != null)(
181
- `CANONICAL: exports {"./templates/*.tsx"} + ${CANONICAL} type-checks under bundler resolution`,
182
- () => {
183
- makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
184
- writeConsumer(SPEC);
185
- const {ok, out} = runTsc();
186
- expect(out).toBe('');
187
- expect(ok).toBe(true);
188
- },
189
- 30_000,
190
- );
191
-
192
- it.runIf(ESBUILD_BIN != null)(
193
- `CANONICAL: the same import resolves + bundles with a real bundler`,
194
- () => {
195
- makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
196
- writeConsumer(SPEC);
197
- const {ok, out} = runEsbuild();
198
- expect(out).toBe('');
199
- expect(ok).toBe(true);
200
- },
201
- 30_000,
202
- );
203
-
204
- it.runIf(TSC_BIN != null)(
205
- 'NEGATIVE: an extensionless import does NOT type-check (TS cannot infer .tsx)',
206
- () => {
207
- makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
208
- writeConsumer('@acme/widgets/templates/Gauge/GaugeShowcase');
209
- const {ok, out} = runTsc();
210
- expect(ok).toBe(false);
211
- expect(out).toContain('TS2307');
212
- },
213
- 30_000,
214
- );
215
-
216
- it.runIf(TSC_BIN != null)(
217
- 'NEGATIVE: a bare "./templates/*" export (no .tsx entry) does NOT type-check the .tsx import',
218
- () => {
219
- // Only a bare mapping — the extensionful subpath is not exported.
220
- makeWidgets({'./templates/*': './templates/*'});
221
- writeConsumer(SPEC);
222
- const {ok, out} = runTsc();
223
- expect(ok).toBe(false);
224
- // Bare export forces the TS5097 opt-in requirement (allowImportingTsExtensions).
225
- expect(out).toContain('TS5097');
226
- },
227
- 30_000,
228
- );
229
-
230
- it.runIf(ESBUILD_BIN != null)(
231
- 'NEGATIVE: an extensionless import does NOT bundle against the .tsx-only export',
232
- () => {
233
- makeWidgets({'./templates/*.tsx': './templates/*.tsx'});
234
- writeConsumer('@acme/widgets/templates/Gauge/GaugeShowcase');
235
- const {ok} = runEsbuild();
236
- expect(ok).toBe(false);
237
- },
238
- 30_000,
239
- );
240
- });
@@ -1,246 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file The canonical `.template.{ts,mjs,js}` suffix is discovered identically
5
- * to the legacy `.doc.{ts,mjs,js}` suffix.
6
- *
7
- * Template-spec files are named for what they are: a scaffoldable TEMPLATE that
8
- * exports `createBlockTemplate`/`createPageTemplate`. The `.doc.*` suffix was
9
- * inherited from the component-doc convention and is still accepted during the
10
- * transition. These tests stand up integration templates and external blocks in
11
- * both families and assert byte-for-byte-equivalent discovery + scaffolding.
12
- */
13
-
14
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
15
- import * as fs from 'node:fs';
16
- import * as path from 'node:path';
17
- import * as os from 'node:os';
18
- import {
19
- template,
20
- findShowcase,
21
- findRelatedBlocks,
22
- } from './template.mjs';
23
-
24
- /** Absolute path to the CLI package so fixtures can import /src/template.mjs. */
25
- const CLI_PKG = path.resolve(import.meta.dirname, '..', '..');
26
-
27
- let tmpDir;
28
- let originalCwd;
29
-
30
- function makeConsumer() {
31
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-template-suffix-'));
32
- fs.writeFileSync(
33
- path.join(dir, 'package.json'),
34
- JSON.stringify({name: 'consumer'}),
35
- );
36
- fs.writeFileSync(
37
- path.join(dir, 'astryx.config.mjs'),
38
- `export default { integrations: ['@acme/widgets'] };\n`,
39
- );
40
- return dir;
41
- }
42
-
43
- function installWidgets(consumerDir) {
44
- const pkgDir = path.join(consumerDir, 'node_modules', '@acme', 'widgets');
45
- fs.mkdirSync(path.join(pkgDir, 'templates'), {recursive: true});
46
- fs.writeFileSync(
47
- path.join(pkgDir, 'package.json'),
48
- JSON.stringify({name: '@acme/widgets', version: '2.0.0'}),
49
- );
50
- fs.writeFileSync(
51
- path.join(pkgDir, 'astryx.integration.mjs'),
52
- `export default { templates: './templates' };\n`,
53
- );
54
- return pkgDir;
55
- }
56
-
57
- /**
58
- * Write a template-spec file (default-export createPageTemplate/BlockTemplate)
59
- * plus its same-stem `.tsx` source under the templates root.
60
- * @param {string} pkgDir
61
- * @param {string} id
62
- * @param {{kind: 'page'|'block', suffix: string}} opts
63
- */
64
- function writeTemplate(pkgDir, id, {kind, suffix}) {
65
- const docPath = path.join(pkgDir, 'templates', `${id}${suffix}`);
66
- fs.mkdirSync(path.dirname(docPath), {recursive: true});
67
- const create =
68
- kind === 'page' ? 'createPageTemplate' : 'createBlockTemplate';
69
- fs.writeFileSync(
70
- docPath,
71
- `import {${create}} from '${CLI_PKG}/src/template.mjs';\n` +
72
- `export default ${create}({name: '${id} name', description: '${id} desc'});\n`,
73
- );
74
- fs.writeFileSync(
75
- path.join(pkgDir, 'templates', `${id}.tsx`),
76
- `export default function ${id.replace(/[^a-zA-Z0-9]/g, '')}() { return null; }\n`,
77
- );
78
- }
79
-
80
- beforeEach(() => {
81
- originalCwd = process.cwd();
82
- tmpDir = makeConsumer();
83
- process.chdir(tmpDir);
84
- });
85
-
86
- afterEach(() => {
87
- process.chdir(originalCwd);
88
- fs.rmSync(tmpDir, {recursive: true, force: true});
89
- });
90
-
91
- describe('integration templates: .template.* discovered like legacy .doc.*', () => {
92
- for (const suffix of ['.template.ts', '.template.mjs', '.doc.mjs']) {
93
- it(`discovers + lists a page template authored as ${suffix}`, async () => {
94
- const pkgDir = installWidgets(tmpDir);
95
- writeTemplate(pkgDir, 'pricing', {kind: 'page', suffix});
96
-
97
- const result = await template(undefined, {list: true, cwd: tmpDir});
98
- const entry = result.data.find(t => t.id === 'pricing');
99
- expect(entry).toBeTruthy();
100
- expect(entry.type).toBe('page');
101
- expect(entry.package).toBe('@acme/widgets');
102
- expect(entry.name).toBe('pricing name');
103
- expect(entry.description).toBe('pricing desc');
104
- });
105
-
106
- it(`scaffolds a page template authored as ${suffix}`, async () => {
107
- const pkgDir = installWidgets(tmpDir);
108
- writeTemplate(pkgDir, 'pricing', {kind: 'page', suffix});
109
-
110
- const result = await template('pricing', {
111
- targetPath: './dest',
112
- cwd: tmpDir,
113
- });
114
- expect(result.type).toBe('template.copy');
115
- expect(result.data.fileName).toBe('page.tsx');
116
- expect(fs.existsSync(path.join(tmpDir, 'dest', 'page.tsx'))).toBe(true);
117
- });
118
-
119
- it(`scaffolds a nested block template authored as ${suffix}`, async () => {
120
- const pkgDir = installWidgets(tmpDir);
121
- writeTemplate(pkgDir, 'marketing/hero', {kind: 'block', suffix});
122
-
123
- const result = await template('marketing/hero', {
124
- targetPath: './dest',
125
- cwd: tmpDir,
126
- });
127
- expect(result.type).toBe('template.copy');
128
- expect(result.data.fileName).toBe('hero.tsx');
129
- expect(fs.existsSync(path.join(tmpDir, 'dest', 'hero.tsx'))).toBe(true);
130
- });
131
- }
132
-
133
- it('treats a .template.ts and a legacy .doc.mjs identically (same shape)', async () => {
134
- const pkgDir = installWidgets(tmpDir);
135
- writeTemplate(pkgDir, 'gauge', {kind: 'block', suffix: '.template.ts'});
136
- writeTemplate(pkgDir, 'chip', {kind: 'block', suffix: '.doc.mjs'});
137
-
138
- const result = await template(undefined, {list: true, cwd: tmpDir});
139
- const gauge = result.data.find(t => t.id === 'gauge');
140
- const chip = result.data.find(t => t.id === 'chip');
141
-
142
- // Both discovered, both blocks, both from the same package, both ready.
143
- for (const entry of [gauge, chip]) {
144
- expect(entry).toBeTruthy();
145
- expect(entry.type).toBe('block');
146
- expect(entry.package).toBe('@acme/widgets');
147
- }
148
- // Field-by-field parity apart from the (intentionally different) id/name.
149
- expect(gauge.type).toBe(chip.type);
150
- expect(gauge.package).toBe(chip.package);
151
- });
152
- });
153
-
154
- describe('external showcase blocks: .template.* discovered like legacy .doc.*', () => {
155
- /**
156
- * Create a consumer whose @test/ext package contributes two showcase blocks,
157
- * one authored as `Foo.template.ts` and one as legacy `Bar.doc.mjs`.
158
- */
159
- function makeShowcaseFixture() {
160
- // Symlink the real core package (needed by findCoreDir during discovery).
161
- const realCoreDir = path.resolve(
162
- import.meta.dirname,
163
- '..',
164
- '..',
165
- '..',
166
- 'core',
167
- );
168
- const coreDir = path.join(tmpDir, 'packages', 'core');
169
- fs.mkdirSync(path.dirname(coreDir), {recursive: true});
170
- fs.symlinkSync(realCoreDir, coreDir);
171
-
172
- const extDir = path.join(tmpDir, 'node_modules', '@test', 'ext');
173
- const blocksDir = path.join(extDir, 'blocks', 'components');
174
-
175
- // Foo showcase — canonical .template.ts (default-export createBlockTemplate).
176
- const fooDir = path.join(blocksDir, 'Foo');
177
- fs.mkdirSync(fooDir, {recursive: true});
178
- fs.writeFileSync(
179
- path.join(fooDir, 'FooShowcase.template.ts'),
180
- `import {createBlockTemplate} from '${CLI_PKG}/src/template.mjs';\n` +
181
- `export default createBlockTemplate({\n` +
182
- ` name: 'Foo — Showcase',\n` +
183
- ` description: 'Foo showcase.',\n` +
184
- ` isShowcase: true,\n` +
185
- ` aspectRatio: 16 / 9,\n` +
186
- ` componentsUsed: ['Foo'],\n` +
187
- `});\n`,
188
- );
189
- fs.writeFileSync(
190
- path.join(fooDir, 'FooShowcase.tsx'),
191
- "'use client';\nexport default function FooShowcase() { return <div>Foo</div>; }",
192
- );
193
-
194
- // Bar showcase — legacy .doc.mjs (export const doc).
195
- const barDir = path.join(blocksDir, 'Bar');
196
- fs.mkdirSync(barDir, {recursive: true});
197
- fs.writeFileSync(
198
- path.join(barDir, 'BarShowcase.doc.mjs'),
199
- `export const doc = {\n` +
200
- ` type: 'block',\n` +
201
- ` name: 'Bar — Showcase',\n` +
202
- ` description: 'Bar showcase.',\n` +
203
- ` isReady: true,\n` +
204
- ` isShowcase: true,\n` +
205
- ` aspectRatio: 4 / 3,\n` +
206
- ` componentsUsed: ['Bar', 'Chip'],\n` +
207
- `};\n`,
208
- );
209
- fs.writeFileSync(
210
- path.join(barDir, 'BarShowcase.tsx'),
211
- "'use client';\nexport default function BarShowcase() { return <div>Bar</div>; }",
212
- );
213
-
214
- fs.writeFileSync(
215
- path.join(extDir, 'package.json'),
216
- JSON.stringify({
217
- name: '@test/ext',
218
- astryx: {docs: './src', category: 'Common', blocks: './blocks/components'},
219
- }),
220
- );
221
- fs.mkdirSync(path.join(extDir, 'src'), {recursive: true});
222
- }
223
-
224
- it('findShowcase resolves a .template.ts external block by directory name', async () => {
225
- makeShowcaseFixture();
226
- const result = await findShowcase('Foo', tmpDir);
227
- expect(result).not.toBeNull();
228
- expect(result.name).toBe('Foo — Showcase');
229
- expect(result.filePath).toContain('FooShowcase.tsx');
230
- });
231
-
232
- it('findShowcase resolves a legacy .doc.mjs external block by componentsUsed', async () => {
233
- makeShowcaseFixture();
234
- const result = await findShowcase('Bar', tmpDir);
235
- expect(result).not.toBeNull();
236
- expect(result.name).toBe('Bar — Showcase');
237
- });
238
-
239
- it('findRelatedBlocks finds both suffix families', async () => {
240
- makeShowcaseFixture();
241
- const foo = await findRelatedBlocks('Foo', tmpDir);
242
- expect(foo.map(b => b.dirName)).toContain('FooShowcase');
243
- const chip = await findRelatedBlocks('Chip', tmpDir);
244
- expect(chip.map(b => b.dirName)).toContain('BarShowcase');
245
- });
246
- });