@astryxdesign/cli 0.7.6-canary.fc44bc3 → 0.7.6-canary.fda92ac
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/README.md +2 -2
- package/api/component/detail/showcase/showcase.mjs +9 -3
- package/api/template/copy/copy.mjs +13 -7
- package/api/template/show/show.mjs +12 -8
- package/api/template/skeleton/skeleton.mjs +14 -5
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +2 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/assets/templates/blocks/components/BottomSheet/BottomSheetShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetShowcase.tsx +12 -12
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +14 -10
- package/assets/templates/blocks/components/Hooks/useCollatorHookUsage.doc.mjs +20 -0
- package/assets/templates/blocks/components/Hooks/useCollatorHookUsage.tsx +55 -0
- package/assets/templates/blocks/components/Toast/useToastHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Toast/useToastHookUsage.tsx +65 -0
- package/clients/cli/commands/template.mjs +29 -3
- package/foundation/discovery/template-adapter.d.mts +76 -1
- package/foundation/discovery/template-adapter.mjs +418 -13
- package/foundation/discovery/template-icons.mjs +7 -89
- package/foundation/discovery/template-source-tree.d.mts +48 -0
- package/foundation/discovery/template-source-tree.mjs +159 -0
- package/foundation/response/response-types.doc.mjs +2 -2
- package/package.json +9 -9
|
@@ -37,7 +37,12 @@
|
|
|
37
37
|
* @position packages/cli/foundation/discovery — read by template show/copy
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
isReference,
|
|
42
|
+
parseTemplateSource as parseSource,
|
|
43
|
+
walk,
|
|
44
|
+
writtenNames,
|
|
45
|
+
} from './template-source-tree.mjs';
|
|
41
46
|
import {definitionsByIcon} from './icon-set-discovery.mjs';
|
|
42
47
|
import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
43
48
|
|
|
@@ -219,86 +224,6 @@ function targetExport(icon, set, variant) {
|
|
|
219
224
|
return {module, export: icon.export};
|
|
220
225
|
}
|
|
221
226
|
|
|
222
|
-
/** @param {string} source */
|
|
223
|
-
function parseSource(source) {
|
|
224
|
-
return parse(source, {
|
|
225
|
-
sourceType: 'module',
|
|
226
|
-
plugins: ['jsx', 'typescript'],
|
|
227
|
-
errorRecovery: false,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Every node in the tree, with its parent and the key it sits under.
|
|
233
|
-
* @param {any} node
|
|
234
|
-
* @param {(node: any, parent: any, key: string) => void} visit
|
|
235
|
-
* @param {any} [parent]
|
|
236
|
-
* @param {string} [key]
|
|
237
|
-
*/
|
|
238
|
-
function walk(node, visit, parent = null, key = '') {
|
|
239
|
-
if (Array.isArray(node)) {
|
|
240
|
-
for (const child of node) walk(child, visit, parent, key);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
if (
|
|
244
|
-
node == null ||
|
|
245
|
-
typeof node !== 'object' ||
|
|
246
|
-
typeof node.type !== 'string'
|
|
247
|
-
) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
visit(node, parent, key);
|
|
251
|
-
for (const childKey of Object.keys(node)) {
|
|
252
|
-
if (
|
|
253
|
-
childKey === 'loc' ||
|
|
254
|
-
childKey === 'extra' ||
|
|
255
|
-
childKey.endsWith('Comments') ||
|
|
256
|
-
childKey === 'comments' ||
|
|
257
|
-
childKey === 'tokens'
|
|
258
|
-
) {
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
const child = node[childKey];
|
|
262
|
-
if (child != null && typeof child === 'object') {
|
|
263
|
-
walk(child, visit, node, childKey);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Whether an identifier node is a reference to a binding, not a property
|
|
270
|
-
* name or a JSX attribute name.
|
|
271
|
-
* @param {any} node
|
|
272
|
-
* @param {any} parent
|
|
273
|
-
* @param {string} key
|
|
274
|
-
*/
|
|
275
|
-
function isReference(node, parent, key) {
|
|
276
|
-
if (!parent) return true;
|
|
277
|
-
switch (parent.type) {
|
|
278
|
-
case 'ImportSpecifier':
|
|
279
|
-
case 'ImportDefaultSpecifier':
|
|
280
|
-
case 'ImportNamespaceSpecifier':
|
|
281
|
-
return false;
|
|
282
|
-
case 'MemberExpression':
|
|
283
|
-
case 'OptionalMemberExpression':
|
|
284
|
-
return key !== 'property' || parent.computed;
|
|
285
|
-
case 'ObjectProperty':
|
|
286
|
-
return key === 'value' || parent.computed;
|
|
287
|
-
case 'ObjectMethod':
|
|
288
|
-
case 'ClassMethod':
|
|
289
|
-
case 'ClassProperty':
|
|
290
|
-
return key !== 'key' || parent.computed;
|
|
291
|
-
case 'JSXAttribute':
|
|
292
|
-
return false;
|
|
293
|
-
case 'JSXMemberExpression':
|
|
294
|
-
return key === 'object';
|
|
295
|
-
case 'TSPropertySignature':
|
|
296
|
-
return key !== 'key';
|
|
297
|
-
default:
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
227
|
/**
|
|
303
228
|
* Whether a module is one of Astryx's own packages (`@astryxdesign/core`,
|
|
304
229
|
* its subpaths, and every other `@astryxdesign/` package).
|
|
@@ -453,14 +378,7 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
453
378
|
);
|
|
454
379
|
|
|
455
380
|
/** Every name the file writes, to keep aliases collision-free. */
|
|
456
|
-
const written =
|
|
457
|
-
walk(ast.program, (node, parent, key) => {
|
|
458
|
-
// The name an import specifier reads from its module binds nothing here.
|
|
459
|
-
if (parent?.type === 'ImportSpecifier' && key === 'imported') return;
|
|
460
|
-
if (node.type === 'Identifier' || node.type === 'JSXIdentifier') {
|
|
461
|
-
written.add(node.name);
|
|
462
|
-
}
|
|
463
|
-
});
|
|
381
|
+
const written = writtenNames(ast);
|
|
464
382
|
|
|
465
383
|
/** @type {Array<{start: number, end: number, text: string}>} */
|
|
466
384
|
const edits = [];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse template source as TSX. Babel loads on first use, so a command that
|
|
6
|
+
* only lists templates never pays for it.
|
|
7
|
+
* @param {string} source
|
|
8
|
+
* @returns {any} The file node.
|
|
9
|
+
*/
|
|
10
|
+
export function parseTemplateSource(source: string): any;
|
|
11
|
+
/**
|
|
12
|
+
* The module scope of a parsed file. Its bindings, and the scope of each path
|
|
13
|
+
* a traversal visits, resolve a name to the declaration it reads, so a rewrite
|
|
14
|
+
* acts on bindings and not on names.
|
|
15
|
+
* @param {any} file - A file node from {@link parseTemplateSource}.
|
|
16
|
+
* @returns {any} The program path; its `scope` is the module scope.
|
|
17
|
+
*/
|
|
18
|
+
export function programPath(file: any): any;
|
|
19
|
+
/**
|
|
20
|
+
* Traverse a parsed file with scope tracking.
|
|
21
|
+
* @param {any} file - A file node from {@link parseTemplateSource}.
|
|
22
|
+
* @param {import('@babel/core').Visitor} visitor
|
|
23
|
+
*/
|
|
24
|
+
export function traverseTemplateSource(file: any, visitor: import("@babel/core").Visitor): void;
|
|
25
|
+
/**
|
|
26
|
+
* Every node in the tree, with its parent and the key it sits under.
|
|
27
|
+
* @param {any} node
|
|
28
|
+
* @param {(node: any, parent: any, key: string) => void} visit
|
|
29
|
+
* @param {any} [parent]
|
|
30
|
+
* @param {string} [key]
|
|
31
|
+
*/
|
|
32
|
+
export function walk(node: any, visit: (node: any, parent: any, key: string) => void, parent?: any, key?: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Whether an identifier node is a reference to a binding, not a property
|
|
35
|
+
* name or a JSX attribute name.
|
|
36
|
+
* @param {any} node
|
|
37
|
+
* @param {any} parent
|
|
38
|
+
* @param {string} key
|
|
39
|
+
*/
|
|
40
|
+
export function isReference(node: any, parent: any, key: string): any;
|
|
41
|
+
/**
|
|
42
|
+
* Every name a file writes, so a name a rewrite adds collides with nothing
|
|
43
|
+
* and shadows nothing. The name an import specifier reads from its module
|
|
44
|
+
* binds nothing in the file, so it is not included.
|
|
45
|
+
* @param {any} file - A file node from {@link parseTemplateSource}.
|
|
46
|
+
* @returns {Set<string>}
|
|
47
|
+
*/
|
|
48
|
+
export function writtenNames(file: any): Set<string>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The syntax tree of a template's source, shared by every rewrite of
|
|
5
|
+
* it: parsing, a walk over every node, whether an identifier is a reference,
|
|
6
|
+
* the names a file writes, and the module scope that resolves bindings.
|
|
7
|
+
*
|
|
8
|
+
* @input Template source text
|
|
9
|
+
* @output Its parsed tree, node visits, names, and module scope
|
|
10
|
+
* @position packages/cli/foundation/discovery — read by template-icons and by
|
|
11
|
+
* the demo-content replacement in template-adapter
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {createRequire} from 'node:module';
|
|
15
|
+
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
|
|
18
|
+
/** @type {typeof import('@babel/parser') | undefined} */
|
|
19
|
+
let babelParser;
|
|
20
|
+
/** @type {typeof import('@babel/core') | undefined} */
|
|
21
|
+
let babelCore;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Parse template source as TSX. Babel loads on first use, so a command that
|
|
25
|
+
* only lists templates never pays for it.
|
|
26
|
+
* @param {string} source
|
|
27
|
+
* @returns {any} The file node.
|
|
28
|
+
*/
|
|
29
|
+
export function parseTemplateSource(source) {
|
|
30
|
+
babelParser ??= /** @type {typeof import('@babel/parser')} */ (
|
|
31
|
+
require('@babel/parser')
|
|
32
|
+
);
|
|
33
|
+
return babelParser.parse(source, {
|
|
34
|
+
sourceType: 'module',
|
|
35
|
+
plugins: ['jsx', 'typescript'],
|
|
36
|
+
errorRecovery: false,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The module scope of a parsed file. Its bindings, and the scope of each path
|
|
42
|
+
* a traversal visits, resolve a name to the declaration it reads, so a rewrite
|
|
43
|
+
* acts on bindings and not on names.
|
|
44
|
+
* @param {any} file - A file node from {@link parseTemplateSource}.
|
|
45
|
+
* @returns {any} The program path; its `scope` is the module scope.
|
|
46
|
+
*/
|
|
47
|
+
export function programPath(file) {
|
|
48
|
+
/** @type {any} */
|
|
49
|
+
let program;
|
|
50
|
+
traverseTemplateSource(file, {
|
|
51
|
+
Program(/** @type {any} */ path) {
|
|
52
|
+
program = path;
|
|
53
|
+
path.stop();
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return program;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Traverse a parsed file with scope tracking.
|
|
61
|
+
* @param {any} file - A file node from {@link parseTemplateSource}.
|
|
62
|
+
* @param {import('@babel/core').Visitor} visitor
|
|
63
|
+
*/
|
|
64
|
+
export function traverseTemplateSource(file, visitor) {
|
|
65
|
+
babelCore ??= /** @type {typeof import('@babel/core')} */ (
|
|
66
|
+
require('@babel/core')
|
|
67
|
+
);
|
|
68
|
+
babelCore.traverse(file, visitor);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Every node in the tree, with its parent and the key it sits under.
|
|
73
|
+
* @param {any} node
|
|
74
|
+
* @param {(node: any, parent: any, key: string) => void} visit
|
|
75
|
+
* @param {any} [parent]
|
|
76
|
+
* @param {string} [key]
|
|
77
|
+
*/
|
|
78
|
+
export function walk(node, visit, parent = null, key = '') {
|
|
79
|
+
if (Array.isArray(node)) {
|
|
80
|
+
for (const child of node) walk(child, visit, parent, key);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (
|
|
84
|
+
node == null ||
|
|
85
|
+
typeof node !== 'object' ||
|
|
86
|
+
typeof node.type !== 'string'
|
|
87
|
+
) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
visit(node, parent, key);
|
|
91
|
+
for (const childKey of Object.keys(node)) {
|
|
92
|
+
if (
|
|
93
|
+
childKey === 'loc' ||
|
|
94
|
+
childKey === 'extra' ||
|
|
95
|
+
childKey.endsWith('Comments') ||
|
|
96
|
+
childKey === 'comments' ||
|
|
97
|
+
childKey === 'tokens'
|
|
98
|
+
) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const child = node[childKey];
|
|
102
|
+
if (child != null && typeof child === 'object') {
|
|
103
|
+
walk(child, visit, node, childKey);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Whether an identifier node is a reference to a binding, not a property
|
|
110
|
+
* name or a JSX attribute name.
|
|
111
|
+
* @param {any} node
|
|
112
|
+
* @param {any} parent
|
|
113
|
+
* @param {string} key
|
|
114
|
+
*/
|
|
115
|
+
export function isReference(node, parent, key) {
|
|
116
|
+
if (!parent) return true;
|
|
117
|
+
switch (parent.type) {
|
|
118
|
+
case 'ImportSpecifier':
|
|
119
|
+
case 'ImportDefaultSpecifier':
|
|
120
|
+
case 'ImportNamespaceSpecifier':
|
|
121
|
+
return false;
|
|
122
|
+
case 'MemberExpression':
|
|
123
|
+
case 'OptionalMemberExpression':
|
|
124
|
+
return key !== 'property' || parent.computed;
|
|
125
|
+
case 'ObjectProperty':
|
|
126
|
+
return key === 'value' || parent.computed;
|
|
127
|
+
case 'ObjectMethod':
|
|
128
|
+
case 'ClassMethod':
|
|
129
|
+
case 'ClassProperty':
|
|
130
|
+
return key !== 'key' || parent.computed;
|
|
131
|
+
case 'JSXAttribute':
|
|
132
|
+
return false;
|
|
133
|
+
case 'JSXMemberExpression':
|
|
134
|
+
return key === 'object';
|
|
135
|
+
case 'TSPropertySignature':
|
|
136
|
+
return key !== 'key';
|
|
137
|
+
default:
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Every name a file writes, so a name a rewrite adds collides with nothing
|
|
144
|
+
* and shadows nothing. The name an import specifier reads from its module
|
|
145
|
+
* binds nothing in the file, so it is not included.
|
|
146
|
+
* @param {any} file - A file node from {@link parseTemplateSource}.
|
|
147
|
+
* @returns {Set<string>}
|
|
148
|
+
*/
|
|
149
|
+
export function writtenNames(file) {
|
|
150
|
+
/** @type {Set<string>} */
|
|
151
|
+
const written = new Set();
|
|
152
|
+
walk(file.program, (node, parent, key) => {
|
|
153
|
+
if (parent?.type === 'ImportSpecifier' && key === 'imported') return;
|
|
154
|
+
if (node.type === 'Identifier' || node.type === 'JSXIdentifier') {
|
|
155
|
+
written.add(node.name);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return written;
|
|
159
|
+
}
|
|
@@ -286,7 +286,7 @@ export const doc = {
|
|
|
286
286
|
{
|
|
287
287
|
value: 'template.show',
|
|
288
288
|
description:
|
|
289
|
-
"The resolved template's source, exactly as a copy writes it, plus its description, kind, the component names it composes, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media).",
|
|
289
|
+
"The resolved template's source, exactly as a copy writes it, plus its description, kind, the component names it composes, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media), and demoContentReplaced (how many Astryx docs-only demo content elements were replaced with a Text placeholder for your own content).",
|
|
290
290
|
},
|
|
291
291
|
{
|
|
292
292
|
value: 'template.skeleton',
|
|
@@ -296,7 +296,7 @@ export const doc = {
|
|
|
296
296
|
{
|
|
297
297
|
value: 'template.copy',
|
|
298
298
|
description:
|
|
299
|
-
"A scaffold receipt: template id, output directory, written file name, file count, demoMediaReplaced (how many Astryx demo media references were replaced with placeholders), notes (setup notes naming what the template needs that the project lacks — missing packages, missing StyleX compiler; empty when satisfied), missingPackages (external package names the template imports that are not in the project), and installCommand (a ready-to-run install command with the detected package manager and workspace version ranges; null when nothing is missing, or when several lockfiles leave the package manager undetermined). The envelope's package names the npm package that owns the template.",
|
|
299
|
+
"A scaffold receipt: template id, output directory, written file name, file count, demoMediaReplaced (how many Astryx demo media references were replaced with placeholders), demoContentReplaced (how many Astryx docs-only demo content elements were replaced with a Text placeholder), notes (setup notes naming what the template needs that the project lacks — missing packages, missing StyleX compiler; empty when satisfied), missingPackages (external package names the template imports that are not in the project), and installCommand (a ready-to-run install command with the detected package manager and workspace version ranges; null when nothing is missing, or when several lockfiles leave the package manager undetermined). The envelope's package names the npm package that owns the template.",
|
|
300
300
|
},
|
|
301
301
|
|
|
302
302
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.6-canary.
|
|
3
|
+
"version": "0.7.6-canary.fda92ac",
|
|
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",
|
|
@@ -124,10 +124,10 @@
|
|
|
124
124
|
"zod": "^4.4.3"
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
|
-
"@astryxdesign/charts": "0.7.6-canary.
|
|
128
|
-
"@astryxdesign/core": "0.7.6-canary.
|
|
129
|
-
"@astryxdesign/lab": "0.7.6-canary.
|
|
130
|
-
"@astryxdesign/theme-neutral": "0.7.6-canary.
|
|
127
|
+
"@astryxdesign/charts": "0.7.6-canary.fda92ac",
|
|
128
|
+
"@astryxdesign/core": "0.7.6-canary.fda92ac",
|
|
129
|
+
"@astryxdesign/lab": "0.7.6-canary.fda92ac",
|
|
130
|
+
"@astryxdesign/theme-neutral": "0.7.6-canary.fda92ac"
|
|
131
131
|
},
|
|
132
132
|
"peerDependenciesMeta": {
|
|
133
133
|
"@astryxdesign/charts": {
|
|
@@ -144,10 +144,10 @@
|
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
146
|
"devDependencies": {
|
|
147
|
-
"@astryxdesign/charts": "0.7.6-canary.
|
|
148
|
-
"@astryxdesign/core": "0.7.6-canary.
|
|
149
|
-
"@astryxdesign/lab": "0.7.6-canary.
|
|
150
|
-
"@astryxdesign/theme-neutral": "0.7.6-canary.
|
|
147
|
+
"@astryxdesign/charts": "0.7.6-canary.fda92ac",
|
|
148
|
+
"@astryxdesign/core": "0.7.6-canary.fda92ac",
|
|
149
|
+
"@astryxdesign/lab": "0.7.6-canary.fda92ac",
|
|
150
|
+
"@astryxdesign/theme-neutral": "0.7.6-canary.fda92ac",
|
|
151
151
|
"@heroicons/react": "^2.2.0",
|
|
152
152
|
"@stylexjs/stylex": "^0.19.0",
|
|
153
153
|
"@types/babel__core": "^7.20.5",
|