@astryxdesign/cli 0.7.15-canary.gf890983 → 0.7.15
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 +353 -3
- package/api/doctor/_adapter.d.mts +2 -1
- package/api/doctor/_adapter.mjs +6 -1
- package/api/doctor/doctor.mjs +2 -2
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +363 -50
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +25 -1
- package/api/theme/build/build.mjs +352 -41
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.mjs +10 -3
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +2 -2
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.mjs +157 -36
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +3 -1
- package/api/theme-edit/_check.mjs +733 -308
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +277 -33
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +25 -0
- package/api/theme-edit/_context.d.mts +2 -0
- package/api/theme-edit/_context.mjs +83 -9
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.mjs +370 -85
- package/api/theme-edit/_how-commands.d.mts +5 -0
- package/api/theme-edit/_how-commands.mjs +20 -13
- package/api/theme-edit/_how-question.d.mts +29 -0
- package/api/theme-edit/_how-question.mjs +1573 -182
- package/api/theme-edit/_how.mjs +306 -22
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +27 -5
- package/api/theme-edit/_palette.mjs +231 -97
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +224 -69
- package/api/theme-edit/_preview-app.d.mts +8 -0
- package/api/theme-edit/_preview-app.mjs +549 -96
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +77 -84
- package/api/theme-edit/_project.d.mts +20 -1
- package/api/theme-edit/_project.mjs +43 -13
- package/api/theme-edit/_settings.d.mts +96 -20
- package/api/theme-edit/_settings.mjs +646 -141
- package/api/theme-edit/_tables.d.mts +18 -12
- package/api/theme-edit/_tables.mjs +144 -147
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +3 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +22 -3
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +325 -48
- package/clients/cli/index.mjs +18 -3
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/template-needs.d.mts +13 -0
- package/foundation/discovery/template-needs.mjs +30 -15
- package/foundation/discovery/theme-discovery.mjs +14 -2
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/doc-compiler/import.mjs +10 -4
- package/foundation/fs/gather-cache.mjs +82 -23
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +7 -2
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/release/cache.d.mts +21 -2
- package/foundation/release/cache.mjs +48 -8
- package/foundation/release/folder-lock.d.mts +7 -0
- package/foundation/release/folder-lock.mjs +60 -26
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +4 -4
- package/package.json +6 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -17,25 +17,21 @@
|
|
|
17
17
|
|
|
18
18
|
import * as fs from 'node:fs';
|
|
19
19
|
import * as path from 'node:path';
|
|
20
|
-
import {
|
|
20
|
+
import {createRequire} from 'node:module';
|
|
21
21
|
import {AstryxError} from '../error.mjs';
|
|
22
22
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
23
|
-
import {importPathOf, installLine} from './_project.mjs';
|
|
23
|
+
import {importPathOf, installLine, literals} from './_project.mjs';
|
|
24
|
+
import {removeEmptyFolder} from './_palette.mjs';
|
|
25
|
+
import {VOID} from '../../foundation/render/html-reader.mjs';
|
|
24
26
|
import {
|
|
25
27
|
RENDER_TIMEOUT_MS,
|
|
26
28
|
renderPage,
|
|
27
29
|
RenderError,
|
|
28
30
|
} from '../../foundation/render/render-page.mjs';
|
|
29
|
-
import {
|
|
30
|
-
EXTRA,
|
|
31
|
-
OPEN_OVERLAYS,
|
|
32
|
-
SAMPLE_PAGE,
|
|
33
|
-
elementNames,
|
|
34
|
-
pageSource,
|
|
35
|
-
} from './_catalog.mjs';
|
|
31
|
+
import {SAMPLE_PAGE, elementNames, pageSource} from './_catalog.mjs';
|
|
36
32
|
|
|
37
33
|
/** Bump when the shape of the cached part data changes. */
|
|
38
|
-
const PART_DATA_VERSION =
|
|
34
|
+
const PART_DATA_VERSION = 4;
|
|
39
35
|
|
|
40
36
|
/**
|
|
41
37
|
* @typedef {object} PartRecord
|
|
@@ -52,33 +48,193 @@ const PART_DATA_VERSION = 3;
|
|
|
52
48
|
*/
|
|
53
49
|
|
|
54
50
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
51
|
+
* A sample value for a required prop the doc declares, from its type: the
|
|
52
|
+
* component's name for text, false for a flag, the first value of a union.
|
|
53
|
+
* Undefined for a type with no plain sample, such as a function.
|
|
54
|
+
* @param {string} name
|
|
55
|
+
* @param {string} type
|
|
56
|
+
* @returns {unknown}
|
|
57
|
+
*/
|
|
58
|
+
function sampleOf(name, type) {
|
|
59
|
+
if (type.includes('=>')) return undefined;
|
|
60
|
+
// Null and undefined are the absence of a value, never a sample.
|
|
61
|
+
const t = type
|
|
62
|
+
.split('|')
|
|
63
|
+
.map(x => x.trim())
|
|
64
|
+
.filter(x => x !== 'null' && x !== 'undefined')
|
|
65
|
+
.join(' | ');
|
|
66
|
+
if (t === 'string' || /ReactNode$/.test(t)) return name;
|
|
67
|
+
if (t === 'boolean') return false;
|
|
68
|
+
if (t === 'number') return 1;
|
|
69
|
+
const words = literals(t);
|
|
70
|
+
if (words.length) return words[0];
|
|
71
|
+
if (/^\d+(\s*\|\s*\d+)*$/.test(t)) return Number(t.split('|')[0]);
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Three items made from the element the doc suggests for a group's
|
|
77
|
+
* children, each with its own label and value; the first takes the group's
|
|
78
|
+
* value, so it shows selected.
|
|
79
|
+
* @param {{__element: string, props?: Record<string, unknown>, children?: unknown}} slot
|
|
80
|
+
* @param {unknown} selected
|
|
81
|
+
*/
|
|
82
|
+
function slotItems(slot, selected) {
|
|
83
|
+
return [1, 2, 3].map(i => {
|
|
84
|
+
const props = {...(slot.props ?? {})};
|
|
85
|
+
if (typeof props.label === 'string') props.label = `${props.label} ${i}`;
|
|
86
|
+
if ('value' in props || typeof selected === 'string')
|
|
87
|
+
props.value =
|
|
88
|
+
i === 1 && typeof selected === 'string'
|
|
89
|
+
? selected
|
|
90
|
+
: `${String(props.value ?? 'item')}-${i}`;
|
|
91
|
+
return {...slot, props};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The props a component renders with: its doc's playground defaults, or,
|
|
97
|
+
* for a doc with none (an older Core), a sample for each required prop.
|
|
98
|
+
* A group with no children gets three of the items its doc suggests. Null
|
|
99
|
+
* for a doc with no defaults that has no theming targets (a hook or a
|
|
100
|
+
* helper), or that is a part its parent lists as an item: it works only
|
|
101
|
+
* inside the parent, whose own entry shows it.
|
|
102
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
103
|
+
* @param {string} name
|
|
104
|
+
* @returns {Record<string, unknown> | null}
|
|
105
|
+
*/
|
|
106
|
+
export function demoProps(project, name) {
|
|
107
|
+
const info = project.components[name];
|
|
108
|
+
const given =
|
|
109
|
+
info.defaults && typeof info.defaults === 'object'
|
|
110
|
+
? /** @type {Record<string, unknown>} */ ({...info.defaults})
|
|
111
|
+
: null;
|
|
112
|
+
if (
|
|
113
|
+
!given &&
|
|
114
|
+
// Only a component a theme styles: hooks, providers and helpers have
|
|
115
|
+
// docs too, and render nothing.
|
|
116
|
+
(!/^[A-Z]/.test(name) ||
|
|
117
|
+
!info.targets.length ||
|
|
118
|
+
// A doc that declares no props of its own name is a family page,
|
|
119
|
+
// not a component the Core exports.
|
|
120
|
+
!Object.keys(info.props ?? {}).length ||
|
|
121
|
+
(info.subComponentOf && isItemOf(project, name)))
|
|
122
|
+
)
|
|
123
|
+
return null;
|
|
124
|
+
const props = given ?? {};
|
|
125
|
+
if (!given)
|
|
126
|
+
for (const [p, d] of Object.entries(info.props ?? {})) {
|
|
127
|
+
if (!d.required || /^on[A-Z]/.test(p)) continue;
|
|
128
|
+
if (p === 'children' && d.slots.length) continue;
|
|
129
|
+
const v = sampleOf(name, d.type);
|
|
130
|
+
// A required prop with no plain sample, such as a render function:
|
|
131
|
+
// the component cannot be shown from its doc alone.
|
|
132
|
+
if (v === undefined) return null;
|
|
133
|
+
props[p] = v;
|
|
134
|
+
}
|
|
135
|
+
const kids = info.props?.children;
|
|
136
|
+
const slot = kids?.slots?.[0];
|
|
137
|
+
if (!('children' in props) && kids) {
|
|
138
|
+
if (slot?.__element && (kids.required || slot.__element.startsWith(name))) {
|
|
139
|
+
if (info.props.value && !('value' in props) && slot.props?.value != null)
|
|
140
|
+
props.value = `${String(slot.props.value)}-1`;
|
|
141
|
+
props.children = slotItems(slot, props.value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return props;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Whether a part's parent lists it as an item of its children.
|
|
149
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
150
|
+
* @param {string} name
|
|
151
|
+
*/
|
|
152
|
+
export function isItemOf(project, name) {
|
|
153
|
+
const parent = project.components[name]?.subComponentOf;
|
|
154
|
+
const slots = parent
|
|
155
|
+
? (project.components[parent]?.props?.children?.slots ?? [])
|
|
156
|
+
: [];
|
|
157
|
+
return slots.some(s => s?.__element === name);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* A component's catalog entries, all from its doc: its demo props
|
|
162
|
+
* ({@link demoProps}), then once per value of each visual prop with a
|
|
163
|
+
* closed set of values (`variant`, `status`, `color`, and a number union
|
|
164
|
+
* such as a heading's level), and its checked and disabled states. An
|
|
165
|
+
* overlay the playground shows in place renders open; on a page people
|
|
166
|
+
* see, once, as some of its variants size the window, not the card.
|
|
167
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
168
|
+
* @param {string} name
|
|
169
|
+
* @param {number} cap at most this many
|
|
170
|
+
* @param {{shown?: boolean}} [opts] `shown`: for a page people see
|
|
171
|
+
* @returns {Array<{label: string, props: Record<string, unknown>}>}
|
|
172
|
+
*/
|
|
173
|
+
export function catalogVariants(project, name, cap, opts = {}) {
|
|
174
|
+
const info = project.components[name];
|
|
175
|
+
const demo = demoProps(project, name);
|
|
176
|
+
if (!demo) return [];
|
|
177
|
+
if (info.opens && opts.shown)
|
|
178
|
+
return [
|
|
179
|
+
{label: '', props: 'isOpen' in demo ? demo : {...demo, isOpen: true}},
|
|
180
|
+
];
|
|
181
|
+
const base =
|
|
182
|
+
info.opens && !('isOpen' in demo) ? {...demo, isOpen: true} : demo;
|
|
183
|
+
const values = info.targets[0]?.values ?? {};
|
|
184
|
+
const variants = [{label: '', props: base}];
|
|
185
|
+
for (const p of ['variant', 'status', 'color'])
|
|
186
|
+
for (const v of values[p] ?? [])
|
|
187
|
+
variants.push({
|
|
188
|
+
label: v,
|
|
189
|
+
// A status like `{type: 'error', message?: string}` takes the
|
|
190
|
+
// value as its `type`; the bare string breaks the component.
|
|
191
|
+
props: {
|
|
192
|
+
...base,
|
|
193
|
+
[p]: info.props?.[p]?.type.startsWith('{') ? {type: v} : v,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
// The states the doc names that a prop sets: checked (a boolean value)
|
|
197
|
+
// and disabled. The label says the state shown.
|
|
198
|
+
const states = new Set(info.targets.flatMap(t => t.states ?? []));
|
|
199
|
+
if (states.has('checked') && info.props?.value?.type.startsWith('boolean')) {
|
|
200
|
+
const on = base.value !== true;
|
|
201
|
+
variants.push({
|
|
202
|
+
label: on ? 'on' : 'off',
|
|
203
|
+
props: {
|
|
204
|
+
...base,
|
|
205
|
+
value: on,
|
|
206
|
+
...(typeof base.label === 'string' ? {label: on ? 'On' : 'Off'} : {}),
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (states.has('disabled') && info.props?.isDisabled)
|
|
211
|
+
variants.push({label: 'disabled', props: {...base, isDisabled: true}});
|
|
212
|
+
for (const p of Object.keys(values)) {
|
|
213
|
+
const type = info.props?.[p]?.type ?? '';
|
|
214
|
+
if (!/^\s*\d+(\s*\|\s*\d+)*\s*$/.test(type)) continue;
|
|
215
|
+
for (const n of type.split('|').map(Number))
|
|
216
|
+
if (n !== base[p])
|
|
217
|
+
variants.push({label: `${p} ${n}`, props: {...base, [p]: n}});
|
|
218
|
+
}
|
|
219
|
+
return variants.slice(0, cap);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The catalog: each component with playground defaults, once per visual
|
|
224
|
+
* variant value ({@link catalogVariants}), and the sample page.
|
|
57
225
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
58
226
|
* @returns {{items: import('./_catalog.mjs').CatalogItem[], imports: Record<string, string>}}
|
|
59
227
|
*/
|
|
60
228
|
export function catalogItems(project) {
|
|
61
229
|
/** @type {import('./_catalog.mjs').CatalogItem[]} */
|
|
62
230
|
const items = [];
|
|
63
|
-
for (const
|
|
64
|
-
const
|
|
65
|
-
if (!defaults || typeof defaults !== 'object') continue;
|
|
66
|
-
const values = info.targets[0]?.values ?? {};
|
|
67
|
-
/** @type {Array<Record<string, string>>} */
|
|
68
|
-
const variants = [{}];
|
|
69
|
-
for (const p of ['variant', 'status', 'color'])
|
|
70
|
-
for (const v of values[p] ?? []) variants.push({[p]: v});
|
|
71
|
-
for (const v of variants.slice(0, 16)) {
|
|
72
|
-
const label = Object.values(v).join(' ');
|
|
231
|
+
for (const name of Object.keys(project.components))
|
|
232
|
+
for (const v of catalogVariants(project, name, 16))
|
|
73
233
|
items.push({
|
|
74
234
|
name,
|
|
75
|
-
label,
|
|
76
|
-
tree: {__element: name, props:
|
|
235
|
+
label: v.label,
|
|
236
|
+
tree: {__element: name, props: v.props},
|
|
77
237
|
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
for (const [name, list] of [...EXTRA, ...OPEN_OVERLAYS])
|
|
81
|
-
for (const [label, tree] of list) items.push({name, label, tree});
|
|
82
238
|
/** @type {Record<string, string>} */
|
|
83
239
|
const imports = {};
|
|
84
240
|
for (const n of elementNames([items.map(i => i.tree), SAMPLE_PAGE])) {
|
|
@@ -88,6 +244,24 @@ export function catalogItems(project) {
|
|
|
88
244
|
return {items, imports};
|
|
89
245
|
}
|
|
90
246
|
|
|
247
|
+
/**
|
|
248
|
+
* What of React the project cannot resolve (react, react-dom/server), to
|
|
249
|
+
* render the editor's pages; empty when both resolve.
|
|
250
|
+
* @param {string} cwd
|
|
251
|
+
* @returns {string[]}
|
|
252
|
+
*/
|
|
253
|
+
export function reactMissing(cwd) {
|
|
254
|
+
const req = createRequire(path.join(cwd, 'package.json'));
|
|
255
|
+
return ['react', 'react-dom/server'].filter(m => {
|
|
256
|
+
try {
|
|
257
|
+
req.resolve(m);
|
|
258
|
+
return false;
|
|
259
|
+
} catch {
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
91
265
|
/** How long the editor's own pages may take to render. */
|
|
92
266
|
const EDITOR_RENDER_MS = 3 * RENDER_TIMEOUT_MS;
|
|
93
267
|
|
|
@@ -106,8 +280,8 @@ export const renderDir = project =>
|
|
|
106
280
|
|
|
107
281
|
/**
|
|
108
282
|
* Remove render folders a stopped command left (killed, out of memory):
|
|
109
|
-
* only `.astryx-render-<pid>-<random>` folders
|
|
110
|
-
* are never followed.
|
|
283
|
+
* only `.astryx-render-<pid>-<random>` folders more than ten minutes old.
|
|
284
|
+
* Links are never followed.
|
|
111
285
|
* @param {string} themes
|
|
112
286
|
*/
|
|
113
287
|
function sweepRenders(themes) {
|
|
@@ -120,8 +294,18 @@ function sweepRenders(themes) {
|
|
|
120
294
|
for (const n of names) {
|
|
121
295
|
const m = /^\.astryx-render-(\d+)-[a-z0-9]+$/.exec(n);
|
|
122
296
|
if (!m || Number(m[1]) === process.pid) continue;
|
|
123
|
-
if (isAlive(Number(m[1]))) continue;
|
|
124
297
|
const p = path.join(themes, n);
|
|
298
|
+
// A process id from another process space may look gone or alive here,
|
|
299
|
+
// so age decides: a render takes at most three minutes, and a folder
|
|
300
|
+
// older than ten is a leftover.
|
|
301
|
+
/** @type {number} */
|
|
302
|
+
let age;
|
|
303
|
+
try {
|
|
304
|
+
age = Date.now() - fs.lstatSync(p).mtimeMs;
|
|
305
|
+
} catch {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (age < 10 * 60_000) continue;
|
|
125
309
|
try {
|
|
126
310
|
if (fs.lstatSync(p).isDirectory())
|
|
127
311
|
fs.rmSync(p, {recursive: true, force: true});
|
|
@@ -165,7 +349,12 @@ export async function renderGenerated(project, file, source, extra = []) {
|
|
|
165
349
|
process.once('SIGINT', onSignal);
|
|
166
350
|
process.once('SIGTERM', onSignal);
|
|
167
351
|
const entry = path.join(dir, file);
|
|
168
|
-
|
|
352
|
+
// Demo images point at the docs site's own folder (`/template-assets/…`),
|
|
353
|
+
// which a page opened from disk cannot reach: the inline placeholder
|
|
354
|
+
// takes their place, as when a template is scaffolded.
|
|
355
|
+
const {stripTemplateAssetRefs} =
|
|
356
|
+
await import('../../foundation/discovery/template-adapter.mjs');
|
|
357
|
+
fs.writeFileSync(entry, stripTemplateAssetRefs(source));
|
|
169
358
|
for (const x of extra) {
|
|
170
359
|
fs.mkdirSync(path.dirname(path.join(dir, x.name)), {recursive: true});
|
|
171
360
|
fs.copyFileSync(x.from, path.join(dir, x.name));
|
|
@@ -191,7 +380,7 @@ export async function renderGenerated(project, file, source, extra = []) {
|
|
|
191
380
|
const slow = e.code === 'ERR_RENDER_TIMEOUT';
|
|
192
381
|
throw new AstryxError(
|
|
193
382
|
slow
|
|
194
|
-
? `The components did not finish rendering within ${EDITOR_RENDER_MS / 1000} seconds, so the render was stopped. The machine may be busy: run
|
|
383
|
+
? `The components did not finish rendering within ${EDITOR_RENDER_MS / 1000} seconds, so the render was stopped. The theme files are written; only its pages were not rendered. The machine may be busy: run show again when it is less loaded.`
|
|
195
384
|
: `Could not render the components with this project's React: ${e.message}${missing ? ' The theme command renders components on the server, so react and react-dom must be installed.' : ''}`,
|
|
196
385
|
missing
|
|
197
386
|
? [
|
|
@@ -212,7 +401,8 @@ export async function renderGenerated(project, file, source, extra = []) {
|
|
|
212
401
|
// it, so a render running beside this one keeps its own.
|
|
213
402
|
for (const f of [entry, ...extra.map(x => path.join(dir, x.name))])
|
|
214
403
|
fs.rmSync(f, {force: true});
|
|
215
|
-
|
|
404
|
+
// Another render may still use it: a folder with a file in it stays.
|
|
405
|
+
removeEmptyFolder(madeThemes ? themes : dir, {deep: true});
|
|
216
406
|
process.removeListener('SIGINT', onSignal);
|
|
217
407
|
process.removeListener('SIGTERM', onSignal);
|
|
218
408
|
}
|
|
@@ -221,21 +411,6 @@ export async function renderGenerated(project, file, source, extra = []) {
|
|
|
221
411
|
/** @param {unknown} v @returns {v is Record<string, unknown>} */
|
|
222
412
|
const isRecord = v => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
223
413
|
|
|
224
|
-
/**
|
|
225
|
-
* Remove `dir` and the folders under it when no file is left in them.
|
|
226
|
-
* @param {string} dir
|
|
227
|
-
*/
|
|
228
|
-
function removeEmpty(dir) {
|
|
229
|
-
if (!fs.existsSync(dir)) return;
|
|
230
|
-
for (const e of fs.readdirSync(dir, {withFileTypes: true}))
|
|
231
|
-
if (e.isDirectory()) removeEmpty(path.join(dir, e.name));
|
|
232
|
-
try {
|
|
233
|
-
fs.rmdirSync(dir);
|
|
234
|
-
} catch {
|
|
235
|
-
// Not empty: another render is using it.
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
414
|
/**
|
|
240
415
|
* The part data for the installed Core, from the cache or built now.
|
|
241
416
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
@@ -336,22 +511,6 @@ export function declarations(css) {
|
|
|
336
511
|
return decls;
|
|
337
512
|
}
|
|
338
513
|
|
|
339
|
-
const VOID = new Set([
|
|
340
|
-
'area',
|
|
341
|
-
'base',
|
|
342
|
-
'br',
|
|
343
|
-
'col',
|
|
344
|
-
'embed',
|
|
345
|
-
'hr',
|
|
346
|
-
'img',
|
|
347
|
-
'input',
|
|
348
|
-
'link',
|
|
349
|
-
'meta',
|
|
350
|
-
'source',
|
|
351
|
-
'track',
|
|
352
|
-
'wbr',
|
|
353
|
-
]);
|
|
354
|
-
|
|
355
514
|
/** @param {string} v */
|
|
356
515
|
const refs = v => [...v.matchAll(/var\((--[a-zA-Z0-9_-]+)/g)].map(m => m[1]);
|
|
357
516
|
|
|
@@ -393,7 +552,6 @@ export function walkMarkup(html, decls, tokens) {
|
|
|
393
552
|
const stack = [{env: {}, target: null, fg: null, bg: null}];
|
|
394
553
|
/** @type {Map<string, TextPair>} */
|
|
395
554
|
const pairs = new Map();
|
|
396
|
-
let inSample = false;
|
|
397
555
|
for (const m of html.matchAll(
|
|
398
556
|
/([^<]+)|<(\/?)([a-zA-Z][a-zA-Z0-9-]*)([^>]*?)(\/?)>/g,
|
|
399
557
|
)) {
|
|
@@ -412,13 +570,10 @@ export function walkMarkup(html, decls, tokens) {
|
|
|
412
570
|
}
|
|
413
571
|
continue;
|
|
414
572
|
}
|
|
415
|
-
if (!close && tag === 'section')
|
|
416
|
-
inSample = /data-cat="sample-page"/.test(attrs);
|
|
417
573
|
if (close) {
|
|
418
574
|
if (stack.length > 1) stack.pop();
|
|
419
575
|
continue;
|
|
420
576
|
}
|
|
421
|
-
void inSample;
|
|
422
577
|
const cls = (/class="([^"]*)"/.exec(attrs)?.[1] ?? '')
|
|
423
578
|
.split(/\s+/)
|
|
424
579
|
.filter(Boolean);
|
|
@@ -50,6 +50,14 @@ export function themeEditPreviewAdd(description?: string, options?: import("./th
|
|
|
50
50
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditPreviewAppResponse>}
|
|
51
51
|
*/
|
|
52
52
|
export function themeEditPreviewApp(dir: string, options?: import("./theme-edit.type.mjs").ThemeEditPreviewAppOptions): Promise<import("./theme-edit.type.mjs").ThemeEditPreviewAppResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Why the in-app preview's record is damaged, with how to fix it, or null
|
|
55
|
+
* (no preview, or a sound one). For answers that would suggest a preview
|
|
56
|
+
* command, which the damage refuses.
|
|
57
|
+
* @param {string} cwd
|
|
58
|
+
* @returns {string | null}
|
|
59
|
+
*/
|
|
60
|
+
export function previewRecordProblem(cwd: string): string | null;
|
|
53
61
|
/**
|
|
54
62
|
* The pages of the in-app theme preview. With no preview, and with no
|
|
55
63
|
* routes folder for one, the list is empty; a damaged theme-preview.json is
|