@astryxdesign/cli 0.6.5-vanilla-poc.6e25cfc → 0.6.6
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 +84 -0
- package/README.md +1 -34
- package/api/build/_adapter.d.mts +14 -0
- package/api/build/_adapter.mjs +58 -1
- package/api/build/build.test.mjs +74 -1
- package/api/build/kit/kit.mjs +39 -7
- package/api/build/kit/rank.d.mts +8 -0
- package/api/build/kit/rank.mjs +14 -0
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/component/_adapter.d.mts +1 -51
- package/api/component/_adapter.mjs +3 -110
- package/api/component/component.d.mts +1 -9
- package/api/component/component.doc.mjs +7 -52
- package/api/component/component.mjs +3 -276
- package/api/component/component.type.d.mts +1 -28
- package/api/component/component.type.mjs +1 -20
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +132 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +44 -1
- package/api/docs/docs.type.d.mts +38 -1
- package/api/docs/docs.type.mjs +18 -1
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +146 -23
- package/api/hook/list/list.d.mts +1 -1
- package/api/index.d.mts +0 -8
- package/api/index.mjs +0 -8
- package/api/integration/add-theme.mjs +93 -3
- package/api/integration/add-theme.test.mjs +100 -0
- package/api/integration/integrationAddTheme.doc.mjs +1 -1
- package/api/search/search.d.mts +8 -1
- package/api/search/search.doc.mjs +3 -3
- package/api/search/search.mjs +58 -73
- package/api/search/search.test.mjs +122 -21
- package/api/search/search.type.d.mts +0 -10
- package/api/search/search.type.mjs +0 -1
- package/api/template/cdn/cdn.test.mjs +2 -50
- package/api/template/template.d.mts +0 -6
- package/api/template/template.doc.mjs +4 -56
- package/api/template/template.mjs +0 -82
- package/api/template/template.type.d.mts +0 -12
- package/api/template/template.type.mjs +0 -7
- package/assets/cdn.template.html +5 -19
- package/assets/docs/tokens.doc.mjs +3 -3
- package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
- package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
- package/clients/cli/commands/component/index.mjs +9 -66
- package/clients/cli/commands/component.doc.mjs +4 -26
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +222 -5
- package/clients/cli/commands/integration-add.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +2 -3
- package/clients/cli/commands/search.mjs +11 -8
- package/clients/cli/commands/search.test.mjs +35 -40
- package/clients/cli/commands/template.doc.mjs +3 -31
- package/clients/cli/commands/template.mjs +2 -37
- package/foundation/discovery/theme-discovery.d.mts +6 -0
- package/foundation/discovery/theme-discovery.mjs +9 -0
- package/foundation/response/response-types.doc.mjs +0 -38
- package/package.json +5 -9
- package/api/_vanilla-assets.d.mts +0 -10
- package/api/_vanilla-assets.mjs +0 -59
- package/api/component/html/html.d.mts +0 -12
- package/api/component/html/html.doc.d.mts +0 -5
- package/api/component/html/html.doc.mjs +0 -66
- package/api/component/html/html.mjs +0 -25
- package/api/component/html/html.test.mjs +0 -61
- package/api/component/html/html.type.d.mts +0 -23
- package/api/component/html/html.type.mjs +0 -27
- package/api/component/web-components/web-components.d.mts +0 -12
- package/api/component/web-components/web-components.doc.d.mts +0 -5
- package/api/component/web-components/web-components.doc.mjs +0 -70
- package/api/component/web-components/web-components.mjs +0 -32
- package/api/component/web-components/web-components.test.mjs +0 -50
- package/api/component/web-components/web-components.type.d.mts +0 -23
- package/api/component/web-components/web-components.type.mjs +0 -27
- package/api/template/_adapter.d.mts +0 -38
- package/api/template/_adapter.mjs +0 -90
- package/api/template/html/html.d.mts +0 -17
- package/api/template/html/html.doc.d.mts +0 -5
- package/api/template/html/html.doc.mjs +0 -72
- package/api/template/html/html.mjs +0 -61
- package/api/template/html/html.test.mjs +0 -71
- package/api/template/html/html.type.d.mts +0 -26
- package/api/template/html/html.type.mjs +0 -28
- package/api/template/web-components/web-components.d.mts +0 -13
- package/api/template/web-components/web-components.doc.d.mts +0 -5
- package/api/template/web-components/web-components.doc.mjs +0 -69
- package/api/template/web-components/web-components.mjs +0 -51
- package/api/template/web-components/web-components.test.mjs +0 -73
- package/api/template/web-components/web-components.type.d.mts +0 -26
- package/api/template/web-components/web-components.type.mjs +0 -28
- package/assets/generated/core-component-docs.json +0 -1
- package/assets/vanilla/elements-markup/Avatar.html +0 -27
- package/assets/vanilla/elements-markup/Badge.html +0 -16
- package/assets/vanilla/elements-markup/Banner.html +0 -32
- package/assets/vanilla/elements-markup/Breadcrumbs.html +0 -23
- package/assets/vanilla/elements-markup/Button.html +0 -37
- package/assets/vanilla/elements-markup/Card.html +0 -24
- package/assets/vanilla/elements-markup/CheckboxInput.html +0 -28
- package/assets/vanilla/elements-markup/Collapsible.html +0 -26
- package/assets/vanilla/elements-markup/DateInput.html +0 -28
- package/assets/vanilla/elements-markup/Dialog.html +0 -33
- package/assets/vanilla/elements-markup/Divider.html +0 -20
- package/assets/vanilla/elements-markup/DropdownMenu.html +0 -26
- package/assets/vanilla/elements-markup/EmptyState.html +0 -27
- package/assets/vanilla/elements-markup/Heading.html +0 -18
- package/assets/vanilla/elements-markup/HoverCard.html +0 -39
- package/assets/vanilla/elements-markup/Layout.html +0 -28
- package/assets/vanilla/elements-markup/Lightbox.html +0 -33
- package/assets/vanilla/elements-markup/Link.html +0 -23
- package/assets/vanilla/elements-markup/NumberInput.html +0 -34
- package/assets/vanilla/elements-markup/ProgressBar.html +0 -47
- package/assets/vanilla/elements-markup/RadioList.html +0 -28
- package/assets/vanilla/elements-markup/Selector.html +0 -34
- package/assets/vanilla/elements-markup/SideNav.html +0 -32
- package/assets/vanilla/elements-markup/Skeleton.html +0 -18
- package/assets/vanilla/elements-markup/Slider.html +0 -31
- package/assets/vanilla/elements-markup/Stack.html +0 -33
- package/assets/vanilla/elements-markup/StatusDot.html +0 -19
- package/assets/vanilla/elements-markup/Switch.html +0 -28
- package/assets/vanilla/elements-markup/Tab.html +0 -18
- package/assets/vanilla/elements-markup/TabList.html +0 -31
- package/assets/vanilla/elements-markup/Table.html +0 -31
- package/assets/vanilla/elements-markup/Text.html +0 -24
- package/assets/vanilla/elements-markup/TextArea.html +0 -32
- package/assets/vanilla/elements-markup/TextInput.html +0 -92
- package/assets/vanilla/elements-markup/Theme.html +0 -16
- package/assets/vanilla/elements-markup/TimeInput.html +0 -29
- package/assets/vanilla/elements-markup/Toast.html +0 -22
- package/assets/vanilla/elements-markup/Tooltip.html +0 -30
- package/assets/vanilla/elements-markup/TopNav.html +0 -85
- package/assets/vanilla/elements-markup/Typeahead.html +0 -31
- package/assets/vanilla/elements-templates/dashboard.html +0 -167
- package/assets/vanilla/elements-templates/detail-page.html +0 -145
- package/assets/vanilla/elements-templates/form-two-column.html +0 -135
- package/assets/vanilla/elements-templates/kanban-board.html +0 -141
- package/assets/vanilla/elements-templates/login.html +0 -100
- package/assets/vanilla/elements-templates/product-detail.html +0 -128
- package/assets/vanilla/elements-templates/settings.html +0 -130
- package/assets/vanilla/elements-templates/shell-side-nav.html +0 -160
- package/assets/vanilla/elements-templates/table-filter.html +0 -154
- package/assets/vanilla/markup/Avatar.html +0 -24
- package/assets/vanilla/markup/Badge.html +0 -12
- package/assets/vanilla/markup/Banner.html +0 -49
- package/assets/vanilla/markup/Breadcrumbs.html +0 -38
- package/assets/vanilla/markup/Button.html +0 -37
- package/assets/vanilla/markup/Card.html +0 -16
- package/assets/vanilla/markup/CheckboxInput.html +0 -45
- package/assets/vanilla/markup/Collapsible.html +0 -9
- package/assets/vanilla/markup/DateInput.html +0 -42
- package/assets/vanilla/markup/Dialog.html +0 -45
- package/assets/vanilla/markup/Divider.html +0 -9
- package/assets/vanilla/markup/DropdownMenu.html +0 -30
- package/assets/vanilla/markup/EmptyState.html +0 -41
- package/assets/vanilla/markup/Heading.html +0 -9
- package/assets/vanilla/markup/HoverCard.html +0 -85
- package/assets/vanilla/markup/Layout.html +0 -35
- package/assets/vanilla/markup/Lightbox.html +0 -107
- package/assets/vanilla/markup/Link.html +0 -6
- package/assets/vanilla/markup/NumberInput.html +0 -55
- package/assets/vanilla/markup/ProgressBar.html +0 -101
- package/assets/vanilla/markup/RadioList.html +0 -90
- package/assets/vanilla/markup/Selector.html +0 -92
- package/assets/vanilla/markup/SideNav.html +0 -82
- package/assets/vanilla/markup/Skeleton.html +0 -26
- package/assets/vanilla/markup/Slider.html +0 -65
- package/assets/vanilla/markup/Stack.html +0 -13
- package/assets/vanilla/markup/StatusDot.html +0 -22
- package/assets/vanilla/markup/Switch.html +0 -47
- package/assets/vanilla/markup/TabList.html +0 -56
- package/assets/vanilla/markup/Table.html +0 -75
- package/assets/vanilla/markup/Text.html +0 -9
- package/assets/vanilla/markup/TextArea.html +0 -37
- package/assets/vanilla/markup/TextInput.html +0 -80
- package/assets/vanilla/markup/Theme.html +0 -48
- package/assets/vanilla/markup/TimeInput.html +0 -43
- package/assets/vanilla/markup/Toast.html +0 -42
- package/assets/vanilla/markup/Tooltip.html +0 -18
- package/assets/vanilla/markup/TopNav.html +0 -81
- package/assets/vanilla/markup/Typeahead.html +0 -60
- package/assets/vanilla/templates/dashboard.html +0 -462
- package/assets/vanilla/templates/detail-page.html +0 -536
- package/assets/vanilla/templates/form-two-column.html +0 -438
- package/assets/vanilla/templates/kanban-board.html +0 -443
- package/assets/vanilla/templates/login.html +0 -199
- package/assets/vanilla/templates/product-detail.html +0 -335
- package/assets/vanilla/templates/settings.html +0 -374
- package/assets/vanilla/templates/shell-side-nav.html +0 -440
- package/assets/vanilla/templates/table-filter.html +0 -514
- package/clients/cli/commands/vanilla-html.test.mjs +0 -245
- package/foundation/discovery/bundled-component-docs.d.mts +0 -39
- package/foundation/discovery/bundled-component-docs.mjs +0 -92
package/api/docs/node/node.mjs
CHANGED
|
@@ -7,14 +7,18 @@
|
|
|
7
7
|
* typed doc such as `cli/api/functions/search`, plus {cwd}.
|
|
8
8
|
* @output { type: 'docs.node', data: DocsNode } — the node's identity, title
|
|
9
9
|
* and summary, the namespaces above it, and either its slots with their
|
|
10
|
-
* children (a namespace) or its content (a typed doc).
|
|
11
|
-
* lists its
|
|
12
|
-
*
|
|
10
|
+
* children (a namespace) or its content (a typed doc). By default a
|
|
11
|
+
* namespace lists its children one level down; a depth read goes as far
|
|
12
|
+
* down as asked, with each doc below as its identity (brief) or with its
|
|
13
|
+
* text (compact, full). Matches `astryx --json docs <route> [--depth <n>]`.
|
|
13
14
|
* @position Leaf under api/docs, beside the topic leaves. A guide the tree
|
|
14
15
|
* places is a topic: the detail leaf reads it by its route.
|
|
15
16
|
*/
|
|
16
17
|
|
|
18
|
+
import {detailView} from '../../../foundation/doc-compiler/lenses.mjs';
|
|
17
19
|
import {
|
|
20
|
+
compileTopic,
|
|
21
|
+
guideEntry,
|
|
18
22
|
nodeContent,
|
|
19
23
|
placeLinks,
|
|
20
24
|
resolveDocsArgument,
|
|
@@ -24,18 +28,34 @@ import {
|
|
|
24
28
|
/**
|
|
25
29
|
* @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
|
|
26
30
|
* @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
|
|
31
|
+
* @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
|
|
27
32
|
*/
|
|
28
33
|
|
|
29
34
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
35
|
+
* How far a read goes below the node it names, and how much of each doc below
|
|
36
|
+
* it shows: `depth` levels (Infinity for every level), and `detail` brief (its
|
|
37
|
+
* identity), or compact or full (with its text: a namespace's intro, a guide's
|
|
38
|
+
* sections, a typed doc's content). `lang` selects the guides' language.
|
|
39
|
+
* @typedef {object} DepthRead
|
|
40
|
+
* @property {number} depth
|
|
41
|
+
* @property {'brief' | 'compact' | 'full'} detail
|
|
42
|
+
* @property {string | null} lang
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The docs.node view of one tree node. Without a depth read, a namespace lists
|
|
47
|
+
* its children one level down.
|
|
48
|
+
* @param {DocsCatalog} catalog
|
|
32
49
|
* @param {DocsTree} tree
|
|
33
50
|
* @param {TreeNode} node
|
|
51
|
+
* @param {DepthRead} [read] how far down to go, and how much of each doc below
|
|
34
52
|
* @returns {Promise<import('../docs.type.mjs').DocsNode>}
|
|
35
53
|
*/
|
|
36
|
-
export async function nodeView(catalog, tree, node) {
|
|
54
|
+
export async function nodeView(catalog, tree, node, read) {
|
|
37
55
|
const {content} = await nodeContent(catalog, tree, node);
|
|
38
|
-
|
|
56
|
+
const slots = node.slots.filter(slot => slot.children.length > 0);
|
|
57
|
+
/** @type {import('../docs.type.mjs').DocsNode} */
|
|
58
|
+
const view = {
|
|
39
59
|
id: node.id,
|
|
40
60
|
route: node.route,
|
|
41
61
|
kind: node.kind,
|
|
@@ -45,25 +65,128 @@ export async function nodeView(catalog, tree, node) {
|
|
|
45
65
|
breadcrumb: tree
|
|
46
66
|
.ancestors(node)
|
|
47
67
|
.map(ancestor => ({route: ancestor.route, title: ancestor.title})),
|
|
48
|
-
slots:
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
title: child.title,
|
|
60
|
-
summary: child.summary,
|
|
61
|
-
};
|
|
62
|
-
}),
|
|
63
|
-
})),
|
|
68
|
+
slots: !read
|
|
69
|
+
? slots.map(slot => ({
|
|
70
|
+
name: slot.name,
|
|
71
|
+
title: slot.title,
|
|
72
|
+
children: slot.children.map(route =>
|
|
73
|
+
childIdentity(/** @type {TreeNode} */ (tree.get(route))),
|
|
74
|
+
),
|
|
75
|
+
}))
|
|
76
|
+
: read.depth >= 1
|
|
77
|
+
? await slotsBelow(catalog, tree, slots, 1, read)
|
|
78
|
+
: [],
|
|
64
79
|
content,
|
|
65
80
|
links: nodeLinks(tree, node),
|
|
66
81
|
};
|
|
82
|
+
if (read && read.depth < 1 && slots.length > 0) {
|
|
83
|
+
view.childCount = countChildren(slots);
|
|
84
|
+
}
|
|
85
|
+
return view;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The fields every child carries: what it is, and the route that opens it.
|
|
90
|
+
* @param {TreeNode} child
|
|
91
|
+
* @returns {import('../docs.type.mjs').DocsNodeChild}
|
|
92
|
+
*/
|
|
93
|
+
function childIdentity(child) {
|
|
94
|
+
return {
|
|
95
|
+
route: child.route,
|
|
96
|
+
name: child.route.slice(child.route.lastIndexOf('/') + 1),
|
|
97
|
+
kind: child.kind,
|
|
98
|
+
title: child.title,
|
|
99
|
+
summary: child.summary,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {TreeNode['slots']} slots
|
|
105
|
+
* @returns {number}
|
|
106
|
+
*/
|
|
107
|
+
function countChildren(slots) {
|
|
108
|
+
return slots.reduce((count, slot) => count + slot.children.length, 0);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Slots read `level` levels below the named node: each child at the read's
|
|
113
|
+
* detail, and its own slots while the read goes deeper.
|
|
114
|
+
* @param {DocsCatalog} catalog
|
|
115
|
+
* @param {DocsTree} tree
|
|
116
|
+
* @param {TreeNode['slots']} slots
|
|
117
|
+
* @param {number} level
|
|
118
|
+
* @param {DepthRead} read
|
|
119
|
+
* @returns {Promise<import('../docs.type.mjs').DocsNodeSlot[]>}
|
|
120
|
+
*/
|
|
121
|
+
async function slotsBelow(catalog, tree, slots, level, read) {
|
|
122
|
+
return Promise.all(
|
|
123
|
+
slots.map(async slot => ({
|
|
124
|
+
name: slot.name,
|
|
125
|
+
title: slot.title,
|
|
126
|
+
children: await Promise.all(
|
|
127
|
+
slot.children.map(route =>
|
|
128
|
+
childBelow(
|
|
129
|
+
catalog,
|
|
130
|
+
tree,
|
|
131
|
+
/** @type {TreeNode} */ (tree.get(route)),
|
|
132
|
+
level,
|
|
133
|
+
read,
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
})),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* One child of a depth read. Where the read stops, a child with docs below it
|
|
143
|
+
* says how many, so a reader knows to go deeper.
|
|
144
|
+
* @param {DocsCatalog} catalog
|
|
145
|
+
* @param {DocsTree} tree
|
|
146
|
+
* @param {TreeNode} child
|
|
147
|
+
* @param {number} level
|
|
148
|
+
* @param {DepthRead} read
|
|
149
|
+
* @returns {Promise<import('../docs.type.mjs').DocsNodeChild>}
|
|
150
|
+
*/
|
|
151
|
+
async function childBelow(catalog, tree, child, level, read) {
|
|
152
|
+
const view = childIdentity(child);
|
|
153
|
+
if (read.detail !== 'brief') {
|
|
154
|
+
Object.assign(view, await childText(catalog, tree, child, read.lang));
|
|
155
|
+
}
|
|
156
|
+
const slots = child.slots.filter(slot => slot.children.length > 0);
|
|
157
|
+
if (slots.length > 0) {
|
|
158
|
+
if (level < read.depth) {
|
|
159
|
+
view.slots = await slotsBelow(catalog, tree, slots, level + 1, read);
|
|
160
|
+
} else {
|
|
161
|
+
view.childCount = countChildren(slots);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return view;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A child's text: a guide's compiled sections, or the content of a namespace
|
|
169
|
+
* or typed doc.
|
|
170
|
+
* @param {DocsCatalog} catalog
|
|
171
|
+
* @param {DocsTree} tree
|
|
172
|
+
* @param {TreeNode} child
|
|
173
|
+
* @param {string | null} lang
|
|
174
|
+
* @returns {Promise<{content?: any[], sections?: any[]}>}
|
|
175
|
+
*/
|
|
176
|
+
async function childText(catalog, tree, child, lang) {
|
|
177
|
+
if (child.kind === 'generic') {
|
|
178
|
+
const entry = child.ref?.topicFile
|
|
179
|
+
? guideEntry(child)
|
|
180
|
+
: child.ref?.flatTopic
|
|
181
|
+
? catalog.resolve(child.ref.flatTopic)
|
|
182
|
+
: null;
|
|
183
|
+
if (!entry) return {};
|
|
184
|
+
return {
|
|
185
|
+
sections: detailView(await compileTopic(catalog, entry, lang)).sections,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const {content} = await nodeContent(catalog, tree, child);
|
|
189
|
+
return {content};
|
|
67
190
|
}
|
|
68
191
|
|
|
69
192
|
/**
|
package/api/hook/list/list.d.mts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
export function list({ cwd, category, detail, zh, lang, }?: {
|
|
14
14
|
cwd?: string | undefined;
|
|
15
15
|
category?: string | undefined;
|
|
16
|
-
detail?: "compact" | "full" | "
|
|
16
|
+
detail?: "compact" | "full" | "brief" | "names" | undefined;
|
|
17
17
|
zh?: boolean | undefined;
|
|
18
18
|
lang?: string | null | undefined;
|
|
19
19
|
}): Promise<import("../hook.type.mjs").HookListResponse>;
|
package/api/index.d.mts
CHANGED
|
@@ -2,14 +2,10 @@
|
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
4
|
export { component } from "./component/component.mjs";
|
|
5
|
-
export { componentHtml } from "./component/html/html.mjs";
|
|
6
|
-
export { componentWebComponents } from "./component/web-components/web-components.mjs";
|
|
7
5
|
export { docs } from "./docs/docs.mjs";
|
|
8
6
|
export { blog } from "./blog/blog.mjs";
|
|
9
7
|
export { discover } from "./discover/discover.mjs";
|
|
10
8
|
export { template } from "./template/template.mjs";
|
|
11
|
-
export { templateHtml } from "./template/html/html.mjs";
|
|
12
|
-
export { templateWebComponents } from "./template/web-components/web-components.mjs";
|
|
13
9
|
export { hook } from "./hook/hook.mjs";
|
|
14
10
|
export { search } from "./search/search.mjs";
|
|
15
11
|
export { build } from "./build/build.mjs";
|
|
@@ -24,14 +20,10 @@ export { AstryxError } from "./error.mjs";
|
|
|
24
20
|
export { logger } from "./logger.mjs";
|
|
25
21
|
export * from "../foundation/response/batch.type.mjs";
|
|
26
22
|
export * from "./component/component.type.mjs";
|
|
27
|
-
export * from "./component/html/html.type.mjs";
|
|
28
|
-
export * from "./component/web-components/web-components.type.mjs";
|
|
29
23
|
export * from "./docs/docs.type.mjs";
|
|
30
24
|
export * from "./blog/blog.type.mjs";
|
|
31
25
|
export * from "./discover/discover.type.mjs";
|
|
32
26
|
export * from "./template/template.type.mjs";
|
|
33
|
-
export * from "./template/html/html.type.mjs";
|
|
34
|
-
export * from "./template/web-components/web-components.type.mjs";
|
|
35
27
|
export * from "./theme/theme.type.mjs";
|
|
36
28
|
export * from "./hook/hook.type.mjs";
|
|
37
29
|
export * from "./search/search.type.mjs";
|
package/api/index.mjs
CHANGED
|
@@ -21,14 +21,10 @@
|
|
|
21
21
|
|
|
22
22
|
// ── Functions (runtime) ──────────────────────────────────────────────
|
|
23
23
|
export {component} from './component/component.mjs';
|
|
24
|
-
export {componentHtml} from './component/html/html.mjs';
|
|
25
|
-
export {componentWebComponents} from './component/web-components/web-components.mjs';
|
|
26
24
|
export {docs} from './docs/docs.mjs';
|
|
27
25
|
export {blog} from './blog/blog.mjs';
|
|
28
26
|
export {discover} from './discover/discover.mjs';
|
|
29
27
|
export {template} from './template/template.mjs';
|
|
30
|
-
export {templateHtml} from './template/html/html.mjs';
|
|
31
|
-
export {templateWebComponents} from './template/web-components/web-components.mjs';
|
|
32
28
|
export {
|
|
33
29
|
themeBuild,
|
|
34
30
|
themeAdd,
|
|
@@ -84,14 +80,10 @@ export {logger} from './logger.mjs';
|
|
|
84
80
|
// the shared receipt vocabulary and every command's Options + response types.
|
|
85
81
|
export * from '../foundation/response/batch.type.mjs';
|
|
86
82
|
export * from './component/component.type.mjs';
|
|
87
|
-
export * from './component/html/html.type.mjs';
|
|
88
|
-
export * from './component/web-components/web-components.type.mjs';
|
|
89
83
|
export * from './docs/docs.type.mjs';
|
|
90
84
|
export * from './blog/blog.type.mjs';
|
|
91
85
|
export * from './discover/discover.type.mjs';
|
|
92
86
|
export * from './template/template.type.mjs';
|
|
93
|
-
export * from './template/html/html.type.mjs';
|
|
94
|
-
export * from './template/web-components/web-components.type.mjs';
|
|
95
87
|
export * from './theme/theme.type.mjs';
|
|
96
88
|
export * from './hook/hook.type.mjs';
|
|
97
89
|
export * from './search/search.type.mjs';
|
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import * as fs from 'node:fs';
|
|
13
|
+
import {isBuiltin} from 'node:module';
|
|
13
14
|
import * as path from 'node:path';
|
|
14
15
|
import {AstryxError} from '../error.mjs';
|
|
16
|
+
import {CLI_ROOT} from '../../foundation/fs/paths.mjs';
|
|
15
17
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
16
18
|
import {
|
|
17
19
|
assertWithin,
|
|
@@ -21,6 +23,7 @@ import {
|
|
|
21
23
|
import {
|
|
22
24
|
discoverBundledThemes,
|
|
23
25
|
discoverThemeDirectory,
|
|
26
|
+
themeFileImports,
|
|
24
27
|
} from '../../foundation/discovery/theme-discovery.mjs';
|
|
25
28
|
import {
|
|
26
29
|
findLocalIntegrationManifestOrNull,
|
|
@@ -214,6 +217,77 @@ function escapeRegExp(s) {
|
|
|
214
217
|
return s.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
215
218
|
}
|
|
216
219
|
|
|
220
|
+
/** What every app that uses Astryx already has: Core, and React through Core's peers. */
|
|
221
|
+
const APP_PROVIDED = new Set(['@astryxdesign/core', 'react', 'react-dom']);
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The npm package a module specifier names, or null for a relative path, an
|
|
225
|
+
* absolute path, or a Node built-in.
|
|
226
|
+
* @param {string} specifier
|
|
227
|
+
* @returns {string | null}
|
|
228
|
+
*/
|
|
229
|
+
function packageOfSpecifier(specifier) {
|
|
230
|
+
if (specifier.startsWith('.') || specifier.startsWith('/')) return null;
|
|
231
|
+
if (isBuiltin(specifier)) return null;
|
|
232
|
+
const parts = specifier.split('/');
|
|
233
|
+
return specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The npm packages a fork's copied files import that its package does not
|
|
238
|
+
* declare yet, each at the range the bundled themes are built against (the
|
|
239
|
+
* CLI's own package.json). The fork depends on them at runtime, so an app that
|
|
240
|
+
* installs the package needs them too. Derived from the imports, not copied
|
|
241
|
+
* from a base's whole dependency list. Core and React are left out, since every
|
|
242
|
+
* Astryx app has them; so is a fork of the package's own theme, whose imports
|
|
243
|
+
* the package already resolves.
|
|
244
|
+
*
|
|
245
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} base
|
|
246
|
+
* @param {Record<string, any>} pkg - The package's package.json.
|
|
247
|
+
* @returns {Record<string, string>} package name to range
|
|
248
|
+
*/
|
|
249
|
+
function forkDependencies(base, pkg) {
|
|
250
|
+
if (!base.bundled) return {};
|
|
251
|
+
/** @type {Record<string, any>} */
|
|
252
|
+
let cli;
|
|
253
|
+
try {
|
|
254
|
+
cli = JSON.parse(
|
|
255
|
+
fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
|
|
256
|
+
);
|
|
257
|
+
} catch {
|
|
258
|
+
return {};
|
|
259
|
+
}
|
|
260
|
+
/** @type {Record<string, string>} */
|
|
261
|
+
const ranges = {
|
|
262
|
+
...cli.devDependencies,
|
|
263
|
+
...cli.peerDependencies,
|
|
264
|
+
...cli.dependencies,
|
|
265
|
+
};
|
|
266
|
+
const declared = {
|
|
267
|
+
...pkg.devDependencies,
|
|
268
|
+
...pkg.peerDependencies,
|
|
269
|
+
...pkg.dependencies,
|
|
270
|
+
};
|
|
271
|
+
/** @type {Record<string, string>} */
|
|
272
|
+
const needed = {};
|
|
273
|
+
for (const file of base.files) {
|
|
274
|
+
const code = /\.(?:[cm]?[jt]sx?)$/u.test(file);
|
|
275
|
+
if (!code || file.endsWith('.doc.mjs')) continue;
|
|
276
|
+
let specifiers;
|
|
277
|
+
try {
|
|
278
|
+
specifiers = themeFileImports(path.join(base.sourceDir, file));
|
|
279
|
+
} catch {
|
|
280
|
+
continue; // discovery already refuses a theme whose source does not parse
|
|
281
|
+
}
|
|
282
|
+
for (const specifier of specifiers) {
|
|
283
|
+
const name = packageOfSpecifier(specifier);
|
|
284
|
+
if (name == null || APP_PROVIDED.has(name) || name in declared) continue;
|
|
285
|
+
if (typeof ranges[name] === 'string') needed[name] = ranges[name];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return needed;
|
|
289
|
+
}
|
|
290
|
+
|
|
217
291
|
/**
|
|
218
292
|
* Build the write plans for a forked theme.
|
|
219
293
|
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} base
|
|
@@ -467,11 +541,27 @@ export async function integrationAddTheme(name, options = {}) {
|
|
|
467
541
|
packageUpdate?.expectedOriginal ?? fs.readFileSync(packageFile);
|
|
468
542
|
const text = packageUpdate?.contents ?? expectedOriginal.toString('utf-8');
|
|
469
543
|
const current = JSON.parse(text);
|
|
470
|
-
|
|
544
|
+
let next =
|
|
545
|
+
themesCliProblem(current) != null
|
|
546
|
+
? withCliPeer(current, THEMES_CLI)
|
|
547
|
+
: current;
|
|
548
|
+
// A fork runs the base's imports: declare the packages they come from.
|
|
549
|
+
const forked = baseTheme ? forkDependencies(baseTheme, next) : {};
|
|
550
|
+
if (Object.keys(forked).length > 0) {
|
|
551
|
+
const dependencies = {...next.dependencies, ...forked};
|
|
552
|
+
next = {
|
|
553
|
+
...next,
|
|
554
|
+
dependencies: Object.fromEntries(
|
|
555
|
+
Object.keys(dependencies)
|
|
556
|
+
.sort()
|
|
557
|
+
.map(name => [name, dependencies[name]]),
|
|
558
|
+
),
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
if (next !== current) {
|
|
471
562
|
packageUpdate = {
|
|
472
563
|
contents:
|
|
473
|
-
JSON.stringify(
|
|
474
|
-
(text.endsWith('\n') ? '\n' : ''),
|
|
564
|
+
JSON.stringify(next, null, 2) + (text.endsWith('\n') ? '\n' : ''),
|
|
475
565
|
expectedOriginal,
|
|
476
566
|
};
|
|
477
567
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
4
|
+
import {execFileSync} from 'node:child_process';
|
|
4
5
|
import * as fs from 'node:fs';
|
|
5
6
|
import * as path from 'node:path';
|
|
7
|
+
import {CLI_ROOT, findInstalledPackage} from '../../foundation/fs/paths.mjs';
|
|
6
8
|
import {integrationAddTheme} from './add-theme.mjs';
|
|
7
9
|
import {validateLocalIntegration} from './validate-integration.mjs';
|
|
8
10
|
|
|
@@ -473,6 +475,104 @@ describe('integrationAddTheme --from', () => {
|
|
|
473
475
|
).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
|
|
474
476
|
});
|
|
475
477
|
|
|
478
|
+
it('declares the npm packages the forked files import, at the range the bundled themes use', async () => {
|
|
479
|
+
setup({includeFiles: false});
|
|
480
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
481
|
+
const pkg = JSON.parse(
|
|
482
|
+
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
483
|
+
);
|
|
484
|
+
const cli = JSON.parse(
|
|
485
|
+
fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
|
|
486
|
+
);
|
|
487
|
+
// The copied icons.tsx imports lucide-react; Core and React are every
|
|
488
|
+
// app's own, so the fork does not declare them.
|
|
489
|
+
expect(pkg.dependencies).toEqual({
|
|
490
|
+
'lucide-react': cli.devDependencies['lucide-react'],
|
|
491
|
+
});
|
|
492
|
+
expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('keeps a dependency the package already declares', async () => {
|
|
496
|
+
setup({includeFiles: false});
|
|
497
|
+
const file = path.join(tmpDir, 'package.json');
|
|
498
|
+
const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
499
|
+
fs.writeFileSync(
|
|
500
|
+
file,
|
|
501
|
+
`${JSON.stringify({...pkg, dependencies: {'lucide-react': '^1.0.0'}}, null, 2)}\n`,
|
|
502
|
+
);
|
|
503
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
504
|
+
expect(JSON.parse(fs.readFileSync(file, 'utf-8')).dependencies).toEqual({
|
|
505
|
+
'lucide-react': '^1.0.0',
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it('declares nothing for a fork of a theme the package owns', async () => {
|
|
510
|
+
setup({includeFiles: false});
|
|
511
|
+
await integrationAddTheme('base', {cwd: tmpDir});
|
|
512
|
+
await integrationAddTheme('variant', {cwd: tmpDir, from: 'base'});
|
|
513
|
+
const pkg = JSON.parse(
|
|
514
|
+
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
515
|
+
);
|
|
516
|
+
expect(pkg.dependencies).toBeUndefined();
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it('builds a forked neutral theme once the package installs what --from declared', async () => {
|
|
520
|
+
setup({includeFiles: false});
|
|
521
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
522
|
+
const pkg = JSON.parse(
|
|
523
|
+
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
524
|
+
);
|
|
525
|
+
// Install exactly what the package declares, plus what every Astryx
|
|
526
|
+
// project has: Core and React.
|
|
527
|
+
for (const name of [
|
|
528
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
529
|
+
'@astryxdesign/core',
|
|
530
|
+
'react',
|
|
531
|
+
]) {
|
|
532
|
+
const installed = findInstalledPackage(CLI_ROOT, name);
|
|
533
|
+
expect(installed, name).not.toBeNull();
|
|
534
|
+
const link = path.join(tmpDir, 'node_modules', ...name.split('/'));
|
|
535
|
+
fs.mkdirSync(path.dirname(link), {recursive: true});
|
|
536
|
+
fs.symlinkSync(
|
|
537
|
+
fs.realpathSync(/** @type {string} */ (installed)),
|
|
538
|
+
link,
|
|
539
|
+
'dir',
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
// A separate process without NODE_PATH, so only what the package
|
|
543
|
+
// installed can resolve.
|
|
544
|
+
let status = 0;
|
|
545
|
+
let output = '';
|
|
546
|
+
try {
|
|
547
|
+
execFileSync(
|
|
548
|
+
process.execPath,
|
|
549
|
+
[
|
|
550
|
+
path.join(CLI_ROOT, 'clients/cli/bin/astryx.mjs'),
|
|
551
|
+
'theme',
|
|
552
|
+
'build',
|
|
553
|
+
'themes/ocean/oceanTheme.ts',
|
|
554
|
+
],
|
|
555
|
+
{
|
|
556
|
+
cwd: tmpDir,
|
|
557
|
+
env: {...process.env, NODE_PATH: ''},
|
|
558
|
+
encoding: 'utf-8',
|
|
559
|
+
stdio: 'pipe',
|
|
560
|
+
},
|
|
561
|
+
);
|
|
562
|
+
} catch (error) {
|
|
563
|
+
const failure = /** @type {any} */ (error);
|
|
564
|
+
status = failure.status ?? 1;
|
|
565
|
+
output = `${failure.stdout ?? ''}${failure.stderr ?? ''}`;
|
|
566
|
+
}
|
|
567
|
+
expect({status, output: status === 0 ? '' : output}).toEqual({
|
|
568
|
+
status: 0,
|
|
569
|
+
output: '',
|
|
570
|
+
});
|
|
571
|
+
expect(fs.existsSync(path.join(tmpDir, 'themes/ocean/ocean.css'))).toBe(
|
|
572
|
+
true,
|
|
573
|
+
);
|
|
574
|
+
});
|
|
575
|
+
|
|
476
576
|
it('works with different bundled themes', async () => {
|
|
477
577
|
setup();
|
|
478
578
|
const result = await integrationAddTheme('dusk', {
|
|
@@ -37,7 +37,7 @@ export const doc = {
|
|
|
37
37
|
name: 'options.from',
|
|
38
38
|
type: 'string',
|
|
39
39
|
description:
|
|
40
|
-
'Slug of an existing theme to fork as the starting point. The new theme copies the base and has no link back.',
|
|
40
|
+
'Slug of an existing theme to fork as the starting point. The new theme copies the base and has no link back, and package.json `dependencies` gains the npm packages the copied files import (other than Core and React).',
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
returns: [
|
package/api/search/search.d.mts
CHANGED
|
@@ -66,6 +66,7 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
66
66
|
* @param {string} term - Lowercased search term.
|
|
67
67
|
* @param {object} candidate
|
|
68
68
|
* @param {string} candidate.name - Primary identifier (component/hook name, topic, template name).
|
|
69
|
+
* @param {string[]} [candidate.aliases] - Other names, scored like the name (a theme's display name).
|
|
69
70
|
* @param {string} [candidate.domain] - A component, hook, or template name
|
|
70
71
|
* also matches typed as words: `command palette` is CommandPalette.
|
|
71
72
|
* @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
|
|
@@ -76,8 +77,9 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
76
77
|
* @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
|
|
77
78
|
* @returns {{score: number, reason: string} | null}
|
|
78
79
|
*/
|
|
79
|
-
export function scoreCandidate(term: string, { name, domain, keywords, weakKeywords, description, prose, guidance, }: {
|
|
80
|
+
export function scoreCandidate(term: string, { name, aliases, domain, keywords, weakKeywords, description, prose, guidance, }: {
|
|
80
81
|
name: string;
|
|
82
|
+
aliases?: string[] | undefined;
|
|
81
83
|
domain?: string | undefined;
|
|
82
84
|
keywords?: string[] | undefined;
|
|
83
85
|
weakKeywords?: string[] | undefined;
|
|
@@ -161,6 +163,11 @@ export const STOPWORDS: Set<string>;
|
|
|
161
163
|
export type Candidate = {
|
|
162
164
|
domain: "component" | "hook" | "doc" | "template" | "theme";
|
|
163
165
|
name: string;
|
|
166
|
+
/**
|
|
167
|
+
* - Other names the candidate answers to, scored
|
|
168
|
+
* with the same name signals: a theme's display name.
|
|
169
|
+
*/
|
|
170
|
+
aliases?: string[] | undefined;
|
|
164
171
|
keywords?: string[] | undefined;
|
|
165
172
|
weakKeywords?: string[] | undefined;
|
|
166
173
|
description?: string | undefined;
|
|
@@ -48,14 +48,14 @@ export const doc = {
|
|
|
48
48
|
name: 'options.cwd',
|
|
49
49
|
type: 'string',
|
|
50
50
|
description:
|
|
51
|
-
"Directory to resolve @astryxdesign/core from. A docs-only or themes-only search (`type: 'doc'` or `type: 'theme'`) does not need it
|
|
51
|
+
"Directory to resolve @astryxdesign/core from. A docs-only or themes-only search (`type: 'doc'` or `type: 'theme'`) does not need it, and a search with no `type` covers the docs and themes alone when core is missing.",
|
|
52
52
|
},
|
|
53
53
|
],
|
|
54
54
|
returns: [
|
|
55
55
|
{
|
|
56
56
|
type: 'search',
|
|
57
57
|
description:
|
|
58
|
-
'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit`: each has domain, name, score, reason, description, and follow-up command, plus `import` for components and hooks, `title` for docs, `displayName` and `kind` for templates, and `displayName` for themes.
|
|
58
|
+
'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit`: each has domain, name, score, reason, description, and follow-up command, plus `import` for components and hooks, `title` for docs, `displayName` and `kind` for templates, and `displayName` for themes. A doc result is the smallest part that answers: one section (with `section`, and a command that reads only it), one docs-tree route, or a topic, whose command lists its sections. `parent` is the command that opens the level above it: the section list of its topic, the namespace a tree node sits in, the Unorganized level for a flat topic, or the topic list for a top-level namespace. Every doc result also carries `package`, the npm package that authored it (for a section, the package its file came from). A theme result is one theme you can add: `name` is its slug, its command is the `astryx theme add` that copies it into the app, and `package` is the npm package that ships it (`@astryxdesign/cli` for the CLI\'s own themes).',
|
|
59
59
|
},
|
|
60
60
|
],
|
|
61
61
|
throws: [
|
|
@@ -65,7 +65,7 @@ export const doc = {
|
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
code: 'ERR_CORE_NOT_FOUND',
|
|
68
|
-
when: '@astryxdesign/core cannot be found from the cwd, and `type` names a
|
|
68
|
+
when: '@astryxdesign/core cannot be found from the cwd, and `type` names a domain that reads it: `component`, `hook`, or `template`',
|
|
69
69
|
},
|
|
70
70
|
],
|
|
71
71
|
examples: [
|