@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e
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/pack-check.mjs +13 -7
- 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 +64 -27
- package/api/theme/build/build.mjs +341 -69
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- 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 +33 -0
- package/api/theme-edit/_adapter.mjs +208 -31
- package/api/theme-edit/_check.d.mts +38 -0
- package/api/theme-edit/_check.mjs +1326 -211
- 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 +29 -0
- package/api/theme-edit/_context.mjs +329 -30
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +1025 -126
- 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/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +11 -0
- package/api/theme-edit/_palette.mjs +194 -65
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +59 -7
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.d.mts +3 -0
- package/api/theme-edit/_preview-app.mjs +843 -45
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +310 -29
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +178 -5
- package/api/theme-edit/_settings.mjs +2035 -86
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +211 -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/api/upgrade/registry/registry.mjs +6 -1
- 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/package.json +1 -0
- 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/assets/templates/pages/dashboard/page.tsx +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 +190 -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 +168 -45
- 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/clients/cli/run.mjs +49 -0
- 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 +79 -15
- package/foundation/fs/paths.d.mts +31 -0
- package/foundation/fs/paths.mjs +43 -10
- 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
|
@@ -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';
|
|
@@ -39,21 +40,23 @@ import {themeCacheRoot} from './_project.mjs';
|
|
|
39
40
|
import * as preview from './_preview-app.mjs';
|
|
40
41
|
import {AstryxError} from '../error.mjs';
|
|
41
42
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
findPackageRoot,
|
|
45
|
-
} from '../../foundation/fs/paths.mjs';
|
|
43
|
+
import {findPackageRoot} from '../../foundation/fs/paths.mjs';
|
|
44
|
+
import {coreApp} from './_context.mjs';
|
|
46
45
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
47
46
|
import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
|
|
48
47
|
import {
|
|
49
48
|
getCliInvocation,
|
|
50
49
|
quoteCommandArgument,
|
|
51
50
|
} from '../../foundation/env/package-manager.mjs';
|
|
52
|
-
import {LIKE, P} from './_tables.mjs';
|
|
53
|
-
import {
|
|
51
|
+
import {DIALS, LIKE, P} from './_tables.mjs';
|
|
52
|
+
import {setLine} from './_check.mjs';
|
|
53
|
+
import {colorProblem} from './_color.mjs';
|
|
54
|
+
import {SHOWCASE_GROUPS} from './_preview.mjs';
|
|
55
|
+
import {camel, typedThemeName} from './_settings.mjs';
|
|
54
56
|
import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
|
|
55
57
|
|
|
56
58
|
export {parsePoints} from './_how.mjs';
|
|
59
|
+
export {newFlagList} from './_edit.mjs';
|
|
57
60
|
import {themeEditHow as howAt} from './_how.mjs';
|
|
58
61
|
|
|
59
62
|
/**
|
|
@@ -90,6 +93,35 @@ export async function themeEditHow(subject, options = {}) {
|
|
|
90
93
|
/** The built-in themes a theme can build on (`--like`). */
|
|
91
94
|
export const builtInThemes = () => [...LIKE];
|
|
92
95
|
|
|
96
|
+
/** The sections `show --section` takes. */
|
|
97
|
+
export const showSections = () => [...SHOWCASE_GROUPS];
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether a value fits what a dial takes, read from the dial's own list of
|
|
101
|
+
* values: a named rung in any case, or a value of the kind it names (a size,
|
|
102
|
+
* a color, a number). `set` still checks the value in full.
|
|
103
|
+
* @param {string} dial
|
|
104
|
+
* @param {string} value
|
|
105
|
+
*/
|
|
106
|
+
export function dialValueFits(dial, value) {
|
|
107
|
+
const spec = DIALS[/** @type {keyof typeof DIALS} */ (dial)]?.values;
|
|
108
|
+
if (!spec) return false;
|
|
109
|
+
const v = String(value).trim();
|
|
110
|
+
if (v === '') return false;
|
|
111
|
+
return spec.split('|').some(option => {
|
|
112
|
+
if (!option.startsWith('<') && !option.startsWith('"'))
|
|
113
|
+
return option === v.toLowerCase();
|
|
114
|
+
if (option.startsWith('"')) return true;
|
|
115
|
+
if (option.includes('size')) return /^\d*\.?\d+(px|rem|em)$/.test(v);
|
|
116
|
+
// A color by the editor's own color check (a bare word only when it
|
|
117
|
+
// names a color).
|
|
118
|
+
if (option === '<color>') return colorProblem(v) == null;
|
|
119
|
+
if (option === '<0-100>') return /^\d{1,3}$/.test(v) && Number(v) <= 100;
|
|
120
|
+
if (option === '<number>') return /^\d*\.?\d+$/.test(v);
|
|
121
|
+
return false;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
93
125
|
/**
|
|
94
126
|
* The project a command acts on: the Astryx project at or above `cwd`, found
|
|
95
127
|
* as `upgrade` finds it (the nearest package that declares an Astryx package
|
|
@@ -102,7 +134,9 @@ export const builtInThemes = () => [...LIKE];
|
|
|
102
134
|
*/
|
|
103
135
|
export function projectRoot(cwd) {
|
|
104
136
|
const start = path.resolve(cwd);
|
|
105
|
-
|
|
137
|
+
// One rule: the nearest folder at or above cwd whose package.json lists
|
|
138
|
+
// @astryxdesign/core.
|
|
139
|
+
const project = coreApp(start);
|
|
106
140
|
const pkg = findPackageRoot(start);
|
|
107
141
|
const inReach = (/** @type {string} */ dir) =>
|
|
108
142
|
project ? !path.relative(project, dir).startsWith('..') : true;
|
|
@@ -112,13 +146,19 @@ export function projectRoot(cwd) {
|
|
|
112
146
|
let json;
|
|
113
147
|
try {
|
|
114
148
|
json = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
115
|
-
} catch {
|
|
149
|
+
} catch (e) {
|
|
150
|
+
// Name the file and what the parser says is wrong, with its place.
|
|
151
|
+
const rel = path.relative(start, file) || 'package.json';
|
|
152
|
+
const why = String(/** @type {Error} */ (e).message ?? '').replace(
|
|
153
|
+
/^Unexpected token.*?, /,
|
|
154
|
+
'',
|
|
155
|
+
);
|
|
116
156
|
throw new AstryxError(
|
|
117
|
-
`${
|
|
157
|
+
`${rel} is not valid JSON (${why}), so the app it belongs to is unknown. Fix it, then run the command again. Nothing was written.`,
|
|
118
158
|
[
|
|
119
159
|
{
|
|
120
|
-
name:
|
|
121
|
-
reason: '
|
|
160
|
+
name: `\${EDITOR:-vi} ${quoteCommandArgument(rel)}`,
|
|
161
|
+
reason: 'open the file and fix it',
|
|
122
162
|
},
|
|
123
163
|
],
|
|
124
164
|
ERROR_CODES.ERR_PROJECT_REQUIRED,
|
|
@@ -195,9 +235,15 @@ function lockDir(root) {
|
|
|
195
235
|
* @param {boolean} [bestEffort] a command that can run read-only runs
|
|
196
236
|
* without the lock when it cannot be taken (a read-only node_modules),
|
|
197
237
|
* told so, and then writes nothing
|
|
238
|
+
* @param {string | null} [again] the command's own words after the CLI
|
|
239
|
+
* name, to suggest running it again (never the host process's argv: an
|
|
240
|
+
* API caller is not a CLI run)
|
|
198
241
|
* @returns {Promise<T>}
|
|
199
242
|
*/
|
|
200
|
-
async function withLock(root, name, fn, bestEffort = false) {
|
|
243
|
+
async function withLock(root, name, fn, bestEffort = false, again = null) {
|
|
244
|
+
// A preview command, which holds the preview lock, suggests the list of
|
|
245
|
+
// previews (what the other command may be changing).
|
|
246
|
+
again ??= name === 'preview' ? 'experimental theme preview list' : null;
|
|
201
247
|
/** @type {string | null} */
|
|
202
248
|
let dir;
|
|
203
249
|
try {
|
|
@@ -239,16 +285,17 @@ async function withLock(root, name, fn, bestEffort = false) {
|
|
|
239
285
|
{
|
|
240
286
|
onBusy: (o, held) => {
|
|
241
287
|
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
|
-
|
|
288
|
+
`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}.`,
|
|
289
|
+
// Every editor command (show too) takes this lock, so none of
|
|
290
|
+
// them works meanwhile: this same command, once the other ends.
|
|
291
|
+
again
|
|
292
|
+
? [
|
|
293
|
+
{
|
|
294
|
+
name: runLine(root, again),
|
|
295
|
+
reason: 'run it again once the other command ends',
|
|
296
|
+
},
|
|
297
|
+
]
|
|
298
|
+
: [],
|
|
252
299
|
ERROR_CODES.ERR_THEME_BUSY,
|
|
253
300
|
);
|
|
254
301
|
},
|
|
@@ -346,9 +393,11 @@ function absolute(result, root, from) {
|
|
|
346
393
|
* @param {O} options
|
|
347
394
|
* @param {string | null} lock
|
|
348
395
|
* @param {(o: O & {cwd: string}) => Promise<T>} fn
|
|
396
|
+
* @param {boolean} [bestEffort]
|
|
397
|
+
* @param {string | null} [again] the command's own words, for a busy lock
|
|
349
398
|
* @returns {Promise<T>}
|
|
350
399
|
*/
|
|
351
|
-
async function inProject(options, lock, fn, bestEffort = false) {
|
|
400
|
+
async function inProject(options, lock, fn, bestEffort = false, again = null) {
|
|
352
401
|
const from = options.cwd ?? process.cwd();
|
|
353
402
|
const o = atRoot(options);
|
|
354
403
|
try {
|
|
@@ -360,6 +409,7 @@ async function inProject(options, lock, fn, bestEffort = false) {
|
|
|
360
409
|
lock,
|
|
361
410
|
locked => fn(locked ? o : {...o, readOnly: true}),
|
|
362
411
|
bestEffort,
|
|
412
|
+
again,
|
|
363
413
|
)
|
|
364
414
|
: await fn(o);
|
|
365
415
|
return absolute(r, o.cwd, from);
|
|
@@ -434,20 +484,74 @@ const withThemeLock = o => ({
|
|
|
434
484
|
) => withLock(o.cwd, lockName(slug), fn),
|
|
435
485
|
});
|
|
436
486
|
|
|
487
|
+
/**
|
|
488
|
+
* A command's own words after the CLI name, from what it was called with,
|
|
489
|
+
* every option kept: set and undo as `set` writes them (scope flags and
|
|
490
|
+
* --only), new with --like and each dial, --png where given.
|
|
491
|
+
* @param {string} line a command as the editor writes one (`astryx …`)
|
|
492
|
+
* @param {{png?: boolean}} [o]
|
|
493
|
+
*/
|
|
494
|
+
const words = (line, o = {}) =>
|
|
495
|
+
`${line.replace(/^astryx /, '').trimEnd()}${o.png ? ' --png' : ''}`;
|
|
496
|
+
|
|
437
497
|
/** @type {typeof edit.themeEditNew} */
|
|
438
498
|
export const themeEditNew = (name, options = {}) =>
|
|
439
|
-
inProject(
|
|
499
|
+
inProject(
|
|
500
|
+
options,
|
|
501
|
+
lockName(name),
|
|
502
|
+
o => edit.themeEditNew(name, o),
|
|
503
|
+
false,
|
|
504
|
+
words(
|
|
505
|
+
`${P} new ${quoteCommandArgument(name)} ${edit
|
|
506
|
+
.newFlagList(
|
|
507
|
+
options.like,
|
|
508
|
+
options.settings ?? {},
|
|
509
|
+
/** @type {boolean} */ (options.png),
|
|
510
|
+
)
|
|
511
|
+
.join(' ')}`,
|
|
512
|
+
),
|
|
513
|
+
);
|
|
440
514
|
/** @type {typeof edit.themeEditSet} */
|
|
441
515
|
export const themeEditSet = (theme, thing, value, options = {}) =>
|
|
442
|
-
inProject(
|
|
443
|
-
|
|
516
|
+
inProject(
|
|
517
|
+
options,
|
|
518
|
+
lockName(theme),
|
|
519
|
+
o => edit.themeEditSet(theme, thing, value, o),
|
|
520
|
+
false,
|
|
521
|
+
words(setLine(theme, thing, value, options), options),
|
|
444
522
|
);
|
|
445
523
|
/** @type {typeof edit.themeEditUndo} */
|
|
446
524
|
export const themeEditUndo = (theme, options = {}) =>
|
|
447
|
-
inProject(
|
|
525
|
+
inProject(
|
|
526
|
+
options,
|
|
527
|
+
lockName(theme),
|
|
528
|
+
o => edit.themeEditUndo(theme, o),
|
|
529
|
+
false,
|
|
530
|
+
words(
|
|
531
|
+
options.thing
|
|
532
|
+
? setLine(
|
|
533
|
+
theme,
|
|
534
|
+
options.thing,
|
|
535
|
+
/** @type {string} */ (options.value ?? ''),
|
|
536
|
+
options,
|
|
537
|
+
true,
|
|
538
|
+
)
|
|
539
|
+
: `${P} undo ${theme}`,
|
|
540
|
+
options,
|
|
541
|
+
),
|
|
542
|
+
);
|
|
448
543
|
/** @type {typeof edit.themeEditShow} */
|
|
449
544
|
export const themeEditShow = (theme, options = {}) =>
|
|
450
|
-
inProject(
|
|
545
|
+
inProject(
|
|
546
|
+
options,
|
|
547
|
+
lockName(theme),
|
|
548
|
+
o => edit.themeEditShow(theme, o),
|
|
549
|
+
true,
|
|
550
|
+
words(
|
|
551
|
+
`${P} show ${theme}${options.section ? ` --section ${quoteCommandArgument(String(options.section))}` : ''}`,
|
|
552
|
+
options,
|
|
553
|
+
),
|
|
554
|
+
);
|
|
451
555
|
/** @type {typeof preview.themeEditPreviewAdd} */
|
|
452
556
|
export const themeEditPreviewAdd = (description, options = {}) =>
|
|
453
557
|
inProject(options, 'preview', o =>
|
|
@@ -577,16 +681,32 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
577
681
|
)
|
|
578
682
|
return null;
|
|
579
683
|
const root = projectRoot(cwd);
|
|
580
|
-
|
|
581
|
-
|
|
684
|
+
// The name as typed, read the way the editor reads a theme name: a path
|
|
685
|
+
// to its folder or a file in it, in any case, names the theme.
|
|
686
|
+
const named = /"([^"]+)"|'([^']+)'/.exec(err.message);
|
|
687
|
+
const word = named ? typedThemeName(named[1] ?? named[2]) : '';
|
|
688
|
+
const slug = word ? editorThemeOf(root, word) : null;
|
|
582
689
|
if (!slug) return null;
|
|
583
690
|
// A local theme of that name (a fork in the app's own themes folder) is
|
|
584
691
|
// one the stable commands take: their own message stands.
|
|
585
692
|
if (fs.existsSync(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
|
|
586
693
|
const id = `${camel(slug)}Theme`;
|
|
587
694
|
const key = /^[a-z][a-z0-9]*$/i.test(slug) ? slug : JSON.stringify(slug);
|
|
695
|
+
// The paths from the folder of the app's generated themes module (where
|
|
696
|
+
// a file that merges themes sits), else from the app root.
|
|
697
|
+
const generated = path.join(root, 'src', 'astryx-themes.ts');
|
|
698
|
+
const from = fs.existsSync(generated) ? path.dirname(generated) : root;
|
|
699
|
+
let rel = path
|
|
700
|
+
.relative(from, path.join(root, 'themes', slug))
|
|
701
|
+
.split(path.sep)
|
|
702
|
+
.join('/');
|
|
703
|
+
if (!rel.startsWith('.')) rel = `./${rel}`;
|
|
704
|
+
const where =
|
|
705
|
+
from === root
|
|
706
|
+
? 'in a file of your own at the app root'
|
|
707
|
+
: `in a file of your own beside ${path.relative(root, generated).split(path.sep).join('/')} (from another folder, change the paths to match)`;
|
|
588
708
|
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
|
|
709
|
+
`${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
710
|
[
|
|
591
711
|
{
|
|
592
712
|
name: runLine(cwd, `experimental theme editor show ${slug}`),
|
|
@@ -613,6 +733,20 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
|
|
|
613
733
|
if (!at || !editorOwnFile(at.slug, file)) continue;
|
|
614
734
|
const {root, slug} = at;
|
|
615
735
|
const source = `themes/${slug}/${slug}.theme.ts`;
|
|
736
|
+
// An editor theme is built from its project's root, as every editor
|
|
737
|
+
// command runs there: from a subfolder the build would write outside
|
|
738
|
+
// its working folder. The run names the root.
|
|
739
|
+
if (path.resolve(cwd) !== path.resolve(root))
|
|
740
|
+
return new AstryxError(
|
|
741
|
+
`${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.`,
|
|
742
|
+
[
|
|
743
|
+
{
|
|
744
|
+
name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${runLine(root, `experimental theme compile ${source}${check ? ' --check' : ''}`)}`,
|
|
745
|
+
reason: 'do this instead',
|
|
746
|
+
},
|
|
747
|
+
],
|
|
748
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
749
|
+
);
|
|
616
750
|
if (/\.settings\.(ts|json)$/.test(file))
|
|
617
751
|
return new AstryxError(
|
|
618
752
|
`${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
|
|
@@ -661,6 +795,22 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
|
|
|
661
795
|
if (e instanceof AstryxError) return e;
|
|
662
796
|
throw e;
|
|
663
797
|
}
|
|
798
|
+
// An own change to the theme source is what compile builds (and what
|
|
799
|
+
// --check compares): never a reason to refuse it.
|
|
800
|
+
if (
|
|
801
|
+
why &&
|
|
802
|
+
/\.theme\.ts (or a module it imports )?changed since the last build$/.test(
|
|
803
|
+
why,
|
|
804
|
+
)
|
|
805
|
+
)
|
|
806
|
+
why = null;
|
|
807
|
+
// A missing built output is one compile writes itself.
|
|
808
|
+
if (
|
|
809
|
+
why &&
|
|
810
|
+
!check &&
|
|
811
|
+
/^[^/]+\.(css|js|d\.ts|css\.d\.ts) was missing$/.test(why)
|
|
812
|
+
)
|
|
813
|
+
why = null;
|
|
664
814
|
if (why && !check)
|
|
665
815
|
return new AstryxError(
|
|
666
816
|
`${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 +906,30 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
756
906
|
}
|
|
757
907
|
return releaseAll;
|
|
758
908
|
}
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* For `compile` of a file that is not there: when it is an editor theme's
|
|
912
|
+
* own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
|
|
913
|
+
* that writes it again; null otherwise.
|
|
914
|
+
* @param {string} file the path as given
|
|
915
|
+
* @param {string} cwd
|
|
916
|
+
* @returns {{name: string, reason: string} | null}
|
|
917
|
+
*/
|
|
918
|
+
export function editorMissingSource(file, cwd) {
|
|
919
|
+
const at = editorThemeAt(projectRoot(cwd), path.resolve(cwd, file));
|
|
920
|
+
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
921
|
+
return {
|
|
922
|
+
name: runLine(cwd, `experimental theme editor show ${at.slug}`),
|
|
923
|
+
reason: `the editor writes ${at.slug}.theme.ts again from its settings`,
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* `theme template` for the experimental command: in a folder the theme
|
|
929
|
+
* editor made, only the editor's own files are protected.
|
|
930
|
+
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} options
|
|
931
|
+
* @returns {import('../theme/theme.type.mjs').ThemeTemplateResponse}
|
|
932
|
+
*/
|
|
933
|
+
export function editorThemeTemplate(options) {
|
|
934
|
+
return writeThemeTemplate(options, true);
|
|
935
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A font pasted as a declaration (`font-family: Georgia, serif;`, from
|
|
6
|
+
* devtools or a stylesheet), as the family list it names; a `font:`
|
|
7
|
+
* shorthand gives its family. Null when the value is not a pasted
|
|
8
|
+
* declaration.
|
|
9
|
+
* @param {string} v
|
|
10
|
+
* @returns {string | null}
|
|
11
|
+
*/
|
|
12
|
+
export function pastedFont(v: string): string | null;
|
|
4
13
|
/**
|
|
5
14
|
* @typedef {object} SetFlags
|
|
6
15
|
* @property {string} [on]
|
|
@@ -44,7 +53,36 @@ export function exampleOf(type: string, name: string): string;
|
|
|
44
53
|
* @returns {import('./_settings.mjs').Setting}
|
|
45
54
|
*/
|
|
46
55
|
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;
|
|
56
|
+
/**
|
|
57
|
+
* A setting's value as set reads it: one line, and tabs as spaces; in a font
|
|
58
|
+
* value every run of spaces or tabs is one space, so `'Open Sans'` and
|
|
59
|
+
* `'Open\tSans'` both name Open Sans.
|
|
60
|
+
* @param {string} thing
|
|
61
|
+
* @param {string} value
|
|
62
|
+
*/
|
|
63
|
+
export function normalValue(thing: string, value: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* The first var() in a value that names no design token and would read
|
|
66
|
+
* nothing (no fallback), or one a letter or two off a token, else null.
|
|
67
|
+
* Dials take their own words, so a dial's var() with no near token passes.
|
|
68
|
+
* @param {string} v
|
|
69
|
+
* @param {Record<string, unknown>} TOKENS
|
|
70
|
+
* @param {string} thing
|
|
71
|
+
* @returns {{message: string, near: string[], close: boolean} | null}
|
|
72
|
+
*/
|
|
73
|
+
export function unknownVarRef(v: string, TOKENS: Record<string, unknown>, thing: string): {
|
|
74
|
+
message: string;
|
|
75
|
+
near: string[];
|
|
76
|
+
close: boolean;
|
|
77
|
+
} | null;
|
|
47
78
|
export { lengthPx };
|
|
79
|
+
export function setLine(slug: string, thing: string, value: string, s: {
|
|
80
|
+
on?: string;
|
|
81
|
+
when?: string;
|
|
82
|
+
state?: string;
|
|
83
|
+
mode?: string;
|
|
84
|
+
only?: boolean;
|
|
85
|
+
}, unset?: boolean): string;
|
|
48
86
|
/** The aspects `how` answers at the whole-theme level. */
|
|
49
87
|
export const ASPECTS: string[];
|
|
50
88
|
export type SetFlags = {
|