@astryxdesign/cli 0.1.6-canary.acd4fe3 → 0.1.6-canary.aeb5ee6

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.acd4fe3",
3
+ "version": "0.1.6-canary.aeb5ee6",
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.acd4fe3",
79
- "@astryxdesign/core": "0.1.6-canary.acd4fe3",
80
- "@astryxdesign/lab": "0.1.6-canary.acd4fe3",
81
- "@astryxdesign/theme-neutral": "0.1.6-canary.acd4fe3",
78
+ "@astryxdesign/charts": "0.1.6-canary.aeb5ee6",
79
+ "@astryxdesign/core": "0.1.6-canary.aeb5ee6",
80
+ "@astryxdesign/lab": "0.1.6-canary.aeb5ee6",
81
+ "@astryxdesign/theme-neutral": "0.1.6-canary.aeb5ee6",
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.acd4fe3",
100
- "@astryxdesign/core": "0.1.6-canary.acd4fe3",
101
- "@astryxdesign/lab": "0.1.6-canary.acd4fe3",
102
- "@astryxdesign/theme-neutral": "0.1.6-canary.acd4fe3",
99
+ "@astryxdesign/charts": "0.1.6-canary.aeb5ee6",
100
+ "@astryxdesign/core": "0.1.6-canary.aeb5ee6",
101
+ "@astryxdesign/lab": "0.1.6-canary.aeb5ee6",
102
+ "@astryxdesign/theme-neutral": "0.1.6-canary.aeb5ee6",
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)
@@ -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={
@@ -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
- });