@astryxdesign/cli 0.7.6-canary.eae71cb → 0.7.6-canary.eb282ba
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/search/_adapter.d.mts +3 -1
- package/api/search/_adapter.mjs +19 -19
- 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/package-tsconfig.mjs +34 -0
- 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/fs/read-record.d.mts +4 -1
- package/foundation/fs/read-record.mjs +9 -5
- package/foundation/response/response-types.doc.mjs +2 -2
- package/package.json +9 -9
|
@@ -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
|
+
}
|
|
@@ -38,8 +38,11 @@ export function recordReads<T>(seen: Map<string, string>, fn: () => T): T;
|
|
|
38
38
|
* read counts as read by the operation that asks for it.
|
|
39
39
|
* @template T
|
|
40
40
|
* @param {() => Promise<T>} load
|
|
41
|
+
* @param {(recorded: Map<string, string>) => boolean} [isUnchanged] - Whether
|
|
42
|
+
* recorded paths are unchanged; `unchangedSince` unless a caller passes the
|
|
43
|
+
* one it imports (so a test of that caller can hold the answer).
|
|
41
44
|
* @returns {(options?: {fresh?: boolean}) => Promise<T>}
|
|
42
45
|
*/
|
|
43
|
-
export function reusedWhileUnchanged<T>(load: () => Promise<T>): (options?: {
|
|
46
|
+
export function reusedWhileUnchanged<T>(load: () => Promise<T>, isUnchanged?: (recorded: Map<string, string>) => boolean): (options?: {
|
|
44
47
|
fresh?: boolean;
|
|
45
48
|
}) => Promise<T>;
|
|
@@ -170,19 +170,23 @@ export function recordReads(seen, fn) {
|
|
|
170
170
|
* read counts as read by the operation that asks for it.
|
|
171
171
|
* @template T
|
|
172
172
|
* @param {() => Promise<T>} load
|
|
173
|
+
* @param {(recorded: Map<string, string>) => boolean} [isUnchanged] - Whether
|
|
174
|
+
* recorded paths are unchanged; `unchangedSince` unless a caller passes the
|
|
175
|
+
* one it imports (so a test of that caller can hold the answer).
|
|
173
176
|
* @returns {(options?: {fresh?: boolean}) => Promise<T>}
|
|
174
177
|
*/
|
|
175
|
-
export function reusedWhileUnchanged(load) {
|
|
178
|
+
export function reusedWhileUnchanged(load, isUnchanged = unchangedSince) {
|
|
176
179
|
/** @type {{reads: Map<string, string>, value: Promise<T>} | undefined} */
|
|
177
180
|
let last;
|
|
178
181
|
return ({fresh = false} = {}) => {
|
|
179
|
-
if (!fresh && last &&
|
|
182
|
+
if (!fresh && last && isUnchanged(last.reads)) {
|
|
180
183
|
const {reads: recorded, value} = last;
|
|
181
184
|
return value.then(result => {
|
|
182
185
|
const runs = reads.getStore();
|
|
183
|
-
if (runs)
|
|
184
|
-
for (const
|
|
185
|
-
|
|
186
|
+
if (runs)
|
|
187
|
+
for (const [file, state] of recorded) {
|
|
188
|
+
for (const seen of runs) if (!seen.has(file)) seen.set(file, state);
|
|
189
|
+
}
|
|
186
190
|
return result;
|
|
187
191
|
});
|
|
188
192
|
}
|
|
@@ -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.eb282ba",
|
|
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.eb282ba",
|
|
128
|
+
"@astryxdesign/core": "0.7.6-canary.eb282ba",
|
|
129
|
+
"@astryxdesign/lab": "0.7.6-canary.eb282ba",
|
|
130
|
+
"@astryxdesign/theme-neutral": "0.7.6-canary.eb282ba"
|
|
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.eb282ba",
|
|
148
|
+
"@astryxdesign/core": "0.7.6-canary.eb282ba",
|
|
149
|
+
"@astryxdesign/lab": "0.7.6-canary.eb282ba",
|
|
150
|
+
"@astryxdesign/theme-neutral": "0.7.6-canary.eb282ba",
|
|
151
151
|
"@heroicons/react": "^2.2.0",
|
|
152
152
|
"@stylexjs/stylex": "^0.19.0",
|
|
153
153
|
"@types/babel__core": "^7.20.5",
|