@astryxdesign/cli 0.6.6-canary.e67fd1e → 0.6.6-canary.ee02ce2

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.
Files changed (58) hide show
  1. package/README.md +83 -83
  2. package/api/build/_adapter.d.mts +15 -0
  3. package/api/build/_adapter.mjs +22 -0
  4. package/api/build/build.doc.mjs +1 -1
  5. package/api/build/build.type.d.mts +4 -0
  6. package/api/build/build.type.mjs +1 -0
  7. package/api/build/help/help.mjs +1 -1
  8. package/api/build/kit/kit.mjs +12 -1
  9. package/api/doctor/theme-checks.mjs +1 -1
  10. package/api/init/run/run.mjs +1 -0
  11. package/api/layout/check/check.d.mts +1 -0
  12. package/api/layout/check/check.mjs +1 -0
  13. package/api/layout/expand/expand.d.mts +1 -0
  14. package/api/layout/expand/expand.mjs +1 -0
  15. package/api/layout/grammar/grammar.d.mts +1 -0
  16. package/api/layout/grammar/grammar.mjs +1 -0
  17. package/api/layout/layoutCheck.doc.mjs +1 -1
  18. package/api/layout/layoutExpand.doc.mjs +1 -1
  19. package/api/layout/layoutGrammar.doc.mjs +1 -1
  20. package/api/template/copy/copy.mjs +12 -0
  21. package/api/template/template.doc.mjs +1 -1
  22. package/api/template/template.type.d.mts +3 -0
  23. package/api/template/template.type.mjs +3 -0
  24. package/api/theme/build/build.d.mts +70 -0
  25. package/api/theme/build/build.mjs +205 -41
  26. package/api/theme/build/font-warning.d.mts +11 -0
  27. package/api/theme/build/font-warning.mjs +28 -3
  28. package/assets/docs/author-a-theme.doc.mjs +1 -1
  29. package/assets/docs/styling-overview.doc.mjs +1 -1
  30. package/assets/docs/theme.doc.dense.mjs +1 -1
  31. package/assets/docs/theme.doc.zh.mjs +1 -1
  32. package/assets/docs/use-a-theme.doc.mjs +1 -1
  33. package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
  34. package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
  35. package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
  36. package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
  37. package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
  38. package/clients/cli/commands/build-theme.mjs +68 -18
  39. package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
  40. package/clients/cli/commands/build.mjs +1 -0
  41. package/clients/cli/commands/import-hint-correctness.test.mjs +23 -0
  42. package/clients/cli/commands/layout-check.doc.mjs +1 -0
  43. package/clients/cli/commands/layout-expand.doc.mjs +1 -0
  44. package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
  45. package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +140 -0
  46. package/clients/cli/commands/layout.doc.mjs +1 -0
  47. package/clients/cli/commands/layout.mjs +6 -11
  48. package/clients/cli/commands/template.mjs +4 -3
  49. package/clients/cli/commands/theme-build.doc.mjs +3 -1
  50. package/clients/cli/index.mjs +1 -1
  51. package/clients/cli/lib/define-command.mjs +4 -0
  52. package/foundation/agent-docs/agent-docs.mjs +4 -1
  53. package/foundation/agent-docs/agent-docs.test.mjs +18 -0
  54. package/foundation/discovery/template-needs.d.mts +31 -0
  55. package/foundation/discovery/template-needs.mjs +156 -0
  56. package/foundation/discovery/template-needs.test.mjs +203 -0
  57. package/foundation/response/response-types.doc.mjs +4 -4
  58. package/package.json +9 -9
