@astryxdesign/cli 0.1.6-canary.aeb5ee6 → 0.1.6-canary.b2a4936
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/docs/integration-authoring.md +105 -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/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
|
@@ -0,0 +1,105 @@
|
|
|
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`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.1.6-canary.
|
|
3
|
+
"version": "0.1.6-canary.b2a4936",
|
|
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.
|
|
79
|
-
"@astryxdesign/core": "0.1.6-canary.
|
|
80
|
-
"@astryxdesign/lab": "0.1.6-canary.
|
|
81
|
-
"@astryxdesign/theme-neutral": "0.1.6-canary.
|
|
78
|
+
"@astryxdesign/charts": "0.1.6-canary.b2a4936",
|
|
79
|
+
"@astryxdesign/core": "0.1.6-canary.b2a4936",
|
|
80
|
+
"@astryxdesign/lab": "0.1.6-canary.b2a4936",
|
|
81
|
+
"@astryxdesign/theme-neutral": "0.1.6-canary.b2a4936",
|
|
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.
|
|
100
|
-
"@astryxdesign/core": "0.1.6-canary.
|
|
101
|
-
"@astryxdesign/lab": "0.1.6-canary.
|
|
102
|
-
"@astryxdesign/theme-neutral": "0.1.6-canary.
|
|
99
|
+
"@astryxdesign/charts": "0.1.6-canary.b2a4936",
|
|
100
|
+
"@astryxdesign/core": "0.1.6-canary.b2a4936",
|
|
101
|
+
"@astryxdesign/lab": "0.1.6-canary.b2a4936",
|
|
102
|
+
"@astryxdesign/theme-neutral": "0.1.6-canary.b2a4936",
|
|
103
103
|
"gpt-tokenizer": "^3.4.0"
|
|
104
104
|
},
|
|
105
105
|
"scripts": {
|
|
@@ -0,0 +1,240 @@
|
|
|
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
|
+
});
|
|
@@ -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)
|
|
@@ -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={
|
|
@@ -54,7 +54,7 @@ export default function ChatComposerInputMultipleTriggers() {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
return (
|
|
57
|
-
<Stack direction="vertical" gap={3} style={{width:
|
|
57
|
+
<Stack direction="vertical" gap={3} style={{width: 450, maxWidth: '100%'}}>
|
|
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:
|
|
10
|
+
<Stack direction="vertical" style={{width: 450, maxWidth: '100%'}}>
|
|
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:
|
|
43
|
+
<Stack direction="vertical" style={{width: 450, maxWidth: '100%'}}>
|
|
44
44
|
<ChatComposer
|
|
45
45
|
onSubmit={() => {}}
|
|
46
46
|
input={
|