@astryxdesign/cli 0.1.5 → 0.1.6-canary.02f2602

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 (53) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/docs/integration-authoring.md +105 -0
  3. package/docs/internationalization.doc.mjs +243 -0
  4. package/package.json +13 -9
  5. package/src/api/integration-block-exports.test.mjs +240 -0
  6. package/src/api/template-suffix.test.mjs +246 -0
  7. package/src/api/template.mjs +104 -28
  8. package/src/api/validate-integration.mjs +0 -8
  9. package/src/config.mjs +5 -14
  10. package/src/doc.mjs +27 -0
  11. package/src/doc.test.mjs +383 -0
  12. package/src/integration.mjs +4 -15
  13. package/src/lib/component-discovery.importpath.test.mjs +59 -0
  14. package/src/lib/component-discovery.mjs +15 -5
  15. package/src/lib/component-format.mjs +45 -13
  16. package/src/lib/component-format.test.mjs +95 -1
  17. package/src/lib/component-loader.mjs +104 -2
  18. package/src/lib/componentDocOverlay.test.mjs +111 -0
  19. package/src/lib/config-schema.mjs +0 -30
  20. package/src/lib/hook-format.mjs +8 -3
  21. package/src/lib/xle/registry.mjs +0 -5
  22. package/src/schemas/doc-schema.mjs +226 -0
  23. package/src/schemas/template-schema.mjs +47 -0
  24. package/src/template.mjs +9 -67
  25. package/src/types/config.d.ts +11 -66
  26. package/src/types/doc.d.ts +23 -0
  27. package/src/types/integration.d.ts +7 -18
  28. package/src/types/template-api.d.ts +14 -50
  29. package/templates/blocks/components/Avatar/AvatarGroup.tsx +5 -7
  30. package/templates/blocks/components/Avatar/AvatarShowcase.tsx +4 -6
  31. package/templates/blocks/components/Avatar/AvatarUserCard.tsx +3 -5
  32. package/templates/blocks/components/Avatar/AvatarWithImage.tsx +8 -6
  33. package/templates/blocks/components/Avatar/AvatarWithStatus.tsx +3 -5
  34. package/templates/blocks/components/ChatComposerInput/ChatComposerInputControlledInput.tsx +1 -1
  35. package/templates/blocks/components/ChatComposerInput/ChatComposerInputDisabled.tsx +1 -1
  36. package/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +1 -1
  37. package/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +1 -1
  38. package/templates/blocks/components/ChatComposerInput/ChatComposerInputShowcase.tsx +1 -1
  39. package/templates/blocks/components/ChatComposerInput/ChatComposerInputSlashCommands.tsx +1 -1
  40. package/templates/blocks/components/Table/TableGroupedRowsTable.doc.mjs +14 -0
  41. package/templates/blocks/components/Table/TableGroupedRowsTable.tsx +66 -0
  42. package/templates/blocks/components/Table/TableRowIndexTable.doc.mjs +14 -0
  43. package/templates/blocks/components/Table/TableRowIndexTable.tsx +47 -0
  44. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.doc.mjs +14 -0
  45. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.tsx +41 -0
  46. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +13 -0
  47. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +78 -0
  48. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.doc.mjs +14 -0
  49. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.tsx +38 -0
  50. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +14 -0
  51. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +47 -0
  52. package/templates/pages/theme-showcase/page.tsx +7 -7
  53. package/templates/themes/neutral/neutralTheme.ts +63 -32
@@ -0,0 +1,246 @@
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
+ });
@@ -6,8 +6,9 @@
6
6
 
7
7
  import * as fs from 'node:fs';
8
8
  import * as path from 'node:path';
9
+ import {createJiti} from 'jiti';
9
10
  import {loadModuleWithSchema} from '../lib/module-loader.mjs';
10
- import {TemplateEnvelopeSchema} from '../template.mjs';
11
+ import {TemplateEnvelopeSchema} from '../schemas/template-schema.mjs';
11
12
  import {CLI_ROOT, discoverExternalPackages} from '../utils/paths.mjs';
