@astryxdesign/cli 0.7.15 → 0.7.16-canary.g8514aae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +1 -21
- package/api/theme/build/build.mjs +149 -37
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +91 -19
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +21 -0
- package/api/theme-edit/_adapter.mjs +176 -22
- package/api/theme-edit/_check.d.mts +7 -0
- package/api/theme-edit/_check.mjs +1050 -173
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +21 -0
- package/api/theme-edit/_context.mjs +235 -12
- package/api/theme-edit/_css.d.mts +50 -1
- package/api/theme-edit/_css.mjs +310 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +907 -123
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_palette.d.mts +6 -0
- package/api/theme-edit/_palette.mjs +164 -62
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +49 -1
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.mjs +514 -27
- package/api/theme-edit/_preview.d.mts +11 -0
- package/api/theme-edit/_preview.mjs +245 -24
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +35 -9
- package/api/theme-edit/_settings.d.mts +122 -5
- package/api/theme-edit/_settings.mjs +1363 -71
- package/api/theme-edit/_tables.d.mts +19 -0
- package/api/theme-edit/_tables.mjs +205 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +188 -37
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +89 -6
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +40 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +50 -14
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +24 -3
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +36 -10
- package/foundation/fs/paths.d.mts +16 -0
- package/foundation/fs/paths.mjs +25 -0
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +7 -6
|
@@ -22,7 +22,9 @@ export const doc = {
|
|
|
22
22
|
'Read it, copy what you need into your own theme file, delete it. Use `theme add` to ' +
|
|
23
23
|
'use an installed built theme, extend that theme for ordinary customization, or use ' +
|
|
24
24
|
'`theme eject` for a complete source fork. This command starts a new blank theme. Refuses to overwrite without ' +
|
|
25
|
-
'`overwrite`, so it is safe to re-run.'
|
|
25
|
+
'`overwrite`, so it is safe to re-run. With no package.json at or above cwd, it writes in cwd ' +
|
|
26
|
+
'and the CLI warns; pass a cwd inside a project, or run `npm init -y` in that folder first, to ' +
|
|
27
|
+
'write it at a project root.',
|
|
26
28
|
importPath: '@astryxdesign/cli/api',
|
|
27
29
|
signature:
|
|
28
30
|
'themeTemplate(options?: {targetPath?: string, overwrite?: boolean, cwd?: string}): ThemeTemplateResponse',
|
|
@@ -31,7 +33,8 @@ export const doc = {
|
|
|
31
33
|
{
|
|
32
34
|
name: 'options.targetPath',
|
|
33
35
|
type: 'string',
|
|
34
|
-
description:
|
|
36
|
+
description:
|
|
37
|
+
'Destination file, read from cwd. Must resolve within the project root: the nearest folder at or above cwd with a package.json. Left out, the template is written at the project root.',
|
|
35
38
|
default: "'theme.template.ts'",
|
|
36
39
|
},
|
|
37
40
|
{
|
|
@@ -55,7 +58,10 @@ export const doc = {
|
|
|
55
58
|
},
|
|
56
59
|
],
|
|
57
60
|
throws: [
|
|
58
|
-
{
|
|
61
|
+
{
|
|
62
|
+
code: 'ERR_PATH_TRAVERSAL',
|
|
63
|
+
when: 'the target path escapes the project root (the nearest folder at or above cwd with a package.json)',
|
|
64
|
+
},
|
|
59
65
|
{
|
|
60
66
|
code: 'ERR_INVALID_ARGUMENT',
|
|
61
67
|
when: 'the target path is blank, names a folder, or is not a .ts file (with or without overwrite)',
|
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditHowResponse>}
|
|
11
11
|
*/
|
|
12
12
|
export function themeEditHow(subject: string, options?: import("./theme-edit.type.mjs").ThemeEditHowOptions): Promise<import("./theme-edit.type.mjs").ThemeEditHowResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Whether a value fits what a dial takes, read from the dial's own list of
|
|
15
|
+
* values: a named rung in any case, or a value of the kind it names (a size,
|
|
16
|
+
* a color, a number). `set` still checks the value in full.
|
|
17
|
+
* @param {string} dial
|
|
18
|
+
* @param {string} value
|
|
19
|
+
*/
|
|
20
|
+
export function dialValueFits(dial: string, value: string): boolean;
|
|
13
21
|
/**
|
|
14
22
|
* The project a command acts on: the Astryx project at or above `cwd`, found
|
|
15
23
|
* as `upgrade` finds it (the nearest package that declares an Astryx package
|
|
@@ -55,8 +63,21 @@ export function editorCompileProblem(files: string[], { cwd, check, family }: {
|
|
|
55
63
|
export function editorThemeHold(files: string[], { cwd }: {
|
|
56
64
|
cwd: string;
|
|
57
65
|
}): Promise<() => Promise<void>>;
|
|
66
|
+
/**
|
|
67
|
+
* `theme template` for the experimental command: in a folder the theme
|
|
68
|
+
* editor made, only the editor's own files are protected.
|
|
69
|
+
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} options
|
|
70
|
+
* @returns {import('../theme/theme.type.mjs').ThemeTemplateResponse}
|
|
71
|
+
*/
|
|
72
|
+
export function editorThemeTemplate(options: {
|
|
73
|
+
targetPath?: string;
|
|
74
|
+
overwrite?: boolean;
|
|
75
|
+
cwd?: string;
|
|
76
|
+
}): import("../theme/theme.type.mjs").ThemeTemplateResponse;
|
|
58
77
|
export { parsePoints } from "./_how.mjs";
|
|
78
|
+
export { newFlagList } from "./_edit.mjs";
|
|
59
79
|
export function builtInThemes(): string[];
|
|
80
|
+
export function showSections(): string[];
|
|
60
81
|
/** @type {typeof edit.themeEditNew} */
|
|
61
82
|
export const themeEditNew: typeof edit.themeEditNew;
|
|
62
83
|
/** @type {typeof edit.themeEditSet} */
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
* @position api/theme-edit — adapter for api/theme-edit/theme-edit.mjs
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
+
import {writeThemeTemplate} from '../theme/template/template.mjs';
|
|
34
35
|
import {createHash} from 'node:crypto';
|
|
35
36
|
import * as fs from 'node:fs';
|
|
36
37
|
import * as path from 'node:path';
|
|
@@ -49,11 +50,15 @@ import {
|
|
|
49
50
|
getCliInvocation,
|
|
50
51
|
quoteCommandArgument,
|
|
51
52
|
} from '../../foundation/env/package-manager.mjs';
|
|
52
|
-
import {LIKE, P} from './_tables.mjs';
|
|
53
|
-
import {
|
|
53
|
+
import {DIALS, LIKE, P} from './_tables.mjs';
|
|
54
|
+
import {setLine} from './_check.mjs';
|
|
55
|
+
import {colorProblem} from './_color.mjs';
|
|
56
|
+
import {SHOWCASE_GROUPS} from './_preview.mjs';
|
|
57
|
+
import {camel, typedThemeName} from './_settings.mjs';
|
|
54
58
|
import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
|
|
55
59
|
|
|
56
60
|
export {parsePoints} from './_how.mjs';
|
|
61
|
+
export {newFlagList} from './_edit.mjs';
|
|
57
62
|
import {themeEditHow as howAt} from './_how.mjs';
|
|
58
63
|
|
|
59
64
|
/**
|
|
@@ -90,6 +95,35 @@ export async function themeEditHow(subject, options = {}) {
|
|
|
90
95
|
/** The built-in themes a theme can build on (`--like`). */
|
|
91
96
|
export const builtInThemes = () => [...LIKE];
|
|
92
97
|
|
|
98
|
+
/** The sections `show --section` takes. */
|
|
99
|
+
export const showSections = () => [...SHOWCASE_GROUPS];
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether a value fits what a dial takes, read from the dial's own list of
|
|
103
|
+
* values: a named rung in any case, or a value of the kind it names (a size,
|
|
104
|
+
* a color, a number). `set` still checks the value in full.
|
|
105
|
+
* @param {string} dial
|
|
106
|
+
* @param {string} value
|
|
107
|
+
*/
|
|
108
|
+
export function dialValueFits(dial, value) {
|
|
109
|
+
const spec = DIALS[/** @type {keyof typeof DIALS} */ (dial)]?.values;
|
|
110
|
+
if (!spec) return false;
|
|
111
|
+
const v = String(value).trim();
|
|
112
|
+
if (v === '') return false;
|
|
113
|
+
return spec.split('|').some(option => {
|
|
114
|
+
if (!option.startsWith('<') && !option.startsWith('"'))
|
|
115
|
+
return option === v.toLowerCase();
|
|
116
|
+
if (option.startsWith('"')) return true;
|
|
117
|
+
if (option.includes('size')) return /^\d*\.?\d+(px|rem|em)$/.test(v);
|
|
118
|
+
// A color by the editor's own color check (a bare word only when it
|
|
119
|
+
// names a color).
|
|
120
|
+
if (option === '<color>') return colorProblem(v) == null;
|
|
121
|
+
if (option === '<0-100>') return /^\d{1,3}$/.test(v) && Number(v) <= 100;
|
|
122
|
+
if (option === '<number>') return /^\d*\.?\d+$/.test(v);
|
|
123
|
+
return false;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
93
127
|
/**
|
|
94
128
|
* The project a command acts on: the Astryx project at or above `cwd`, found
|
|
95
129
|
* as `upgrade` finds it (the nearest package that declares an Astryx package
|
|
@@ -195,9 +229,15 @@ function lockDir(root) {
|
|
|
195
229
|
* @param {boolean} [bestEffort] a command that can run read-only runs
|
|
196
230
|
* without the lock when it cannot be taken (a read-only node_modules),
|
|
197
231
|
* told so, and then writes nothing
|
|
232
|
+
* @param {string | null} [again] the command's own words after the CLI
|
|
233
|
+
* name, to suggest running it again (never the host process's argv: an
|
|
234
|
+
* API caller is not a CLI run)
|
|
198
235
|
* @returns {Promise<T>}
|
|
199
236
|
*/
|
|
200
|
-
async function withLock(root, name, fn, bestEffort = false) {
|
|
237
|
+
async function withLock(root, name, fn, bestEffort = false, again = null) {
|
|
238
|
+
// A preview command, which holds the preview lock, suggests the list of
|
|
239
|
+
// previews (what the other command may be changing).
|
|
240
|
+
again ??= name === 'preview' ? 'experimental theme preview list' : null;
|
|
201
241
|
/** @type {string | null} */
|
|
202
242
|
let dir;
|
|
203
243
|
try {
|
|
@@ -239,16 +279,17 @@ async function withLock(root, name, fn, bestEffort = false) {
|
|
|
239
279
|
{
|
|
240
280
|
onBusy: (o, held) => {
|
|
241
281
|
throw new AstryxError(
|
|
242
|
-
`Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
282
|
+
`Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again once the other one ends. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
|
|
283
|
+
// Every editor command (show too) takes this lock, so none of
|
|
284
|
+
// them works meanwhile: this same command, once the other ends.
|
|
285
|
+
again
|
|
286
|
+
? [
|
|
287
|
+
{
|
|
288
|
+
name: runLine(root, again),
|
|
289
|
+
reason: 'run it again once the other command ends',
|
|
290
|
+
},
|
|
291
|
+
]
|
|
292
|
+
: [],
|
|
252
293
|
ERROR_CODES.ERR_THEME_BUSY,
|
|
253
294
|
);
|
|
254
295
|
},
|
|
@@ -346,9 +387,11 @@ function absolute(result, root, from) {
|
|
|
346
387
|
* @param {O} options
|
|
347
388
|
* @param {string | null} lock
|
|
348
389
|
* @param {(o: O & {cwd: string}) => Promise<T>} fn
|
|
390
|
+
* @param {boolean} [bestEffort]
|
|
391
|
+
* @param {string | null} [again] the command's own words, for a busy lock
|
|
349
392
|
* @returns {Promise<T>}
|
|
350
393
|
*/
|
|
351
|
-
async function inProject(options, lock, fn, bestEffort = false) {
|
|
394
|
+
async function inProject(options, lock, fn, bestEffort = false, again = null) {
|
|
352
395
|
const from = options.cwd ?? process.cwd();
|
|
353
396
|
const o = atRoot(options);
|
|
354
397
|
try {
|
|
@@ -360,6 +403,7 @@ async function inProject(options, lock, fn, bestEffort = false) {
|
|
|
360
403
|
lock,
|
|
361
404
|
locked => fn(locked ? o : {...o, readOnly: true}),
|
|
362
405
|
bestEffort,
|
|
406
|
+
again,
|
|
363
407
|
)
|
|
364
408
|
: await fn(o);
|
|
365
409
|
return absolute(r, o.cwd, from);
|
|
@@ -434,20 +478,74 @@ const withThemeLock = o => ({
|
|
|
434
478
|
) => withLock(o.cwd, lockName(slug), fn),
|
|
435
479
|
});
|
|
436
480
|
|
|
481
|
+
/**
|
|
482
|
+
* A command's own words after the CLI name, from what it was called with,
|
|
483
|
+
* every option kept: set and undo as `set` writes them (scope flags and
|
|
484
|
+
* --only), new with --like and each dial, --png where given.
|
|
485
|
+
* @param {string} line a command as the editor writes one (`astryx …`)
|
|
486
|
+
* @param {{png?: boolean}} [o]
|
|
487
|
+
*/
|
|
488
|
+
const words = (line, o = {}) =>
|
|
489
|
+
`${line.replace(/^astryx /, '').trimEnd()}${o.png ? ' --png' : ''}`;
|
|
490
|
+
|
|
437
491
|
/** @type {typeof edit.themeEditNew} */
|
|
438
492
|
export const themeEditNew = (name, options = {}) =>
|
|
439
|
-
inProject(
|
|
493
|
+
inProject(
|
|
494
|
+
options,
|
|
495
|
+
lockName(name),
|
|
496
|
+
o => edit.themeEditNew(name, o),
|
|
497
|
+
false,
|
|
498
|
+
words(
|
|
499
|
+
`${P} new ${quoteCommandArgument(name)} ${edit
|
|
500
|
+
.newFlagList(
|
|
501
|
+
options.like,
|
|
502
|
+
options.settings ?? {},
|
|
503
|
+
/** @type {boolean} */ (options.png),
|
|
504
|
+
)
|
|
505
|
+
.join(' ')}`,
|
|
506
|
+
),
|
|
507
|
+
);
|
|
440
508
|
/** @type {typeof edit.themeEditSet} */
|
|
441
509
|
export const themeEditSet = (theme, thing, value, options = {}) =>
|
|
442
|
-
inProject(
|
|
443
|
-
|
|
510
|
+
inProject(
|
|
511
|
+
options,
|
|
512
|
+
lockName(theme),
|
|
513
|
+
o => edit.themeEditSet(theme, thing, value, o),
|
|
514
|
+
false,
|
|
515
|
+
words(setLine(theme, thing, value, options), options),
|
|
444
516
|
);
|
|
445
517
|
/** @type {typeof edit.themeEditUndo} */
|
|
446
518
|
export const themeEditUndo = (theme, options = {}) =>
|
|
447
|
-
inProject(
|
|
519
|
+
inProject(
|
|
520
|
+
options,
|
|
521
|
+
lockName(theme),
|
|
522
|
+
o => edit.themeEditUndo(theme, o),
|
|
523
|
+
false,
|
|
524
|
+
words(
|
|
525
|
+
options.thing
|
|
526
|
+
? setLine(
|
|
527
|
+
theme,
|
|
528
|
+
options.thing,
|
|
529
|
+
/** @type {string} */ (options.value ?? ''),
|
|
530
|
+
options,
|
|
531
|
+
true,
|
|
532
|
+
)
|
|
533
|
+
: `${P} undo ${theme}`,
|
|
534
|
+
options,
|
|
535
|
+
),
|
|
536
|
+
);
|
|
448
537
|
/** @type {typeof edit.themeEditShow} */
|
|
449
538
|
export const themeEditShow = (theme, options = {}) =>
|
|
450
|
-
inProject(
|
|
539
|
+
inProject(
|
|
540
|
+
options,
|
|
541
|
+
lockName(theme),
|
|
542
|
+
o => edit.themeEditShow(theme, o),
|
|
543
|
+
true,
|
|
544
|
+
words(
|
|
545
|
+
`${P} show ${theme}${options.section ? ` --section ${quoteCommandArgument(String(options.section))}` : ''}`,
|
|
546
|
+
options,
|
|
547
|
+
),
|
|
548
|
+
);
|
|
451
549
|
/** @type {typeof preview.themeEditPreviewAdd} */
|
|
452
550
|
export const themeEditPreviewAdd = (description, options = {}) =>
|
|
453
551
|
inProject(options, 'preview', o =>
|
|
@@ -577,16 +675,32 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
577
675
|
)
|
|
578
676
|
return null;
|
|
579
677
|
const root = projectRoot(cwd);
|
|
580
|
-
|
|
581
|
-
|
|
678
|
+
// The name as typed, read the way the editor reads a theme name: a path
|
|
679
|
+
// to its folder or a file in it, in any case, names the theme.
|
|
680
|
+
const named = /"([^"]+)"|'([^']+)'/.exec(err.message);
|
|
681
|
+
const word = named ? typedThemeName(named[1] ?? named[2]) : '';
|
|
682
|
+
const slug = word ? editorThemeOf(root, word) : null;
|
|
582
683
|
if (!slug) return null;
|
|
583
684
|
// A local theme of that name (a fork in the app's own themes folder) is
|
|
584
685
|
// one the stable commands take: their own message stands.
|
|
585
686
|
if (fs.existsSync(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
|
|
586
687
|
const id = `${camel(slug)}Theme`;
|
|
587
688
|
const key = /^[a-z][a-z0-9]*$/i.test(slug) ? slug : JSON.stringify(slug);
|
|
689
|
+
// The paths from the folder of the app's generated themes module (where
|
|
690
|
+
// a file that merges themes sits), else from the app root.
|
|
691
|
+
const generated = path.join(root, 'src', 'astryx-themes.ts');
|
|
692
|
+
const from = fs.existsSync(generated) ? path.dirname(generated) : root;
|
|
693
|
+
let rel = path
|
|
694
|
+
.relative(from, path.join(root, 'themes', slug))
|
|
695
|
+
.split(path.sep)
|
|
696
|
+
.join('/');
|
|
697
|
+
if (!rel.startsWith('.')) rel = `./${rel}`;
|
|
698
|
+
const where =
|
|
699
|
+
from === root
|
|
700
|
+
? 'in a file of your own at the app root'
|
|
701
|
+
: `in a file of your own beside ${path.relative(root, generated).split(path.sep).join('/')} (from another folder, change the paths to match)`;
|
|
588
702
|
return new AstryxError(
|
|
589
|
-
`${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet
|
|
703
|
+
`${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet ${where} (import {${id}} from '${rel}/${slug}.js'; import '${rel}/${slug}.css';) and merge it into the themes there ({...themes, ${key}: ${id}}); do not add it to src/astryx-themes.ts, which add, use and remove write again. Change it with the editor.`,
|
|
590
704
|
[
|
|
591
705
|
{
|
|
592
706
|
name: runLine(cwd, `experimental theme editor show ${slug}`),
|
|
@@ -613,6 +727,20 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
|
|
|
613
727
|
if (!at || !editorOwnFile(at.slug, file)) continue;
|
|
614
728
|
const {root, slug} = at;
|
|
615
729
|
const source = `themes/${slug}/${slug}.theme.ts`;
|
|
730
|
+
// An editor theme is built from its project's root, as every editor
|
|
731
|
+
// command runs there: from a subfolder the build would write outside
|
|
732
|
+
// its working folder. The run names the root.
|
|
733
|
+
if (path.resolve(cwd) !== path.resolve(root))
|
|
734
|
+
return new AstryxError(
|
|
735
|
+
`${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.`,
|
|
736
|
+
[
|
|
737
|
+
{
|
|
738
|
+
name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${runLine(root, `experimental theme compile ${source}${check ? ' --check' : ''}`)}`,
|
|
739
|
+
reason: 'do this instead',
|
|
740
|
+
},
|
|
741
|
+
],
|
|
742
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
743
|
+
);
|
|
616
744
|
if (/\.settings\.(ts|json)$/.test(file))
|
|
617
745
|
return new AstryxError(
|
|
618
746
|
`${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
|
|
@@ -661,6 +789,22 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
|
|
|
661
789
|
if (e instanceof AstryxError) return e;
|
|
662
790
|
throw e;
|
|
663
791
|
}
|
|
792
|
+
// An own change to the theme source is what compile builds (and what
|
|
793
|
+
// --check compares): never a reason to refuse it.
|
|
794
|
+
if (
|
|
795
|
+
why &&
|
|
796
|
+
/\.theme\.ts (or a module it imports )?changed since the last build$/.test(
|
|
797
|
+
why,
|
|
798
|
+
)
|
|
799
|
+
)
|
|
800
|
+
why = null;
|
|
801
|
+
// A missing built output is one compile writes itself.
|
|
802
|
+
if (
|
|
803
|
+
why &&
|
|
804
|
+
!check &&
|
|
805
|
+
/^[^/]+\.(css|js|d\.ts|css\.d\.ts) was missing$/.test(why)
|
|
806
|
+
)
|
|
807
|
+
why = null;
|
|
664
808
|
if (why && !check)
|
|
665
809
|
return new AstryxError(
|
|
666
810
|
`${slug}'s generated settings do not match its settings (${why}), so compile would build the old ones. The editor builds it from its settings.`,
|
|
@@ -756,3 +900,13 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
756
900
|
}
|
|
757
901
|
return releaseAll;
|
|
758
902
|
}
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* `theme template` for the experimental command: in a folder the theme
|
|
906
|
+
* editor made, only the editor's own files are protected.
|
|
907
|
+
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} options
|
|
908
|
+
* @returns {import('../theme/theme.type.mjs').ThemeTemplateResponse}
|
|
909
|
+
*/
|
|
910
|
+
export function editorThemeTemplate(options) {
|
|
911
|
+
return writeThemeTemplate(options, true);
|
|
912
|
+
}
|
|
@@ -45,6 +45,13 @@ export function exampleOf(type: string, name: string): string;
|
|
|
45
45
|
*/
|
|
46
46
|
export function checkSetting(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, thing: string, value: string | undefined, flags: SetFlags, unset?: boolean): import("./_settings.mjs").Setting;
|
|
47
47
|
export { lengthPx };
|
|
48
|
+
export function setLine(slug: string, thing: string, value: string, s: {
|
|
49
|
+
on?: string;
|
|
50
|
+
when?: string;
|
|
51
|
+
state?: string;
|
|
52
|
+
mode?: string;
|
|
53
|
+
only?: boolean;
|
|
54
|
+
}, unset?: boolean): string;
|
|
48
55
|
/** The aspects `how` answers at the whole-theme level. */
|
|
49
56
|
export const ASPECTS: string[];
|
|
50
57
|
export type SetFlags = {
|