@@ -18,7 +18,7 @@ export const doc = {
18
18
  description:
19
19
  'The reference behind `astryx layout grammar`: the agent cheatsheet for writing XLE/XLO ' +
20
20
  "layout expressions, with the alias table generated from this branch's registry rather than " +
21
- 'hand-maintained, so short names always reflect the components actually installed.',
21
+ 'hand-maintained, so short names always reflect the components actually installed. **Deprecated (DEP-0006).** Use `build`, `template`, and `docs layout` instead. This function will be removed in a future minor release.',
22
22
  importPath: '@astryxdesign/cli/api',
23
23
  signature:
24
24
  'layoutGrammar(options?: LayoutGrammarOptions): Promise<LayoutGrammarResponse>',
@@ -19,6 +19,7 @@ import {
19
19
  import {AstryxError, writeFailed} from '../../error.mjs';
20
20
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
21
21
  import {pkgOf, replaceDemoMedia} from '../../../foundation/discovery/template-adapter.mjs';
22
+ import {analyzeTemplateNeeds} from '../../../foundation/discovery/template-needs.mjs';
22
23
 
23
24
  /**
24
25
  * Scaffold an already-resolved template to `targetPath` (relative to `cwd`) and
@@ -93,6 +94,14 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
93
94
  throw writeFailed(outputFilePath, cwd, err);
94
95
  }
95
96
 
97
+ // Analyze what the template needs that the project lacks: external packages
98
+ // and the StyleX compiler. Derived from the source's own imports.
99
+ const {notes, missingPackages, installCommand} = analyzeTemplateNeeds(
100
+ outputSource,
101
+ cwd,
102
+ );
103
+ const missing = missingPackages;
104
+
96
105
  const relOutput = path.relative(cwd, outputDir) || '.';
97
106
  return {
98
107
  type: 'template.copy',
@@ -103,6 +112,9 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
103
112
  fileName: outputFileName,
104
113
  filesCopied: 1,
105
114
  demoMediaReplaced,
115
+ notes,
116
+ missingPackages: missing,
117
+ installCommand,
106
118
  },
107
119
  };
108
120
  }
@@ -124,7 +124,7 @@ export const doc = {
124
124
  {
125
125
  type: 'template.copy',
126
126
  description:
127
- 'A receipt after scaffolding the template into the project: the template id, output directory, written file name, file count, and `demoMediaReplaced` — how many Astryx demo media references (images, posters, videos) in the written file were replaced with placeholders for you to swap for your own media.',
127
+ 'A receipt after scaffolding the template into the project: the template id, output directory, written file name, file count, `demoMediaReplaced` — how many Astryx demo media references were replaced with placeholders, `notes` — setup notes naming what the template needs that the project lacks (missing packages, missing StyleX compiler; empty when satisfied), `missingPackages` — external package names the template imports that are not in the project, and `installCommand` — a ready-to-run install command with the detected package manager and workspace version ranges (null when nothing is missing).',
128
128
  },
129
129
  {
130
130
  type: 'template.cdn',
@@ -105,6 +105,9 @@ export type TemplateCopyResponse = {
105
105
  fileName: string;
106
106
  filesCopied: number;
107
107
  demoMediaReplaced: number;
108
+ notes: string[];
109
+ missingPackages: string[];
110
+ installCommand: string | null;
108
111
  };
109
112
  };
110
113
  /**
@@ -80,6 +80,9 @@
80
80
  * @property {string} data.fileName
81
81
  * @property {number} data.filesCopied
82
82
  * @property {number} data.demoMediaReplaced Astryx demo media references (images, posters, videos) replaced in the written file: images with a neutral placeholder, videos with an empty source. Swap in your own media at those points; no media is installed. 0 when the template carried none.
83
+ * @property {string[]} data.notes Setup notes: what the template needs that the project lacks (missing packages, missing StyleX compiler). Each note is one actionable line. Empty when the template needs nothing the project lacks.
84
+ * @property {string[]} data.missingPackages External package names the template imports that are not in the project's dependencies. Empty when none are missing.
85
+ * @property {string | null} data.installCommand A ready-to-run install command for the missing packages, using the project's package manager and the CLI workspace's version ranges. Null when no packages are missing.
83
86
  */
84
87
 
85
88
  /**
@@ -71,6 +71,46 @@ export function validateComponentOverridesAgainstRegistry(themeDef: {
71
71
  propsByKey: Record<string, string[]>;
72
72
  deprecatedByKey: Record<string, string>;
73
73
  }): string[];
74
+ /**
75
+ * Print the install snippet and font guidance once for a batch: the first
76
+ * theme as the full example, one import line per built theme, and one font
77
+ * recipe naming every family the themes do not load.
78
+ * @param {ThemeBuildTrailer[]} trailers
79
+ */
80
+ export function printBatchTrailer(trailers: ThemeBuildTrailer[]): void;
81
+ /**
82
+ * Print what a short report keeps after its one line per theme: one line
83
+ * naming the fonts the themes do not load, and, when the caller chose no
84
+ * detail level, where the install example and font recipe are.
85
+ * @param {ThemeBuildTrailer[]} trailers
86
+ * @param {{hint?: boolean}} [options]
87
+ */
88
+ export function printCompactTrailer(trailers: ThemeBuildTrailer[], { hint }?: {
89
+ hint?: boolean;
90
+ }): void;
91
+ /**
92
+ * Build one theme for a batch or compact CLI report. Same build, outputs, and
93
+ * receipt as {@link themeBuild}; the install snippet and font guidance come
94
+ * back as `trailer` instead of being printed, and `compact` leaves out the
95
+ * per-file progress lines. CLI-internal: not exported from the API entry.
96
+ * @param {string} file
97
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options]
98
+ * @param {{cwd?: string}} [ctx]
99
+ * @param {{compact?: boolean}} [report]
100
+ * @returns {Promise<{receipt: import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null, trailer: ThemeBuildTrailer | null}>}
101
+ */
102
+ export function themeBuildForReport(file: string, options?: {
103
+ out?: string;
104
+ check?: boolean;
105
+ iconsSpecifier?: string;
106
+ }, ctx?: {
107
+ cwd?: string;
108
+ }, { compact }?: {
109
+ compact?: boolean;
110
+ }): Promise<{
111
+ receipt: import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null;
112
+ trailer: ThemeBuildTrailer | null;
113
+ }>;
74
114
  /** @param {string} file @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] @param {{cwd?: string}} [ctx] @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>} */
75
115
  export function themeBuild(file: string, options?: {
76
116
  out?: string;
@@ -140,6 +180,36 @@ export function themeBuildFamily(files: string[], options: {
140
180
  * validateAdaptationEnrollment)
141
181
  */
142
182
  export type ComponentValueClass = "builtin" | "enrollment" | "unresolved";
183
+ /**
184
+ * What a standalone build prints after its [ok] lines, kept as data so a
185
+ * batch can print it once for every theme.
186
+ */
187
+ export type ThemeBuildTrailer = {
188
+ /**
189
+ * The theme's name.
190
+ */
191
+ themeName: string;
192
+ /**
193
+ * The built module's theme export.
194
+ */
195
+ exportName: string;
196
+ /**
197
+ * Import specifier of the built JS module.
198
+ */
199
+ jsImport: string;
200
+ /**
201
+ * Import specifier of the built CSS.
202
+ */
203
+ cssImport: string;
204
+ /**
205
+ * Font families the theme names but does not load.
206
+ */
207
+ unloadedFonts: string[];
208
+ /**
209
+ * One notice per unloaded font family.
210
+ */
211
+ fontNotices: string[];
212
+ };
143
213
  /**
144
214
  * The bindings one Core provides: the namespaces interception spreads, the
145
215
  * functions the build calls, and why the import failed, if it did.
@@ -74,7 +74,11 @@ import {
74
74
  collectThemingTargets,
75
75
  targetValidationRegistry,
76
76
  } from '../../../foundation/discovery/theming-targets.mjs';
77
- import {collectUnloadedFonts, formatFontLoadingHelp} from './font-warning.mjs';
77
+ import {
78
+ collectUnloadedFonts,
79
+ formatBatchFontLoadingHelp,
80
+ formatFontLoadingHelp,
81
+ } from './font-warning.mjs';
78
82
  import {interceptCore} from './core-interception.mjs';
79
83
  import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
80
84
  import {resolveIconImports} from './icon-imports.mjs';
@@ -2339,6 +2343,7 @@ async function themeBuildInternal(
2339
2343
  file,
2340
2344
  options = {},
2341
2345
  {cwd = process.cwd()} = {},
2346
+ /** @type {{compact?: boolean, trailers?: ThemeBuildTrailer[]}} */ report = {},
2342
2347
  ) {
2343
2348
  const filePath = path.resolve(cwd, file);
2344
2349
 
@@ -2350,7 +2355,11 @@ async function themeBuildInternal(
2350
2355
  );
2351
2356
  }
2352
2357
 
2353
- logger.log(`\nBuilding theme from ${path.relative(cwd, filePath)}...`);
2358
+ if (!report.compact) {
2359
+ logger.log(`\nBuilding theme from ${path.relative(cwd, filePath)}...`);
2360
+ }
2361
+ // A compact report has no per-theme heading, so each warning names its file.
2362
+ const source = report.compact ? `${path.relative(cwd, filePath)}: ` : '';
2354
2363
 
2355
2364
  await selectCore(cwd);
2356
2365
 
@@ -2469,18 +2478,18 @@ async function themeBuildInternal(
2469
2478
  const noticeMessages = [];
2470
2479
  for (const w of warnings) {
2471
2480
  warningMessages.push(w);
2472
- logger.warn(` [warn] ${w}`);
2481
+ logger.warn(` [warn] ${source}${w}`);
2473
2482
  }
2474
2483
 
2475
2484
  // Validate no private vars are set directly
2476
2485
  const privateVarErrors = validatePrivateVars(themeDef);
2477
2486
  for (const e of privateVarErrors) {
2478
2487
  warningMessages.push(e);
2479
- logger.error(` [error] ${e}`);
2488
+ logger.error(` [error] ${source}${e}`);
2480
2489
  }
2481
2490
  if (privateVarErrors.length > 0) {
2482
2491
  logger.error(
2483
- `\n ${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
2492
+ `\n ${source}${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
2484
2493
  );
2485
2494
  }
2486
2495
 
@@ -2719,7 +2728,7 @@ async function themeBuildInternal(
2719
2728
  for (const message of droppedDeclarations) {
2720
2729
  const w = `Declaration ${message}. The generated CSS omits it; fix the value in the theme source.`;
2721
2730
  warningMessages.push(w);
2722
- logger.warn(` [warn] ${w}`);
2731
+ logger.warn(` [warn] ${source}${w}`);
2723
2732
  }
2724
2733
  const unemittedHeadingTypes = headingTypesWithoutEmittedRule(
2725
2734
  customHeadingTypes(themeDef),
@@ -2741,7 +2750,7 @@ async function themeBuildInternal(
2741
2750
  );
2742
2751
  }
2743
2752
  if (cssParts.length === 0) {
2744
- logger.log('No overrides found; nothing to build.');
2753
+ logger.log(`${source}No overrides found; nothing to build.`);
2745
2754
  return null;
2746
2755
  }
2747
2756
  // The data-token defaults are theme-independent and go in @layer
@@ -2933,19 +2942,21 @@ async function themeBuildInternal(
2933
2942
 
2934
2943
  writeBuildOutputs(writes);
2935
2944
 
2936
- logger.log(`\n[ok] ${path.relative(cwd, outPath)}`);
2937
- logger.log(`[ok] ${path.relative(cwd, cssDtsPath)}`);
2938
- logger.log(
2939
- ` ${tokenCount} token overrides, ${componentCount} component overrides`,
2940
- );
2941
- logger.log(` ${size} KB`);
2942
- logger.log(`[ok] ${path.relative(cwd, jsPath)}`);
2943
- logger.log(`[ok] ${path.relative(cwd, dtsPath)}`);
2944
- if (variantDtsPath && variantDecl) {
2945
- const augCount = (variantDecl.match(/': true;/g) || []).length;
2945
+ if (!report.compact) {
2946
+ logger.log(`\n[ok] ${path.relative(cwd, outPath)}`);
2947
+ logger.log(`[ok] ${path.relative(cwd, cssDtsPath)}`);
2946
2948
  logger.log(
2947
- `[ok] ${path.relative(cwd, variantDtsPath)} (${augCount} type augmentations)`,
2949
+ ` ${tokenCount} token overrides, ${componentCount} component overrides`,
2948
2950
  );
2951
+ logger.log(` ${size} KB`);
2952
+ logger.log(`[ok] ${path.relative(cwd, jsPath)}`);
2953
+ logger.log(`[ok] ${path.relative(cwd, dtsPath)}`);
2954
+ if (variantDtsPath && variantDecl) {
2955
+ const augCount = (variantDecl.match(/': true;/g) || []).length;
2956
+ logger.log(
2957
+ `[ok] ${path.relative(cwd, variantDtsPath)} (${augCount} type augmentations)`,
2958
+ );
2959
+ }
2949
2960
  }
2950
2961
 
2951
2962
  const relOutDir = path.relative(cwd, outDir) || '.';
@@ -2953,25 +2964,6 @@ async function themeBuildInternal(
2953
2964
  const jsImport = importSpecifier(relOutDir, baseName);
2954
2965
  const cssImport = importSpecifier(relOutDir, cssBase) + '.css';
2955
2966
  const exportName = `${toIdentifier(baseName)}Theme`;
2956
- logger.log(`
2957
- Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
2958
-
2959
- import { ${exportName} } from '${jsImport}';
2960
- import '${cssImport}';
2961
-
2962
- <Theme theme={${exportName}}>
2963
- <App />
2964
- </Theme>
2965
-
2966
- Or with a <link> tag:
2967
-
2968
- import { ${exportName} } from '${jsImport}';
2969
-
2970
- <link rel="stylesheet" href="${cssImport}" />
2971
- <Theme theme={${exportName}}>
2972
- <App />
2973
- </Theme>
2974
- `);
2975
2967
 
2976
2968
  // Fonts the theme names but nothing loads (#5015). Resolved tokens and
2977
2969
  // component overrides carry the final font-family values on both load
@@ -2985,15 +2977,27 @@ Or with a <link> tag:
2985
2977
  // permanently in violation of its own "compiles with no warnings" guard).
2986
2978
  // Adaptation rules are resolved theme writes in their own right, so a family
2987
2979
  // named only inside one needs the same notice as one named at the root.
2980
+ /** @type {string[]} */
2981
+ const fontNotices = [];
2988
2982
  for (const family of unloadedFonts) {
2989
2983
  const msg = `Font "${family}" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: astryx docs typography)`;
2990
2984
  noticeMessages.push(msg);
2991
- logger.log(` note: ${msg}`);
2992
- }
2993
- if (unloadedFonts.length > 0) {
2994
- logger.log(formatFontLoadingHelp(themeDef.name, unloadedFonts));
2985
+ fontNotices.push(msg);
2995
2986
  }
2996
2987
 
2988
+ /** @type {ThemeBuildTrailer} */
2989
+ const trailer = {
2990
+ themeName: themeDef.name,
2991
+ exportName,
2992
+ jsImport,
2993
+ cssImport,
2994
+ unloadedFonts,
2995
+ fontNotices,
2996
+ };
2997
+ // A batch or compact report prints this once for the whole run instead.
2998
+ if (report.trailers) report.trailers.push(trailer);
2999
+ else printBuildTrailer(trailer);
3000
+
2997
3001
  return {
2998
3002
  type: 'theme.build',
2999
3003
  data: {
@@ -3016,6 +3020,166 @@ Or with a <link> tag:
3016
3020
  };
3017
3021
  }
3018
3022
 
3023
+ /**
3024
+ * What a standalone build prints after its [ok] lines, kept as data so a
3025
+ * batch can print it once for every theme.
3026
+ * @typedef {object} ThemeBuildTrailer
3027
+ * @property {string} themeName The theme's name.
3028
+ * @property {string} exportName The built module's theme export.
3029
+ * @property {string} jsImport Import specifier of the built JS module.
3030
+ * @property {string} cssImport Import specifier of the built CSS.
3031
+ * @property {string[]} unloadedFonts Font families the theme names but does not load.
3032
+ * @property {string[]} fontNotices One notice per unloaded font family.
3033
+ */
3034
+
3035
+ /**
3036
+ * Print a standalone build's install snippet and font guidance.
3037
+ * @param {ThemeBuildTrailer} trailer
3038
+ */
3039
+ function printBuildTrailer(trailer) {
3040
+ logger.log(`
3041
+ Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3042
+
3043
+ import { Theme } from '@astryxdesign/core';
3044
+ import { ${trailer.exportName} } from '${trailer.jsImport}';
3045
+ import '${trailer.cssImport}';
3046
+
3047
+ <Theme theme={${trailer.exportName}}>
3048
+ <App />
3049
+ </Theme>
3050
+
3051
+ Or with a <link> tag:
3052
+
3053
+ import { Theme } from '@astryxdesign/core';
3054
+ import { ${trailer.exportName} } from '${trailer.jsImport}';
3055
+
3056
+ <link rel="stylesheet" href="${trailer.cssImport}" />
3057
+ <Theme theme={${trailer.exportName}}>
3058
+ <App />
3059
+ </Theme>
3060
+ `);
3061
+ for (const msg of trailer.fontNotices) logger.log(` note: ${msg}`);
3062
+ if (trailer.unloadedFonts.length > 0) {
3063
+ logger.log(formatFontLoadingHelp(trailer.themeName, trailer.unloadedFonts));
3064
+ }
3065
+ }
3066
+
3067
+ /**
3068
+ * Print the install snippet and font guidance once for a batch: the first
3069
+ * theme as the full example, one import line per built theme, and one font
3070
+ * recipe naming every family the themes do not load.
3071
+ * @param {ThemeBuildTrailer[]} trailers
3072
+ */
3073
+ export function printBatchTrailer(trailers) {
3074
+ if (trailers.length === 0) return;
3075
+ const [first] = trailers;
3076
+ logger.log(`
3077
+ Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3078
+
3079
+ import { Theme } from '@astryxdesign/core';
3080
+ import { ${first.exportName} } from '${first.jsImport}';
3081
+ import '${first.cssImport}';
3082
+
3083
+ <Theme theme={${first.exportName}}>
3084
+ <App />
3085
+ </Theme>
3086
+
3087
+ Or with a <link> tag:
3088
+
3089
+ import { Theme } from '@astryxdesign/core';
3090
+ import { ${first.exportName} } from '${first.jsImport}';
3091
+
3092
+ <link rel="stylesheet" href="${first.cssImport}" />
3093
+ <Theme theme={${first.exportName}}>
3094
+ <App />
3095
+ </Theme>
3096
+ `);
3097
+ if (trailers.length > 1) {
3098
+ logger.log('Each built theme imports the same way:');
3099
+ for (const trailer of trailers) {
3100
+ logger.log(
3101
+ ` import { ${trailer.exportName} } from '${trailer.jsImport}'; import '${trailer.cssImport}';`,
3102
+ );
3103
+ }
3104
+ }
3105
+ const fonts = groupUnloadedFonts(trailers);
3106
+ if (fonts.length > 0) logger.log(formatBatchFontLoadingHelp(fonts));
3107
+ }
3108
+
3109
+ /**
3110
+ * Print what a short report keeps after its one line per theme: one line
3111
+ * naming the fonts the themes do not load, and, when the caller chose no
3112
+ * detail level, where the install example and font recipe are.
3113
+ * @param {ThemeBuildTrailer[]} trailers
3114
+ * @param {{hint?: boolean}} [options]
3115
+ */
3116
+ export function printCompactTrailer(trailers, {hint = false} = {}) {
3117
+ if (trailers.length === 0) return;
3118
+ const fonts = groupUnloadedFonts(trailers);
3119
+ if (fonts.length > 0) {
3120
+ const named = fonts
3121
+ .map(({family, themes}) =>
3122
+ trailers.length > 1
3123
+ ? `"${family}" (${themes.join(', ')})`
3124
+ : `"${family}"`,
3125
+ )
3126
+ .join(', ');
3127
+ logger.log(
3128
+ `[note] Fonts named but not loaded: ${named}. Load them in your app (recipe: astryx docs typography).`,
3129
+ );
3130
+ }
3131
+ if (hint) {
3132
+ logger.log(
3133
+ 'Run with --detail full for the install example and font recipe.',
3134
+ );
3135
+ }
3136
+ }
3137
+
3138
+ /**
3139
+ * Each font family the themes name but do not load, with the themes that
3140
+ * name it, in first-seen order.
3141
+ * @param {ThemeBuildTrailer[]} trailers
3142
+ * @returns {Array<{family: string, themes: string[]}>}
3143
+ */
3144
+ function groupUnloadedFonts(trailers) {
3145
+ /** @type {Map<string, {family: string, themes: string[]}>} */
3146
+ const byFamily = new Map();
3147
+ for (const trailer of trailers) {
3148
+ for (const family of trailer.unloadedFonts) {
3149
+ const key = family.toLowerCase();
3150
+ const entry = byFamily.get(key) ?? {family, themes: []};
3151
+ entry.themes.push(trailer.themeName);
3152
+ byFamily.set(key, entry);
3153
+ }
3154
+ }
3155
+ return [...byFamily.values()];
3156
+ }
3157
+
3158
+ /**
3159
+ * Build one theme for a batch or compact CLI report. Same build, outputs, and
3160
+ * receipt as {@link themeBuild}; the install snippet and font guidance come
3161
+ * back as `trailer` instead of being printed, and `compact` leaves out the
3162
+ * per-file progress lines. CLI-internal: not exported from the API entry.
3163
+ * @param {string} file
3164
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options]
3165
+ * @param {{cwd?: string}} [ctx]
3166
+ * @param {{compact?: boolean}} [report]
3167
+ * @returns {Promise<{receipt: import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null, trailer: ThemeBuildTrailer | null}>}
3168
+ */
3169
+ export async function themeBuildForReport(
3170
+ file,
3171
+ options = {},
3172
+ ctx = {},
3173
+ {compact = false} = {},
3174
+ ) {
3175
+ /** @type {ThemeBuildTrailer[]} */
3176
+ const trailers = [];
3177
+ const receipt = /** @type {any} */ (
3178
+ await themeBuildInternal(file, options, ctx, {compact, trailers})
3179
+ );
3180
+ return {receipt, trailer: trailers[0] ?? null};
3181
+ }
3182
+
3019
3183
  /** @param {string} file @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] @param {{cwd?: string}} [ctx] @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>} */
3020
3184
  export async function themeBuild(file, options = {}, ctx = {}) {
3021
3185
  return /** @type {any} */ (themeBuildInternal(file, options, ctx));
@@ -38,3 +38,14 @@ export function collectUnloadedFonts(resolvedTheme: {
38
38
  * @returns {string}
39
39
  */
40
40
  export function formatFontLoadingHelp(themeName: string, families: string[]): string;
41
+ /**
42
+ * The same fix once for a batch build: each family the built themes name but
43
+ * do not load, with the themes that name it, then one recipe for all of them.
44
+ *
45
+ * @param {Array<{family: string, themes: string[]}>} entries
46
+ * @returns {string}
47
+ */
48
+ export function formatBatchFontLoadingHelp(entries: Array<{
49
+ family: string;
50
+ themes: string[];
51
+ }>): string;
@@ -202,6 +202,33 @@ export function collectUnloadedFonts(resolvedTheme) {
202
202
  */
203
203
  export function formatFontLoadingHelp(themeName, families) {
204
204
  const named = families.map(f => `"${f}"`).join(', ');
205
+ return `
206
+ [note] Theme "${themeName}" names fonts it does not load: ${named}
207
+ ${fontLoadingRecipe(families)}`;
208
+ }
209
+
210
+ /**
211
+ * The same fix once for a batch build: each family the built themes name but
212
+ * do not load, with the themes that name it, then one recipe for all of them.
213
+ *
214
+ * @param {Array<{family: string, themes: string[]}>} entries
215
+ * @returns {string}
216
+ */
217
+ export function formatBatchFontLoadingHelp(entries) {
218
+ const named = entries
219
+ .map(({family, themes}) => ` "${family}" (${themes.join(', ')})`)
220
+ .join('\n');
221
+ return `
222
+ [note] The built themes name fonts they do not load:
223
+ ${named}
224
+ ${fontLoadingRecipe(entries.map(entry => entry.family))}`;
225
+ }
226
+
227
+ /**
228
+ * @param {string[]} families
229
+ * @returns {string}
230
+ */
231
+ function fontLoadingRecipe(families) {
205
232
  const cssHref =
206
233
  'https://fonts.googleapis.com/css2?' +
207
234
  families
@@ -210,9 +237,7 @@ export function formatFontLoadingHelp(themeName, families) {
210
237
  '&display=swap';
211
238
  const first = families[0];
212
239
  const slug = first.toLowerCase().replace(/ /g, '-');
213
- return `
214
- [note] Theme "${themeName}" names fonts it does not load: ${named}
215
- The built CSS only sets font-family; load these in your app, or every
240
+ return ` The built CSS only sets font-family; load these in your app, or every
216
241
  browser quietly falls back.
217
242
 
218
243
  Google Fonts (add :wght@... axes as your theme's weights require):
@@ -118,7 +118,7 @@ export const docs = {
118
118
  ['ocean.d.ts', 'TypeScript declarations for the theme and icon registry exports'],
119
119
  ['ocean.variants.d.ts', "(Optional) Module augmentations for custom component prop values"],
120
120
  ]},
121
- {type: 'code', lang: 'tsx', label: 'Using a custom built theme', code: "import {oceanTheme} from './themes/ocean';\nimport './themes/ocean.css';\n\n<Theme theme={oceanTheme}>\n <App />\n</Theme>"},
121
+ {type: 'code', lang: 'tsx', label: 'Using a custom built theme', code: "import {Theme} from '@astryxdesign/core';\nimport {oceanTheme} from './themes/ocean';\nimport './themes/ocean.css';\n\n<Theme theme={oceanTheme}>\n <App />\n</Theme>"},
122
122
  {type: 'prose', text: "After upgrading Astryx, rerun `astryx theme build` for every custom prebuilt theme. Deploy the regenerated files together. The build also warns when the theme names font families it does not load. See {@link generic:typography} for the full recipe."},
123
123
  {type: 'prose', text: 'For the runtime vs built tradeoff, see the Runtime vs Built section of {@link generic:use-a-theme}.'},
124
124
  ],
@@ -122,7 +122,7 @@ export const docs = {
122
122
  content: [
123
123
  {
124
124
  type: 'prose',
125
- text: 'Only needed when you swizzle a component (`astryx swizzle <Component>`) or write your own StyleX. The plain path already supports `xstyle` overrides \u2014 this path is for editing component internals.',
125
+ text: 'Only needed when you swizzle a component (`astryx swizzle <Component>`) or write your own StyleX. The plain path already supports `xstyle` overrides \u2014 this path is for editing component internals. Some built-in page templates also use StyleX for layout; if you scaffold one and see "Unexpected stylex.create call at runtime", add the compiler plugin for your bundler below.',
126
126
  },
127
127
  {
128
128
  type: 'code',
@@ -9,7 +9,7 @@ export const docsDense = {
9
9
  section: 'Wrap your app in a theme',
10
10
  title: 'Quick start',
11
11
  content: [
12
- {type: 'prose', text: 'Install a theme, wrap in `<Theme>`. {@link generic:use-a-theme} for full guide.'},
12
+ {type: 'prose', text: "Install a theme, wrap in `<Theme>` (`import {Theme} from '@astryxdesign/core'`). {@link generic:use-a-theme} for full guide."},
13
13
  ],
14
14
  },
15
15
  {
@@ -11,7 +11,7 @@ export const docsZh = {
11
11
  content: [
12
12
  {
13
13
  type: 'prose',
14
- text: '安装主题包,用 `<Theme>` 包裹应用,选择浅色或深色模式。完整指南——可用主题、集成主题、深色模式、嵌套主题和生产构建——请参阅 {@link generic:use-a-theme}。',
14
+ text: "安装主题包,用 `<Theme>`(`import {Theme} from '@astryxdesign/core'`)包裹应用,选择浅色或深色模式。完整指南——可用主题、集成主题、深色模式、嵌套主题和生产构建——请参阅 {@link generic:use-a-theme}。",
15
15
  },
16
16
  ],
17
17
  },
@@ -31,7 +31,7 @@ export const docs = {
31
31
  type: 'code',
32
32
  lang: 'tsx',
33
33
  label: 'Switch among added themes',
34
- code: "import {useState} from 'react';\nimport {themes, type ThemeSlug} from './astryx-themes';\n\nconst [slug, setSlug] = useState<ThemeSlug>('neutral');\nconst app = <Theme theme={themes[slug]}><YourApp /></Theme>;",
34
+ code: "import {useState} from 'react';\nimport {Theme} from '@astryxdesign/core';\nimport {themes, type ThemeSlug} from './astryx-themes';\n\nconst [slug, setSlug] = useState<ThemeSlug>('neutral');\nconst app = <Theme theme={themes[slug]}><YourApp /></Theme>;",
35
35
  },
36
36
  {
37
37
  type: 'prose',
@@ -353,7 +353,7 @@ describe('theme build adaptations', () => {
353
353
  expect(rebuiltCss).toContain('light-dark(#111111, #eeeeee)');
354
354
  expect(rebuiltCss).toContain(':root { color-scheme: light dark; }');
355
355
  expect(`${rebuilt.stdout}${rebuilt.stderr}`).toContain(
356
- 'Font "Revision Webfont" is named by this theme but not loaded',
356
+ '[note] Fonts named but not loaded: "Revision Webfont".',
357
357
  );
358
358
  });
359
359
 
@@ -72,7 +72,17 @@ function run(args) {
72
72
 
73
73
  describe('theme command human output is plain ASCII', () => {
74
74
  it('a standalone build: ok, warning, error, notice, and font help lines', async () => {
75
- const result = await run(['build', 'ocean.mjs']);
75
+ const short = await run(['build', 'ocean.mjs']);
76
+ expect(short.code).toBe(0);
77
+ expect(short.stdout).toContain(
78
+ '[note] Fonts named but not loaded: "Inter"',
79
+ );
80
+ expect(nonAscii(short)).toEqual([]);
81
+
82
+ const result = await runCli(
83
+ ['--detail', 'full', 'theme', 'build', 'ocean.mjs'],
84
+ dir,
85
+ );
76
86
 
77
87
  expect(result.code).toBe(0);
78
88
  expect(result.stdout).toContain('[ok] ocean.css');