12
13
  import {
13
14
  assertWithin,
@@ -21,9 +22,54 @@ import {Project} from '../lib/project.mjs';
21
22
  /** Identity used for core (built-in) templates in package-scoped listings. */
22
23
  const CORE_PACKAGE = '@astryxdesign/core';
23
24
 
24
- /** Doc-file basename suffixes for integration templates, in precedence order. */
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
+ */
25
37
  const DOC_SUFFIXES = ['.doc.ts', '.doc.mjs', '.doc.js'];
26
38
 
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
+
27
73
  /**
28
74
  * Load an integration template doc module and validate it against the template
29
75
  * envelope at the load boundary. Default export only — `.ts` via jiti,
@@ -87,12 +133,29 @@ export function stripTemplateAssetRefs(source) {
87
133
  source,
88
134
  );
89
135
  }
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
+ */
90
150
  async function loadDocModule(docPath) {
91
151
  if (!fs.existsSync(docPath)) return null;
92
- const docModule = await import(`file://${docPath}`);
93
- return docModule.doc;
152
+ const docModule = docPath.endsWith('.ts')
153
+ ? await getJiti().import(docPath)
154
+ : await import(`file://${docPath}`);
155
+ return docModule.default ?? docModule.doc;
94
156
  }
95
157
 
158
+
96
159
  export {discoverAll as discoverTemplates};
97
160
 
98
161
  export function listTemplates() {
@@ -122,6 +185,20 @@ function findDocFiles(dir, pattern) {
122
185
  return results;
123
186
  }
124
187
 
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
+
125
202
  async function discoverPages() {
126
203
  if (!fs.existsSync(PAGES_DIR)) return [];
127
204
  const dirs = fs
@@ -131,7 +208,9 @@ async function discoverPages() {
131
208
  const templates = [];
132
209
  for (const dir of dirs) {
133
210
  const dirPath = path.join(PAGES_DIR, dir.name);
134
- const doc = await loadDocModule(path.join(dirPath, 'template.doc.mjs'));
211
+ const docPath =
212
+ findPageDocFile(dirPath) ?? path.join(dirPath, 'template.doc.mjs');
213
+ const doc = await loadDocModule(docPath);
135
214
  templates.push({
136
215
  type: 'page',
137
216
  dirName: dir.name,
@@ -141,17 +220,18 @@ async function discoverPages() {
141
220
  isReady: doc?.isReady ?? true,
142
221
  scaffold: doc?.scaffold ?? false,
143
222
  filePath: path.join(dirPath, 'page.tsx'),
144
- docPath: path.join(dirPath, 'template.doc.mjs'),
223
+ docPath,
145
224
  });
146
225
  }
147
226
  return templates;
148
227
  }
149
228
 
150
229
  async function discoverBlocks() {
151
- const docFiles = findDocFiles(BLOCKS_DIR, /\.doc\.mjs$/);
230
+ const docFiles = findDocFiles(BLOCKS_DIR, TEMPLATE_SUFFIX_RE);
152
231
  const blocks = [];
153
232
  for (const docPath of docFiles) {
154
- const basename = path.basename(docPath, '.doc.mjs');
233
+ const suffix = matchedTemplateSuffix(docPath);
234
+ const basename = path.basename(docPath, suffix);
155
235
  const tsxPath = path.join(path.dirname(docPath), basename + '.tsx');
156
236
  if (!fs.existsSync(tsxPath)) continue;
157
237
  const doc = await loadDocModule(docPath);
@@ -173,6 +253,7 @@ async function discoverBlocks() {
173
253
  return blocks;
174
254
  }
175
255
 
256
+
176
257
  /**
177
258
  * Discover blocks from external packages that declare `astryx.blocks` in
178
259
  * their package.json. Same shape as discoverBlocks() output.
@@ -185,9 +266,10 @@ async function discoverExternalBlocks(cwd = process.cwd()) {
185
266
 
186
267
  for (const ext of externals) {
187
268
  if (!ext.blocksDir || !fs.existsSync(ext.blocksDir)) continue;
188
- const docFiles = findDocFiles(ext.blocksDir, /\.doc\.mjs$/);
269
+ const docFiles = findDocFiles(ext.blocksDir, TEMPLATE_SUFFIX_RE);
189
270
  for (const docPath of docFiles) {
190
- const basename = path.basename(docPath, '.doc.mjs');
271
+ const suffix = matchedTemplateSuffix(docPath);
272
+ const basename = path.basename(docPath, suffix);
191
273
  const tsxPath = path.join(path.dirname(docPath), basename + '.tsx');
192
274
  if (!fs.existsSync(tsxPath)) continue;
193
275
  const doc = await loadDocModule(docPath);
@@ -258,8 +340,9 @@ async function discoverAllWithErrors(cwd = process.cwd()) {
258
340
  export {discoverAllWithErrors};
259
341
 
260
342
  /**
261
- * Recursively collect integration template doc files under `root`.
262
- * Returns absolute paths to files ending in one of DOC_SUFFIXES.
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.*`).
263
346
  *
264
347
  * @param {string} root
265
348
  * @returns {string[]}
@@ -272,7 +355,7 @@ function findIntegrationDocFiles(root) {
272
355
  const full = path.join(dir, entry.name);
273
356
  if (entry.isDirectory()) {
274
357
  walk(full);
275
- } else if (DOC_SUFFIXES.some(suffix => entry.name.endsWith(suffix))) {
358
+ } else if (ALL_TEMPLATE_SUFFIXES.some(suffix => entry.name.endsWith(suffix))) {
276
359
  results.push(full);
277
360
  }
278
361
  }
@@ -281,24 +364,17 @@ function findIntegrationDocFiles(root) {
281
364
  return results;
282
365
  }
283
366
 
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
-
292
367
  /**
293
368
  * Discover templates contributed by configured integrations.
294
369
  *
295
370
  * For each integration with a resolved `templates` root, every
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`).
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`).
302
378
  *
303
379
  * @param {string} [cwd]
304
380
  * @returns {Promise<{templates: object[], errors: {package: string, template?: string, message: string}[]}>}
@@ -344,7 +420,7 @@ export async function discoverIntegrationTemplatesForOne(integration) {
344
420
  if (!root || !fs.existsSync(root)) return {templates, errors};
345
421
 
346
422
  for (const docPath of findIntegrationDocFiles(root)) {
347
- const suffix = matchedDocSuffix(docPath);
423
+ const suffix = matchedTemplateSuffix(docPath);
348
424
  const id = path
349
425
  .relative(root, docPath)
350
426
  .slice(0, -suffix.length)
@@ -67,11 +67,6 @@ function error(code, message) {
67
67
  return {code, severity: 'error', message};
68
68
  }
69
69
 
70
- /** @param {string} code @param {string} message @returns {Issue} */
71
- function warning(code, message) {
72
- return {code, severity: 'warning', message};
73
- }
74
-
75
70
  /**
76
71
  * Verify each declared contribution root exists on disk. A declared-but-missing
77
72
  * root is a `missing_root` error.
@@ -365,6 +360,3 @@ export function summarizeIssues(issues) {
365
360
  }
366
361
  return {errors, warnings};
367
362
  }
368
-
369
- // Re-export issue constructors for callers/tests that want them.
370
- export {error as integrationError, warning as integrationWarning};
package/src/config.mjs CHANGED
@@ -1,18 +1,9 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * Type-preserving helper for the Astryx config file.
5
- *
6
- * This is an intentionally tiny runtime identity function: it returns its
7
- * argument unchanged. Its value is the exported TypeScript surface from
8
- * `@astryxdesign/cli/config`, so config files get editor/type feedback without
9
- * coupling to CLI internals. Validation is NOT performed here — it happens at
10
- * the load boundary (see `loadModuleWithSchema` + `AstryxConfigSchema`).
11
- *
12
- * @template {import('./types/config').AstryxConfig} T
13
- * @param {T} config
14
- * @returns {T}
4
+ * Re-export of the config-authoring helper, which now lives in
5
+ * `@astryxdesign/core/config` so an app's config file gets type feedback
6
+ * without depending on the CLI. Kept here so existing
7
+ * `@astryxdesign/cli/config` imports continue to work unchanged.
15
8
  */
16
- export function createConfig(config) {
17
- return config;
18
- }
9
+ export {createConfig} from '@astryxdesign/core/config';
package/src/doc.mjs ADDED
@@ -0,0 +1,27 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Doc-authoring API (public `@astryxdesign/cli/doc`).
5
+ *
6
+ * The `createComponentDoc`/`createFunctionDoc`/`createDoc` authoring helpers now
7
+ * live in `@astryxdesign/core/authoring` and are re-exported here so existing
8
+ * `@astryxdesign/cli/doc` imports keep working. The Zod load-boundary schemas
9
+ * live in `./schemas/doc-schema.mjs` (core-free) and are re-exported here for
10
+ * back-compat; internal hot-path code imports them from the schema module
11
+ * directly so it never depends on core's built `dist/`.
12
+ */
13
+
14
+ export {
15
+ createComponentDoc,
16
+ createFunctionDoc,
17
+ createDoc,
18
+ } from '@astryxdesign/core/authoring';
19
+
20
+ export {
21
+ ComponentDocKindSchema,
22
+ FunctionDocKindSchema,
23
+ GenericDocKindSchema,
24
+ StampedDocSchema,
25
+ LegacyDocSchema,
26
+ ComponentDocSchema,
27
+ } from './schemas/doc-schema.mjs';