@astryxdesign/cli 0.7.16-canary.ge95b87c → 0.7.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +369 -0
- package/README.md +1 -1
- package/api/build/_adapter.d.mts +9 -0
- package/api/build/_adapter.mjs +24 -0
- package/api/build/kit/shell.weights.json +1 -0
- package/api/build/kit/shellcall.d.mts +26 -0
- package/api/build/kit/shellcall.mjs +87 -0
- package/api/build/kit/start.mjs +67 -4
- package/api/build/kit/weights.d.mts +15 -0
- package/api/build/kit/weights.mjs +27 -0
- package/api/component/__fixtures__/resolutions/modules.txt +1 -1
- package/api/doctor/_adapter.d.mts +3 -2
- package/api/doctor/_adapter.mjs +7 -1
- package/api/doctor/doctor.d.mts +8 -0
- package/api/doctor/doctor.mjs +53 -8
- package/api/doctor/theme-checks.mjs +157 -8
- package/api/icon/_adapter.d.mts +7 -3
- package/api/icon/_adapter.mjs +12 -3
- package/api/icon/icon.type.d.mts +15 -0
- package/api/icon/icon.type.mjs +10 -3
- package/api/icon/iconUse.doc.mjs +19 -5
- package/api/icon/list/list.mjs +7 -1
- package/api/icon/use/use.d.mts +8 -5
- package/api/icon/use/use.mjs +95 -13
- package/api/init/run/run.mjs +1 -0
- package/api/template/template.type.d.mts +6 -2
- package/api/template/template.type.mjs +2 -1
- package/api/theme/_adapter.mjs +16 -2
- package/api/theme/build/build.d.mts +10 -6
- package/api/theme/build/build.mjs +42 -29
- package/api/theme/generateTonalPalette.doc.mjs +2 -2
- package/api/theme/palette/generate/generator.mjs +141 -2
- package/api/theme/theme.type.d.mts +39 -0
- package/api/theme/theme.type.mjs +21 -0
- package/api/theme/themeBuild.doc.mjs +1 -1
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +1 -0
- package/api/theme-edit/_adapter.mjs +79 -21
- package/api/theme-edit/_check.d.mts +25 -2
- package/api/theme-edit/_check.mjs +251 -61
- package/api/theme-edit/_context.d.mts +2 -1
- package/api/theme-edit/_context.mjs +19 -1
- package/api/theme-edit/_edit.d.mts +16 -0
- package/api/theme-edit/_edit.mjs +360 -59
- package/api/theme-edit/_how-question.d.mts +8 -0
- package/api/theme-edit/_how-question.mjs +169 -22
- package/api/theme-edit/_marks.d.mts +13 -0
- package/api/theme-edit/_marks.mjs +15 -0
- package/api/theme-edit/_palette.d.mts +27 -0
- package/api/theme-edit/_palette.mjs +112 -8
- package/api/theme-edit/_preview-app.d.mts +46 -1
- package/api/theme-edit/_preview-app.mjs +367 -36
- package/api/theme-edit/_preview.d.mts +55 -0
- package/api/theme-edit/_preview.mjs +231 -6
- package/api/theme-edit/_project.d.mts +4 -0
- package/api/theme-edit/_project.mjs +27 -6
- package/api/theme-edit/_settings.d.mts +61 -2
- package/api/theme-edit/_settings.mjs +317 -115
- package/api/theme-edit/_tables.mjs +1 -1
- package/api/theme-edit/theme-edit.type.d.mts +30 -2
- package/api/theme-edit/theme-edit.type.mjs +10 -2
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.zh.mjs +4 -3
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +63 -8
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
- package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/page.tsx +20 -2
- package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
- package/authoring/config/config.doc.mjs +8 -0
- package/authoring/config/parse.d.mts +1 -0
- package/authoring/config/parse.mjs +12 -0
- package/authoring/config/type.ts +8 -0
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/icon.mjs +61 -6
- package/clients/cli/commands/experimental/theme.mjs +9 -2
- package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.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-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +7 -2
- package/clients/cli/commands/theme.mjs +41 -18
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/index.mjs +25 -5
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/config-writer.d.mts +23 -0
- package/foundation/config/config-writer.mjs +150 -56
- package/foundation/config/project.mjs +43 -2
- package/foundation/discovery/component-discovery.mjs +6 -5
- package/foundation/discovery/icon-set-checks.mjs +164 -48
- package/foundation/discovery/icon-set-discovery.d.mts +38 -5
- package/foundation/discovery/icon-set-discovery.mjs +50 -6
- package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
- package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -3
- package/foundation/discovery/icon-set-writer.mjs +57 -16
- package/foundation/discovery/template-icons.d.mts +27 -10
- package/foundation/discovery/template-icons.mjs +142 -26
- package/foundation/discovery/theme-discovery.d.mts +25 -0
- package/foundation/discovery/theme-discovery.mjs +48 -7
- package/foundation/fs/gather-cache.mjs +6 -2
- package/foundation/integrations/autolink.d.mts +4 -2
- package/foundation/integrations/autolink.mjs +4 -2
- package/foundation/integrations/cli-requirement.d.mts +16 -5
- package/foundation/integrations/cli-requirement.mjs +27 -6
- package/foundation/integrations/may-have-integrations.mjs +5 -2
- package/foundation/integrations/missing-dependency.d.mts +9 -0
- package/foundation/integrations/missing-dependency.mjs +100 -0
- package/package.json +6 -6
|
@@ -31,7 +31,15 @@ import {
|
|
|
31
31
|
renderGenerated,
|
|
32
32
|
} from './_parts.mjs';
|
|
33
33
|
import {OVERVIEW_SECTIONS} from './_overview.mjs';
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
FOLDER_JUNK,
|
|
36
|
+
folderIsEmpty,
|
|
37
|
+
camel,
|
|
38
|
+
fontPackages,
|
|
39
|
+
modesOf,
|
|
40
|
+
themeFiles,
|
|
41
|
+
shown,
|
|
42
|
+
} from './_settings.mjs';
|
|
35
43
|
import {writeWhole} from './_palette.mjs';
|
|
36
44
|
import {cliVersion} from '../../foundation/release/run-context.mjs';
|
|
37
45
|
import {importPathOf, installLine} from './_project.mjs';
|
|
@@ -466,13 +474,13 @@ const withRenderKey = (html, key) => {
|
|
|
466
474
|
};
|
|
467
475
|
|
|
468
476
|
/**
|
|
469
|
-
*
|
|
477
|
+
* The sample page source of a theme's preview.html, its file, and the key
|
|
478
|
+
* of the inputs it is rendered from.
|
|
470
479
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
471
480
|
* @param {string} slug
|
|
472
481
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
473
|
-
* @returns {Promise<string>} the file written, as shown
|
|
474
482
|
*/
|
|
475
|
-
|
|
483
|
+
function previewInputs(ctx, slug, data) {
|
|
476
484
|
const {project} = ctx;
|
|
477
485
|
const imports = /** @type {Record<string, string>} */ ({});
|
|
478
486
|
for (const n of elementNames(SAMPLE_PAGE)) {
|
|
@@ -487,8 +495,36 @@ export async function renderPreview(ctx, slug, data) {
|
|
|
487
495
|
title: `${slug}: sample page`,
|
|
488
496
|
});
|
|
489
497
|
const out = themeFiles(project.cwd, slug).preview;
|
|
498
|
+
return {source, out, key: renderKey(project, slug, source, data.like)};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Whether themes/<slug>/preview.html was rendered from the theme as it is
|
|
503
|
+
* now (the same check renderPreview makes before it renders again).
|
|
504
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
505
|
+
* @param {string} slug
|
|
506
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
507
|
+
*/
|
|
508
|
+
export function previewIsCurrent(ctx, slug, data) {
|
|
509
|
+
try {
|
|
510
|
+
const {out, key} = previewInputs(ctx, slug, data);
|
|
511
|
+
return renderedFrom(out, key);
|
|
512
|
+
} catch {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Render the sample app page with the theme to themes/<slug>/preview.html.
|
|
519
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
520
|
+
* @param {string} slug
|
|
521
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
522
|
+
* @returns {Promise<string>} the file written, as shown
|
|
523
|
+
*/
|
|
524
|
+
export async function renderPreview(ctx, slug, data) {
|
|
525
|
+
const {project} = ctx;
|
|
526
|
+
const {source, out, key} = previewInputs(ctx, slug, data);
|
|
490
527
|
// Rendered from the same inputs before: the page is as it would be.
|
|
491
|
-
const key = renderKey(project, slug, source, data.like);
|
|
492
528
|
if (renderedFrom(out, key)) return shown(project.cwd, out);
|
|
493
529
|
const {html} = await renderGenerated(project, `preview-${slug}.mjs`, source);
|
|
494
530
|
// Written whole and renamed in, never through a link.
|
|
@@ -1274,7 +1310,9 @@ export function previewRouteSource({
|
|
|
1274
1310
|
' sideNav={',
|
|
1275
1311
|
' <SideNav>',
|
|
1276
1312
|
' {PAGES.map(p => (',
|
|
1277
|
-
|
|
1313
|
+
// Only a plain left click switches the page in place; a modified or
|
|
1314
|
+
// middle click opens the page's URL as a link does (a new tab).
|
|
1315
|
+
' <SideNavItem key={p.id} label={p.label} isSelected={p.id === current.id} href={`?page=${p.id}`} onClick={e => { if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return; e.preventDefault(); go(p.id); }} />',
|
|
1278
1316
|
' ))}',
|
|
1279
1317
|
' </SideNav>',
|
|
1280
1318
|
' }>',
|
|
@@ -1328,6 +1366,22 @@ export function previewRouteSource({
|
|
|
1328
1366
|
'',
|
|
1329
1367
|
'export default function ThemePreviewPage() {',
|
|
1330
1368
|
' const [page, setPage] = React.useState(PAGES[0]?.id);',
|
|
1369
|
+
// Each page has its own URL (?page=<id>), so a link, a reload, the back
|
|
1370
|
+
// button or a screenshot reaches any page; the page renders after mount.
|
|
1371
|
+
" const fromUrl = () => new URLSearchParams(window.location.search).get('page');",
|
|
1372
|
+
' React.useEffect(() => {',
|
|
1373
|
+
// A URL with no (or an unknown) ?page shows the first page, as a reload does.
|
|
1374
|
+
' const sync = () => { const id = fromUrl(); setPage(id && PAGES.some(p => p.id === id) ? id : PAGES[0]?.id); };',
|
|
1375
|
+
' sync();',
|
|
1376
|
+
" window.addEventListener('popstate', sync);",
|
|
1377
|
+
" return () => window.removeEventListener('popstate', sync);",
|
|
1378
|
+
' }, []);',
|
|
1379
|
+
' const go = (id: string) => {',
|
|
1380
|
+
' setPage(id);',
|
|
1381
|
+
' const url = new URL(window.location.href);',
|
|
1382
|
+
" url.searchParams.set('page', id);",
|
|
1383
|
+
" window.history.pushState(null, '', url);",
|
|
1384
|
+
' };',
|
|
1331
1385
|
// Pages render only in the browser: some components crash a server
|
|
1332
1386
|
// render, and Next prerenders a client page's first state.
|
|
1333
1387
|
' const [ready, setReady] = React.useState(false);',
|
|
@@ -1470,3 +1524,174 @@ function chromeBinary() {
|
|
|
1470
1524
|
}
|
|
1471
1525
|
return null;
|
|
1472
1526
|
}
|
|
1527
|
+
|
|
1528
|
+
/** The first line of every file the editor writes into a theme's app copy. */
|
|
1529
|
+
export {APP_COPY_MARK} from './_marks.mjs';
|
|
1530
|
+
import {APP_COPY_MARK} from './_marks.mjs';
|
|
1531
|
+
|
|
1532
|
+
/**
|
|
1533
|
+
* The app's copy of an editor theme: a standard local theme in
|
|
1534
|
+
* src/themes/<theme>/ (a descriptor, a source that re-exports the built
|
|
1535
|
+
* module, the built module, its stylesheet and font stylesheet), the shape
|
|
1536
|
+
* `astryx theme add <theme>` reads, so the theme goes into the app with the
|
|
1537
|
+
* stable theme commands. It is written again after every build of the
|
|
1538
|
+
* theme, never edited by hand. A folder there that is not the editor's own
|
|
1539
|
+
* copy is left alone: returns null then, else the folder.
|
|
1540
|
+
* The built module and stylesheet are written whole: a local theme's source
|
|
1541
|
+
* may import only files inside its own folder.
|
|
1542
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1543
|
+
* @param {string} slug
|
|
1544
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1545
|
+
* @returns {string | null}
|
|
1546
|
+
*/
|
|
1547
|
+
export function writeAppCopy(ctx, slug, data) {
|
|
1548
|
+
return writeAppCopyAt(
|
|
1549
|
+
ctx.project.cwd,
|
|
1550
|
+
slug,
|
|
1551
|
+
themeImports(
|
|
1552
|
+
ctx,
|
|
1553
|
+
slug,
|
|
1554
|
+
data,
|
|
1555
|
+
path.join(ctx.project.cwd, 'src', 'themes', slug),
|
|
1556
|
+
).css.slice(1),
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
/**
|
|
1561
|
+
* {@link writeAppCopy} with the font stylesheets given, or null to keep the
|
|
1562
|
+
* copy's own (a compile, which changes no setting).
|
|
1563
|
+
* @param {string} cwd
|
|
1564
|
+
* @param {string} slug
|
|
1565
|
+
* @param {string[] | null} fontsCss
|
|
1566
|
+
* @returns {string | null}
|
|
1567
|
+
*/
|
|
1568
|
+
export function writeAppCopyAt(cwd, slug, fontsCss) {
|
|
1569
|
+
const f = themeFiles(cwd, slug);
|
|
1570
|
+
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1571
|
+
const name = `${camel(slug)}Theme`;
|
|
1572
|
+
const first = !fs.existsSync(path.join(dir, `${name}.doc.mjs`));
|
|
1573
|
+
if (!fs.existsSync(f.js) || !fs.existsSync(f.css)) return null;
|
|
1574
|
+
// The copy's source, as the stable build's header names it.
|
|
1575
|
+
const source = `src/themes/${slug}/${name}.ts`;
|
|
1576
|
+
// Only the editor's own copy is written over.
|
|
1577
|
+
if (appCopyBlocker(cwd, slug) !== null) return null;
|
|
1578
|
+
const head = (/** @type {string} */ open, /** @type {string} */ close) =>
|
|
1579
|
+
`${open} ${APP_COPY_MARK} after every build of themes/${slug}/; do not edit it here. Change the theme with the editor. ${close}\n`;
|
|
1580
|
+
const keptFonts = path.join(dir, `${slug}.fonts.css`);
|
|
1581
|
+
const fonts =
|
|
1582
|
+
fontsCss ??
|
|
1583
|
+
(fs.existsSync(keptFonts)
|
|
1584
|
+
? [
|
|
1585
|
+
...fs.readFileSync(keptFonts, 'utf8').matchAll(/@import "([^"]+)";/g),
|
|
1586
|
+
].map(m => m[1])
|
|
1587
|
+
: []);
|
|
1588
|
+
// A built file as `theme build` of the copy's source writes it: the
|
|
1589
|
+
// editor's build of the same theme, with the header naming that source.
|
|
1590
|
+
const asBuilt = (/** @type {string} */ text) =>
|
|
1591
|
+
text
|
|
1592
|
+
.replace(/^( \* Source: ).*$/m, `$1${source}`)
|
|
1593
|
+
.replace(/^( \* Command: ).*$/m, `$1astryx theme build ${source}`);
|
|
1594
|
+
/** @type {Record<string, string>} */
|
|
1595
|
+
const built = {};
|
|
1596
|
+
for (const ext of APP_COPY_BUILT) {
|
|
1597
|
+
const from = path.join(f.dir, `${slug}${ext}`);
|
|
1598
|
+
if (fs.existsSync(from))
|
|
1599
|
+
built[`${slug}${ext}`] = asBuilt(fs.readFileSync(from, 'utf8'));
|
|
1600
|
+
}
|
|
1601
|
+
const files = {
|
|
1602
|
+
[`${name}.doc.mjs`]: `${head('//', '')}\n/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */\nexport default {\n type: 'theme',\n name: ${JSON.stringify(slug)},\n displayName: ${JSON.stringify(slug)},\n description: ${JSON.stringify(`The ${slug} theme, made with the theme editor (themes/${slug}/).`)},\n maintained: false,\n};\n`,
|
|
1603
|
+
[`${name}.ts`]: `${head('//', '')}export {${name}} from './${slug}';\n`,
|
|
1604
|
+
...built,
|
|
1605
|
+
...(fonts.length
|
|
1606
|
+
? {
|
|
1607
|
+
[`${slug}.fonts.css`]: `${head('/*', '*/')}${fonts.map(c => `@import ${JSON.stringify(c)};`).join('\n')}\n`,
|
|
1608
|
+
}
|
|
1609
|
+
: {}),
|
|
1610
|
+
};
|
|
1611
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
1612
|
+
for (const [n, text] of Object.entries(files)) {
|
|
1613
|
+
const file = path.join(dir, n);
|
|
1614
|
+
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === text) continue;
|
|
1615
|
+
writeWhole(file, text);
|
|
1616
|
+
}
|
|
1617
|
+
// A file an earlier copy had (a font stylesheet no longer needed) goes;
|
|
1618
|
+
// system files stay.
|
|
1619
|
+
for (const n of fs.readdirSync(dir))
|
|
1620
|
+
if (!(n in files) && !FOLDER_JUNK.has(n))
|
|
1621
|
+
fs.rmSync(path.join(dir, n), {force: true});
|
|
1622
|
+
// The first write is named in the command's result; later ones are not.
|
|
1623
|
+
if (first)
|
|
1624
|
+
FIRST_COPIES.set(
|
|
1625
|
+
`${path.resolve(cwd)}\0${slug}`,
|
|
1626
|
+
Object.keys(files)
|
|
1627
|
+
.sort()
|
|
1628
|
+
.map(n =>
|
|
1629
|
+
path.relative(cwd, path.join(dir, n)).split(path.sep).join('/'),
|
|
1630
|
+
),
|
|
1631
|
+
);
|
|
1632
|
+
return dir;
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
/**
|
|
1636
|
+
* Why the editor will not write a theme's app copy, or null when it will:
|
|
1637
|
+
* the folder is not there yet, or its descriptor carries the editor's mark
|
|
1638
|
+
* and it holds only the copy's own files (system files such as .DS_Store
|
|
1639
|
+
* aside). Otherwise the name of what is in the way (a file of yours), or
|
|
1640
|
+
* the folder itself when it is not the editor's copy. Built bytes are not
|
|
1641
|
+
* compared, so a stable rebuild of the copy leaves it the editor's. The one
|
|
1642
|
+
* test the copy's writer and `wiring` both use.
|
|
1643
|
+
* @param {string} cwd
|
|
1644
|
+
* @param {string} slug
|
|
1645
|
+
* @returns {string | null}
|
|
1646
|
+
*/
|
|
1647
|
+
export function appCopyBlocker(cwd, slug) {
|
|
1648
|
+
const dir = path.join(cwd, 'src', 'themes', slug);
|
|
1649
|
+
const name = `${camel(slug)}Theme`;
|
|
1650
|
+
const rel = path.relative(cwd, dir).split(path.sep).join('/');
|
|
1651
|
+
if (folderIsEmpty(dir)) return null;
|
|
1652
|
+
/** @type {string[]} */
|
|
1653
|
+
let names;
|
|
1654
|
+
try {
|
|
1655
|
+
names = fs.readdirSync(dir);
|
|
1656
|
+
} catch {
|
|
1657
|
+
return rel;
|
|
1658
|
+
}
|
|
1659
|
+
/** @type {boolean} */
|
|
1660
|
+
let marked;
|
|
1661
|
+
try {
|
|
1662
|
+
marked = fs
|
|
1663
|
+
.readFileSync(path.join(dir, `${name}.doc.mjs`), 'utf8')
|
|
1664
|
+
.includes(APP_COPY_MARK);
|
|
1665
|
+
} catch {
|
|
1666
|
+
marked = false;
|
|
1667
|
+
}
|
|
1668
|
+
if (!marked) return rel;
|
|
1669
|
+
const own = new Set([
|
|
1670
|
+
`${name}.doc.mjs`,
|
|
1671
|
+
`${name}.ts`,
|
|
1672
|
+
`${slug}.fonts.css`,
|
|
1673
|
+
...APP_COPY_BUILT.map(ext => `${slug}${ext}`),
|
|
1674
|
+
]);
|
|
1675
|
+
const other = names.find(n => !own.has(n) && !FOLDER_JUNK.has(n));
|
|
1676
|
+
return other ? `${rel}/${other}` : null;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
/** The build outputs of a theme, by their ending after `<theme>`. */
|
|
1680
|
+
const APP_COPY_BUILT = ['.css', '.css.d.ts', '.js', '.d.ts', '.variants.d.ts'];
|
|
1681
|
+
|
|
1682
|
+
/** App copies written for the first time in this process, by app and theme. @type {Map<string, string[]>} */
|
|
1683
|
+
const FIRST_COPIES = new Map();
|
|
1684
|
+
|
|
1685
|
+
/**
|
|
1686
|
+
* The files of a theme's app copy when this command wrote it for the first
|
|
1687
|
+
* time (then forgotten, so one result names them), else null.
|
|
1688
|
+
* @param {string} cwd
|
|
1689
|
+
* @param {string} slug
|
|
1690
|
+
* @returns {string[] | null}
|
|
1691
|
+
*/
|
|
1692
|
+
export function takeFirstAppCopy(cwd, slug) {
|
|
1693
|
+
const key = `${path.resolve(cwd)}\0${slug}`;
|
|
1694
|
+
const wrote = FIRST_COPIES.get(key) ?? null;
|
|
1695
|
+
FIRST_COPIES.delete(key);
|
|
1696
|
+
return wrote;
|
|
1697
|
+
}
|
|
@@ -37,6 +37,10 @@ export function importPathOf(project: ThemeProject, name: string): string | null
|
|
|
37
37
|
* resolves it: from the project (an open project, or its folder, relative
|
|
38
38
|
* or not). Null when it is not installed there. The one base resolution:
|
|
39
39
|
* `new`, `set base`, `how` and every suggestion ask this.
|
|
40
|
+
*
|
|
41
|
+
* Only the packages the project installs count, as the app's bundler reads
|
|
42
|
+
* them: its node_modules folders, or Plug'n'Play. NODE_PATH and Node's global
|
|
43
|
+
* folders do not: a base found only there would not build.
|
|
40
44
|
* @param {ThemeProject | string} from
|
|
41
45
|
* @param {string} like
|
|
42
46
|
* @returns {string | null}
|
|
@@ -21,7 +21,10 @@ import {loadComponentDoc} from '../../foundation/discovery/component-loader.mjs'
|
|
|
21
21
|
import {collectThemingTargets} from '../../foundation/discovery/theming-targets.mjs';
|
|
22
22
|
import {resolveImportPath} from '../../foundation/discovery/component-discovery.mjs';
|
|
23
23
|
import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
findInstalledPackage,
|
|
26
|
+
findProjectCoreDir,
|
|
27
|
+
} from '../../foundation/fs/paths.mjs';
|
|
25
28
|
import {
|
|
26
29
|
oncePerListing,
|
|
27
30
|
withListingCache,
|
|
@@ -334,17 +337,35 @@ export function importPathOf(project, name) {
|
|
|
334
337
|
* resolves it: from the project (an open project, or its folder, relative
|
|
335
338
|
* or not). Null when it is not installed there. The one base resolution:
|
|
336
339
|
* `new`, `set base`, `how` and every suggestion ask this.
|
|
340
|
+
*
|
|
341
|
+
* Only the packages the project installs count, as the app's bundler reads
|
|
342
|
+
* them: its node_modules folders, or Plug'n'Play. NODE_PATH and Node's global
|
|
343
|
+
* folders do not: a base found only there would not build.
|
|
337
344
|
* @param {ThemeProject | string} from
|
|
338
345
|
* @param {string} like
|
|
339
346
|
* @returns {string | null}
|
|
340
347
|
*/
|
|
341
348
|
export function baseModule(from, like) {
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
349
|
+
const name = `@astryxdesign/theme-${like}`;
|
|
350
|
+
const start = typeof from === 'string' ? path.resolve(from) : from.cwd;
|
|
351
|
+
const pkg = findInstalledPackage(start, name, Infinity);
|
|
352
|
+
return pkg == null ? null : builtModule(pkg, name);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The `built` export of the package in `pkg`, or null. A file Node finds
|
|
357
|
+
* anywhere else (it searches NODE_PATH after a miss) does not count.
|
|
358
|
+
* @param {string} pkg
|
|
359
|
+
* @param {string} name
|
|
360
|
+
* @returns {string | null}
|
|
361
|
+
*/
|
|
362
|
+
function builtModule(pkg, name) {
|
|
346
363
|
try {
|
|
347
|
-
|
|
364
|
+
const file = createRequire(path.join(pkg, 'package.json')).resolve(
|
|
365
|
+
`${name}/built`,
|
|
366
|
+
);
|
|
367
|
+
const root = fs.realpathSync(pkg) + path.sep;
|
|
368
|
+
return fs.realpathSync(file).startsWith(root) ? file : null;
|
|
348
369
|
} catch {
|
|
349
370
|
return null;
|
|
350
371
|
}
|
|
@@ -21,6 +21,13 @@ export function themeFiles(cwd: string, slug: string): {
|
|
|
21
21
|
pictures: string;
|
|
22
22
|
sheetPng: string;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Whether `dir` holds nothing of anyone's: absent, empty, or only system
|
|
26
|
+
* files (what `git rm -r` or a branch switch leaves). A path that is not a
|
|
27
|
+
* folder, or one that does not read, is not empty.
|
|
28
|
+
* @param {string} dir
|
|
29
|
+
*/
|
|
30
|
+
export function folderIsEmpty(dir: string): boolean;
|
|
24
31
|
/**
|
|
25
32
|
* Whether a value fits what a dial takes, read from the dial's own list of
|
|
26
33
|
* values: a named rung in any case, or a value of the kind it names (a size,
|
|
@@ -123,10 +130,19 @@ export function refuse(code: string, message: string, extra?: {
|
|
|
123
130
|
fix?: string;
|
|
124
131
|
also?: string[];
|
|
125
132
|
}): never;
|
|
133
|
+
/**
|
|
134
|
+
* A theme name without a pasted label: `theme: t`, `name=t`, `--theme t`
|
|
135
|
+
* and `slug: "t"` name t; quotes and backticks around it go. Case is kept.
|
|
136
|
+
* A space is no label separator without dashes: "Theme Park" stays.
|
|
137
|
+
* The one reader of such labels, for --theme and every editor command.
|
|
138
|
+
* @param {unknown} s
|
|
139
|
+
* @returns {string}
|
|
140
|
+
*/
|
|
141
|
+
export function unlabeledThemeName(s: unknown): string;
|
|
126
142
|
/**
|
|
127
143
|
* A theme name as typed, read the way the editor reads it: a path to its
|
|
128
144
|
* folder or a file in it (t.theme.ts, Brand.settings.json), in any case,
|
|
129
|
-
* names the theme. The result may still need slugFor.
|
|
145
|
+
* or a pasted label (`theme: t`, `name: t`), names the theme. The result may still need slugFor.
|
|
130
146
|
* @param {unknown} s
|
|
131
147
|
* @returns {string}
|
|
132
148
|
*/
|
|
@@ -226,9 +242,10 @@ export function partRuleTokens(cwd: string, slug: string, like: string | null |
|
|
|
226
242
|
* @param {string} part
|
|
227
243
|
* @param {string} [scope] the rule: `base` (the plain one), or a variant
|
|
228
244
|
* such as `variant:primary`
|
|
245
|
+
* @param {string | null} [state] a state block inside that rule (`:hover`)
|
|
229
246
|
* @returns {Map<string, string | null>}
|
|
230
247
|
*/
|
|
231
|
-
export function ownPartTokens(cwd: string, slug: string, part: string, scope?: string): Map<string, string | null>;
|
|
248
|
+
export function ownPartTokens(cwd: string, slug: string, part: string, scope?: string, state?: string | null): Map<string, string | null>;
|
|
232
249
|
/**
|
|
233
250
|
* The page-wide tokens a theme's own source sets itself (see ownTokens):
|
|
234
251
|
* they win over the settings it extends.
|
|
@@ -325,6 +342,18 @@ export function stopsIn(source: string): Record<string, Record<"light" | "dark",
|
|
|
325
342
|
stop: number;
|
|
326
343
|
alpha?: string;
|
|
327
344
|
}>>;
|
|
345
|
+
/**
|
|
346
|
+
* Control heights scaled with the spacing dial (a denser theme has shorter
|
|
347
|
+
* controls), each kept distinct and in order: smallest to largest, a
|
|
348
|
+
* control never under 24px (the smallest target a pointer can use
|
|
349
|
+
* comfortably, unless the theme starts below it), each the plain scaled
|
|
350
|
+
* value unless it would meet the one below, which then keeps its own step
|
|
351
|
+
* scaled above it.
|
|
352
|
+
* @param {Array<[string, string]>} sizes token name and the theme's value
|
|
353
|
+
* @param {number} f the spacing rung's factor
|
|
354
|
+
* @returns {Array<[string, string]>} the tokens it writes, in px
|
|
355
|
+
*/
|
|
356
|
+
export function controlSizes(sizes: Array<[string, string]>, f: number): Array<[string, string]>;
|
|
328
357
|
/**
|
|
329
358
|
* The settings, as a `defineTheme` object.
|
|
330
359
|
* @param {Ctx} ctx
|
|
@@ -390,6 +419,34 @@ export function refuseThemeParse(cwd: string, slug: string): void;
|
|
|
390
419
|
* @param {string} slug
|
|
391
420
|
*/
|
|
392
421
|
export function refuseThemeSource(cwd: string, slug: string): void;
|
|
422
|
+
/**
|
|
423
|
+
* The tokens that are not colors the theme as it builds now gives a
|
|
424
|
+
* [light, dark] pair (light-dark()), however its file writes them (a
|
|
425
|
+
* constant, `as const`, `satisfies`, a spread from an imported module):
|
|
426
|
+
* read from a build made into the project's cache folder, never beside the
|
|
427
|
+
* theme. Empty when it does not build there (the build names that itself).
|
|
428
|
+
* @param {Ctx} ctx
|
|
429
|
+
* @param {string} slug
|
|
430
|
+
* @returns {Promise<string[]>}
|
|
431
|
+
*/
|
|
432
|
+
export function builtPairs(ctx: Ctx, slug: string): Promise<string[]>;
|
|
433
|
+
/**
|
|
434
|
+
* The refusal of a [light, dark] pair on tokens that are not colors.
|
|
435
|
+
* @param {string} slug
|
|
436
|
+
* @param {string[]} names
|
|
437
|
+
*/
|
|
438
|
+
export function ownPairMessage(slug: string, names: string[]): string;
|
|
439
|
+
/**
|
|
440
|
+
* Set what runs after every build of a theme.
|
|
441
|
+
* @param {((ctx: Ctx, slug: string, data: ThemeData) => void) | null} fn
|
|
442
|
+
*/
|
|
443
|
+
export function setAfterBuild(fn: ((ctx: Ctx, slug: string, data: ThemeData) => void) | null): void;
|
|
444
|
+
/**
|
|
445
|
+
* Hold the after-build hook for this command's builds: the command writes
|
|
446
|
+
* the app copy itself once it succeeds (show).
|
|
447
|
+
* @param {Ctx} ctx
|
|
448
|
+
*/
|
|
449
|
+
export function holdAfterBuild(ctx: Ctx): void;
|
|
393
450
|
/**
|
|
394
451
|
* Generate the theme source, build it with the theme build, then repeat any
|
|
395
452
|
* part setting a more specific rule would beat and build again.
|
|
@@ -636,6 +693,8 @@ export function windowsReserved(s: string): boolean;
|
|
|
636
693
|
export function slugFor(name: unknown): string;
|
|
637
694
|
export function kebab(s: string): string;
|
|
638
695
|
export function camel(s: string): string;
|
|
696
|
+
/** Files a system or a tool puts in any folder; a folder of only these is empty. */
|
|
697
|
+
export const FOLDER_JUNK: Set<string>;
|
|
639
698
|
export function shown(cwd: string, f: string): string;
|
|
640
699
|
export function keyOf(s: Setting): string;
|
|
641
700
|
export function cornerPx(v: string): number;
|