@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa
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 +12 -23
- package/api/build/_adapter.d.mts +5 -0
- package/api/build/_adapter.mjs +49 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +2 -1
- package/api/build/kit/rank.mjs +47 -9
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +238 -31
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +32 -0
- package/api/build/kit/words.mjs +49 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -5
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +217 -5
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +77 -6
- package/api/doctor/built-checks.mjs +38 -13
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/render/_adapter.mjs +491 -186
- package/api/render/render.doc.mjs +10 -3
- package/api/render/render.type.d.mts +30 -0
- package/api/render/render.type.mjs +19 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_result.d.mts +5 -5
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +10 -0
- package/api/theme/build/build.d.mts +38 -0
- package/api/theme/build/build.mjs +144 -24
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +35 -0
- package/api/theme-edit/_adapter.mjs +477 -41
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1077 -200
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +932 -82
- package/api/theme-edit/_how-commands.d.mts +49 -0
- package/api/theme-edit/_how-commands.mjs +386 -1
- package/api/theme-edit/_how-question.d.mts +56 -0
- package/api/theme-edit/_how-question.mjs +3509 -168
- package/api/theme-edit/_how.mjs +104 -4
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +137 -0
- package/api/theme-edit/_normal.mjs +612 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +4 -0
- package/api/theme-edit/_parts.mjs +28 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +191 -15
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +401 -83
- package/api/theme-edit/_settings.d.mts +139 -5
- package/api/theme-edit/_settings.mjs +1659 -112
- package/api/theme-edit/_tables.mjs +17 -1
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +2 -2
- package/assets/codemods/run-codemod.mjs +73 -6
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +43 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +8 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +1 -7
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +20 -2
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +22 -14
- package/clients/cli/commands/experimental/render.mjs +32 -1
- package/clients/cli/commands/experimental/theme.mjs +27 -2
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- 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-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +138 -3
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +27 -2
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +20 -7
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +169 -0
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +138 -52
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/module-loader.d.mts +18 -2
- package/foundation/fs/module-loader.mjs +92 -20
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +79 -10
- package/foundation/render/render-page.d.mts +34 -2
- package/foundation/render/render-page.mjs +210 -29
- package/foundation/render/source-block.d.mts +73 -6
- package/foundation/render/source-block.mjs +170 -19
- package/foundation/render/ts-paths.d.mts +4 -1
- package/foundation/render/ts-paths.mjs +7 -3
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.doc.mjs +7 -1
- package/foundation/response/error-codes.mjs +7 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +16 -3
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +13 -0
- package/package.json +6 -6
|
@@ -35,6 +35,7 @@ import {writeThemeTemplate} from '../theme/template/template.mjs';
|
|
|
35
35
|
import {buildSuggestion} from '../theme/build/build.mjs';
|
|
36
36
|
import {createHash} from 'node:crypto';
|
|
37
37
|
import * as fs from 'node:fs';
|
|
38
|
+
import {createRequire} from 'node:module';
|
|
38
39
|
import * as path from 'node:path';
|
|
39
40
|
import * as edit from './_edit.mjs';
|
|
40
41
|
import {baseInstalled, themeCacheRoot} from './_project.mjs';
|
|
@@ -42,7 +43,7 @@ import * as preview from './_preview-app.mjs';
|
|
|
42
43
|
import {AstryxError} from '../error.mjs';
|
|
43
44
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
44
45
|
import {findPackageRoot} from '../../foundation/fs/paths.mjs';
|
|
45
|
-
import {coreApp} from './_context.mjs';
|
|
46
|
+
import {context, coreApp} from './_context.mjs';
|
|
46
47
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
47
48
|
import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
|
|
48
49
|
import {
|
|
@@ -50,15 +51,30 @@ import {
|
|
|
50
51
|
quoteCommandArgument,
|
|
51
52
|
} from '../../foundation/env/package-manager.mjs';
|
|
52
53
|
import {LIKE, P} from './_tables.mjs';
|
|
54
|
+
|
|
55
|
+
/** The preview command, as a person runs it. */
|
|
56
|
+
const PREVIEW_WORDS = P.replace(/ editor$/, ' preview');
|
|
53
57
|
import {setLine} from './_check.mjs';
|
|
54
58
|
import {
|
|
55
59
|
SHOWCASE_GROUPS,
|
|
60
|
+
appCopyBehind,
|
|
61
|
+
appCopyStale,
|
|
62
|
+
copyFontsCss,
|
|
56
63
|
takeFirstAppCopy,
|
|
57
64
|
writeAppCopy,
|
|
58
65
|
writeAppCopyAt,
|
|
59
66
|
} from './_preview.mjs';
|
|
60
67
|
import {humanWarn} from '../../foundation/response/json.mjs';
|
|
61
|
-
import {
|
|
68
|
+
import {
|
|
69
|
+
buildColorModes,
|
|
70
|
+
camel,
|
|
71
|
+
folderIsEmpty,
|
|
72
|
+
loadTheme,
|
|
73
|
+
setAfterBuild,
|
|
74
|
+
editedThemes,
|
|
75
|
+
themeFiles,
|
|
76
|
+
typedThemeName,
|
|
77
|
+
} from './_settings.mjs';
|
|
62
78
|
|
|
63
79
|
// Every build of a theme writes its app copy (src/themes/<theme>/).
|
|
64
80
|
setAfterBuild(writeAppCopy);
|
|
@@ -367,16 +383,43 @@ const lockName = name =>
|
|
|
367
383
|
*/
|
|
368
384
|
function absolute(result, root, from) {
|
|
369
385
|
if (path.resolve(from) === root) return result;
|
|
370
|
-
/**
|
|
371
|
-
|
|
386
|
+
/**
|
|
387
|
+
* Lines that name project files inside them: `see`, a picture note, the
|
|
388
|
+
* in-app preview's stale entries. Every project path in them (a theme
|
|
389
|
+
* file, an in-app preview folder) is made absolute, one style per line.
|
|
390
|
+
*/
|
|
391
|
+
const PROSE = new Set(['see', 'pictureProblem', 'previewStale']);
|
|
392
|
+
/** A project-relative path that names a file or folder there. @param {string} p */
|
|
393
|
+
const inRoot = p => {
|
|
394
|
+
const bare = p.replace(/\/+$/, '');
|
|
395
|
+
return (
|
|
396
|
+
Boolean(bare) &&
|
|
397
|
+
!path.isAbsolute(bare) &&
|
|
398
|
+
!bare.startsWith('.') &&
|
|
399
|
+
fs.existsSync(path.join(root, bare))
|
|
400
|
+
);
|
|
401
|
+
};
|
|
402
|
+
/** @param {any} v @param {string} [key] @returns {any} */
|
|
403
|
+
const map = (v, key) =>
|
|
372
404
|
typeof v === 'string'
|
|
373
|
-
?
|
|
405
|
+
? // A path alone; a line that starts with one is read as prose below.
|
|
406
|
+
/^themes\/\S*$/.test(v) && !(key && PROSE.has(key))
|
|
374
407
|
? path.join(root, v)
|
|
375
|
-
:
|
|
408
|
+
: key && PROSE.has(key)
|
|
409
|
+
? v.replace(
|
|
410
|
+
/(^|[\s(,])((?:themes|src|app)\/[^\s,;)]*)/g,
|
|
411
|
+
(all, before, file) =>
|
|
412
|
+
/^themes\//.test(file) || inRoot(file)
|
|
413
|
+
? `${before}${path.join(root, file)}`
|
|
414
|
+
: all,
|
|
415
|
+
)
|
|
416
|
+
: v
|
|
376
417
|
: Array.isArray(v)
|
|
377
|
-
? v.map(map)
|
|
418
|
+
? v.map(x => map(x, key))
|
|
378
419
|
: v && typeof v === 'object'
|
|
379
|
-
? Object.fromEntries(
|
|
420
|
+
? Object.fromEntries(
|
|
421
|
+
Object.entries(v).map(([k, x]) => [k, map(x, k)]),
|
|
422
|
+
)
|
|
380
423
|
: v;
|
|
381
424
|
return map(result);
|
|
382
425
|
}
|
|
@@ -550,37 +593,114 @@ export const themeEditShow = (theme, options = {}) =>
|
|
|
550
593
|
);
|
|
551
594
|
/** @type {typeof preview.themeEditPreviewAdd} */
|
|
552
595
|
export const themeEditPreviewAdd = (description, options = {}) =>
|
|
553
|
-
|
|
554
|
-
preview
|
|
596
|
+
stopTold(
|
|
597
|
+
`a preview change stopped part way is finished by the next ${PREVIEW_WORDS} add, and one written in full stands (${PREVIEW_WORDS} list says which)`,
|
|
598
|
+
() =>
|
|
599
|
+
inProject(options, 'preview', o =>
|
|
600
|
+
preview.themeEditPreviewAdd(description, withThemeLock(o)),
|
|
601
|
+
),
|
|
555
602
|
);
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Run a preview command with a stop (Ctrl-C, SIGTERM) heard for its whole
|
|
606
|
+
* run, and after it: the stop ends the process as stopped, with one line
|
|
607
|
+
* saying where the change stands (a change stopped part way is finished by
|
|
608
|
+
* the next preview command), never an ok with exit 0.
|
|
609
|
+
* @template T
|
|
610
|
+
* @param {string} where where the change stands, and what finishes it
|
|
611
|
+
* @param {() => Promise<T>} fn
|
|
612
|
+
* @returns {Promise<T>}
|
|
613
|
+
*/
|
|
614
|
+
async function stopTold(where, fn) {
|
|
615
|
+
const on = (/** @type {NodeJS.Signals} */ sig) => {
|
|
616
|
+
process.removeListener('SIGINT', on);
|
|
617
|
+
process.removeListener('SIGTERM', on);
|
|
618
|
+
process.stderr.write(`Stopped: ${where}.\n`);
|
|
619
|
+
// With no other listener (a lock's, which ends the process itself),
|
|
620
|
+
// the stop ends it here.
|
|
621
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
622
|
+
};
|
|
623
|
+
process.on('SIGINT', on);
|
|
624
|
+
process.on('SIGTERM', on);
|
|
625
|
+
try {
|
|
626
|
+
const r = await fn();
|
|
627
|
+
// A turn of the event loop, so a stop that came while the work ran
|
|
628
|
+
// without a pause is heard now, before the result is printed.
|
|
629
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
630
|
+
return r;
|
|
631
|
+
} finally {
|
|
632
|
+
process.removeListener('SIGINT', on);
|
|
633
|
+
process.removeListener('SIGTERM', on);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
556
636
|
/**
|
|
557
637
|
* `preview app` runs from the project root, with `dir` kept pointing where
|
|
558
638
|
* it was given. With a theme it holds that theme's lock, since it may build
|
|
559
639
|
* the theme and copies its files: a `set` beside it waits.
|
|
560
640
|
* @type {typeof preview.themeEditPreviewApp}
|
|
561
641
|
*/
|
|
562
|
-
export const themeEditPreviewApp = (dir, options = {}) => {
|
|
642
|
+
export const themeEditPreviewApp = async (dir, options = {}) => {
|
|
563
643
|
const from = options.cwd ?? process.cwd();
|
|
564
|
-
return
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
644
|
+
return fromHere(
|
|
645
|
+
await stopTold(
|
|
646
|
+
`the new app may be part made; ${PREVIEW_WORDS} app with a new folder name makes a whole one`,
|
|
647
|
+
() =>
|
|
648
|
+
inProject(
|
|
649
|
+
options,
|
|
650
|
+
options.theme == null ? null : lockName(options.theme),
|
|
651
|
+
o =>
|
|
652
|
+
preview.themeEditPreviewApp(
|
|
653
|
+
typeof dir === 'string' && dir.trim() && dir === dir.trim()
|
|
654
|
+
? path.relative(o.cwd, path.resolve(from, dir)) || '.'
|
|
655
|
+
: dir,
|
|
656
|
+
o,
|
|
657
|
+
),
|
|
658
|
+
true,
|
|
659
|
+
),
|
|
660
|
+
),
|
|
661
|
+
from,
|
|
575
662
|
);
|
|
576
663
|
};
|
|
664
|
+
/**
|
|
665
|
+
* A new app's folder and its open line, as they work from where the command
|
|
666
|
+
* ran (`cd ../../theme-app` from src/app), not from the project root.
|
|
667
|
+
* @template T
|
|
668
|
+
* @param {T} r
|
|
669
|
+
* @param {string} from
|
|
670
|
+
* @returns {T}
|
|
671
|
+
*/
|
|
672
|
+
function fromHere(r, from) {
|
|
673
|
+
const d = /** @type {any} */ (r)?.data;
|
|
674
|
+
if (!d || typeof d.folder !== 'string') return r;
|
|
675
|
+
const root = projectRoot(from);
|
|
676
|
+
if (!root || path.resolve(from) === root) return r;
|
|
677
|
+
const here = path.relative(from, path.join(root, d.folder)) || '.';
|
|
678
|
+
const shown = here.split(path.sep).join('/');
|
|
679
|
+
const cdArg = quoteCommandArgument(
|
|
680
|
+
shown.startsWith('-') ? `./${shown}` : shown,
|
|
681
|
+
);
|
|
682
|
+
return /** @type {T} */ ({
|
|
683
|
+
...r,
|
|
684
|
+
data: {
|
|
685
|
+
...d,
|
|
686
|
+
folder: shown,
|
|
687
|
+
...(typeof d.open === 'string'
|
|
688
|
+
? {open: d.open.replace(/^cd \S+ &&/, `cd ${cdArg} &&`)}
|
|
689
|
+
: {}),
|
|
690
|
+
},
|
|
691
|
+
});
|
|
692
|
+
}
|
|
577
693
|
/** @type {typeof preview.themeEditPreviewList} */
|
|
578
694
|
export const themeEditPreviewList = (options = {}) =>
|
|
579
695
|
inProject(options, null, async o => preview.themeEditPreviewList(o));
|
|
580
696
|
/** @type {typeof preview.themeEditPreviewRemove} */
|
|
581
697
|
export const themeEditPreviewRemove = (page, options = {}) =>
|
|
582
|
-
|
|
583
|
-
|
|
698
|
+
stopTold(
|
|
699
|
+
`a removal stopped part way is finished by the next ${PREVIEW_WORDS} remove, and one made in full stands (${PREVIEW_WORDS} list says which)`,
|
|
700
|
+
() =>
|
|
701
|
+
inProject(options, 'preview', o =>
|
|
702
|
+
preview.themeEditPreviewRemove(page, withThemeLock(o)),
|
|
703
|
+
),
|
|
584
704
|
);
|
|
585
705
|
|
|
586
706
|
/**
|
|
@@ -669,8 +789,9 @@ function runLine(cwd, rest) {
|
|
|
669
789
|
* @returns {AstryxError | null}
|
|
670
790
|
*/
|
|
671
791
|
export function editorThemeRefusal(err, cwd) {
|
|
672
|
-
// A refused compile ends here: its theme locks go now, not at exit
|
|
673
|
-
|
|
792
|
+
// A refused compile ends here: its theme locks go now, not at exit, and
|
|
793
|
+
// it writes no app copy (from build files it refused).
|
|
794
|
+
void releaseCompileHold?.(true);
|
|
674
795
|
if (
|
|
675
796
|
err.code !== ERROR_CODES.ERR_UNKNOWN_THEME &&
|
|
676
797
|
!/unknown theme|is not added|not a theme package/i.test(err.message)
|
|
@@ -683,10 +804,43 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
683
804
|
const word = named ? typedThemeName(named[1] ?? named[2]) : '';
|
|
684
805
|
const slug = word ? editorThemeOf(root, word) : null;
|
|
685
806
|
if (!slug) return null;
|
|
807
|
+
// The command that refused: list, add, use, remove or eject.
|
|
808
|
+
const verb =
|
|
809
|
+
process.argv
|
|
810
|
+
.slice(2)
|
|
811
|
+
.find(a => ['list', 'add', 'use', 'remove', 'eject'].includes(a)) ?? null;
|
|
812
|
+
// eject copies a theme package's source into the app; an editor theme's
|
|
813
|
+
// source is the app's already.
|
|
814
|
+
if (verb === 'eject')
|
|
815
|
+
return new AstryxError(
|
|
816
|
+
`${slug} is a theme the editor made: its source is yours already, themes/${slug}/${slug}.theme.ts (your edits there survive every change), and the editor changes the rest. eject copies a theme package's source into the app, so it has nothing to do for ${slug}.`,
|
|
817
|
+
[
|
|
818
|
+
{
|
|
819
|
+
name: runLine(cwd, `experimental theme editor show ${slug}`),
|
|
820
|
+
reason: 'the theme as it is now',
|
|
821
|
+
},
|
|
822
|
+
],
|
|
823
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
824
|
+
);
|
|
825
|
+
const copyThere = !folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug));
|
|
826
|
+
// A path to the theme ("themes/d", "src/themes/d"): the commands take its
|
|
827
|
+
// name.
|
|
828
|
+
const typed = named ? (named[1] ?? named[2]) : '';
|
|
829
|
+
if (copyThere && verb && typed !== slug)
|
|
830
|
+
return new AstryxError(
|
|
831
|
+
`"${typed}" is ${/[\\/]|\.[a-z]+$/i.test(typed) ? 'a path' : "not the theme's name"}; the theme commands take the theme's name: ${slug}.`,
|
|
832
|
+
[
|
|
833
|
+
{
|
|
834
|
+
name: runLine(cwd, `theme ${verb} ${slug}`),
|
|
835
|
+
reason: 'the same, by name',
|
|
836
|
+
},
|
|
837
|
+
],
|
|
838
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
839
|
+
);
|
|
686
840
|
// A local theme of that name (a fork in the app's own themes folder) is
|
|
687
841
|
// one the stable commands take: their own message stands.
|
|
688
842
|
// A folder of only system files (or empty) holds no theme: as absent.
|
|
689
|
-
if (
|
|
843
|
+
if (copyThere) return null;
|
|
690
844
|
// No app copy yet (a theme made before the editor wrote one, or the
|
|
691
845
|
// copy removed): the next build writes it, then the same steps every
|
|
692
846
|
// place gives (`wiring` of new and show).
|
|
@@ -757,8 +911,92 @@ export async function editorCompileProblem(
|
|
|
757
911
|
from,
|
|
758
912
|
COMPILE,
|
|
759
913
|
);
|
|
914
|
+
// An --out into an editor theme's app copy folder: the copy refresh would
|
|
915
|
+
// write the theme's own build over it.
|
|
916
|
+
if (out) {
|
|
917
|
+
// Any --out in the copy folder, the folder itself too, in any case.
|
|
918
|
+
const rel = path
|
|
919
|
+
.relative(cwdRoot, path.resolve(cwd, out))
|
|
920
|
+
.split(path.sep)
|
|
921
|
+
.filter(Boolean)
|
|
922
|
+
.map(x => x.toLowerCase());
|
|
923
|
+
if (
|
|
924
|
+
rel[0] === 'src' &&
|
|
925
|
+
rel[1] === 'themes' &&
|
|
926
|
+
rel.length >= 3 &&
|
|
927
|
+
fs.existsSync(themeFiles(cwdRoot, rel[2]).settings)
|
|
928
|
+
) {
|
|
929
|
+
const t = rel[2];
|
|
930
|
+
return new AstryxError(
|
|
931
|
+
`--out ${out} is in ${t}'s app copy (src/themes/${t}/), which the editor writes after every build of themes/${t}/; write the build somewhere else.`,
|
|
932
|
+
[
|
|
933
|
+
{
|
|
934
|
+
// The same compile without --out: it builds into themes/<t>/,
|
|
935
|
+
// and the copy follows.
|
|
936
|
+
name: buildSuggestion(
|
|
937
|
+
files.length === 1 ? files[0] : `themes/${t}/${t}.theme.ts`,
|
|
938
|
+
{check, iconsSpecifier},
|
|
939
|
+
cwd,
|
|
940
|
+
COMPILE,
|
|
941
|
+
),
|
|
942
|
+
reason: 'do this instead',
|
|
943
|
+
},
|
|
944
|
+
],
|
|
945
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
946
|
+
);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
760
949
|
for (const file of files) {
|
|
761
|
-
const
|
|
950
|
+
const abs = path.resolve(cwd, file);
|
|
951
|
+
const relParts = path.relative(cwdRoot, abs).split(path.sep);
|
|
952
|
+
// The app's theme module `theme add` writes: not a theme source.
|
|
953
|
+
if (relParts.join('/') === 'src/astryx-themes.ts')
|
|
954
|
+
return new AstryxError(
|
|
955
|
+
`${file} is the app's theme module (\`theme add\` writes it), not a theme source; compile the editor theme instead.`,
|
|
956
|
+
editedThemes(cwdRoot)
|
|
957
|
+
.slice(0, 3)
|
|
958
|
+
.map(t => ({
|
|
959
|
+
name: compileLine(`themes/${t}/${t}.theme.ts`, cwdRoot),
|
|
960
|
+
reason: 'do this instead',
|
|
961
|
+
})),
|
|
962
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
963
|
+
);
|
|
964
|
+
// A file of an editor theme's app copy (src/themes/<t>/): the copy
|
|
965
|
+
// is written from themes/<t>/, so that is what compiles.
|
|
966
|
+
if (
|
|
967
|
+
relParts[0] === 'src' &&
|
|
968
|
+
relParts[1] === 'themes' &&
|
|
969
|
+
(relParts.length === 3 || relParts.length === 4) &&
|
|
970
|
+
fs.existsSync(themeFiles(cwdRoot, relParts[2]).settings)
|
|
971
|
+
) {
|
|
972
|
+
const t = relParts[2];
|
|
973
|
+
const own = `themes/${t}/${t}.theme.ts`;
|
|
974
|
+
if (path.resolve(cwd) !== path.resolve(cwdRoot))
|
|
975
|
+
return new AstryxError(
|
|
976
|
+
`${t} is a theme the editor made; compile it from the app root (${path.relative(cwd, cwdRoot) || '.'}), where the editor builds it.`,
|
|
977
|
+
[
|
|
978
|
+
{
|
|
979
|
+
name: `cd ${quoteCommandArgument(path.relative(cwd, cwdRoot) || '.')} && ${compileLine(own, cwdRoot)}`,
|
|
980
|
+
reason: 'do this instead',
|
|
981
|
+
},
|
|
982
|
+
],
|
|
983
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
984
|
+
);
|
|
985
|
+
// Its source too: a compile of the copy builds neither the theme
|
|
986
|
+
// nor a current copy.
|
|
987
|
+
return new AstryxError(
|
|
988
|
+
`${file} is ${relParts.length === 3 ? '' : 'part of '}${t}'s app copy, which the editor writes from themes/${t}/ after every build; compile the theme itself.`,
|
|
989
|
+
[
|
|
990
|
+
{name: compileLine(own, cwd), reason: 'do this instead'},
|
|
991
|
+
{
|
|
992
|
+
name: runLine(cwdRoot, `experimental theme editor show ${t}`),
|
|
993
|
+
reason: 'writes the app copy again from the theme',
|
|
994
|
+
},
|
|
995
|
+
],
|
|
996
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
997
|
+
);
|
|
998
|
+
}
|
|
999
|
+
const at = editorThemeAt(cwdRoot, abs);
|
|
762
1000
|
if (!at || !editorOwnFile(at.slug, file)) continue;
|
|
763
1001
|
const {root, slug} = at;
|
|
764
1002
|
const source = `themes/${slug}/${slug}.theme.ts`;
|
|
@@ -874,6 +1112,9 @@ export async function editorCompileProblem(
|
|
|
874
1112
|
if (path.basename(file) === `${slug}.theme.ts`) {
|
|
875
1113
|
const pairs = await edit.editorPairRefusal(root, slug);
|
|
876
1114
|
if (pairs) return pairs;
|
|
1115
|
+
// A token value the file gives that set refuses ships as it is.
|
|
1116
|
+
const values = await edit.editorOwnTokenRefusal(root, slug);
|
|
1117
|
+
if (values) return values;
|
|
877
1118
|
}
|
|
878
1119
|
}
|
|
879
1120
|
}
|
|
@@ -883,7 +1124,7 @@ export async function editorCompileProblem(
|
|
|
883
1124
|
/** The editor themes a running `compile` holds the lock of, by project and name. */
|
|
884
1125
|
const COMPILE_HELD = new Set();
|
|
885
1126
|
|
|
886
|
-
/** @type {(() => Promise<void>) | null} The release of the running compile's hold. */
|
|
1127
|
+
/** @type {((refused?: boolean) => Promise<void>) | null} The release of the running compile's hold; `refused`: it wrote nothing, so no app copy either. */
|
|
887
1128
|
let releaseCompileHold = null;
|
|
888
1129
|
|
|
889
1130
|
/**
|
|
@@ -903,13 +1144,23 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
903
1144
|
const at = editorThemeAt(cwdRoot, path.resolve(cwd, f));
|
|
904
1145
|
if (at && editorOwnFile(at.slug, f))
|
|
905
1146
|
found.set(`${at.root}\0${at.slug}`, at);
|
|
1147
|
+
// The app copy's source (src/themes/<t>/<t>Theme.ts) of an editor
|
|
1148
|
+
// theme: built under the theme's lock, so it never lands between a
|
|
1149
|
+
// change's two writes.
|
|
1150
|
+
const copy = appCopyTheme(cwdRoot, path.resolve(cwd, f));
|
|
1151
|
+
if (copy) found.set(`${copy.root}\0${copy.slug}`, copy);
|
|
906
1152
|
}
|
|
907
1153
|
const themes = [...found.keys()].sort().map(k => found.get(k));
|
|
908
|
-
/** @type {Array<() => Promise<void
|
|
1154
|
+
/** @type {Array<{copy: (refused: boolean) => boolean, finish: (later: boolean) => Promise<void>}>} */
|
|
909
1155
|
const releases = [];
|
|
910
|
-
|
|
1156
|
+
// Every theme's copy is written first, at once (a refusal ends the run
|
|
1157
|
+
// without waiting), then each lock goes.
|
|
1158
|
+
const releaseAll = async (refused = false) => {
|
|
911
1159
|
if (releaseCompileHold === releaseAll) releaseCompileHold = null;
|
|
912
|
-
|
|
1160
|
+
const items = releases.splice(0);
|
|
1161
|
+
const later = items.map(x => x.copy(refused));
|
|
1162
|
+
for (const [i, x] of [...items.entries()].reverse())
|
|
1163
|
+
await x.finish(later[i]);
|
|
913
1164
|
};
|
|
914
1165
|
releaseCompileHold = releaseAll;
|
|
915
1166
|
for (const {
|
|
@@ -927,6 +1178,17 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
927
1178
|
ready = r;
|
|
928
1179
|
});
|
|
929
1180
|
const key = `${root}\0${slug}`;
|
|
1181
|
+
// When the lock was taken, and the context a copy write needs (its
|
|
1182
|
+
// font stylesheets), ready before the build so the copy is written at
|
|
1183
|
+
// once when the run ends.
|
|
1184
|
+
const heldAt = Date.now() - 1;
|
|
1185
|
+
/** @type {any} */
|
|
1186
|
+
let copyCtx = null;
|
|
1187
|
+
try {
|
|
1188
|
+
copyCtx = await context(root);
|
|
1189
|
+
} catch {
|
|
1190
|
+
copyCtx = null;
|
|
1191
|
+
}
|
|
930
1192
|
const done = withLock(root, lockName(slug), async () => {
|
|
931
1193
|
COMPILE_HELD.add(key);
|
|
932
1194
|
ready();
|
|
@@ -941,12 +1203,45 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
941
1203
|
await releaseAll();
|
|
942
1204
|
throw err;
|
|
943
1205
|
}
|
|
944
|
-
releases.push(
|
|
1206
|
+
releases.push({
|
|
945
1207
|
// A compile that wrote the build refreshes the app's copy too
|
|
946
|
-
// (src/themes/<theme>/), under the same lock; a check writes
|
|
947
|
-
|
|
1208
|
+
// (src/themes/<theme>/), under the same lock; a check writes
|
|
1209
|
+
// nothing. Each theme's copy follows its own build: a theme this run
|
|
1210
|
+
// built (its build now matches its settings) gets its copy, whatever
|
|
1211
|
+
// a later theme did; one that was refused or failed keeps its copy.
|
|
1212
|
+
// True when the copy still needs its font stylesheet from the
|
|
1213
|
+
// theme's settings (written in finish).
|
|
1214
|
+
copy: (/** @type {boolean} */ refused) => {
|
|
1215
|
+
if (process.argv.includes('--check')) return false;
|
|
1216
|
+
// This run built the theme: its outputs were written since the
|
|
1217
|
+
// lock was taken, or the run ended well. A refused or failed
|
|
1218
|
+
// compile writes no copy.
|
|
1219
|
+
const f = themeFiles(root, slug);
|
|
1220
|
+
const written = [f.css, f.js].some(x => {
|
|
1221
|
+
try {
|
|
1222
|
+
return fs.statSync(x).mtimeMs >= heldAt;
|
|
1223
|
+
} catch {
|
|
1224
|
+
return false;
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
if (!written && (refused || (process.exitCode ?? 0) !== 0))
|
|
1228
|
+
return false;
|
|
948
1229
|
try {
|
|
949
|
-
|
|
1230
|
+
// From what was just built, its font stylesheets from the fonts
|
|
1231
|
+
// the theme loads now.
|
|
1232
|
+
if (copyCtx) writeAppCopy(copyCtx, slug, loadTheme(root, slug));
|
|
1233
|
+
else writeAppCopyAt(root, slug, null);
|
|
1234
|
+
} catch {
|
|
1235
|
+
try {
|
|
1236
|
+
writeAppCopyAt(root, slug, null);
|
|
1237
|
+
} catch {
|
|
1238
|
+
// A theme that does not load keeps its copy as it was.
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
return false;
|
|
1242
|
+
},
|
|
1243
|
+
finish: async () => {
|
|
1244
|
+
if (!process.argv.includes('--check')) {
|
|
950
1245
|
// The first write of the app copy is named once (the compile's
|
|
951
1246
|
// own JSON envelope is the stable command's).
|
|
952
1247
|
const wrote = takeFirstAppCopy(root, slug);
|
|
@@ -954,17 +1249,150 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
954
1249
|
humanWarn(
|
|
955
1250
|
`wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${wrote.join(', ')}`,
|
|
956
1251
|
);
|
|
957
|
-
|
|
958
|
-
//
|
|
1252
|
+
// A copy a file or a link keeps behind, or one that could not be
|
|
1253
|
+
// written, is said, as set and show say it.
|
|
1254
|
+
const stale = appCopyStale(root, slug).appCopyStale;
|
|
1255
|
+
if (stale) humanWarn(stale);
|
|
959
1256
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1257
|
+
release();
|
|
1258
|
+
await done;
|
|
1259
|
+
},
|
|
963
1260
|
});
|
|
964
1261
|
}
|
|
965
1262
|
return releaseAll;
|
|
966
1263
|
}
|
|
967
1264
|
|
|
1265
|
+
/**
|
|
1266
|
+
* The editor theme whose app copy source a file is
|
|
1267
|
+
* (`src/themes/<t>/<t>Theme.ts`, with themes/<t>/ an editor theme), or
|
|
1268
|
+
* null.
|
|
1269
|
+
* @param {string} root the project root
|
|
1270
|
+
* @param {string} file absolute
|
|
1271
|
+
* @returns {{root: string, slug: string} | null}
|
|
1272
|
+
*/
|
|
1273
|
+
function appCopyTheme(root, file) {
|
|
1274
|
+
const rel = path.relative(root, file).split(path.sep);
|
|
1275
|
+
if (rel.length !== 4 || rel[0] !== 'src' || rel[1] !== 'themes') return null;
|
|
1276
|
+
const slug = rel[2];
|
|
1277
|
+
if (rel[3] !== `${camel(slug)}Theme.ts`) return null;
|
|
1278
|
+
return fs.existsSync(themeFiles(root, slug).settings) ? {root, slug} : null;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* For `compile` of an editor theme: `appCopyStale` for its result data when
|
|
1283
|
+
* the app copy is behind (the same line set and show give); null for any
|
|
1284
|
+
* other file or a current copy.
|
|
1285
|
+
* @param {string} file the path as given
|
|
1286
|
+
* @param {string} cwd
|
|
1287
|
+
* @param {{check: boolean, upToDate?: boolean}} opts `upToDate`: the
|
|
1288
|
+
* check's own verdict on the theme's outputs
|
|
1289
|
+
* @returns {Promise<Record<string, unknown> | null>}
|
|
1290
|
+
*/
|
|
1291
|
+
export async function editorBuildExtra(file, cwd, opts) {
|
|
1292
|
+
const root = projectRoot(cwd);
|
|
1293
|
+
const abs = path.resolve(cwd, file);
|
|
1294
|
+
const own = editorThemeAt(root, abs);
|
|
1295
|
+
const slug =
|
|
1296
|
+
appCopyTheme(root, abs)?.slug ??
|
|
1297
|
+
(own && editorOwnFile(own.slug, file) ? own.slug : null);
|
|
1298
|
+
if (!slug) return null;
|
|
1299
|
+
if (opts.check) {
|
|
1300
|
+
// A theme output that is stale is the check's own finding (it names
|
|
1301
|
+
// the file); the copy is compared only with a current build.
|
|
1302
|
+
if (opts.upToDate === false) return null;
|
|
1303
|
+
/** @type {string[] | null} */
|
|
1304
|
+
let fonts;
|
|
1305
|
+
try {
|
|
1306
|
+
fonts = copyFontsCss(await context(root), slug, loadTheme(root, slug));
|
|
1307
|
+
} catch {
|
|
1308
|
+
fonts = null;
|
|
1309
|
+
}
|
|
1310
|
+
const behind = appCopyBehind(root, slug, fonts);
|
|
1311
|
+
return behind
|
|
1312
|
+
? {
|
|
1313
|
+
upToDate: false,
|
|
1314
|
+
code: 'ERR_THEME_STALE',
|
|
1315
|
+
appCopyStale: `${slug}'s app copy in src/themes/${slug}/ is not up to date: ${behind}. ${runLine(root, `experimental theme editor show ${slug}`)} writes it again`,
|
|
1316
|
+
}
|
|
1317
|
+
: null;
|
|
1318
|
+
}
|
|
1319
|
+
const stale = appCopyStale(root, slug).appCopyStale;
|
|
1320
|
+
return stale ? {appCopyStale: stale} : null;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
/**
|
|
1324
|
+
* For `compile` of an editor theme's own source (themes/<t>/<t>.theme.ts):
|
|
1325
|
+
* the one color mode a light-only or dark-only theme has, which its source
|
|
1326
|
+
* cannot say, for the build to write into the built module. Null for any
|
|
1327
|
+
* other file (the app copy's source re-exports it from its build).
|
|
1328
|
+
* @param {string} file the path as given
|
|
1329
|
+
* @param {string} cwd
|
|
1330
|
+
* @returns {['light'] | ['dark'] | null}
|
|
1331
|
+
*/
|
|
1332
|
+
export function editorColorModes(file, cwd) {
|
|
1333
|
+
const root = projectRoot(cwd);
|
|
1334
|
+
const at = editorThemeAt(root, path.resolve(cwd, file));
|
|
1335
|
+
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
1336
|
+
return buildColorModes(at.root, at.slug);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* For `compile` of an editor theme (themes/<t>/ or its app copy's source):
|
|
1341
|
+
* whether a font family is loaded by the app copy's font stylesheet
|
|
1342
|
+
* (src/themes/<t>/<t>.fonts.css: an @fontsource package by its name, a
|
|
1343
|
+
* stylesheet by the `family=` it requests), so the build's "named but not
|
|
1344
|
+
* loaded" notice leaves it out. Null for any other file.
|
|
1345
|
+
* @param {string} file the path as given
|
|
1346
|
+
* @param {string} cwd
|
|
1347
|
+
* @returns {((family: string) => boolean) | null}
|
|
1348
|
+
*/
|
|
1349
|
+
export function editorLoadedFonts(file, cwd) {
|
|
1350
|
+
const root = projectRoot(cwd);
|
|
1351
|
+
const abs = path.resolve(cwd, file);
|
|
1352
|
+
const slug =
|
|
1353
|
+
appCopyTheme(root, abs)?.slug ??
|
|
1354
|
+
(editorThemeAt(root, abs) &&
|
|
1355
|
+
editorOwnFile(editorThemeAt(root, abs)?.slug ?? '', file)
|
|
1356
|
+
? editorThemeAt(root, abs)?.slug
|
|
1357
|
+
: null);
|
|
1358
|
+
if (!slug) return null;
|
|
1359
|
+
/** @param {string} s */
|
|
1360
|
+
const key = s =>
|
|
1361
|
+
String(s)
|
|
1362
|
+
.replace(/["']/g, '')
|
|
1363
|
+
.toLowerCase()
|
|
1364
|
+
.replace(/[^a-z0-9]/g, '');
|
|
1365
|
+
/** @type {Set<string>} */
|
|
1366
|
+
const loaded = new Set();
|
|
1367
|
+
/** @type {string} */
|
|
1368
|
+
let text;
|
|
1369
|
+
try {
|
|
1370
|
+
text = fs.readFileSync(
|
|
1371
|
+
path.join(root, 'src', 'themes', slug, `${slug}.fonts.css`),
|
|
1372
|
+
'utf8',
|
|
1373
|
+
);
|
|
1374
|
+
} catch {
|
|
1375
|
+
return null;
|
|
1376
|
+
}
|
|
1377
|
+
const req = createRequire(path.join(root, 'package.json'));
|
|
1378
|
+
for (const m of text.matchAll(/@import\s+"([^"]+)"/g)) {
|
|
1379
|
+
const spec = m[1];
|
|
1380
|
+
const pkg = /^@fontsource(?:-variable)?\/([^/]+)/.exec(spec);
|
|
1381
|
+
if (pkg) {
|
|
1382
|
+
loaded.add(key(pkg[1]));
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
try {
|
|
1386
|
+
const css = fs.readFileSync(req.resolve(spec), 'utf8');
|
|
1387
|
+
for (const f of css.matchAll(/family=([^:&'")]+)/g))
|
|
1388
|
+
loaded.add(key(decodeURIComponent(f[1].replace(/\+/g, ' '))));
|
|
1389
|
+
} catch {
|
|
1390
|
+
// A stylesheet that cannot be read loads nothing known here.
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
return family => loaded.has(key(family));
|
|
1394
|
+
}
|
|
1395
|
+
|
|
968
1396
|
/**
|
|
969
1397
|
* For `compile` of a file that is not there: when it is an editor theme's
|
|
970
1398
|
* own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
|
|
@@ -974,6 +1402,14 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
974
1402
|
* @returns {{name: string, reason: string} | null}
|
|
975
1403
|
*/
|
|
976
1404
|
export function editorMissingSource(file, cwd) {
|
|
1405
|
+
// The app copy's source of an editor theme, its folder gone: the editor
|
|
1406
|
+
// writes it again.
|
|
1407
|
+
const copy = appCopyTheme(projectRoot(cwd), path.resolve(cwd, file));
|
|
1408
|
+
if (copy)
|
|
1409
|
+
return {
|
|
1410
|
+
name: runLine(cwd, `experimental theme editor show ${copy.slug}`),
|
|
1411
|
+
reason: `the editor writes ${copy.slug}'s app copy in src/themes/${copy.slug}/ again`,
|
|
1412
|
+
};
|
|
977
1413
|
const at = editorThemeAt(projectRoot(cwd), path.resolve(cwd, file));
|
|
978
1414
|
if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
|
|
979
1415
|
return {
|