@astryxdesign/cli 0.1.5 → 0.1.6-canary.0121ab3
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/CHANGELOG.md +4 -0
- package/docs/integration-authoring.md +105 -0
- package/docs/internationalization.doc.mjs +243 -0
- package/package.json +9 -9
- package/src/api/integration-block-exports.test.mjs +240 -0
- package/src/api/template-suffix.test.mjs +246 -0
- package/src/api/template.mjs +103 -27
- package/templates/blocks/components/Avatar/AvatarGroup.tsx +5 -7
- package/templates/blocks/components/Avatar/AvatarShowcase.tsx +4 -6
- package/templates/blocks/components/Avatar/AvatarUserCard.tsx +3 -5
- package/templates/blocks/components/Avatar/AvatarWithImage.tsx +8 -6
- package/templates/blocks/components/Avatar/AvatarWithStatus.tsx +3 -5
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputControlledInput.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputDisabled.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputShowcase.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputSlashCommands.tsx +1 -1
- package/templates/blocks/components/Table/TableGroupedRowsTable.doc.mjs +14 -0
- package/templates/blocks/components/Table/TableGroupedRowsTable.tsx +66 -0
- package/templates/blocks/components/Table/TableRowIndexTable.doc.mjs +14 -0
- package/templates/blocks/components/Table/TableRowIndexTable.tsx +47 -0
- package/templates/pages/theme-showcase/page.tsx +7 -7
- 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
|
+
});
|
package/src/api/template.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
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
11
|
import {TemplateEnvelopeSchema} from '../template.mjs';
|
|
11
12
|
import {CLI_ROOT, discoverExternalPackages} from '../utils/paths.mjs';
|
|
@@ -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
|
-
/**
|
|
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 =
|
|
93
|
-
|
|
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
|
|
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
|
|
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,
|
|
230
|
+
const docFiles = findDocFiles(BLOCKS_DIR, TEMPLATE_SUFFIX_RE);
|
|
152
231
|
const blocks = [];
|
|
153
232
|
for (const docPath of docFiles) {
|
|
154
|
-
const
|
|
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,
|
|
269
|
+
const docFiles = findDocFiles(ext.blocksDir, TEMPLATE_SUFFIX_RE);
|
|
189
270
|
for (const docPath of docFiles) {
|
|
190
|
-
const
|
|
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
|
|
262
|
-
* Returns absolute paths to files ending in one of
|
|
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 (
|
|
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
|
|
297
|
-
*
|
|
298
|
-
* nested). The doc's `type`
|
|
299
|
-
* `/pages` vs `/blocks`
|
|
300
|
-
* (`<id>.tsx`) is required; a doc
|
|
301
|
-
*
|
|
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 =
|
|
423
|
+
const suffix = matchedTemplateSuffix(docPath);
|
|
348
424
|
const id = path
|
|
349
425
|
.relative(root, docPath)
|
|
350
426
|
.slice(0, -suffix.length)
|
|
@@ -7,28 +7,26 @@ 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
|
-
|
|
12
10
|
const USERS = [
|
|
13
11
|
{
|
|
14
12
|
name: 'Ami Pena',
|
|
15
|
-
src:
|
|
13
|
+
src: 'https://lookaside.facebook.com/assets/astryx/DATA-Ami-Pena.png',
|
|
16
14
|
},
|
|
17
15
|
{
|
|
18
16
|
name: 'Drew Young',
|
|
19
|
-
src:
|
|
17
|
+
src: 'https://lookaside.facebook.com/assets/astryx/DATA-Drew-Young.png',
|
|
20
18
|
},
|
|
21
19
|
{
|
|
22
20
|
name: 'Gabriela Fernandez',
|
|
23
|
-
src:
|
|
21
|
+
src: 'https://lookaside.facebook.com/assets/astryx/DATA-Gabriela-Fernandez.png',
|
|
24
22
|
},
|
|
25
23
|
{
|
|
26
24
|
name: 'Jihoo Song',
|
|
27
|
-
src:
|
|
25
|
+
src: 'https://lookaside.facebook.com/assets/astryx/DATA-Jihoo-Song.png',
|
|
28
26
|
},
|
|
29
27
|
{
|
|
30
28
|
name: 'Nam Tran',
|
|
31
|
-
src:
|
|
29
|
+
src: 'https://lookaside.facebook.com/assets/astryx/DATA-Nam-Tran.png',
|
|
32
30
|
},
|
|
33
31
|
];
|
|
34
32
|
|
|
@@ -5,29 +5,27 @@
|
|
|
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
|
-
|
|
10
8
|
export default function AvatarShowcase() {
|
|
11
9
|
return (
|
|
12
10
|
<Stack direction="horizontal" gap={4} vAlign="center">
|
|
13
11
|
<Avatar
|
|
14
|
-
src=
|
|
12
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Ana-Thomas.png"
|
|
15
13
|
name="Ana Thomas"
|
|
16
14
|
size="large"
|
|
17
15
|
status={<AvatarStatusDot variant="success" label="Online" />}
|
|
18
16
|
/>
|
|
19
17
|
<Avatar
|
|
20
|
-
src=
|
|
18
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Drew-Young.png"
|
|
21
19
|
name="Drew Young"
|
|
22
20
|
size="large"
|
|
23
21
|
/>
|
|
24
22
|
<Avatar
|
|
25
|
-
src=
|
|
23
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Jihoo-Song.png"
|
|
26
24
|
name="Jihoo Song"
|
|
27
25
|
size="large"
|
|
28
26
|
/>
|
|
29
27
|
<Avatar
|
|
30
|
-
src=
|
|
28
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Nam-Tran.png"
|
|
31
29
|
name="Nam Tran"
|
|
32
30
|
size="large"
|
|
33
31
|
status={<AvatarStatusDot variant="error" label="Online" />}
|
|
@@ -6,24 +6,22 @@ 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
|
-
|
|
11
9
|
const USERS = [
|
|
12
10
|
{
|
|
13
11
|
name: 'Itai Jordaan',
|
|
14
|
-
src:
|
|
12
|
+
src: 'https://lookaside.facebook.com/assets/astryx/DATA-Itai-Jordaan.png',
|
|
15
13
|
role: 'Engineering Lead',
|
|
16
14
|
variant: 'success' as const,
|
|
17
15
|
},
|
|
18
16
|
{
|
|
19
17
|
name: 'Margot Schroder',
|
|
20
|
-
src:
|
|
18
|
+
src: 'https://lookaside.facebook.com/assets/astryx/DATA-Margot-Schroder.png',
|
|
21
19
|
role: 'Product Designer',
|
|
22
20
|
variant: 'neutral' as const,
|
|
23
21
|
},
|
|
24
22
|
{
|
|
25
23
|
name: 'Daniela Gimenez',
|
|
26
|
-
src:
|
|
24
|
+
src: 'https://lookaside.facebook.com/assets/astryx/DATA-Daniela-Gimenez.png',
|
|
27
25
|
role: 'Engineering Manager',
|
|
28
26
|
variant: 'error' as const,
|
|
29
27
|
},
|
|
@@ -5,24 +5,26 @@
|
|
|
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
|
-
|
|
10
8
|
export default function AvatarWithImage() {
|
|
11
9
|
return (
|
|
12
10
|
<Stack direction="horizontal" gap={4} vAlign="center">
|
|
13
|
-
<Avatar src={`${CDN}/DATA-Ami-Pena.png`} name="Ami Pena" size="tiny" />
|
|
14
11
|
<Avatar
|
|
15
|
-
src=
|
|
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"
|
|
16
18
|
name="Ana Thomas"
|
|
17
19
|
size="small"
|
|
18
20
|
/>
|
|
19
21
|
<Avatar
|
|
20
|
-
src=
|
|
22
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Daniela-Gimenez.png"
|
|
21
23
|
name="Daniela Gimenez"
|
|
22
24
|
size="medium"
|
|
23
25
|
/>
|
|
24
26
|
<Avatar
|
|
25
|
-
src=
|
|
27
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Gabriela-Fernandez.png"
|
|
26
28
|
name="Gabriela Fernandez"
|
|
27
29
|
size="large"
|
|
28
30
|
/>
|
|
@@ -5,25 +5,23 @@
|
|
|
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
|
-
|
|
10
8
|
export default function AvatarWithStatus() {
|
|
11
9
|
return (
|
|
12
10
|
<Stack direction="horizontal" gap={4} vAlign="center">
|
|
13
11
|
<Avatar
|
|
14
|
-
src=
|
|
12
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Itai-Jordaan.png"
|
|
15
13
|
name="Itai Jordaan"
|
|
16
14
|
size="large"
|
|
17
15
|
status={<AvatarStatusDot variant="success" label="Online" />}
|
|
18
16
|
/>
|
|
19
17
|
<Avatar
|
|
20
|
-
src=
|
|
18
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Margot-Schroder.png"
|
|
21
19
|
name="Margot Schroder"
|
|
22
20
|
size="large"
|
|
23
21
|
status={<AvatarStatusDot variant="neutral" label="Offline" />}
|
|
24
22
|
/>
|
|
25
23
|
<Avatar
|
|
26
|
-
src=
|
|
24
|
+
src="https://lookaside.facebook.com/assets/astryx/DATA-Pablo-Morales.png"
|
|
27
25
|
name="Pablo Morales"
|
|
28
26
|
size="large"
|
|
29
27
|
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:
|
|
13
|
+
<Stack direction="vertical" gap={3} style={{width: 450, maxWidth: '100%'}}>
|
|
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:
|
|
10
|
+
<Stack direction="vertical" style={{width: 450, maxWidth: '100%'}}>
|
|
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:
|
|
46
|
+
<Stack direction="vertical" gap={3} style={{width: 450, maxWidth: '100%'}}>
|
|
47
47
|
<ChatComposer
|
|
48
48
|
onSubmit={() => setValue('')}
|
|
49
49
|
input={
|