@astryxdesign/cli 0.7.14-canary.gfdb9213 → 0.7.14
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 +197 -0
- package/api/theme/_adapter.d.mts +33 -0
- package/api/theme/_adapter.mjs +352 -16
- package/api/theme/build/build.mjs +261 -10
- package/api/theme/eject/eject.mjs +13 -1
- package/api/theme/list/list.mjs +11 -2
- package/api/theme/template/template.mjs +139 -6
- package/api/theme/theme.type.d.mts +15 -1
- package/api/theme/theme.type.mjs +9 -3
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeBuild.doc.mjs +10 -2
- package/api/theme/themeEject.doc.mjs +2 -2
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +8 -0
- package/api/theme/themeUse.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +10 -2
- package/api/theme-edit/_adapter.mjs +52 -31
- package/api/theme-edit/_check.d.mts +28 -25
- package/api/theme-edit/_check.mjs +586 -548
- package/api/theme-edit/_color.d.mts +28 -2
- package/api/theme-edit/_color.mjs +306 -68
- package/api/theme-edit/_compiler.d.mts +8 -4
- package/api/theme-edit/_compiler.mjs +30 -27
- package/api/theme-edit/_context.d.mts +10 -4
- package/api/theme-edit/_context.mjs +21 -4
- package/api/theme-edit/_edit.mjs +300 -43
- package/api/theme-edit/_how-commands.d.mts +91 -0
- package/api/theme-edit/_how-commands.mjs +269 -0
- package/api/theme-edit/_how-question.d.mts +57 -0
- package/api/theme-edit/_how-question.mjs +2574 -0
- package/api/theme-edit/_how.d.mts +25 -17
- package/api/theme-edit/_how.mjs +727 -305
- package/api/theme-edit/_palette.d.mts +127 -19
- package/api/theme-edit/_palette.mjs +1313 -399
- package/api/theme-edit/_parts.mjs +36 -3
- package/api/theme-edit/_png.d.mts +18 -6
- package/api/theme-edit/_png.mjs +135 -25
- package/api/theme-edit/_preview-app.d.mts +26 -7
- package/api/theme-edit/_preview-app.mjs +1611 -280
- package/api/theme-edit/_preview.d.mts +4 -2
- package/api/theme-edit/_preview.mjs +18 -7
- package/api/theme-edit/_settings.d.mts +56 -5
- package/api/theme-edit/_settings.mjs +197 -49
- package/api/theme-edit/_tables.d.mts +0 -12
- package/api/theme-edit/_tables.mjs +24 -97
- package/api/theme-edit/theme-edit.type.d.mts +22 -5
- package/api/theme-edit/theme-edit.type.mjs +17 -6
- package/api/theme-edit/themeEditHow.doc.mjs +13 -3
- package/api/theme-edit/themeEditNew.doc.mjs +2 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +16 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -4
- package/api/theme-edit/themeEditPreviewList.doc.mjs +9 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +27 -2
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs.generated.json +1 -0
- package/assets/preview-app/gitignore +3 -0
- package/assets/templates/components.generated.json +1 -0
- package/clients/cli/bin/astryx.mjs +37 -5
- package/clients/cli/commands/experimental/theme.mjs +231 -31
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +14 -5
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/commands/theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/theme-remove.doc.mjs +2 -2
- package/clients/cli/commands/theme-template.doc.mjs +11 -4
- package/clients/cli/commands/theme.mjs +104 -40
- package/clients/cli/commands.generated.json +1 -0
- package/clients/cli/index.mjs +96 -4
- package/clients/cli/lib/json-shim.mjs +29 -1
- package/foundation/config/project.d.mts +16 -2
- package/foundation/config/project.mjs +40 -6
- package/foundation/config/theme-state.d.mts +9 -0
- package/foundation/config/theme-state.mjs +20 -1
- package/foundation/discovery/template-adapter.d.mts +12 -1
- package/foundation/discovery/template-adapter.mjs +24 -1
- package/foundation/discovery/template-needs.d.mts +7 -0
- package/foundation/discovery/template-needs.mjs +117 -8
- package/foundation/discovery/template-source-tree.d.mts +5 -1
- package/foundation/discovery/template-source-tree.mjs +6 -4
- package/foundation/discovery/theme-discovery.d.mts +14 -3
- package/foundation/discovery/theme-discovery.mjs +45 -12
- package/foundation/doc-compiler/import.mjs +68 -3
- package/foundation/doc-compiler/stored-docs.d.mts +27 -0
- package/foundation/doc-compiler/stored-docs.mjs +65 -0
- package/foundation/fs/fs-error.d.mts +17 -0
- package/foundation/fs/fs-error.mjs +34 -0
- package/package.json +6 -6
|
@@ -102,12 +102,13 @@ export function colorsPageSource({ slug, module, seeds, uses }: {
|
|
|
102
102
|
* preview page, a top bar with the theme name and, with a theme, a
|
|
103
103
|
* light/dark/system switch, and the selected page in the content area. It is a normal page of
|
|
104
104
|
* the app, so it keeps the app's layout, global CSS and providers.
|
|
105
|
-
* @param {{pages: Array<{id: string, label: string, file: string}>, theme: {name: string, module: string, css: string[], mode?: 'system' | 'light' | 'dark'} | null}} spec
|
|
105
|
+
* @param {{pages: Array<{id: string, label: string, file: string}>, theme: {name: string, module: string, css: string[], mode?: 'system' | 'light' | 'dark'} | null, by?: string}} spec
|
|
106
106
|
* `file` relative to the route folder, without extension; no theme: the
|
|
107
107
|
* app's own theme. A theme with one mode starts in it, with no switch.
|
|
108
|
+
* `by`: the command that wrote the route, for its header.
|
|
108
109
|
* @returns {string}
|
|
109
110
|
*/
|
|
110
|
-
export function previewRouteSource({ pages, theme }: {
|
|
111
|
+
export function previewRouteSource({ pages, theme, by, }: {
|
|
111
112
|
pages: Array<{
|
|
112
113
|
id: string;
|
|
113
114
|
label: string;
|
|
@@ -119,6 +120,7 @@ export function previewRouteSource({ pages, theme }: {
|
|
|
119
120
|
css: string[];
|
|
120
121
|
mode?: "system" | "light" | "dark";
|
|
121
122
|
} | null;
|
|
123
|
+
by?: string;
|
|
122
124
|
}): string;
|
|
123
125
|
/**
|
|
124
126
|
* A PNG of an HTML file, with a Playwright the project has installed, else
|
|
@@ -335,7 +335,13 @@ export async function renderSheet(ctx, slug, data, options = {}) {
|
|
|
335
335
|
source,
|
|
336
336
|
templateFiles(imports),
|
|
337
337
|
);
|
|
338
|
-
|
|
338
|
+
// One section goes to its own file, so the full sheet stays whole.
|
|
339
|
+
const full = themeFiles(project.cwd, slug).sheet;
|
|
340
|
+
const out =
|
|
341
|
+
options.out ??
|
|
342
|
+
(options.group
|
|
343
|
+
? path.join(path.dirname(full), `sheet-${options.group}.html`)
|
|
344
|
+
: full);
|
|
339
345
|
fs.mkdirSync(path.dirname(out), {recursive: true});
|
|
340
346
|
// Written whole and renamed in, never through a link.
|
|
341
347
|
writeWhole(out, html);
|
|
@@ -902,7 +908,7 @@ export function colorsPageSource({slug, module, seeds, uses}) {
|
|
|
902
908
|
`const SEEDS: Record<string, string> = ${JSON.stringify(seeds)};`,
|
|
903
909
|
'// The tokens that use each shade, by color, mode and shade.',
|
|
904
910
|
`const USES: Record<string, Partial<Record<Mode, Record<string, string[]>>>> = ${JSON.stringify(uses)};`,
|
|
905
|
-
'const COLORS = Object.entries(palette) as Array<[string, Readonly<Record<Mode, Ramp
|
|
911
|
+
'const COLORS = Object.entries(palette) as Array<[string, Readonly<Partial<Record<Mode, Ramp>>>]>;',
|
|
906
912
|
"const MODES: Mode[] = ['light', 'dark'];",
|
|
907
913
|
'',
|
|
908
914
|
'export default function ColorsPage() {',
|
|
@@ -924,11 +930,11 @@ export function colorsPageSource({slug, module, seeds, uses}) {
|
|
|
924
930
|
' </span>',
|
|
925
931
|
' ) : null}',
|
|
926
932
|
' </h2>',
|
|
927
|
-
' {MODES.map(mode => (',
|
|
933
|
+
' {MODES.filter(mode => ramps[mode]).map(mode => (',
|
|
928
934
|
" <div key={mode} style={{display: 'grid', gap: 6}}>",
|
|
929
935
|
" <div style={{fontSize: 13, fontWeight: 600, textTransform: 'capitalize'}}>{mode}</div>",
|
|
930
936
|
" <div style={{display: 'grid', gridTemplateColumns: 'repeat(7, minmax(0, 1fr))', gap: 8}}>",
|
|
931
|
-
' {Object.entries(ramps[mode]).map(([shade, hex]) => {',
|
|
937
|
+
' {Object.entries(ramps[mode] ?? {}).map(([shade, hex]) => {',
|
|
932
938
|
' const tokens = USES[name]?.[mode]?.[shade] ?? [];',
|
|
933
939
|
' return (',
|
|
934
940
|
' <div',
|
|
@@ -971,12 +977,17 @@ export function colorsPageSource({slug, module, seeds, uses}) {
|
|
|
971
977
|
* preview page, a top bar with the theme name and, with a theme, a
|
|
972
978
|
* light/dark/system switch, and the selected page in the content area. It is a normal page of
|
|
973
979
|
* the app, so it keeps the app's layout, global CSS and providers.
|
|
974
|
-
* @param {{pages: Array<{id: string, label: string, file: string}>, theme: {name: string, module: string, css: string[], mode?: 'system' | 'light' | 'dark'} | null}} spec
|
|
980
|
+
* @param {{pages: Array<{id: string, label: string, file: string}>, theme: {name: string, module: string, css: string[], mode?: 'system' | 'light' | 'dark'} | null, by?: string}} spec
|
|
975
981
|
* `file` relative to the route folder, without extension; no theme: the
|
|
976
982
|
* app's own theme. A theme with one mode starts in it, with no switch.
|
|
983
|
+
* `by`: the command that wrote the route, for its header.
|
|
977
984
|
* @returns {string}
|
|
978
985
|
*/
|
|
979
|
-
export function previewRouteSource({
|
|
986
|
+
export function previewRouteSource({
|
|
987
|
+
pages,
|
|
988
|
+
theme,
|
|
989
|
+
by = 'astryx experimental theme preview add',
|
|
990
|
+
}) {
|
|
980
991
|
const name = theme?.name ?? 'app theme';
|
|
981
992
|
const oneMode = theme?.mode && theme.mode !== 'system' ? theme.mode : null;
|
|
982
993
|
const mode =
|
|
@@ -1012,7 +1023,7 @@ export function previewRouteSource({pages, theme}) {
|
|
|
1012
1023
|
' </div>',
|
|
1013
1024
|
];
|
|
1014
1025
|
return [
|
|
1015
|
-
|
|
1026
|
+
`// Written by \`${by}\`. \`preview add\`, \`preview remove\` and`,
|
|
1016
1027
|
'// theme-preview.json keep it: edit the list with those commands, not by hand.',
|
|
1017
1028
|
"'use client';",
|
|
1018
1029
|
'',
|
|
@@ -61,12 +61,17 @@ export function loadTheme(cwd: string, slug: string, skip?: string): ThemeData;
|
|
|
61
61
|
*/
|
|
62
62
|
export function settingsProblem(data: any, skip?: string): string | null;
|
|
63
63
|
/**
|
|
64
|
-
* The
|
|
65
|
-
*
|
|
64
|
+
* The words that name a setting for `undo`.
|
|
65
|
+
* @param {import('./_settings.mjs').Setting} x
|
|
66
|
+
*/
|
|
67
|
+
export function undoArgs(x: import("./_settings.mjs").Setting): string;
|
|
68
|
+
/**
|
|
69
|
+
* The first setting whose only problem is its value (made under looser
|
|
70
|
+
* rules): `undo <theme> <undoArgs>` removes it.
|
|
66
71
|
* @param {any} data
|
|
67
|
-
* @returns {
|
|
72
|
+
* @returns {Setting | null}
|
|
68
73
|
*/
|
|
69
|
-
export function
|
|
74
|
+
export function badSetting(data: any): Setting | null;
|
|
70
75
|
/**
|
|
71
76
|
* The settings without those whose only problem is their value (made under
|
|
72
77
|
* looser rules), and the ones left out.
|
|
@@ -136,11 +141,12 @@ export function findOverrides(cssText: string, theme: any): Array<{
|
|
|
136
141
|
* @param {Ctx} ctx
|
|
137
142
|
* @param {string} slug
|
|
138
143
|
* @param {ThemeData} data
|
|
139
|
-
* @returns {Promise<{warnings: string[], lifted: string[]}>}
|
|
144
|
+
* @returns {Promise<{warnings: string[], lifted: string[], notes: string[]}>} `notes`: what the color config kept or replaced of a hand edit
|
|
140
145
|
*/
|
|
141
146
|
export function buildTheme(ctx: Ctx, slug: string, data: ThemeData): Promise<{
|
|
142
147
|
warnings: string[];
|
|
143
148
|
lifted: string[];
|
|
149
|
+
notes: string[];
|
|
144
150
|
}>;
|
|
145
151
|
/**
|
|
146
152
|
* Resolved tokens of the built theme in both modes.
|
|
@@ -188,6 +194,16 @@ export function settingsStamp(data: ThemeData): string;
|
|
|
188
194
|
* @param {ThemeData} data
|
|
189
195
|
*/
|
|
190
196
|
export function buildCurrent(cwd: string, slug: string, data: ThemeData): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Why the theme's build does not match its settings, in words, or null when
|
|
199
|
+
* it does: a file missing, another CLI version, settings changed since the
|
|
200
|
+
* build (a hand edit), or a build left half done (a command stopped).
|
|
201
|
+
* @param {string} cwd
|
|
202
|
+
* @param {string} slug
|
|
203
|
+
* @param {ThemeData} data
|
|
204
|
+
* @returns {string | null}
|
|
205
|
+
*/
|
|
206
|
+
export function staleBuild(cwd: string, slug: string, data: ThemeData): string | null;
|
|
191
207
|
/**
|
|
192
208
|
* Write a file whole: a new file beside it, renamed into place.
|
|
193
209
|
* @param {string} file
|
|
@@ -233,6 +249,35 @@ export function fontPackages(ctx: Ctx, data: ThemeData): {
|
|
|
233
249
|
family: string;
|
|
234
250
|
installed: boolean;
|
|
235
251
|
}[];
|
|
252
|
+
/**
|
|
253
|
+
* One setting the CLI owns.
|
|
254
|
+
* @typedef {object} Setting
|
|
255
|
+
* @property {string} thing - A dial, a token (`--color-accent`), or a CSS property.
|
|
256
|
+
* @property {string} value
|
|
257
|
+
* @property {'dial' | 'token' | 'property'} source
|
|
258
|
+
* @property {string} [on] - A part, a group, or a typography role (font).
|
|
259
|
+
* @property {string} [when] - `<prop>:<value>`.
|
|
260
|
+
* @property {string} [state]
|
|
261
|
+
* @property {'light' | 'dark'} [mode]
|
|
262
|
+
* @property {boolean} [only]
|
|
263
|
+
* @property {string} [axis] - For the `headings` dial: `weight` or `tracking`.
|
|
264
|
+
* @property {string} [note]
|
|
265
|
+
*/
|
|
266
|
+
/**
|
|
267
|
+
* The settings file.
|
|
268
|
+
* @typedef {object} ThemeData
|
|
269
|
+
* @property {string} name
|
|
270
|
+
* @property {string} [like] - The built-in theme it builds on.
|
|
271
|
+
* @property {'both' | 'light-only' | 'dark-only'} mode
|
|
272
|
+
* @property {Setting[]} settings
|
|
273
|
+
* @property {string[]} [lifted] - Variant keys the last build repeated a part setting on.
|
|
274
|
+
* @property {string} [palette] - The hash of the palette.config.json the editor last wrote.
|
|
275
|
+
*/
|
|
276
|
+
/** @typedef {{project: import('./_project.mjs').ThemeProject, C: import('./_compiler.mjs').Compiler, unchecked?: string | null, wrote?: Map<string, string | null>, base?: {light: Record<string, string>, dark: Record<string, string>}}} Ctx */
|
|
277
|
+
/** @typedef {import('./_parts.mjs').PaintSide} PaintSide */
|
|
278
|
+
/** @typedef {import('./_parts.mjs').TextPair} TextPair */
|
|
279
|
+
/** What a theme name may be, in words. */
|
|
280
|
+
export const NAME_RULE: "lowercase letters, digits and dashes, starting with a letter, 64 characters at most";
|
|
236
281
|
export function slugOk(s: string): boolean;
|
|
237
282
|
export function kebab(s: string): string;
|
|
238
283
|
export function camel(s: string): string;
|
|
@@ -296,7 +341,13 @@ export type Ctx = {
|
|
|
296
341
|
C: import("./_compiler.mjs").Compiler;
|
|
297
342
|
unchecked?: string | null;
|
|
298
343
|
wrote?: Map<string, string | null>;
|
|
344
|
+
base?: {
|
|
345
|
+
light: Record<string, string>;
|
|
346
|
+
dark: Record<string, string>;
|
|
347
|
+
};
|
|
299
348
|
};
|
|
349
|
+
export type PaintSide = import("./_parts.mjs").PaintSide;
|
|
350
|
+
export type TextPair = import("./_parts.mjs").TextPair;
|
|
300
351
|
/**
|
|
301
352
|
* What a part reads for a property when the theme does not set it, so a
|
|
302
353
|
* one-mode component setting keeps the other mode as it was.
|
|
@@ -14,12 +14,12 @@ import {createHash} from 'node:crypto';
|
|
|
14
14
|
import * as fs from 'node:fs';
|
|
15
15
|
import * as path from 'node:path';
|
|
16
16
|
import {pathToFileURL} from 'node:url';
|
|
17
|
+
import {cliVersion} from '../../foundation/release/run-context.mjs';
|
|
17
18
|
import {AstryxError} from '../error.mjs';
|
|
18
19
|
import {logger} from '../logger.mjs';
|
|
19
20
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
20
21
|
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
21
22
|
import {themeBuildForReport} from '../theme/build/build.mjs';
|
|
22
|
-
import {cliVersion} from '../../foundation/release/run-context.mjs';
|
|
23
23
|
import {
|
|
24
24
|
AUTO_SPREAD,
|
|
25
25
|
CORNERS,
|
|
@@ -49,9 +49,11 @@ import {
|
|
|
49
49
|
} from './_color.mjs';
|
|
50
50
|
import {
|
|
51
51
|
PALETTE_DIALS,
|
|
52
|
-
|
|
52
|
+
assertNoPlaceholder,
|
|
53
|
+
paletteImport,
|
|
53
54
|
paletteMapping,
|
|
54
55
|
syncPalette,
|
|
56
|
+
syncPaletteRefs,
|
|
55
57
|
writeWhole,
|
|
56
58
|
} from './_palette.mjs';
|
|
57
59
|
import {MODAL} from './_compiler.mjs';
|
|
@@ -83,7 +85,13 @@ import {baseResolved, baseThemeFile} from './_project.mjs';
|
|
|
83
85
|
* @property {string} [palette] - The hash of the palette.config.json the editor last wrote.
|
|
84
86
|
*/
|
|
85
87
|
|
|
86
|
-
/** @typedef {{project: import('./_project.mjs').ThemeProject, C: import('./_compiler.mjs').Compiler, unchecked?: string | null, wrote?: Map<string, string | null>}} Ctx */
|
|
88
|
+
/** @typedef {{project: import('./_project.mjs').ThemeProject, C: import('./_compiler.mjs').Compiler, unchecked?: string | null, wrote?: Map<string, string | null>, base?: {light: Record<string, string>, dark: Record<string, string>}}} Ctx */
|
|
89
|
+
/** @typedef {import('./_parts.mjs').PaintSide} PaintSide */
|
|
90
|
+
/** @typedef {import('./_parts.mjs').TextPair} TextPair */
|
|
91
|
+
|
|
92
|
+
/** What a theme name may be, in words. */
|
|
93
|
+
export const NAME_RULE =
|
|
94
|
+
'lowercase letters, digits and dashes, starting with a letter, 64 characters at most';
|
|
87
95
|
|
|
88
96
|
/** A theme name: lowercase letters, digits and dashes, starting with a letter, 64 characters at most. @param {string} s */
|
|
89
97
|
export const slugOk = s =>
|
|
@@ -192,12 +200,24 @@ export function refuse(code, message, extra = {}) {
|
|
|
192
200
|
* @returns {ThemeData}
|
|
193
201
|
*/
|
|
194
202
|
export function loadTheme(cwd, slug, skip = '') {
|
|
195
|
-
if (!slugOk(slug))
|
|
203
|
+
if (!slugOk(slug)) {
|
|
204
|
+
// A path or a capital letter typed for a theme that exists names it.
|
|
205
|
+
const plain = String(slug ?? '')
|
|
206
|
+
.toLowerCase()
|
|
207
|
+
.replace(/^.*themes[\\/]/, '')
|
|
208
|
+
.replace(/[\\/].*$/, '');
|
|
209
|
+
const same =
|
|
210
|
+
slugOk(plain) && fs.existsSync(themeFiles(cwd, plain).settings)
|
|
211
|
+
? plain
|
|
212
|
+
: null;
|
|
196
213
|
refuse(
|
|
197
214
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
198
|
-
`"${slug ?? ''}" is not a theme name (
|
|
199
|
-
|
|
215
|
+
`"${String(slug ?? '').slice(0, 80)}" is not a theme name (${NAME_RULE}).`,
|
|
216
|
+
same
|
|
217
|
+
? {didYouMean: [same], run: [`${P} show ${same}`]}
|
|
218
|
+
: {run: [`${P} new my-theme`]},
|
|
200
219
|
);
|
|
220
|
+
}
|
|
201
221
|
const f = themeFiles(cwd, slug);
|
|
202
222
|
if (!fs.existsSync(f.settings)) {
|
|
203
223
|
const have = fs.existsSync(f.root)
|
|
@@ -205,13 +225,30 @@ export function loadTheme(cwd, slug, skip = '') {
|
|
|
205
225
|
.readdirSync(f.root)
|
|
206
226
|
.filter(d => fs.existsSync(themeFiles(cwd, d).settings))
|
|
207
227
|
: [];
|
|
228
|
+
// A typed path or case of a theme that exists names that theme.
|
|
229
|
+
const plain = String(slug)
|
|
230
|
+
.toLowerCase()
|
|
231
|
+
.replace(/^.*themes[\\/]/, '')
|
|
232
|
+
.replace(/[\\/].*$/, '');
|
|
233
|
+
const same = have.includes(plain) ? plain : null;
|
|
208
234
|
refuse(
|
|
209
235
|
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
210
236
|
`There is no theme "${slug}" made by this command (no themes/${slug}/${slug}.settings.json).`,
|
|
211
|
-
{
|
|
237
|
+
{
|
|
238
|
+
didYouMean: same ? [same] : nearest(slug, have),
|
|
239
|
+
run: same ? [`${P} show ${same}`] : [`${P} new ${slug}`],
|
|
240
|
+
},
|
|
212
241
|
);
|
|
213
242
|
}
|
|
214
243
|
refuseLinks(cwd, slug);
|
|
244
|
+
// undo is offered only when there is a step to go back to.
|
|
245
|
+
const steps = readHistory(f.history).steps.length;
|
|
246
|
+
const recover = steps
|
|
247
|
+
? {
|
|
248
|
+
text: `, or step back to the settings before the last change with ${P} undo ${slug} (the last change is then lost)`,
|
|
249
|
+
run: [{name: `${P} undo ${slug}`, reason: 'do this instead'}],
|
|
250
|
+
}
|
|
251
|
+
: {text: '; there is no earlier step to go back to', run: []};
|
|
215
252
|
/** @type {any} */
|
|
216
253
|
let data;
|
|
217
254
|
try {
|
|
@@ -220,31 +257,42 @@ export function loadTheme(cwd, slug, skip = '') {
|
|
|
220
257
|
);
|
|
221
258
|
} catch (e) {
|
|
222
259
|
throw new AstryxError(
|
|
223
|
-
`themes/${slug}/${slug}.settings.json is not valid JSON (${e instanceof Error ? e.message : String(e)}). Fix it by hand
|
|
224
|
-
|
|
260
|
+
`themes/${slug}/${slug}.settings.json is not valid JSON (${e instanceof Error ? e.message : String(e)}). Fix it by hand${recover.text}.`,
|
|
261
|
+
recover.run,
|
|
225
262
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
226
263
|
);
|
|
227
264
|
}
|
|
228
265
|
const problem = settingsProblem(data, skip);
|
|
229
266
|
// A value made under looser rules is not damage: the command that
|
|
230
267
|
// changes or removes that setting still works.
|
|
231
|
-
const
|
|
232
|
-
if (problem &&
|
|
268
|
+
const bad = problem ? badSetting(data) : null;
|
|
269
|
+
if (problem && bad && settingsProblem(data, bad.thing) !== problem) {
|
|
270
|
+
// A value it takes, for a dial; a color for a color token.
|
|
271
|
+
const example = DIALS[bad.thing]
|
|
272
|
+
? DIALS[bad.thing].values.split('|').find(w => !w.startsWith('<'))
|
|
273
|
+
: bad.thing.startsWith('--color-')
|
|
274
|
+
? '#1f2937'
|
|
275
|
+
: null;
|
|
233
276
|
throw new AstryxError(
|
|
234
277
|
`themes/${slug}/${slug}.settings.json: ${problem}, a value the editor no longer accepts. Remove or change that setting; nothing else needs to change. Nothing was changed.`,
|
|
235
278
|
[
|
|
236
|
-
{name: `${P} undo ${slug} ${
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
279
|
+
{name: `${P} undo ${slug} ${undoArgs(bad)}`, reason: 'do this instead'},
|
|
280
|
+
...(example
|
|
281
|
+
? [
|
|
282
|
+
{
|
|
283
|
+
name: `${P} set ${slug} ${undoArgs(bad).replace(bad.thing, `${bad.thing} ${q(example)}`)}`,
|
|
284
|
+
reason: 'or give it a value it takes',
|
|
285
|
+
},
|
|
286
|
+
]
|
|
287
|
+
: []),
|
|
241
288
|
],
|
|
242
289
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
243
290
|
);
|
|
291
|
+
}
|
|
244
292
|
if (problem)
|
|
245
293
|
throw new AstryxError(
|
|
246
|
-
`themes/${slug}/${slug}.settings.json: ${problem}. Fix it by hand
|
|
247
|
-
|
|
294
|
+
`themes/${slug}/${slug}.settings.json: ${problem}. Fix it by hand${recover.text}. Nothing was changed.`,
|
|
295
|
+
recover.run,
|
|
248
296
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
249
297
|
);
|
|
250
298
|
return data;
|
|
@@ -267,6 +315,7 @@ export function settingsProblem(data, skip = '') {
|
|
|
267
315
|
if (data.like != null && !LIKE.includes(data.like))
|
|
268
316
|
return `base "${data.like}" is not a built-in theme (${LIKE.join(', ')})`;
|
|
269
317
|
if (!Array.isArray(data.settings)) return 'settings is not a list';
|
|
318
|
+
const keys = new Set();
|
|
270
319
|
for (const s of data.settings) {
|
|
271
320
|
if (!s || typeof s.thing !== 'string' || typeof s.value !== 'string')
|
|
272
321
|
return 'a setting has no thing or value';
|
|
@@ -277,6 +326,9 @@ export function settingsProblem(data, skip = '') {
|
|
|
277
326
|
return `${s.thing} has a ${k} that is not a word`;
|
|
278
327
|
if (s.mode != null && s.mode !== 'light' && s.mode !== 'dark')
|
|
279
328
|
return `${s.thing} has mode "${s.mode}"`;
|
|
329
|
+
const key = keyOf(s);
|
|
330
|
+
if (keys.has(key)) return `${describe(s)} is listed twice`;
|
|
331
|
+
keys.add(key);
|
|
280
332
|
if (s.thing === skip) continue;
|
|
281
333
|
const problem = valueProblem(s);
|
|
282
334
|
if (problem) return problem;
|
|
@@ -285,14 +337,29 @@ export function settingsProblem(data, skip = '') {
|
|
|
285
337
|
}
|
|
286
338
|
|
|
287
339
|
/**
|
|
288
|
-
* The
|
|
289
|
-
*
|
|
340
|
+
* The words that name a setting for `undo`.
|
|
341
|
+
* @param {import('./_settings.mjs').Setting} x
|
|
342
|
+
*/
|
|
343
|
+
export function undoArgs(x) {
|
|
344
|
+
return [
|
|
345
|
+
x.thing,
|
|
346
|
+
...(x.on ? [`--on ${x.on}`] : []),
|
|
347
|
+
...(x.when ? [`--when ${x.when}`] : []),
|
|
348
|
+
...(x.state ? [`--state ${x.state}`] : []),
|
|
349
|
+
...(x.mode ? [`--mode ${x.mode}`] : []),
|
|
350
|
+
...(x.only ? ['--only'] : []),
|
|
351
|
+
].join(' ');
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* The first setting whose only problem is its value (made under looser
|
|
356
|
+
* rules): `undo <theme> <undoArgs>` removes it.
|
|
290
357
|
* @param {any} data
|
|
291
|
-
* @returns {
|
|
358
|
+
* @returns {Setting | null}
|
|
292
359
|
*/
|
|
293
|
-
export function
|
|
360
|
+
export function badSetting(data) {
|
|
294
361
|
for (const s of Array.isArray(data?.settings) ? data.settings : [])
|
|
295
|
-
if (s && typeof s.thing === 'string' && valueProblem(s)) return s
|
|
362
|
+
if (s && typeof s.thing === 'string' && valueProblem(s)) return s;
|
|
296
363
|
return null;
|
|
297
364
|
}
|
|
298
365
|
|
|
@@ -319,6 +386,12 @@ function valueProblem(s) {
|
|
|
319
386
|
{
|
|
320
387
|
const bad = `${s.thing} "${s.value}"`;
|
|
321
388
|
if (!isSafeValue(s.value)) return `${bad} cannot be a CSS value`;
|
|
389
|
+
if (s.source === 'token') {
|
|
390
|
+
if (s.mode && !s.thing.startsWith('--color-'))
|
|
391
|
+
return `${s.thing} is set for ${s.mode} only, but only colors differ by mode`;
|
|
392
|
+
if (new RegExp(`var\\(\\s*${s.thing}\\s*[,)]`, 'i').test(s.value))
|
|
393
|
+
return `${bad} reads itself`;
|
|
394
|
+
}
|
|
322
395
|
if (s.source !== 'dial') return null;
|
|
323
396
|
const d = DIALS[s.thing];
|
|
324
397
|
if (!d) return `${s.thing} is not a dial`;
|
|
@@ -553,7 +626,17 @@ export function compileTheme(ctx, data, base) {
|
|
|
553
626
|
const headingWeightTokens = Object.keys(TOKENS).filter(k =>
|
|
554
627
|
/^--text-(heading|display)-\d-weight$/.test(k),
|
|
555
628
|
);
|
|
556
|
-
|
|
629
|
+
// Dials first, then exact tokens and part properties: an exact setting
|
|
630
|
+
// always wins over a dial, whatever the order they were made in.
|
|
631
|
+
// A font for one role (body, heading, code) comes after the whole-theme
|
|
632
|
+
// font, so the role keeps its own font whatever the order.
|
|
633
|
+
const roleFont = (/** @type {Setting} */ x) => x.thing === 'font' && !!x.on;
|
|
634
|
+
const ordered = [
|
|
635
|
+
...data.settings.filter(x => x.source === 'dial' && !roleFont(x)),
|
|
636
|
+
...data.settings.filter(x => x.source === 'dial' && roleFont(x)),
|
|
637
|
+
...data.settings.filter(x => x.source !== 'dial'),
|
|
638
|
+
];
|
|
639
|
+
for (const s of ordered) {
|
|
557
640
|
// A setting for the mode a one-mode theme does not have stays saved but
|
|
558
641
|
// does not apply (maskedSettings names it).
|
|
559
642
|
if (modeOnly && s.mode && s.mode !== modeOnly) continue;
|
|
@@ -568,7 +651,11 @@ export function compileTheme(ctx, data, base) {
|
|
|
568
651
|
putComp({...s, mode: undefined}, t, 'borderRadius', val(px));
|
|
569
652
|
else {
|
|
570
653
|
putTok('--radius-element', val(px));
|
|
571
|
-
|
|
654
|
+
// A checkbox stays a rounded square next to a round radio.
|
|
655
|
+
putTok(
|
|
656
|
+
'--radius-inner',
|
|
657
|
+
px >= 9999 ? '6px' : val(Math.round(px * 0.6)),
|
|
658
|
+
);
|
|
572
659
|
putTok(
|
|
573
660
|
'--radius-container',
|
|
574
661
|
px >= 9999 ? '24px' : `${Math.round(px * 1.25)}px`,
|
|
@@ -655,9 +742,11 @@ export function compileTheme(ctx, data, base) {
|
|
|
655
742
|
};
|
|
656
743
|
} else if (s.thing === 'spacing') {
|
|
657
744
|
const f = SPACING.find(([n]) => n === s.value)?.[1] ?? 1;
|
|
658
|
-
|
|
745
|
+
// The rungs scale the spacing the base theme starts from.
|
|
746
|
+
for (const [k, core] of Object.entries(
|
|
659
747
|
/** @type {Record<string, string>} */ (TOKENS),
|
|
660
748
|
)) {
|
|
749
|
+
const v = base.light[k] ?? core;
|
|
661
750
|
let nv = null;
|
|
662
751
|
if (/^--spacing-/.test(k) && /rem$/.test(v))
|
|
663
752
|
nv = `${Number((parseFloat(v) * f).toFixed(3))}rem`;
|
|
@@ -858,7 +947,9 @@ function settingsSource(slug, data, theme, pal) {
|
|
|
858
947
|
const REF = '@@palette:';
|
|
859
948
|
/** @param {string} family @param {'light' | 'dark'} m @param {import('./_palette.mjs').StopRef} r */
|
|
860
949
|
const refOf = (family, m, r) =>
|
|
861
|
-
|
|
950
|
+
r.family === 'black' || r.family === 'white'
|
|
951
|
+
? `${REF}${r.family}`
|
|
952
|
+
: `${REF}${r.family ?? family}.${m}.${r.stop}${r.alpha ? `+${r.alpha}` : ''}`;
|
|
862
953
|
const out = {...theme, name: `${slug}-settings`};
|
|
863
954
|
const only =
|
|
864
955
|
data.mode === 'light-only'
|
|
@@ -886,9 +977,10 @@ function settingsSource(slug, data, theme, pal) {
|
|
|
886
977
|
}
|
|
887
978
|
let usesPalette = false;
|
|
888
979
|
const body = JSON.stringify(out, null, 2).replace(
|
|
889
|
-
/"@@palette:([a-z][a-z0-9-]*)\.(light|dark)\.(\d+)(?:\+([0-9a-f]{2}))?"/g,
|
|
890
|
-
(_, family, m, stop, alpha) => {
|
|
980
|
+
/"@@palette:(?:(black|white)|([a-z][a-z0-9-]*)\.(light|dark)\.(\d+(?:\.\d+)?)(?:\+([0-9a-f]{2}))?)"/g,
|
|
981
|
+
(_, end, family, m, stop, alpha) => {
|
|
891
982
|
usesPalette = true;
|
|
983
|
+
if (end) return `palette.${end}`;
|
|
892
984
|
return `palette${/^[a-z]\w*$/.test(family) ? `.${family}` : `[${JSON.stringify(family)}]`}.${m}[${stop}]${alpha ? ` + '${alpha}'` : ''}`;
|
|
893
985
|
},
|
|
894
986
|
);
|
|
@@ -902,9 +994,7 @@ function settingsSource(slug, data, theme, pal) {
|
|
|
902
994
|
`import {${like}Theme as base} from '@astryxdesign/theme-${like}/built';`,
|
|
903
995
|
]
|
|
904
996
|
: []),
|
|
905
|
-
...(usesPalette
|
|
906
|
-
? [`import {palette} from '${paletteFiles(slug).importPath}';`]
|
|
907
|
-
: []),
|
|
997
|
+
...(usesPalette ? [paletteImport(slug)] : []),
|
|
908
998
|
'',
|
|
909
999
|
`export const ${camel(slug)}Settings = defineTheme({`,
|
|
910
1000
|
...(like ? [' extends: base,'] : []),
|
|
@@ -941,7 +1031,7 @@ function themeModuleSource(slug) {
|
|
|
941
1031
|
* @param {Ctx} ctx
|
|
942
1032
|
* @param {string} slug
|
|
943
1033
|
* @param {ThemeData} data
|
|
944
|
-
* @returns {Promise<{warnings: string[], lifted: string[]}>}
|
|
1034
|
+
* @returns {Promise<{warnings: string[], lifted: string[], notes: string[]}>} `notes`: what the color config kept or replaced of a hand edit
|
|
945
1035
|
*/
|
|
946
1036
|
export async function buildTheme(ctx, slug, data) {
|
|
947
1037
|
const {cwd} = ctx.project;
|
|
@@ -960,9 +1050,12 @@ export async function buildTheme(ctx, slug, data) {
|
|
|
960
1050
|
// Each write is recorded for a rollback; the time between them is not.
|
|
961
1051
|
/** @type {<T>(fn: () => T) => Promise<Awaited<T>>} */
|
|
962
1052
|
const step = fn => track(f.dir, ctx.wrote ?? new Map(), fn);
|
|
1053
|
+
/** @type {string[]} */
|
|
1054
|
+
let notes = [];
|
|
963
1055
|
await step(() => {
|
|
964
|
-
syncPalette(cwd, slug, data);
|
|
1056
|
+
notes = syncPalette(cwd, slug, data, base);
|
|
965
1057
|
writeAtomic(f.settingsTs, settingsSource(slug, data, theme, pal));
|
|
1058
|
+
syncPaletteRefs(cwd, slug, fs.readFileSync(f.settingsTs, 'utf8'), pal);
|
|
966
1059
|
if (!fs.existsSync(f.ts)) writeAtomic(f.ts, themeModuleSource(slug));
|
|
967
1060
|
});
|
|
968
1061
|
let receipt = await step(() => runBuild(ctx, slug));
|
|
@@ -977,11 +1070,15 @@ export async function buildTheme(ctx, slug, data) {
|
|
|
977
1070
|
(t[x.key] ??= {})[x.prop] ??= x.value;
|
|
978
1071
|
lifted.push(`${x.target} ${x.key} ${kebab(x.prop)}`);
|
|
979
1072
|
}
|
|
980
|
-
await step(() =>
|
|
981
|
-
writeAtomic(f.settingsTs, settingsSource(slug, data, theme, pal))
|
|
982
|
-
|
|
1073
|
+
await step(() => {
|
|
1074
|
+
writeAtomic(f.settingsTs, settingsSource(slug, data, theme, pal));
|
|
1075
|
+
syncPaletteRefs(cwd, slug, fs.readFileSync(f.settingsTs, 'utf8'), pal);
|
|
1076
|
+
});
|
|
983
1077
|
receipt = await step(() => runBuild(ctx, slug));
|
|
984
1078
|
}
|
|
1079
|
+
for (const out of [f.css, f.js])
|
|
1080
|
+
if (fs.existsSync(out))
|
|
1081
|
+
assertNoPlaceholder(shown(cwd, out), fs.readFileSync(out, 'utf8'));
|
|
985
1082
|
// Font notices are reported by the font dial itself, once.
|
|
986
1083
|
const warnings = [
|
|
987
1084
|
...(receipt?.data?.warnings ?? []),
|
|
@@ -989,7 +1086,7 @@ export async function buildTheme(ctx, slug, data) {
|
|
|
989
1086
|
]
|
|
990
1087
|
.map(String)
|
|
991
1088
|
.filter(w => !/^Font "/.test(w));
|
|
992
|
-
return {warnings, lifted};
|
|
1089
|
+
return {warnings, lifted, notes};
|
|
993
1090
|
}
|
|
994
1091
|
|
|
995
1092
|
/** @param {Ctx} ctx @param {string} slug @returns {Promise<any>} */
|
|
@@ -1075,7 +1172,7 @@ export async function resolvedTokens(ctx, slug) {
|
|
|
1075
1172
|
*/
|
|
1076
1173
|
export async function contrastProblems(ctx, data, res) {
|
|
1077
1174
|
const base = await baseResolved(ctx.project, data.like);
|
|
1078
|
-
/** @param {
|
|
1175
|
+
/** @param {PaintSide} side @param {'fg' | 'bg'} which @param {string} m */
|
|
1079
1176
|
const override = (side, which, m) => {
|
|
1080
1177
|
if (!side.target) return null;
|
|
1081
1178
|
const props =
|
|
@@ -1093,7 +1190,7 @@ export async function contrastProblems(ctx, data, res) {
|
|
|
1093
1190
|
);
|
|
1094
1191
|
return hit?.value ?? null;
|
|
1095
1192
|
};
|
|
1096
|
-
/** @type {(p:
|
|
1193
|
+
/** @type {(p: TextPair, side: 'fg' | 'bg', m: string) => string | null} */
|
|
1097
1194
|
const value = (p, side, m) => {
|
|
1098
1195
|
const s = p[side];
|
|
1099
1196
|
return (
|
|
@@ -1103,7 +1200,7 @@ export async function contrastProblems(ctx, data, res) {
|
|
|
1103
1200
|
: s.raw)
|
|
1104
1201
|
);
|
|
1105
1202
|
};
|
|
1106
|
-
/** @type {(p:
|
|
1203
|
+
/** @type {(p: TextPair, side: 'fg' | 'bg', m: string) => string | null} */
|
|
1107
1204
|
const baseValue = (p, side, m) => {
|
|
1108
1205
|
const s = p[side];
|
|
1109
1206
|
return s.tokens.length
|
|
@@ -1131,6 +1228,28 @@ export async function contrastProblems(ctx, data, res) {
|
|
|
1131
1228
|
...(more
|
|
1132
1229
|
? [`and ${more} more text pair${more > 1 ? 's' : ''} below 4.5:1`]
|
|
1133
1230
|
: []),
|
|
1231
|
+
// Pairs styled for one variant or state are not measured yet.
|
|
1232
|
+
...(() => {
|
|
1233
|
+
const scoped = data.settings.filter(
|
|
1234
|
+
x =>
|
|
1235
|
+
(x.on &&
|
|
1236
|
+
(x.when || x.state) &&
|
|
1237
|
+
(/^(color|background|background-color)$/.test(x.thing) ||
|
|
1238
|
+
/^--color-/.test(x.thing))) ||
|
|
1239
|
+
// The button style recolors the primary button only.
|
|
1240
|
+
(x.thing === 'buttons' && ['soft', 'outline'].includes(x.value)),
|
|
1241
|
+
);
|
|
1242
|
+
return scoped.length
|
|
1243
|
+
? [
|
|
1244
|
+
`not checked: text contrast for ${scoped
|
|
1245
|
+
.slice(0, 3)
|
|
1246
|
+
.map(describe)
|
|
1247
|
+
.join(
|
|
1248
|
+
'; ',
|
|
1249
|
+
)}${scoped.length > 3 ? ` and ${scoped.length - 3} more` : ''}, set for one variant or state`,
|
|
1250
|
+
]
|
|
1251
|
+
: [];
|
|
1252
|
+
})(),
|
|
1134
1253
|
...(unchecked.length
|
|
1135
1254
|
? [
|
|
1136
1255
|
`not checked: text on or in ${unchecked.slice(0, 3).join(', ')}${unchecked.length > 3 ? ` and ${unchecked.length - 3} more` : ''}, which ${unchecked.length === 1 ? 'is' : 'are'} not a fixed color`,
|
|
@@ -1317,14 +1436,36 @@ export function settingsStamp(data) {
|
|
|
1317
1436
|
* @param {ThemeData} data
|
|
1318
1437
|
*/
|
|
1319
1438
|
export function buildCurrent(cwd, slug, data) {
|
|
1439
|
+
return staleBuild(cwd, slug, data) == null;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
/**
|
|
1443
|
+
* Why the theme's build does not match its settings, in words, or null when
|
|
1444
|
+
* it does: a file missing, another CLI version, settings changed since the
|
|
1445
|
+
* build (a hand edit), or a build left half done (a command stopped).
|
|
1446
|
+
* @param {string} cwd
|
|
1447
|
+
* @param {string} slug
|
|
1448
|
+
* @param {ThemeData} data
|
|
1449
|
+
* @returns {string | null}
|
|
1450
|
+
*/
|
|
1451
|
+
export function staleBuild(cwd, slug, data) {
|
|
1320
1452
|
const f = themeFiles(cwd, slug);
|
|
1321
|
-
|
|
1453
|
+
const missing = [f.js, f.css, f.settingsTs].find(p => !fs.existsSync(p));
|
|
1454
|
+
if (missing) return `${path.basename(missing)} was missing`;
|
|
1322
1455
|
const ts = fs.readFileSync(f.settingsTs, 'utf8');
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1456
|
+
const stamp =
|
|
1457
|
+
/\/\/ Built from settings ([0-9a-f]{16}) \(CLI ([^)]+)\)\./.exec(ts);
|
|
1458
|
+
const [hash] = settingsStamp(data).split(' ');
|
|
1459
|
+
if (stamp && stamp[1] === hash && stamp[2] !== cliVersion())
|
|
1460
|
+
return `it was built by CLI ${stamp[2]}, and this is ${cliVersion()}`;
|
|
1461
|
+
if (!stamp || stamp[1] !== hash)
|
|
1462
|
+
return `${slug}.settings.json changed after the build (edited by hand, or by another tool)`;
|
|
1463
|
+
if (
|
|
1464
|
+
!ts.trimEnd().endsWith('});') ||
|
|
1465
|
+
fs.statSync(f.css).mtimeMs < fs.statSync(f.settingsTs).mtimeMs - 1000
|
|
1466
|
+
)
|
|
1467
|
+
return 'the last build did not finish (a command stopped while building)';
|
|
1468
|
+
return null;
|
|
1328
1469
|
}
|
|
1329
1470
|
|
|
1330
1471
|
/** @param {string} dir */
|
|
@@ -1446,7 +1587,7 @@ export async function commitTheme(ctx, slug, data, {history, historyAfter}) {
|
|
|
1446
1587
|
const wrote = new Map();
|
|
1447
1588
|
ctx.wrote = wrote;
|
|
1448
1589
|
fs.mkdirSync(f.dir, {recursive: true});
|
|
1449
|
-
/** @type {{warnings: string[], lifted: string[]}} */
|
|
1590
|
+
/** @type {{warnings: string[], lifted: string[], notes: string[]}} */
|
|
1450
1591
|
let built;
|
|
1451
1592
|
try {
|
|
1452
1593
|
built = await buildTheme(ctx, slug, data);
|
|
@@ -1484,7 +1625,13 @@ export async function commitTheme(ctx, slug, data, {history, historyAfter}) {
|
|
|
1484
1625
|
[],
|
|
1485
1626
|
ERROR_CODES.ERR_WRITE_FAILED,
|
|
1486
1627
|
);
|
|
1487
|
-
|
|
1628
|
+
// The color config's own refusals already name the file and the fix.
|
|
1629
|
+
if (
|
|
1630
|
+
e instanceof AstryxError &&
|
|
1631
|
+
(e.code === ERROR_CODES.ERR_UNKNOWN_THEME ||
|
|
1632
|
+
e.code === ERROR_CODES.ERR_THEME_INVALID ||
|
|
1633
|
+
e.code === ERROR_CODES.ERR_PALETTE_GENERATION)
|
|
1634
|
+
)
|
|
1488
1635
|
throw e;
|
|
1489
1636
|
const why = (e instanceof Error ? e.message : String(e))
|
|
1490
1637
|
.split(`${cwd}${path.sep}`)
|
|
@@ -1505,6 +1652,7 @@ export async function commitTheme(ctx, slug, data, {history, historyAfter}) {
|
|
|
1505
1652
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
1506
1653
|
);
|
|
1507
1654
|
}
|
|
1655
|
+
notes.push(...built.notes);
|
|
1508
1656
|
// The change is saved from here on: a failure to check it is reported
|
|
1509
1657
|
// as "saved, not checked", never as a failed change.
|
|
1510
1658
|
/** @type {Record<'light' | 'dark', Record<string, string>>} */
|