@astryxdesign/cli 0.7.17-canary.g16fe6a8 → 0.7.17-canary.g2df3446
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/api/discover/_adapter.mjs +34 -1
- package/api/discover/discover.type.d.mts +4 -1
- package/api/discover/discover.type.mjs +4 -1
- package/api/docs/_adapter.d.mts +19 -0
- package/api/docs/_adapter.mjs +68 -19
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/theme/_adapter.d.mts +2 -1
- package/api/theme/_adapter.mjs +106 -12
- package/api/theme/build/build.mjs +9 -1
- package/api/theme/build/font-warning.mjs +27 -0
- package/api/theme/remove/remove.d.mts +2 -1
- package/api/theme/remove/remove.mjs +3 -2
- package/api/theme/theme.type.d.mts +6 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeRemove.doc.mjs +8 -5
- package/api/theme-edit/_adapter.d.mts +1 -1
- package/api/theme-edit/_adapter.mjs +30 -17
- package/api/theme-edit/_check.mjs +271 -68
- package/api/theme-edit/_color.d.mts +8 -0
- package/api/theme-edit/_color.mjs +12 -6
- package/api/theme-edit/_context.d.mts +16 -1
- package/api/theme-edit/_context.mjs +101 -32
- package/api/theme-edit/_css.d.mts +7 -0
- package/api/theme-edit/_css.mjs +41 -13
- package/api/theme-edit/_edit.mjs +609 -107
- package/api/theme-edit/_normal.d.mts +4 -2
- package/api/theme-edit/_normal.mjs +31 -7
- package/api/theme-edit/_palette.d.mts +8 -0
- package/api/theme-edit/_palette.mjs +12 -1
- package/api/theme-edit/_preview-app.mjs +109 -30
- package/api/theme-edit/_preview.d.mts +18 -4
- package/api/theme-edit/_preview.mjs +64 -16
- package/api/theme-edit/_project.d.mts +39 -0
- package/api/theme-edit/_project.mjs +95 -4
- package/api/theme-edit/_settings.d.mts +70 -11
- package/api/theme-edit/_settings.mjs +343 -66
- package/api/theme-edit/_tables.d.mts +9 -0
- package/api/theme-edit/_tables.mjs +129 -0
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/tree/font-setup.doc.mjs +1 -1
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/render-pages.doc.mjs +2 -2
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/theme.template.ts +3 -2
- package/authoring/doctypes/_schema.d.mts +6 -6
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/theme.mjs +71 -22
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +4 -4
- package/clients/cli/commands/theme-remove.doc.mjs +13 -5
- package/clients/cli/commands/theme.mjs +19 -2
- package/clients/cli/lib/json-shim.mjs +9 -7
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/theme-state.d.mts +19 -2
- package/foundation/config/theme-state.mjs +93 -1
- package/foundation/fonts/font-stylesheet.mjs +7 -2
- package/foundation/render/charts.d.mts +78 -27
- package/foundation/render/charts.mjs +266 -90
- package/foundation/render/page-worker.mjs +83 -8
- package/foundation/render/render-page.d.mts +2 -2
- package/foundation/render/render-page.mjs +12 -1
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +6 -6
|
@@ -30,6 +30,7 @@ import {hostedRun} from '../../foundation/runtime/package-root.mjs';
|
|
|
30
30
|
import {scanAllPackages, findComponentInPackages} from './_package-scanner.mjs';
|
|
31
31
|
import {loadDocs} from '../../foundation/discovery/component-loader.mjs';
|
|
32
32
|
import {collectIdentities} from '../../foundation/integrations/contribution-inventory.mjs';
|
|
33
|
+
import {packageDocNames, projectTree} from '../docs/_adapter.mjs';
|
|
33
34
|
import {discoverIntegrationIconSets} from '../../foundation/discovery/icon-set-discovery.mjs';
|
|
34
35
|
import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
|
|
35
36
|
import {isValidSemver, semverCompare} from '../../foundation/env/semver.mjs';
|
|
@@ -221,6 +222,7 @@ export async function discoverPackages() {
|
|
|
221
222
|
export async function describeInstalled(project, scanned) {
|
|
222
223
|
if (project == null) return scanned;
|
|
223
224
|
const byName = new Map(scanned.map(pkg => [pkg.name, pkg]));
|
|
225
|
+
const docs = await projectDocs(project);
|
|
224
226
|
/** @type {InstalledPackage[]} */
|
|
225
227
|
const installed = [];
|
|
226
228
|
for (const integration of project.loadedIntegrations) {
|
|
@@ -238,10 +240,12 @@ export async function describeInstalled(project, scanned) {
|
|
|
238
240
|
// Components come from the scan above; loading every component doc again
|
|
239
241
|
// here would only slow the list down.
|
|
240
242
|
// Icon sets are read below, only with the opt-in.
|
|
243
|
+
// Docs are named from the project's docs catalog, below.
|
|
241
244
|
const {identities} = await collectIdentities({
|
|
242
245
|
...integration,
|
|
243
246
|
components: undefined,
|
|
244
247
|
iconSets: undefined,
|
|
248
|
+
docs: undefined,
|
|
245
249
|
});
|
|
246
250
|
// Icon sets are listed the way every icon surface sees them: a set that
|
|
247
251
|
// is invalid or whose module does not resolve answers nothing (FR9).
|
|
@@ -253,7 +257,11 @@ export async function describeInstalled(project, scanned) {
|
|
|
253
257
|
installed.push({
|
|
254
258
|
...base,
|
|
255
259
|
templates: identities.templates.map(t => t.id),
|
|
256
|
-
docs
|
|
260
|
+
// Each doc by the name `astryx docs` opens it by, not the name on its
|
|
261
|
+
// file: a doc that adds sections to `theme` opens as `theme`.
|
|
262
|
+
docs: docs
|
|
263
|
+
? packageDocNames(docs.catalog, docs.tree, integration.name)
|
|
264
|
+
: [],
|
|
257
265
|
themes: identities.themes.map(t => t.slug),
|
|
258
266
|
codemods: identities.codemods.map(c => `${c.version}/${c.id}`),
|
|
259
267
|
iconSets: sets.map(set => set.name),
|
|
@@ -280,6 +288,31 @@ export async function describeInstalled(project, scanned) {
|
|
|
280
288
|
return installed;
|
|
281
289
|
}
|
|
282
290
|
|
|
291
|
+
/**
|
|
292
|
+
* The project's docs catalog and tree, as a docs read builds them, so discover
|
|
293
|
+
* names each doc the way `astryx docs` opens it. Null when no integration
|
|
294
|
+
* ships docs, so there is nothing to name and nothing is built, or when they
|
|
295
|
+
* cannot be built: a docs read then answers from the CLI's own topics alone,
|
|
296
|
+
* so no integration doc opens.
|
|
297
|
+
* @param {Project} project
|
|
298
|
+
* @returns {Promise<{catalog: import('../../foundation/discovery/docs-discovery.mjs').DocsCatalog, tree: import('../../foundation/doc-compiler/tree.mjs').DocsTree} | null>}
|
|
299
|
+
*/
|
|
300
|
+
async function projectDocs(project) {
|
|
301
|
+
if (
|
|
302
|
+
!project.loadedIntegrations.some(
|
|
303
|
+
integration => !integration.__loadError && integration.docs,
|
|
304
|
+
)
|
|
305
|
+
) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
const catalog = await project.docs();
|
|
310
|
+
return {catalog, tree: await projectTree(catalog)};
|
|
311
|
+
} catch {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
283
316
|
/**
|
|
284
317
|
* Whether the project has any discover source: its own `discover` config field,
|
|
285
318
|
* or an integration's `discover` named export (valid or not).
|
|
@@ -56,7 +56,10 @@ export type DiscoverListEntry = {
|
|
|
56
56
|
*/
|
|
57
57
|
templates?: string[] | undefined;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* What `astryx docs` opens each doc it adds by,
|
|
60
|
+
* when it adds any: a topic's name, the name of a topic it adds sections
|
|
61
|
+
* to, or the route of a namespace doc or guide it places, or of a guide it
|
|
62
|
+
* replaces or extends.
|
|
60
63
|
*/
|
|
61
64
|
docs?: string[] | undefined;
|
|
62
65
|
/**
|
|
@@ -51,7 +51,10 @@
|
|
|
51
51
|
* @property {string} [description]
|
|
52
52
|
* @property {string} [displayName]
|
|
53
53
|
* @property {string[]} [templates] Template ids, when it adds any.
|
|
54
|
-
* @property {string[]} [docs]
|
|
54
|
+
* @property {string[]} [docs] What `astryx docs` opens each doc it adds by,
|
|
55
|
+
* when it adds any: a topic's name, the name of a topic it adds sections
|
|
56
|
+
* to, or the route of a namespace doc or guide it places, or of a guide it
|
|
57
|
+
* replaces or extends.
|
|
55
58
|
* @property {string[]} [themes] Theme slugs, when it adds any.
|
|
56
59
|
* @property {string[]} [codemods] `<version>/<id>`, when it adds any.
|
|
57
60
|
* @property {string[]} [agentDocs] Agent guidance, when a source lists any.
|
package/api/docs/_adapter.d.mts
CHANGED
|
@@ -350,6 +350,25 @@ export function childIdentity(tree: DocsTree, child: TreeNode): import("./docs.t
|
|
|
350
350
|
* @returns {boolean}
|
|
351
351
|
*/
|
|
352
352
|
export function holdsOwnName(tree: DocsTree, catalog: DocsCatalog, entry: import("../../foundation/discovery/docs-discovery.mjs").DocsTopicEntry): boolean;
|
|
353
|
+
/**
|
|
354
|
+
* The names `astryx docs` opens a package's docs by, sorted: the one rule
|
|
355
|
+
* every surface that lists a package's docs names them by, so each name it
|
|
356
|
+
* prints opens (`astryx discover` lists an installed integration's docs this
|
|
357
|
+
* way). The docs are what the package's docs root ships, and each opens where
|
|
358
|
+
* it lands, not by the name on its file: a topic the package wrote or took
|
|
359
|
+
* over opens by its own name; a doc that adds sections to another topic opens
|
|
360
|
+
* with that topic, by its name; a namespace doc or guide the package places,
|
|
361
|
+
* and a guide it replaces or extends by its route, open by that route. A topic
|
|
362
|
+
* whose name opens another doc is left out, as the topic list leaves it out
|
|
363
|
+
* (spec:AST-046 FR11). Typed docs of the package's other contributions, such
|
|
364
|
+
* as an icon set's own icon definitions, are listed with those contributions,
|
|
365
|
+
* not here.
|
|
366
|
+
* @param {DocsCatalog} catalog
|
|
367
|
+
* @param {DocsTree} tree
|
|
368
|
+
* @param {string} owner the package
|
|
369
|
+
* @returns {string[]}
|
|
370
|
+
*/
|
|
371
|
+
export function packageDocNames(catalog: DocsCatalog, tree: DocsTree, owner: string): string[];
|
|
353
372
|
/**
|
|
354
373
|
* The doc that took a flat topic's route in the docs tree, when it is not
|
|
355
374
|
* that topic (spec:AST-046 FR11): the CLI keeps its routes, such as `cli`
|
package/api/docs/_adapter.mjs
CHANGED
|
@@ -1178,6 +1178,35 @@ async function includedContent(catalog, tree, block, found) {
|
|
|
1178
1178
|
return {content: linked.content, problems};
|
|
1179
1179
|
}
|
|
1180
1180
|
|
|
1181
|
+
/**
|
|
1182
|
+
* Whether a package owns a topic: it wrote the topic, or adds sections to it.
|
|
1183
|
+
* @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
|
|
1184
|
+
* @param {string} owner the package
|
|
1185
|
+
* @returns {boolean}
|
|
1186
|
+
*/
|
|
1187
|
+
function ownsTopic(entry, owner) {
|
|
1188
|
+
return (
|
|
1189
|
+
entry.package === owner ||
|
|
1190
|
+
entry.extensions.some(extension => extension.package === owner)
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* Whether a package owns a node of the docs tree: it placed the node, or
|
|
1196
|
+
* replaces or extends the guide there by its route.
|
|
1197
|
+
* @param {TreeNode} node
|
|
1198
|
+
* @param {string} owner the package
|
|
1199
|
+
* @returns {boolean}
|
|
1200
|
+
*/
|
|
1201
|
+
function ownsNode(node, owner) {
|
|
1202
|
+
return (
|
|
1203
|
+
node.provider === owner ||
|
|
1204
|
+
node.guideOverlay?.replacement?.package === owner ||
|
|
1205
|
+
(node.guideOverlay?.extensions.some(each => each.package === owner) ??
|
|
1206
|
+
false)
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1181
1210
|
/**
|
|
1182
1211
|
* Every link in the project's docs that names no doc: in each topic, each
|
|
1183
1212
|
* guide the tree places, and each typed doc.
|
|
@@ -1206,15 +1235,7 @@ export async function docsLinkProblems(
|
|
|
1206
1235
|
}
|
|
1207
1236
|
};
|
|
1208
1237
|
for (const entry of catalog.entries()) {
|
|
1209
|
-
|
|
1210
|
-
// package's topic.
|
|
1211
|
-
if (
|
|
1212
|
-
owner != null &&
|
|
1213
|
-
entry.package !== owner &&
|
|
1214
|
-
!entry.extensions.some(extension => extension.package === owner)
|
|
1215
|
-
) {
|
|
1216
|
-
continue;
|
|
1217
|
-
}
|
|
1238
|
+
if (owner != null && !ownsTopic(entry, owner)) continue;
|
|
1218
1239
|
try {
|
|
1219
1240
|
note(entry.name, await topicLinkProblems(catalog, entry));
|
|
1220
1241
|
} catch {
|
|
@@ -1222,16 +1243,7 @@ export async function docsLinkProblems(
|
|
|
1222
1243
|
}
|
|
1223
1244
|
}
|
|
1224
1245
|
for (const node of tree.nodes.values()) {
|
|
1225
|
-
|
|
1226
|
-
// its route.
|
|
1227
|
-
if (
|
|
1228
|
-
owner != null &&
|
|
1229
|
-
node.provider !== owner &&
|
|
1230
|
-
node.guideOverlay?.replacement?.package !== owner &&
|
|
1231
|
-
!node.guideOverlay?.extensions.some(each => each.package === owner)
|
|
1232
|
-
) {
|
|
1233
|
-
continue;
|
|
1234
|
-
}
|
|
1246
|
+
if (owner != null && !ownsNode(node, owner)) continue;
|
|
1235
1247
|
if (node.kind === 'generic' && node.ref?.topicFile) {
|
|
1236
1248
|
try {
|
|
1237
1249
|
note(node.route, await topicLinkProblems(catalog, guideEntry(node)));
|
|
@@ -1916,6 +1928,43 @@ export function holdsOwnName(tree, catalog, entry) {
|
|
|
1916
1928
|
);
|
|
1917
1929
|
}
|
|
1918
1930
|
|
|
1931
|
+
/**
|
|
1932
|
+
* The names `astryx docs` opens a package's docs by, sorted: the one rule
|
|
1933
|
+
* every surface that lists a package's docs names them by, so each name it
|
|
1934
|
+
* prints opens (`astryx discover` lists an installed integration's docs this
|
|
1935
|
+
* way). The docs are what the package's docs root ships, and each opens where
|
|
1936
|
+
* it lands, not by the name on its file: a topic the package wrote or took
|
|
1937
|
+
* over opens by its own name; a doc that adds sections to another topic opens
|
|
1938
|
+
* with that topic, by its name; a namespace doc or guide the package places,
|
|
1939
|
+
* and a guide it replaces or extends by its route, open by that route. A topic
|
|
1940
|
+
* whose name opens another doc is left out, as the topic list leaves it out
|
|
1941
|
+
* (spec:AST-046 FR11). Typed docs of the package's other contributions, such
|
|
1942
|
+
* as an icon set's own icon definitions, are listed with those contributions,
|
|
1943
|
+
* not here.
|
|
1944
|
+
* @param {DocsCatalog} catalog
|
|
1945
|
+
* @param {DocsTree} tree
|
|
1946
|
+
* @param {string} owner the package
|
|
1947
|
+
* @returns {string[]}
|
|
1948
|
+
*/
|
|
1949
|
+
export function packageDocNames(catalog, tree, owner) {
|
|
1950
|
+
/** @type {Set<string>} */
|
|
1951
|
+
const names = new Set();
|
|
1952
|
+
for (const entry of catalog.entries()) {
|
|
1953
|
+
if (ownsTopic(entry, owner) && holdsOwnName(tree, catalog, entry)) {
|
|
1954
|
+
names.add(entry.name);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
for (const node of tree.nodes.values()) {
|
|
1958
|
+
// What a docs root ships to the tree: a namespace doc, or a guide (a topic
|
|
1959
|
+
// file the tree places). A generated level has no doc of its own, and a
|
|
1960
|
+
// topic the tree files in one opens by its name, named above.
|
|
1961
|
+
if (node.generated) continue;
|
|
1962
|
+
if (node.kind !== 'namespace' && node.ref?.topicFile == null) continue;
|
|
1963
|
+
if (ownsNode(node, owner)) names.add(node.route);
|
|
1964
|
+
}
|
|
1965
|
+
return [...names].sort();
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1919
1968
|
/**
|
|
1920
1969
|
* What a tree node opens as: a guide the tree places reads like a topic; a
|
|
1921
1970
|
* namespace or a typed doc is a node.
|
|
@@ -31,7 +31,7 @@ export type RenderWarning = {
|
|
|
31
31
|
/**
|
|
32
32
|
* - What kind of problem.
|
|
33
33
|
*/
|
|
34
|
-
code: "dropped-children" | "remote-asset" | "missing-asset" | "page-output" | "page-script" | "no-astryx-styles" | "chart-size" | "not-embedded" | "node-crash";
|
|
34
|
+
code: "dropped-children" | "remote-asset" | "missing-asset" | "page-output" | "page-script" | "no-astryx-styles" | "chart-size" | "screen-query" | "not-embedded" | "node-crash";
|
|
35
35
|
/**
|
|
36
36
|
* - What happened and what to do, in one sentence.
|
|
37
37
|
*/
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* author meant.
|
|
23
23
|
* @experimental May change or be removed in a patch release.
|
|
24
24
|
* @typedef {object} RenderWarning
|
|
25
|
-
* @property {'dropped-children' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'not-embedded' | 'node-crash'} code - What kind of problem.
|
|
25
|
+
* @property {'dropped-children' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'screen-query' | 'not-embedded' | 'node-crash'} code - What kind of problem.
|
|
26
26
|
* @property {string} message - What happened and what to do, in one sentence.
|
|
27
27
|
*/
|
|
28
28
|
|
package/api/theme/_adapter.d.mts
CHANGED
|
@@ -172,7 +172,8 @@ export function addThemeToApp(slug: string, options?: {
|
|
|
172
172
|
package?: string;
|
|
173
173
|
}): Promise<import("./theme.type.mjs").ThemeAppResponse>;
|
|
174
174
|
/**
|
|
175
|
-
* Remove one
|
|
175
|
+
* Remove one added theme from the app record. The default is removed only
|
|
176
|
+
* when it is the only added theme: that deletes the generated module.
|
|
176
177
|
* @param {string} slug
|
|
177
178
|
* @param {{cwd?: string}} [options]
|
|
178
179
|
* @returns {Promise<import('./theme.type.mjs').ThemeAppResponse>}
|
package/api/theme/_adapter.mjs
CHANGED
|
@@ -38,10 +38,12 @@ import {
|
|
|
38
38
|
findThemeProject,
|
|
39
39
|
editorThemeRecord,
|
|
40
40
|
isLocalThemeOwner,
|
|
41
|
+
isUneditedThemeModule,
|
|
41
42
|
LOCAL_THEME_ROOT,
|
|
42
43
|
ThemeStateError,
|
|
43
44
|
planThemeAppWrite,
|
|
44
45
|
readThemeState,
|
|
46
|
+
resolveThemeModule,
|
|
45
47
|
} from '../../foundation/config/theme-state.mjs';
|
|
46
48
|
import {AstryxError} from '../error.mjs';
|
|
47
49
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
@@ -1415,7 +1417,8 @@ function recordedThemeSlug(state, slug) {
|
|
|
1415
1417
|
}
|
|
1416
1418
|
|
|
1417
1419
|
/**
|
|
1418
|
-
* Remove one
|
|
1420
|
+
* Remove one added theme from the app record. The default is removed only
|
|
1421
|
+
* when it is the only added theme: that deletes the generated module.
|
|
1419
1422
|
* @param {string} slug
|
|
1420
1423
|
* @param {{cwd?: string}} [options]
|
|
1421
1424
|
* @returns {Promise<import('./theme.type.mjs').ThemeAppResponse>}
|
|
@@ -1436,22 +1439,14 @@ async function removeThemeFromAppLocked(slug, cwd) {
|
|
|
1436
1439
|
const others = Object.keys(state.themes).filter(
|
|
1437
1440
|
other => other !== recordedSlug,
|
|
1438
1441
|
);
|
|
1442
|
+
if (others.length === 0) return await removeLastTheme(state, recordedSlug);
|
|
1439
1443
|
const uses = others.slice(0, 3).map(other => ({
|
|
1440
1444
|
name: formatCliCommand(`theme use ${other}`, state.projectDir),
|
|
1441
1445
|
reason: `make ${other} the default`,
|
|
1442
1446
|
}));
|
|
1443
1447
|
throw new AstryxError(
|
|
1444
|
-
uses.
|
|
1445
|
-
|
|
1446
|
-
: `Theme "${recordedSlug}" is the default and the only added theme. Add another theme and make it the default before removing it.`,
|
|
1447
|
-
uses.length > 0
|
|
1448
|
-
? uses
|
|
1449
|
-
: [
|
|
1450
|
-
{
|
|
1451
|
-
name: formatCliCommand('theme list', state.projectDir),
|
|
1452
|
-
reason: 'the themes you can add',
|
|
1453
|
-
},
|
|
1454
|
-
],
|
|
1448
|
+
`Theme "${recordedSlug}" is the default. Run \`${uses[0].name}\` before removing it.`,
|
|
1449
|
+
uses,
|
|
1455
1450
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
1456
1451
|
);
|
|
1457
1452
|
}
|
|
@@ -1484,6 +1479,105 @@ async function removeThemeFromAppLocked(slug, cwd) {
|
|
|
1484
1479
|
);
|
|
1485
1480
|
}
|
|
1486
1481
|
|
|
1482
|
+
/**
|
|
1483
|
+
* Remove the only added theme by deleting the generated module, which is the
|
|
1484
|
+
* app's whole theme record. A module with changes the CLI did not write stays,
|
|
1485
|
+
* and the error says how to finish by hand.
|
|
1486
|
+
* @param {ReturnType<typeof readThemeState>} state
|
|
1487
|
+
* @param {string} slug
|
|
1488
|
+
* @returns {Promise<import('./theme.type.mjs').ThemeAppResponse>}
|
|
1489
|
+
*/
|
|
1490
|
+
async function removeLastTheme(state, slug) {
|
|
1491
|
+
let module;
|
|
1492
|
+
try {
|
|
1493
|
+
// The project-root check every theme write runs: a `src` that is a
|
|
1494
|
+
// symlink to a folder outside the project must not lose a file there.
|
|
1495
|
+
module = resolveThemeModule(state.projectDir, {forWrite: true});
|
|
1496
|
+
} catch (error) {
|
|
1497
|
+
throw asThemeError(error);
|
|
1498
|
+
}
|
|
1499
|
+
const original = module.expectedOriginal;
|
|
1500
|
+
const source = original?.toString('utf-8') ?? '';
|
|
1501
|
+
if (original == null || !(await isUneditedModule(state, source))) {
|
|
1502
|
+
// A module the CLI wrote whose imports differ from what it writes now (a
|
|
1503
|
+
// theme package upgrade moves them) is rewritten by `theme use`.
|
|
1504
|
+
const use = formatCliCommand(`theme use ${slug}`, state.projectDir);
|
|
1505
|
+
const rewritable =
|
|
1506
|
+
original != null && isUneditedThemeModule(source, module.typescript);
|
|
1507
|
+
throw new AstryxError(
|
|
1508
|
+
rewritable
|
|
1509
|
+
? `Theme "${slug}" is the only added theme, and ${module.path} differs from what the CLI writes for it now, as after a theme package upgrade, so the CLI leaves it. Run \`${use}\` to rewrite it, then remove the theme again.`
|
|
1510
|
+
: `Theme "${slug}" is the only added theme, and ${module.path} has changes the CLI did not write, so the CLI leaves it. To stop using app themes, delete ${module.path} and remove its import and the Theme wrapper from the app root.`,
|
|
1511
|
+
rewritable
|
|
1512
|
+
? [{name: use, reason: 'rewrite the module, then remove the theme'}]
|
|
1513
|
+
: undefined,
|
|
1514
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
1515
|
+
);
|
|
1516
|
+
}
|
|
1517
|
+
try {
|
|
1518
|
+
if (fs.lstatSync(module.file).isSymbolicLink()) {
|
|
1519
|
+
throw new Error(`${module.path} is a symlink`);
|
|
1520
|
+
}
|
|
1521
|
+
if (!fs.readFileSync(module.file).equals(original)) {
|
|
1522
|
+
throw new Error(`${module.path} changed while the command ran`);
|
|
1523
|
+
}
|
|
1524
|
+
fs.unlinkSync(module.file);
|
|
1525
|
+
} catch (error) {
|
|
1526
|
+
throw new AstryxError(
|
|
1527
|
+
`Failed to delete the generated theme module: ${fsErrorMessage(error, module.path) ?? (error instanceof Error ? error.message : String(error))}`,
|
|
1528
|
+
undefined,
|
|
1529
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
return {
|
|
1533
|
+
type: 'theme.app',
|
|
1534
|
+
data: {
|
|
1535
|
+
themes: [],
|
|
1536
|
+
default: '',
|
|
1537
|
+
modulePath: module.path,
|
|
1538
|
+
change: {
|
|
1539
|
+
action: 'remove',
|
|
1540
|
+
slug,
|
|
1541
|
+
changed: true,
|
|
1542
|
+
firstAdd: false,
|
|
1543
|
+
moduleRemoved: true,
|
|
1544
|
+
...(/\bexport const themeModes\b/u.test(source)
|
|
1545
|
+
? {themeModes: true}
|
|
1546
|
+
: {}),
|
|
1547
|
+
},
|
|
1548
|
+
},
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
/**
|
|
1553
|
+
* Is the module exactly what the CLI writes for its record? While the recorded
|
|
1554
|
+
* themes resolve, it must equal the module the CLI would write now. When one
|
|
1555
|
+
* no longer resolves (its package is already uninstalled), the module is
|
|
1556
|
+
* re-rendered from its own imports, which must still come from the recorded
|
|
1557
|
+
* owners.
|
|
1558
|
+
* @param {ReturnType<typeof readThemeState>} state
|
|
1559
|
+
* @param {string} source
|
|
1560
|
+
*/
|
|
1561
|
+
async function isUneditedModule(state, source) {
|
|
1562
|
+
let resolved;
|
|
1563
|
+
try {
|
|
1564
|
+
resolved = resolveRecordedThemes(
|
|
1565
|
+
state,
|
|
1566
|
+
await listAvailableThemes(state.projectDir),
|
|
1567
|
+
);
|
|
1568
|
+
} catch {
|
|
1569
|
+
return isUneditedThemeModule(source, state.module.typescript);
|
|
1570
|
+
}
|
|
1571
|
+
try {
|
|
1572
|
+
return (
|
|
1573
|
+
planThemeAppWrite(state, state.themes, state.defaultSlug ?? '', resolved)
|
|
1574
|
+
.moduleContents === source
|
|
1575
|
+
);
|
|
1576
|
+
} catch {
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1487
1581
|
/**
|
|
1488
1582
|
* Select one added theme as the app default.
|
|
1489
1583
|
* @param {string} slug
|
|
@@ -3123,7 +3123,15 @@ function themeLoadReason(error) {
|
|
|
3123
3123
|
// Node's "Require stack" names absolute paths; the package is the fact.
|
|
3124
3124
|
return `Cannot find module '${missing}'.\nThe theme imports ${missing}, which is not installed. Install it, then build again.`;
|
|
3125
3125
|
}
|
|
3126
|
-
|
|
3126
|
+
// A module that did not resolve: the import hint. Any other failure (the
|
|
3127
|
+
// theme's own code, or Core refusing its input) is told as it is.
|
|
3128
|
+
const unresolved =
|
|
3129
|
+
/^(?:ERR_MODULE_NOT_FOUND|MODULE_NOT_FOUND)$/.test(
|
|
3130
|
+
String(/** @type {any} */ (error).code ?? ''),
|
|
3131
|
+
) || /Cannot (?:find|resolve) (?:module|package)/.test(message);
|
|
3132
|
+
return unresolved
|
|
3133
|
+
? `${message}\nMake sure all imports in the theme file are resolvable.`
|
|
3134
|
+
: message;
|
|
3127
3135
|
}
|
|
3128
3136
|
|
|
3129
3137
|
/** A theme module that loaded but exports no theme object. */
|
|
@@ -103,6 +103,33 @@ const SYSTEM_FAMILIES = new Set([
|
|
|
103
103
|
'liberation serif',
|
|
104
104
|
'dejavu sans',
|
|
105
105
|
'dejavu sans mono',
|
|
106
|
+
// The interface and text fonts the systems ship for Chinese, Japanese and
|
|
107
|
+
// Korean, which CJK stylesheets name.
|
|
108
|
+
'pingfang sc',
|
|
109
|
+
'pingfang tc',
|
|
110
|
+
'pingfang hk',
|
|
111
|
+
'hiragino sans',
|
|
112
|
+
'hiragino sans gb',
|
|
113
|
+
'hiragino kaku gothic pron',
|
|
114
|
+
'hiragino mincho pron',
|
|
115
|
+
'apple sd gothic neo',
|
|
116
|
+
'microsoft yahei',
|
|
117
|
+
'microsoft yahei ui',
|
|
118
|
+
'microsoft jhenghei',
|
|
119
|
+
'microsoft jhenghei ui',
|
|
120
|
+
'simsun',
|
|
121
|
+
'simhei',
|
|
122
|
+
'nsimsun',
|
|
123
|
+
'meiryo',
|
|
124
|
+
'yu gothic',
|
|
125
|
+
'yu mincho',
|
|
126
|
+
'ms gothic',
|
|
127
|
+
'ms mincho',
|
|
128
|
+
'malgun gothic',
|
|
129
|
+
// The same Windows fonts by their Chinese names.
|
|
130
|
+
'微软雅黑',
|
|
131
|
+
'宋体',
|
|
132
|
+
'黑体',
|
|
106
133
|
]);
|
|
107
134
|
|
|
108
135
|
/**
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Remove one added
|
|
5
|
+
* Remove one added theme and regenerate the app module, or remove the module
|
|
6
|
+
* file when it was the only added theme.
|
|
6
7
|
* @param {string} slug
|
|
7
8
|
* @param {{cwd?: string}} [options]
|
|
8
9
|
* @returns {Promise<import('../theme.type.mjs').ThemeAppResponse>}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
-
/** @file `astryx theme remove` — stop importing one
|
|
3
|
+
/** @file `astryx theme remove` — stop importing one app theme. */
|
|
4
4
|
|
|
5
5
|
import {removeThemeFromApp} from '../_adapter.mjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Remove one added
|
|
8
|
+
* Remove one added theme and regenerate the app module, or remove the module
|
|
9
|
+
* file when it was the only added theme.
|
|
9
10
|
* @param {string} slug
|
|
10
11
|
* @param {{cwd?: string}} [options]
|
|
11
12
|
* @returns {Promise<import('../theme.type.mjs').ThemeAppResponse>}
|
|
@@ -158,6 +158,10 @@ export type ThemeAppResponse = {
|
|
|
158
158
|
* `change.wireModes` is present when the module lists a theme's one color
|
|
159
159
|
* mode (`themeModes`) for the first time after the app was wired: the app's
|
|
160
160
|
* `Theme` then takes `mode={themeModes[defaultThemeSlug] ?? 'system'}`.
|
|
161
|
+
* `change.moduleRemoved` is present when `theme remove` removed the only
|
|
162
|
+
* added theme and deleted the module at `modulePath`: `themes` is empty,
|
|
163
|
+
* `default` is `''`, and the app root must drop the module's wiring.
|
|
164
|
+
* `change.themeModes` is present then when that wiring imported `themeModes`.
|
|
161
165
|
*/
|
|
162
166
|
package?: string | undefined;
|
|
163
167
|
data: {
|
|
@@ -170,6 +174,8 @@ export type ThemeAppResponse = {
|
|
|
170
174
|
changed: boolean;
|
|
171
175
|
firstAdd: boolean;
|
|
172
176
|
wireModes?: true;
|
|
177
|
+
moduleRemoved?: true;
|
|
178
|
+
themeModes?: true;
|
|
173
179
|
};
|
|
174
180
|
notes?: string[];
|
|
175
181
|
};
|
package/api/theme/theme.type.mjs
CHANGED
|
@@ -109,7 +109,11 @@
|
|
|
109
109
|
* `change.wireModes` is present when the module lists a theme's one color
|
|
110
110
|
* mode (`themeModes`) for the first time after the app was wired: the app's
|
|
111
111
|
* `Theme` then takes `mode={themeModes[defaultThemeSlug] ?? 'system'}`.
|
|
112
|
-
*
|
|
112
|
+
* `change.moduleRemoved` is present when `theme remove` removed the only
|
|
113
|
+
* added theme and deleted the module at `modulePath`: `themes` is empty,
|
|
114
|
+
* `default` is `''`, and the app root must drop the module's wiring.
|
|
115
|
+
* `change.themeModes` is present then when that wiring imported `themeModes`.
|
|
116
|
+
* @property {{themes: ThemeAppEntry[], default: string, modulePath: string, change: {action: 'add'|'remove'|'use', slug: string, changed: boolean, firstAdd: boolean, wireModes?: true, moduleRemoved?: true, themeModes?: true}, notes?: string[]}} data
|
|
113
117
|
*/
|
|
114
118
|
|
|
115
119
|
/**
|
|
@@ -9,9 +9,9 @@ export const doc = {
|
|
|
9
9
|
name: 'themeRemove',
|
|
10
10
|
namespace: 'cli/api',
|
|
11
11
|
displayName: 'themeRemove()',
|
|
12
|
-
summary: "Remove a
|
|
12
|
+
summary: "Remove a theme from an app's generated theme module.",
|
|
13
13
|
description:
|
|
14
|
-
'Reads the generated module record, removes one added theme, and regenerates the whole module. The default cannot be removed
|
|
14
|
+
'Reads the generated module record, removes one added theme, and regenerates the whole module. The default cannot be removed while other themes are added: themeUse selects another one first. The only added theme can be removed: that removes the module file when it is exactly what the CLI wrote.',
|
|
15
15
|
importPath: '@astryxdesign/cli/api',
|
|
16
16
|
signature:
|
|
17
17
|
'themeRemove(slug: string, options?: {cwd?: string}): Promise<ThemeAppResponse>',
|
|
@@ -33,7 +33,7 @@ export const doc = {
|
|
|
33
33
|
{
|
|
34
34
|
type: 'theme.app',
|
|
35
35
|
description:
|
|
36
|
-
'Every remaining theme and its imports, the default slug, the generated module path, and the remove change.
|
|
36
|
+
'Every remaining theme and its imports, the default slug, the generated module path, and the remove change. While other themes are added, the default is not removed: choose another with themeUse first, which also works when the folder or package of the default is gone. Other added themes whose local folder or package is gone are left out, with a note in data.notes. When the only added theme is removed, the module file goes too: themes is empty, default is an empty string, and change.moduleRemoved is true (change.themeModes is true when that module exported themeModes).',
|
|
37
37
|
},
|
|
38
38
|
],
|
|
39
39
|
throws: [
|
|
@@ -43,9 +43,12 @@ export const doc = {
|
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
code: 'ERR_THEME_INVALID',
|
|
46
|
-
when: 'the theme is the default (the suggestions name `theme use` with up to three
|
|
46
|
+
when: 'the theme is the default and other themes are added (the suggestions name `theme use` with up to three of them), it is the only added theme and the module has changes the CLI did not write (the module stays and the message gives the steps by hand; when only its imports differ, as after a theme package upgrade, the suggestion is `theme use <slug>`, which rewrites it), generated state is invalid, or the slug is not added and names a local theme folder that is broken',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
code: 'ERR_WRITE_FAILED',
|
|
50
|
+
when: 'the generated module cannot be written or removed',
|
|
47
51
|
},
|
|
48
|
-
{code: 'ERR_WRITE_FAILED', when: 'the generated module cannot be written'},
|
|
49
52
|
],
|
|
50
53
|
examples: [{label: 'Remove a theme', code: "await themeRemove('ocean');"}],
|
|
51
54
|
command: 'theme remove',
|
|
@@ -221,5 +221,5 @@ import { AstryxError } from '../error.mjs';
|
|
|
221
221
|
import * as edit from './_edit.mjs';
|
|
222
222
|
import * as preview from './_preview-app.mjs';
|
|
223
223
|
export { newFlagList, checkedChangeLine as editorCheckedLine, checkedNewLines as editorCheckedNewLines } from "./_edit.mjs";
|
|
224
|
-
export { dialValueFits, usableNewName as editorFreeName } from "./_settings.mjs";
|
|
224
|
+
export { dialTakesText, dialValueFits, usableNewName as editorFreeName } from "./_settings.mjs";
|
|
225
225
|
export { booleanWord, typoNear, typoOf } from "./_normal.mjs";
|