@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
|
@@ -25,6 +25,7 @@ import {baseResolved, installLine, openProject} from './_project.mjs';
|
|
|
25
25
|
import {P, wordTable} from './_tables.mjs';
|
|
26
26
|
import {
|
|
27
27
|
buildTheme,
|
|
28
|
+
camel,
|
|
28
29
|
editedThemes,
|
|
29
30
|
fontPackages,
|
|
30
31
|
loadTheme,
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
34
35
|
shown,
|
|
35
36
|
staleBuild,
|
|
36
37
|
themeFiles,
|
|
38
|
+
unlabeledThemeName,
|
|
37
39
|
usableNewName,
|
|
38
40
|
windowsReserved,
|
|
39
41
|
} from './_settings.mjs';
|
|
@@ -43,6 +45,7 @@ import {
|
|
|
43
45
|
componentsPageSource,
|
|
44
46
|
overviewPageSource,
|
|
45
47
|
previewRouteSource,
|
|
48
|
+
appCopyBlocker,
|
|
46
49
|
themeImports,
|
|
47
50
|
} from './_preview.mjs';
|
|
48
51
|
import {
|
|
@@ -512,7 +515,7 @@ function readNextConfig(cwd) {
|
|
|
512
515
|
const v = str(n);
|
|
513
516
|
return v == null
|
|
514
517
|
? null
|
|
515
|
-
:
|
|
518
|
+
: v.replace(/^(\.\/)+/, '').replace(/\/+$/, '') || null;
|
|
516
519
|
}),
|
|
517
520
|
};
|
|
518
521
|
}
|
|
@@ -566,9 +569,15 @@ function reservedFolder(cwd, dir) {
|
|
|
566
569
|
return 'node_modules/ belongs to the package manager, which replaces it';
|
|
567
570
|
if (segs[0] === 'public')
|
|
568
571
|
return 'Next serves every file in public/ as it is, at the site root, so anyone could download it';
|
|
572
|
+
// The build folders by their real path: a distDir with a subfolder
|
|
573
|
+
// (src/.next-build) covers that folder only, not the rest of src/.
|
|
569
574
|
const built = [
|
|
570
575
|
...new Set(['.next', 'out', readNextConfig(cwd).distDir]),
|
|
571
|
-
].find(d =>
|
|
576
|
+
].find(d => {
|
|
577
|
+
if (typeof d !== 'string' || !d.trim()) return false;
|
|
578
|
+
const at = path.resolve(cwd, d);
|
|
579
|
+
return at !== cwd && (dir === at || dir.startsWith(at + path.sep));
|
|
580
|
+
});
|
|
572
581
|
if (built)
|
|
573
582
|
return `${built}/ is where Next writes its build, and the next build empties it`;
|
|
574
583
|
const odd = segs.find(seg => windowsReserved(seg) || /^\.+$/.test(seg));
|
|
@@ -1252,6 +1261,83 @@ function nextAppsUnder(cwd) {
|
|
|
1252
1261
|
return out.sort((a, b) => a.root.localeCompare(b.root));
|
|
1253
1262
|
}
|
|
1254
1263
|
|
|
1264
|
+
/**
|
|
1265
|
+
* The steps that put an editor theme into the app through its app copy
|
|
1266
|
+
* (src/themes/<theme>/): one `theme add`, which prints the one-time wiring
|
|
1267
|
+
* of the app's theme module, and what keeps the copy in step. The one text
|
|
1268
|
+
* every place that says how to use an editor theme gives.
|
|
1269
|
+
* @param {string} cwd
|
|
1270
|
+
* @param {string} slug
|
|
1271
|
+
* @param {'light' | 'dark' | 'system'} [mode]
|
|
1272
|
+
* @returns {string[]}
|
|
1273
|
+
*/
|
|
1274
|
+
export function addWiring(cwd, slug, mode = 'system') {
|
|
1275
|
+
return [
|
|
1276
|
+
`${formatCliCommand(`theme add ${slug}`, cwd)}: adds the theme's app copy (src/themes/${slug}/, written again after every build) to the app's theme module, and prints the one-time wiring of that module in the app root; ${formatCliCommand(`theme use ${slug}`, cwd)} makes it the default`,
|
|
1277
|
+
// Core has no mode inside a theme: a one-mode theme's mode is the one
|
|
1278
|
+
// the app's <Theme> is given.
|
|
1279
|
+
...(mode === 'system'
|
|
1280
|
+
? []
|
|
1281
|
+
: [
|
|
1282
|
+
`${slug} is ${mode}-only: give the <Theme> that theme add's wiring puts in the app root mode="${mode}" (<Theme theme={…} mode="${mode}">); the theme keeps both halves of its colors, so a toast or a lightbox Core draws in the other mode stays readable`,
|
|
1283
|
+
]),
|
|
1284
|
+
`every set and undo builds the theme and its app copy again, so the app takes each change; after editing ${shown(cwd, themeFiles(cwd, slug).ts)} by hand, ${P.replace(/ editor$/, '')} compile ${shown(cwd, themeFiles(cwd, slug).ts)} builds both again`,
|
|
1285
|
+
];
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* How to use an editor theme in this app: `theme add <theme>` for the app
|
|
1290
|
+
* copy the editor writes in src/themes/<theme>/; when a folder of the
|
|
1291
|
+
* user's is there instead, step by step by hand: the file of the app's root
|
|
1292
|
+
* (a Next app's root layout, else the file that renders the app), the
|
|
1293
|
+
* imports the preview route uses for the same theme (its module, its
|
|
1294
|
+
* stylesheet and the font stylesheets) and the Theme around the app. Then
|
|
1295
|
+
* what builds it.
|
|
1296
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1297
|
+
* @param {string} slug
|
|
1298
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1299
|
+
* @returns {string[]}
|
|
1300
|
+
*/
|
|
1301
|
+
export function appWiring(ctx, slug, data) {
|
|
1302
|
+
const cwd = ctx.project.cwd;
|
|
1303
|
+
const routes = nextRoutesOf(cwd);
|
|
1304
|
+
const layout = routes
|
|
1305
|
+
? fs.readdirSync(routes).find(f => /^layout\.(tsx|ts|jsx|js)$/.test(f))
|
|
1306
|
+
: undefined;
|
|
1307
|
+
const file = routes && layout ? path.join(routes, layout) : null;
|
|
1308
|
+
const ti = themeImports(ctx, slug, data, file ? path.dirname(file) : cwd);
|
|
1309
|
+
const name = `${camel(slug)}Theme`;
|
|
1310
|
+
const where = file
|
|
1311
|
+
? `${shown(cwd, file)} (the app's root layout)`
|
|
1312
|
+
: "the file that renders your app's root (paths below are from the app folder)";
|
|
1313
|
+
const appModule = ['src/astryx-themes.ts', 'astryx-themes.ts'].find(m =>
|
|
1314
|
+
fs.existsSync(path.join(cwd, m)),
|
|
1315
|
+
);
|
|
1316
|
+
// The app's copy (src/themes/<theme>/, a standard local theme) is what
|
|
1317
|
+
// the stable theme commands add: one command, which prints the one-time
|
|
1318
|
+
// app wiring itself.
|
|
1319
|
+
// Only while the copy is the editor's (the same test its writer uses);
|
|
1320
|
+
// else the steps by hand, naming what is in the way.
|
|
1321
|
+
const blocker = appCopyBlocker(cwd, slug);
|
|
1322
|
+
if (blocker === null && fs.existsSync(path.join(cwd, 'src', 'themes', slug)))
|
|
1323
|
+
return addWiring(cwd, slug, ti.mode);
|
|
1324
|
+
return [
|
|
1325
|
+
...(blocker
|
|
1326
|
+
? [
|
|
1327
|
+
`${blocker} is not the editor's, so the editor does not write the theme's app copy in src/themes/${slug}/ (and theme add does not take it); the steps by hand:`,
|
|
1328
|
+
]
|
|
1329
|
+
: []),
|
|
1330
|
+
`in ${where}, import the theme and its stylesheets: import {Theme} from '@astryxdesign/core/theme'; import {${name}} from '${ti.module.replace(/\.js$/, '')}'; ${ti.css.map(c => `import '${c}';`).join(' ')}`,
|
|
1331
|
+
`wrap the app in it: <Theme theme={${name}}${ti.mode === 'system' ? '' : ` mode="${ti.mode}"`}>{children}</Theme>`,
|
|
1332
|
+
...(appModule
|
|
1333
|
+
? [
|
|
1334
|
+
`${appModule} (written by theme add and use) stays as it is: to keep its themes too, merge them in your own file ({...themes, ${JSON.stringify(slug)}: ${name}}), never in ${appModule}, which add, use and remove write again`,
|
|
1335
|
+
]
|
|
1336
|
+
: []),
|
|
1337
|
+
`every set and undo builds ${shown(cwd, themeFiles(cwd, slug).js)} and ${shown(cwd, themeFiles(cwd, slug).css)} again, so the app takes each change; after editing ${shown(cwd, themeFiles(cwd, slug).ts)} by hand, ${P.replace(/ editor$/, '')} compile ${shown(cwd, themeFiles(cwd, slug).ts)} builds it again`,
|
|
1338
|
+
];
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1255
1341
|
/**
|
|
1256
1342
|
* The routes folder of a Next app in `dir` (app/, else src/app/, with a
|
|
1257
1343
|
* root layout), when its package.json depends on `next`; else null.
|
|
@@ -2871,7 +2957,10 @@ async function routeTheme(cwd, dir, data, opts = {}) {
|
|
|
2871
2957
|
if (!data.theme) return null;
|
|
2872
2958
|
const t = loadTheme(cwd, data.theme);
|
|
2873
2959
|
const ctx = await context(cwd);
|
|
2874
|
-
|
|
2960
|
+
// The same rule `preview app` uses: any output missing, or a build that
|
|
2961
|
+
// does not match the settings, is built again (judged by content).
|
|
2962
|
+
const stale = staleBuild(cwd, data.theme, t);
|
|
2963
|
+
const unbuilt = stale != null;
|
|
2875
2964
|
if (unbuilt && opts.build !== false) await buildTheme(ctx, data.theme, t);
|
|
2876
2965
|
const ti = themeImports(ctx, data.theme, t, dir);
|
|
2877
2966
|
return {
|
|
@@ -2908,16 +2997,21 @@ async function themeLocked(options, slug, fn) {
|
|
|
2908
2997
|
async function buildWorn(cwd, theme, options, notes) {
|
|
2909
2998
|
if (!theme?.unbuilt) return;
|
|
2910
2999
|
const slug = theme.name;
|
|
3000
|
+
/** @type {string | null} */
|
|
3001
|
+
let why = null;
|
|
2911
3002
|
const build = async () => {
|
|
2912
|
-
|
|
2913
|
-
|
|
3003
|
+
const t = loadTheme(cwd, slug);
|
|
3004
|
+
why = staleBuild(cwd, slug, t);
|
|
3005
|
+
if (!why) return;
|
|
3006
|
+
await buildTheme(await context(cwd), slug, t);
|
|
2914
3007
|
};
|
|
2915
3008
|
await (typeof options?.lockTheme === 'function'
|
|
2916
3009
|
? options.lockTheme(slug, build)
|
|
2917
3010
|
: build());
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
3011
|
+
if (why)
|
|
3012
|
+
notes.push(
|
|
3013
|
+
`built ${shown(cwd, themeFiles(cwd, slug).dir)}/ first: its build was not current (${why})`,
|
|
3014
|
+
);
|
|
2921
3015
|
}
|
|
2922
3016
|
|
|
2923
3017
|
/** The Colors page: its id and file, relative to the route folder. */
|
|
@@ -3219,17 +3313,121 @@ function recordPreview(cwd, slug, dir, keep = true) {
|
|
|
3219
3313
|
}
|
|
3220
3314
|
|
|
3221
3315
|
/**
|
|
3222
|
-
*
|
|
3316
|
+
* The routes folder a preview folder is in, by place (also one a command
|
|
3317
|
+
* has just made), or null.
|
|
3223
3318
|
* @param {string} cwd
|
|
3224
3319
|
* @param {{dir: string, app: string | null}} at
|
|
3225
3320
|
*/
|
|
3226
|
-
function
|
|
3227
|
-
|
|
3228
|
-
const app =
|
|
3321
|
+
function routesOf(cwd, at) {
|
|
3322
|
+
return (
|
|
3229
3323
|
at.app ??
|
|
3230
3324
|
[path.join(cwd, 'app'), path.join(cwd, 'src', 'app')].find(r =>
|
|
3231
3325
|
at.dir.startsWith(r + path.sep),
|
|
3232
|
-
)
|
|
3326
|
+
) ??
|
|
3327
|
+
null
|
|
3328
|
+
);
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
/**
|
|
3332
|
+
* The URL path the app serves a preview at (with the basePath next.config
|
|
3333
|
+
* sets), or null when no URL can be told: outside the routes folder, under
|
|
3334
|
+
* a [param] folder, or a basePath set from code.
|
|
3335
|
+
* @param {string} cwd
|
|
3336
|
+
* @param {{dir: string, app: string | null}} at
|
|
3337
|
+
* @returns {string | null}
|
|
3338
|
+
*/
|
|
3339
|
+
function previewPath(cwd, at) {
|
|
3340
|
+
const app = routesOf(cwd, at);
|
|
3341
|
+
if (!app) return null;
|
|
3342
|
+
const segs = urlSegments(app, at.dir);
|
|
3343
|
+
if (segs.some(seg => /^\[.+\]$/.test(seg))) return null;
|
|
3344
|
+
const base = nextBasePath(cwd);
|
|
3345
|
+
if (base == null) return null;
|
|
3346
|
+
return `${base}/${segs.map(seg => encodeURIComponent(seg)).join('/')}`;
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
/**
|
|
3350
|
+
* Each page's own URL in the running app: the preview's path with
|
|
3351
|
+
* ?page=<id>, the first page at the bare path too. Empty when no URL can
|
|
3352
|
+
* be told.
|
|
3353
|
+
* @param {string} cwd
|
|
3354
|
+
* @param {{dir: string, app: string | null}} at
|
|
3355
|
+
* @param {string[]} ids
|
|
3356
|
+
* @returns {Record<string, string>}
|
|
3357
|
+
*/
|
|
3358
|
+
function pageUrls(cwd, at, ids) {
|
|
3359
|
+
const base = previewPath(cwd, at);
|
|
3360
|
+
if (base == null) return {};
|
|
3361
|
+
return Object.fromEntries(ids.map(id => [id, `${base}?page=${id}`]));
|
|
3362
|
+
}
|
|
3363
|
+
|
|
3364
|
+
/**
|
|
3365
|
+
* One line that says how to see a theme after a change. First a look that
|
|
3366
|
+
* changes nothing in the app: the editor's own preview.html (current after
|
|
3367
|
+
* the change) and --png, which takes pictures with no dev server; then the
|
|
3368
|
+
* in-app preview page most about what changed (Colors after a color,
|
|
3369
|
+
* Components after a part, else Overview) at its own URL when there is a
|
|
3370
|
+
* preview; adding one to the app last, as an option. A change that could
|
|
3371
|
+
* not be rendered names why instead of the editor's page.
|
|
3372
|
+
* @param {string} cwd
|
|
3373
|
+
* @param {string} slug
|
|
3374
|
+
* @param {'colors' | 'components' | 'overview'} focus
|
|
3375
|
+
* @param {{code: string, cause: string} | null} [notChecked] why the change
|
|
3376
|
+
* could not be rendered
|
|
3377
|
+
* @returns {string}
|
|
3378
|
+
*/
|
|
3379
|
+
export function seeLine(cwd, slug, focus, notChecked = null) {
|
|
3380
|
+
/** @type {string[]} */
|
|
3381
|
+
const urls = [];
|
|
3382
|
+
/** Previews whose URL depends on the app's routing. @type {string[]} */
|
|
3383
|
+
const unplain = [];
|
|
3384
|
+
// The previews recorded for the theme, and any found in the routes
|
|
3385
|
+
// folders that wear it (a folder renamed by hand), as remove finds them.
|
|
3386
|
+
const dirs = [
|
|
3387
|
+
...new Set([...recordedPreviews(cwd, slug), ...previewsIn(cwd)]),
|
|
3388
|
+
];
|
|
3389
|
+
for (const dir of dirs) {
|
|
3390
|
+
/** @type {any} */
|
|
3391
|
+
let data;
|
|
3392
|
+
try {
|
|
3393
|
+
data = JSON.parse(fs.readFileSync(path.join(dir, PREVIEW_DATA), 'utf8'));
|
|
3394
|
+
} catch {
|
|
3395
|
+
continue;
|
|
3396
|
+
}
|
|
3397
|
+
if (data?.theme !== slug) continue;
|
|
3398
|
+
const ids = Array.isArray(data?.pages)
|
|
3399
|
+
? data.pages.map((/** @type {any} */ x) => String(x?.id))
|
|
3400
|
+
: [];
|
|
3401
|
+
// Only a page the preview has.
|
|
3402
|
+
const id = ids.includes(focus) ? focus : ids[0];
|
|
3403
|
+
const url = id ? pageUrls(cwd, {dir, app: null}, [id])[id] : undefined;
|
|
3404
|
+
if (url) urls.push(url);
|
|
3405
|
+
else
|
|
3406
|
+
unplain.push(
|
|
3407
|
+
`${shownDir(cwd, dir)}/${id ? ` (its ${id} page: add ?page=${id} to its URL)` : ''}`,
|
|
3408
|
+
);
|
|
3409
|
+
}
|
|
3410
|
+
const f = themeFiles(cwd, slug);
|
|
3411
|
+
const own = notChecked
|
|
3412
|
+
? /could not be written/.test(notChecked.cause)
|
|
3413
|
+
? `the change is saved, but ${notChecked.cause}; --png takes no pictures until that is fixed`
|
|
3414
|
+
: `the change is saved, but the components could not be rendered here (${notChecked.cause}), so ${shown(cwd, f.preview)} still shows the theme as it was and --png takes no pictures until that is fixed`
|
|
3415
|
+
: `look without changing your app: open or screenshot ${shown(cwd, f.preview)} (one self-contained page, current after this change; ${EDITOR} show ${slug} also writes ${shown(cwd, f.sheet)}, every component), or run it with --png for pictures in ${shownDir(cwd, f.dir)}/ with no dev server (it needs a Playwright or a Chrome)`;
|
|
3416
|
+
if (urls.length)
|
|
3417
|
+
return `${own}; in the running app: open ${urls.slice(0, 2).join(' or ')}`;
|
|
3418
|
+
if (unplain.length)
|
|
3419
|
+
return `${own}; the in-app preview is in ${unplain.slice(0, 2).join(', ')}, at a URL that depends on the app's routing`;
|
|
3420
|
+
return `${own}; to see it inside your app, ${PREVIEW} add puts the preview pages there, each at its own URL`;
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
/**
|
|
3424
|
+
* How to open the preview, from where it is.
|
|
3425
|
+
* @param {string} cwd
|
|
3426
|
+
* @param {{dir: string, app: string | null}} at
|
|
3427
|
+
*/
|
|
3428
|
+
function openLine(cwd, at) {
|
|
3429
|
+
// The routes folder by place, also one this command has just made.
|
|
3430
|
+
const app = routesOf(cwd, at);
|
|
3233
3431
|
if (app) {
|
|
3234
3432
|
// A (group) folder is not part of the URL; a [param] folder is a value
|
|
3235
3433
|
// the person picks; each other folder is one URL segment, encoded.
|
|
@@ -3825,6 +4023,16 @@ async function reportingRecovery(fn) {
|
|
|
3825
4023
|
}
|
|
3826
4024
|
}
|
|
3827
4025
|
|
|
4026
|
+
/**
|
|
4027
|
+
* A --theme value as the editor reads a pasted entry: `theme: t`,
|
|
4028
|
+
* `--theme=t` and the like name the theme t.
|
|
4029
|
+
* @param {string | undefined} v
|
|
4030
|
+
* @returns {string | undefined}
|
|
4031
|
+
*/
|
|
4032
|
+
function themeArg(v) {
|
|
4033
|
+
return typeof v === 'string' ? unlabeledThemeName(v) : v;
|
|
4034
|
+
}
|
|
4035
|
+
|
|
3828
4036
|
/**
|
|
3829
4037
|
* {@link themeEditPreviewAdd}, with the note of a recovery in `box`.
|
|
3830
4038
|
* @param {string | undefined} description
|
|
@@ -3833,6 +4041,7 @@ async function reportingRecovery(fn) {
|
|
|
3833
4041
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditPreviewAddResponse>}
|
|
3834
4042
|
*/
|
|
3835
4043
|
async function addPreview(description, options, box) {
|
|
4044
|
+
options = {...options, theme: themeArg(options.theme)};
|
|
3836
4045
|
const {cwd = process.cwd()} = options;
|
|
3837
4046
|
if (isOutsideProject(cwd))
|
|
3838
4047
|
refuse(
|
|
@@ -4309,13 +4518,20 @@ async function addPreview(description, options, box) {
|
|
|
4309
4518
|
pages: data.pages.map(x => x.id),
|
|
4310
4519
|
files: data.files.map(f => shown(cwd, path.join(at.dir, f))),
|
|
4311
4520
|
open: openLine(cwd, at),
|
|
4521
|
+
// Each page's own URL, so any page can be opened or pictured.
|
|
4522
|
+
urls: pageUrls(
|
|
4523
|
+
cwd,
|
|
4524
|
+
at,
|
|
4525
|
+
data.pages.map(x => x.id),
|
|
4526
|
+
),
|
|
4312
4527
|
},
|
|
4313
4528
|
};
|
|
4314
4529
|
}
|
|
4315
4530
|
|
|
4316
4531
|
/**
|
|
4317
4532
|
* Make a new starter app (Next.js app router, Core and the neutral theme,
|
|
4318
|
-
* with the Astryx packages pinned to this CLI's release
|
|
4533
|
+
* with the Astryx packages pinned to this CLI's release, or with `theme` to
|
|
4534
|
+
* the versions the project has) in `dir`, with the
|
|
4319
4535
|
* theme preview route and its default pages inside. With `theme`, the theme
|
|
4320
4536
|
* folder is copied into the app and the pages wear it. No install runs.
|
|
4321
4537
|
* Every check runs before the first write, so a refusal changes nothing.
|
|
@@ -4332,6 +4548,7 @@ export async function themeEditPreviewApp(dir, options = {}) {
|
|
|
4332
4548
|
'Name the folder for the new app: a new or empty folder inside the current one.',
|
|
4333
4549
|
{run: [`${PREVIEW} app theme-app`]},
|
|
4334
4550
|
);
|
|
4551
|
+
options = {...options, theme: themeArg(options.theme)};
|
|
4335
4552
|
const slug = options.theme ?? null;
|
|
4336
4553
|
const theme =
|
|
4337
4554
|
slug == null
|
|
@@ -4417,6 +4634,27 @@ export async function themeEditPreviewApp(dir, options = {}) {
|
|
|
4417
4634
|
copyDir('');
|
|
4418
4635
|
if (theme.like && theme.like !== 'neutral')
|
|
4419
4636
|
dependencies[`@astryxdesign/theme-${theme.like}`] = cliVersion();
|
|
4637
|
+
// The copied build was made on this project's Core and base theme: the
|
|
4638
|
+
// new app installs those same versions, so the build is current there.
|
|
4639
|
+
/** @type {string[]} */
|
|
4640
|
+
const pinnedTo = [];
|
|
4641
|
+
for (const pkg of [
|
|
4642
|
+
'@astryxdesign/core',
|
|
4643
|
+
'@astryxdesign/theme-neutral',
|
|
4644
|
+
...(theme.like && theme.like !== 'neutral'
|
|
4645
|
+
? [`@astryxdesign/theme-${theme.like}`]
|
|
4646
|
+
: []),
|
|
4647
|
+
]) {
|
|
4648
|
+
const v = installedVersion(cwd, pkg);
|
|
4649
|
+
if (v && v !== cliVersion()) {
|
|
4650
|
+
dependencies[pkg] = v;
|
|
4651
|
+
pinnedTo.push(`${pkg} ${v}`);
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
if (pinnedTo.length)
|
|
4655
|
+
notes.push(
|
|
4656
|
+
`the new app installs ${pinnedTo.join(', ')}, the versions this project has and ${slug}'s build was made on, not this CLI's ${cliVersion()}; to move it to ${cliVersion()}, update those packages in the new app and run ${EDITOR} show ${slug} there`,
|
|
4657
|
+
);
|
|
4420
4658
|
/** @param {string} rel */
|
|
4421
4659
|
const fromRoute = rel => {
|
|
4422
4660
|
const r = path.relative(routeDir, rel).split(path.sep).join('/');
|
|
@@ -4521,6 +4759,9 @@ export async function themeEditPreviewApp(dir, options = {}) {
|
|
|
4521
4759
|
folder,
|
|
4522
4760
|
theme: slug,
|
|
4523
4761
|
pages: data.pages.map(x => x.id),
|
|
4762
|
+
urls: Object.fromEntries(
|
|
4763
|
+
data.pages.map(x => [x.id, `/theme-preview?page=${x.id}`]),
|
|
4764
|
+
),
|
|
4524
4765
|
files,
|
|
4525
4766
|
notes,
|
|
4526
4767
|
// A folder named like a flag (`-`, `-k`) is a path to cd only with ./.
|
|
@@ -4532,6 +4773,26 @@ export async function themeEditPreviewApp(dir, options = {}) {
|
|
|
4532
4773
|
/** The version range of an open font package the host project lacks. */
|
|
4533
4774
|
const OPEN_FONT_RANGE = '^5.0.0';
|
|
4534
4775
|
|
|
4776
|
+
/**
|
|
4777
|
+
* The version of a package installed for the project, read off disk (a
|
|
4778
|
+
* package need not export its package.json).
|
|
4779
|
+
* @param {string} cwd
|
|
4780
|
+
* @param {string} pkg
|
|
4781
|
+
* @returns {string | null}
|
|
4782
|
+
*/
|
|
4783
|
+
function installedVersion(cwd, pkg) {
|
|
4784
|
+
const found = findNodeModulesPackage(cwd, pkg);
|
|
4785
|
+
if (!found) return null;
|
|
4786
|
+
try {
|
|
4787
|
+
const v = JSON.parse(
|
|
4788
|
+
fs.readFileSync(path.join(found.packageDir, 'package.json'), 'utf8'),
|
|
4789
|
+
).version;
|
|
4790
|
+
return typeof v === 'string' ? v : null;
|
|
4791
|
+
} catch {
|
|
4792
|
+
return null;
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4795
|
+
|
|
4535
4796
|
/**
|
|
4536
4797
|
* The installed version of a package, as the project resolves it.
|
|
4537
4798
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
@@ -4609,9 +4870,27 @@ export async function themeEditPreviewList(options = {}) {
|
|
|
4609
4870
|
notes.push(
|
|
4610
4871
|
`${[...missing].join(', ')} ${missing.size > 1 ? 'are' : 'is'} listed, but ${missing.size > 1 ? 'their files are' : 'its file is'} gone, so the route does not build; ${PREVIEW} add${pf} writes ${missing.size > 1 ? 'them' : 'it'} again`,
|
|
4611
4872
|
);
|
|
4873
|
+
// No preview here, but one elsewhere in the routes folders (a folder
|
|
4874
|
+
// renamed by hand, as remove finds it): name it, with its list.
|
|
4875
|
+
const elsewhere = !data
|
|
4876
|
+
? previewsIn(cwd).filter(d => !at || d !== at.dir)
|
|
4877
|
+
: [];
|
|
4878
|
+
if (elsewhere.length)
|
|
4879
|
+
notes.push(
|
|
4880
|
+
`no preview here; ${elsewhere.length > 1 ? 'the previews are in' : 'the preview is in'} ${elsewhere
|
|
4881
|
+
.slice(0, 3)
|
|
4882
|
+
.map(d => `${shownDir(cwd, d)}/`)
|
|
4883
|
+
.join(', ')}: ${elsewhere
|
|
4884
|
+
.slice(0, 3)
|
|
4885
|
+
.map(
|
|
4886
|
+
d =>
|
|
4887
|
+
`${PREVIEW} list --path ${quoteCommandArgument(shownDir(cwd, d))}`,
|
|
4888
|
+
)
|
|
4889
|
+
.join('; ')}`,
|
|
4890
|
+
);
|
|
4612
4891
|
// No preview yet: say so when `add` would refuse the folder, with its
|
|
4613
4892
|
// reason and the way on, rather than suggest it.
|
|
4614
|
-
if (!data) {
|
|
4893
|
+
if (!data && !elsewhere.length) {
|
|
4615
4894
|
try {
|
|
4616
4895
|
previewDir(cwd, options.path, {
|
|
4617
4896
|
write: true,
|
|
@@ -4638,11 +4917,16 @@ export async function themeEditPreviewList(options = {}) {
|
|
|
4638
4917
|
folder: at && data ? shownDir(cwd, at.dir) : null,
|
|
4639
4918
|
theme: data?.theme ?? null,
|
|
4640
4919
|
themeMissing,
|
|
4641
|
-
pages: (data?.pages ?? []).map(x =>
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4920
|
+
pages: (data?.pages ?? []).map(x => {
|
|
4921
|
+
const url = at && data ? pageUrls(cwd, at, [x.id])[x.id] : undefined;
|
|
4922
|
+
return {
|
|
4923
|
+
id: x.id,
|
|
4924
|
+
label: x.label,
|
|
4925
|
+
// The page's own URL in the running app, when one can be told.
|
|
4926
|
+
...(url ? {url} : {}),
|
|
4927
|
+
...(missing.has(x.id) ? {missing: true} : {}),
|
|
4928
|
+
};
|
|
4929
|
+
}),
|
|
4646
4930
|
notes,
|
|
4647
4931
|
},
|
|
4648
4932
|
};
|
|
@@ -4662,6 +4946,39 @@ export async function themeEditPreviewRemove(page, options = {}) {
|
|
|
4662
4946
|
return reportingRecovery(box => removePreview(page, options, box));
|
|
4663
4947
|
}
|
|
4664
4948
|
|
|
4949
|
+
/**
|
|
4950
|
+
* The preview folders in the app: every folder under the routes folders
|
|
4951
|
+
* (app/, src/app/) holding a theme-preview.json, a few levels deep.
|
|
4952
|
+
* @param {string} cwd
|
|
4953
|
+
* @returns {string[]}
|
|
4954
|
+
*/
|
|
4955
|
+
function previewsIn(cwd) {
|
|
4956
|
+
/** @type {string[]} */
|
|
4957
|
+
const out = [];
|
|
4958
|
+
/** @param {string} dir @param {number} depth */
|
|
4959
|
+
const walk = (dir, depth) => {
|
|
4960
|
+
if (depth > 6 || out.length >= 20) return;
|
|
4961
|
+
if (fs.existsSync(path.join(dir, PREVIEW_DATA))) out.push(dir);
|
|
4962
|
+
/** @type {fs.Dirent[]} */
|
|
4963
|
+
let entries;
|
|
4964
|
+
try {
|
|
4965
|
+
entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
4966
|
+
} catch {
|
|
4967
|
+
return;
|
|
4968
|
+
}
|
|
4969
|
+
for (const e of entries)
|
|
4970
|
+
if (
|
|
4971
|
+
e.isDirectory() &&
|
|
4972
|
+
e.name !== 'node_modules' &&
|
|
4973
|
+
!e.name.startsWith('.')
|
|
4974
|
+
)
|
|
4975
|
+
walk(path.join(dir, e.name), depth + 1);
|
|
4976
|
+
};
|
|
4977
|
+
for (const r of [path.join(cwd, 'app'), path.join(cwd, 'src', 'app')])
|
|
4978
|
+
if (fs.existsSync(r)) walk(r, 0);
|
|
4979
|
+
return out.sort();
|
|
4980
|
+
}
|
|
4981
|
+
|
|
4665
4982
|
/**
|
|
4666
4983
|
* {@link themeEditPreviewRemove}, with the note of a recovery in `box`.
|
|
4667
4984
|
* @param {string | undefined} page
|
|
@@ -4703,26 +5020,40 @@ async function removePreview(page, options, box) {
|
|
|
4703
5020
|
if (!data) {
|
|
4704
5021
|
// A folder that holds the app takes no preview: the way on is the
|
|
4705
5022
|
// preview elsewhere, or a new one in its own folder.
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
5023
|
+
// The previews there are, each with its remove; `add` there only
|
|
5024
|
+
// when add would take the folder.
|
|
5025
|
+
const others = previewsIn(cwd).filter(d => d !== at.dir);
|
|
5026
|
+
/** @type {string | undefined} */
|
|
5027
|
+
let usual;
|
|
5028
|
+
try {
|
|
5029
|
+
usual = previewDir(cwd, undefined, {optional: true, retry})?.dir;
|
|
5030
|
+
} catch {
|
|
5031
|
+
// Several previews, or none.
|
|
5032
|
+
}
|
|
5033
|
+
const pageArg = page != null ? ` ${quoteCommandArgument(page)}` : '';
|
|
5034
|
+
let addable = true;
|
|
5035
|
+
try {
|
|
5036
|
+
previewDir(cwd, options.path, {write: true, retry});
|
|
5037
|
+
} catch {
|
|
5038
|
+
addable = false;
|
|
5039
|
+
}
|
|
4716
5040
|
refuse(
|
|
4717
5041
|
E.ERR_NOT_FOUND,
|
|
4718
|
-
`There is no theme preview in ${shownDir(cwd, at.dir)}/ (no ${PREVIEW_DATA})
|
|
5042
|
+
`There is no theme preview in ${shownDir(cwd, at.dir)}/ (no ${PREVIEW_DATA}).${others.length ? ` ${others.length > 1 ? 'The previews here are in' : 'The preview here is in'} ${others.map(d => `${shownDir(cwd, d)}/`).join(', ')}.` : ''}`,
|
|
4719
5043
|
{
|
|
4720
5044
|
run: [
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
5045
|
+
...others.slice(0, 3).map(
|
|
5046
|
+
d =>
|
|
5047
|
+
// The usual preview folder needs no --path.
|
|
5048
|
+
`${PREVIEW} remove${pageArg}${d === usual ? '' : ` --path ${quoteCommandArgument(shownDir(cwd, d))}`}`,
|
|
5049
|
+
),
|
|
5050
|
+
...(others.length
|
|
5051
|
+
? []
|
|
5052
|
+
: [
|
|
5053
|
+
addable && !holdsApp(cwd, at.dir)
|
|
5054
|
+
? `${PREVIEW} add${pf}`
|
|
5055
|
+
: `${PREVIEW} add`,
|
|
5056
|
+
]),
|
|
4726
5057
|
],
|
|
4727
5058
|
},
|
|
4728
5059
|
);
|
|
@@ -38,6 +38,14 @@ export function themeImports(ctx: import("./_settings.mjs").Ctx, slug: string, d
|
|
|
38
38
|
css: string[];
|
|
39
39
|
mode: "system" | "light" | "dark";
|
|
40
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Whether themes/<slug>/preview.html was rendered from the theme as it is
|
|
43
|
+
* now (the same check renderPreview makes before it renders again).
|
|
44
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
45
|
+
* @param {string} slug
|
|
46
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
47
|
+
*/
|
|
48
|
+
export function previewIsCurrent(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData): boolean;
|
|
41
49
|
/**
|
|
42
50
|
* Render the sample app page with the theme to themes/<slug>/preview.html.
|
|
43
51
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
@@ -154,5 +162,52 @@ export function screenshot(project: import("./_project.mjs").ThemeProject, html:
|
|
|
154
162
|
ok: false;
|
|
155
163
|
reason: string;
|
|
156
164
|
}>;
|
|
165
|
+
/**
|
|
166
|
+
* The app's copy of an editor theme: a standard local theme in
|
|
167
|
+
* src/themes/<theme>/ (a descriptor, a source that re-exports the built
|
|
168
|
+
* module, the built module, its stylesheet and font stylesheet), the shape
|
|
169
|
+
* `astryx theme add <theme>` reads, so the theme goes into the app with the
|
|
170
|
+
* stable theme commands. It is written again after every build of the
|
|
171
|
+
* theme, never edited by hand. A folder there that is not the editor's own
|
|
172
|
+
* copy is left alone: returns null then, else the folder.
|
|
173
|
+
* The built module and stylesheet are written whole: a local theme's source
|
|
174
|
+
* may import only files inside its own folder.
|
|
175
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
176
|
+
* @param {string} slug
|
|
177
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
178
|
+
* @returns {string | null}
|
|
179
|
+
*/
|
|
180
|
+
export function writeAppCopy(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData): string | null;
|
|
181
|
+
/**
|
|
182
|
+
* {@link writeAppCopy} with the font stylesheets given, or null to keep the
|
|
183
|
+
* copy's own (a compile, which changes no setting).
|
|
184
|
+
* @param {string} cwd
|
|
185
|
+
* @param {string} slug
|
|
186
|
+
* @param {string[] | null} fontsCss
|
|
187
|
+
* @returns {string | null}
|
|
188
|
+
*/
|
|
189
|
+
export function writeAppCopyAt(cwd: string, slug: string, fontsCss: string[] | null): string | null;
|
|
190
|
+
/**
|
|
191
|
+
* Why the editor will not write a theme's app copy, or null when it will:
|
|
192
|
+
* the folder is not there yet, or its descriptor carries the editor's mark
|
|
193
|
+
* and it holds only the copy's own files (system files such as .DS_Store
|
|
194
|
+
* aside). Otherwise the name of what is in the way (a file of yours), or
|
|
195
|
+
* the folder itself when it is not the editor's copy. Built bytes are not
|
|
196
|
+
* compared, so a stable rebuild of the copy leaves it the editor's. The one
|
|
197
|
+
* test the copy's writer and `wiring` both use.
|
|
198
|
+
* @param {string} cwd
|
|
199
|
+
* @param {string} slug
|
|
200
|
+
* @returns {string | null}
|
|
201
|
+
*/
|
|
202
|
+
export function appCopyBlocker(cwd: string, slug: string): string | null;
|
|
203
|
+
/**
|
|
204
|
+
* The files of a theme's app copy when this command wrote it for the first
|
|
205
|
+
* time (then forgotten, so one result names them), else null.
|
|
206
|
+
* @param {string} cwd
|
|
207
|
+
* @param {string} slug
|
|
208
|
+
* @returns {string[] | null}
|
|
209
|
+
*/
|
|
210
|
+
export function takeFirstAppCopy(cwd: string, slug: string): string[] | null;
|
|
157
211
|
/** The groups of the theme-building page, in order. */
|
|
158
212
|
export const SHOWCASE_GROUPS: string[];
|
|
213
|
+
export { APP_COPY_MARK } from "./_marks.mjs";
|