@astryxdesign/cli 0.7.15 → 0.7.16-canary.g22213fd

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 (222) hide show
  1. package/README.md +6 -4
  2. package/api/build/_adapter.d.mts +10 -0
  3. package/api/build/_adapter.mjs +24 -0
  4. package/api/build/blocks/blocks.d.mts +1 -0
  5. package/api/build/blocks/blocks.mjs +18 -1
  6. package/api/build/kit/shell.weights.json +1 -0
  7. package/api/build/kit/shellcall.d.mts +26 -0
  8. package/api/build/kit/shellcall.mjs +87 -0
  9. package/api/build/kit/start.mjs +67 -4
  10. package/api/build/kit/weights.d.mts +15 -0
  11. package/api/build/kit/weights.mjs +27 -0
  12. package/api/component/__fixtures__/resolutions/modules.txt +1 -1
  13. package/api/component/_adapter.d.mts +1 -1
  14. package/api/component/_adapter.mjs +28 -1
  15. package/api/doctor/_adapter.d.mts +38 -2
  16. package/api/doctor/_adapter.mjs +76 -1
  17. package/api/doctor/built-checks.mjs +1 -1
  18. package/api/doctor/doctor.d.mts +26 -0
  19. package/api/doctor/doctor.doc.mjs +1 -1
  20. package/api/doctor/doctor.mjs +156 -11
  21. package/api/doctor/theme-checks.mjs +163 -18
  22. package/api/icon/_adapter.d.mts +7 -3
  23. package/api/icon/_adapter.mjs +12 -3
  24. package/api/icon/icon.type.d.mts +15 -0
  25. package/api/icon/icon.type.mjs +10 -3
  26. package/api/icon/iconUse.doc.mjs +19 -5
  27. package/api/icon/list/list.mjs +7 -1
  28. package/api/icon/use/use.d.mts +8 -5
  29. package/api/icon/use/use.mjs +95 -13
  30. package/api/init/run/run.mjs +1 -0
  31. package/api/integration/add-contribution.mjs +3 -3
  32. package/api/integration/pack-check.mjs +14 -8
  33. package/api/integration/validate-integration.mjs +1 -1
  34. package/api/search/_adapter.mjs +15 -16
  35. package/api/search/_entries.d.mts +2 -1
  36. package/api/search/_entries.mjs +28 -1
  37. package/api/swizzle/_moduleGraph.mjs +1 -1
  38. package/api/template/template.type.d.mts +6 -2
  39. package/api/template/template.type.mjs +2 -1
  40. package/api/theme/_adapter.d.mts +5 -2
  41. package/api/theme/_adapter.mjs +59 -14
  42. package/api/theme/_fork.mjs +1 -1
  43. package/api/theme/build/build.d.mts +120 -32
  44. package/api/theme/build/build.mjs +471 -111
  45. package/api/theme/eject/eject.mjs +22 -1
  46. package/api/theme/generateTonalPalette.doc.mjs +2 -2
  47. package/api/theme/palette/generate/generator.mjs +141 -2
  48. package/api/theme/template/template.d.mts +19 -0
  49. package/api/theme/template/template.mjs +102 -25
  50. package/api/theme/theme.type.d.mts +44 -1
  51. package/api/theme/theme.type.mjs +23 -1
  52. package/api/theme/themeBuild.doc.mjs +4 -4
  53. package/api/theme/themeEject.doc.mjs +1 -1
  54. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  55. package/api/theme/themeTemplate.doc.mjs +9 -3
  56. package/api/theme-edit/_adapter.d.mts +33 -2
  57. package/api/theme-edit/_adapter.mjs +276 -41
  58. package/api/theme-edit/_check.d.mts +93 -4
  59. package/api/theme-edit/_check.mjs +1712 -223
  60. package/api/theme-edit/_color.d.mts +2 -8
  61. package/api/theme-edit/_color.mjs +292 -219
  62. package/api/theme-edit/_compiler.d.mts +1 -0
  63. package/api/theme-edit/_compiler.mjs +20 -1
  64. package/api/theme-edit/_context.d.mts +31 -1
  65. package/api/theme-edit/_context.mjs +445 -41
  66. package/api/theme-edit/_css.d.mts +60 -1
  67. package/api/theme-edit/_css.mjs +404 -28
  68. package/api/theme-edit/_edit.d.mts +25 -0
  69. package/api/theme-edit/_edit.mjs +1620 -154
  70. package/api/theme-edit/_how-commands.d.mts +11 -26
  71. package/api/theme-edit/_how-commands.mjs +30 -2
  72. package/api/theme-edit/_how-question.d.mts +15 -0
  73. package/api/theme-edit/_how-question.mjs +1469 -194
  74. package/api/theme-edit/_how.mjs +144 -30
  75. package/api/theme-edit/_marks.d.mts +13 -0
  76. package/api/theme-edit/_marks.mjs +15 -0
  77. package/api/theme-edit/_overview.mjs +2 -0
  78. package/api/theme-edit/_palette.d.mts +38 -0
  79. package/api/theme-edit/_palette.mjs +306 -73
  80. package/api/theme-edit/_parts.d.mts +33 -0
  81. package/api/theme-edit/_parts.mjs +138 -9
  82. package/api/theme-edit/_png.d.mts +18 -0
  83. package/api/theme-edit/_png.mjs +95 -14
  84. package/api/theme-edit/_preview-app.d.mts +55 -1
  85. package/api/theme-edit/_preview-app.mjs +1552 -101
  86. package/api/theme-edit/_preview.d.mts +71 -3
  87. package/api/theme-edit/_preview.mjs +565 -35
  88. package/api/theme-edit/_project.d.mts +15 -0
  89. package/api/theme-edit/_project.mjs +68 -13
  90. package/api/theme-edit/_settings.d.mts +299 -5
  91. package/api/theme-edit/_settings.mjs +2806 -158
  92. package/api/theme-edit/_tables.d.mts +24 -0
  93. package/api/theme-edit/_tables.mjs +212 -150
  94. package/api/theme-edit/_vet.d.mts +42 -0
  95. package/api/theme-edit/_vet.mjs +144 -0
  96. package/api/theme-edit/theme-edit.type.d.mts +31 -2
  97. package/api/theme-edit/theme-edit.type.mjs +10 -2
  98. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  99. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  100. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  101. package/api/upgrade/registry/registry.mjs +6 -1
  102. package/assets/codemods/parse.mjs +2 -2
  103. package/assets/docs/author-a-theme.doc.mjs +1 -1
  104. package/assets/docs/theme.doc.dense.mjs +1 -1
  105. package/assets/docs/theme.doc.mjs +1 -1
  106. package/assets/docs/theme.doc.zh.mjs +4 -3
  107. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  108. package/assets/docs/tree/icon-sets.doc.mjs +63 -8
  109. package/assets/docs/tree/single-component.doc.mjs +11 -2
  110. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  111. package/assets/docs.generated.json +2 -2
  112. package/assets/preview-app/next.config.mjs +7 -1
  113. package/assets/preview-app/package.json +1 -0
  114. package/assets/preview-app/src/app/globals.css +1 -0
  115. package/assets/self-audit.generated.json +1 -1
  116. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
  117. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
  118. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  119. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  120. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  121. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  122. package/assets/templates/components.generated.json +1 -1
  123. package/assets/templates/pages/ai-chat/page.tsx +20 -2
  124. package/assets/templates/pages/dashboard/page.tsx +1 -1
  125. package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
  126. package/authoring/config/config.doc.mjs +8 -0
  127. package/authoring/config/parse.d.mts +1 -0
  128. package/authoring/config/parse.mjs +12 -0
  129. package/authoring/config/type.ts +8 -0
  130. package/authoring/doctypes/_schema.d.mts +52 -5
  131. package/authoring/doctypes/_schema.mjs +62 -7
  132. package/authoring/doctypes/base/type.ts +10 -0
  133. package/authoring/doctypes/component/component.doc.mjs +1 -1
  134. package/authoring/doctypes/function/function.doc.mjs +6 -0
  135. package/authoring/doctypes/function/type.ts +3 -0
  136. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
  137. package/authoring/doctypes/legacy.mjs +5 -1
  138. package/authoring/index.d.ts +1 -0
  139. package/authoring/shadcn/source-variants.d.mts +1 -1
  140. package/authoring/shadcn/source-variants.mjs +32 -10
  141. package/clients/cli/build-id.generated.json +1 -1
  142. package/clients/cli/commands/doctor.doc.mjs +2 -2
  143. package/clients/cli/commands/experimental/icon.mjs +61 -6
  144. package/clients/cli/commands/experimental/theme.mjs +244 -45
  145. package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
  146. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  147. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  148. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  149. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  150. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  151. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  152. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  153. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  154. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  155. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  156. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  157. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  158. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  159. package/clients/cli/commands/theme.doc.mjs +7 -2
  160. package/clients/cli/commands/theme.mjs +222 -55
  161. package/clients/cli/commands.generated.json +1 -1
  162. package/clients/cli/formatters/index.mjs +7 -4
  163. package/clients/cli/index.mjs +25 -5
  164. package/clients/cli/lib/cli-error.mjs +9 -3
  165. package/clients/cli/lib/component-format.mjs +27 -9
  166. package/clients/cli/lib/json-shim.mjs +72 -2
  167. package/clients/cli/manifest.generated.json +1 -1
  168. package/clients/cli/run.mjs +49 -0
  169. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  170. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  171. package/foundation/agent-docs/agent-docs.mjs +4 -3
  172. package/foundation/config/config-writer.d.mts +23 -0
  173. package/foundation/config/config-writer.mjs +152 -58
  174. package/foundation/config/project.mjs +103 -16
  175. package/foundation/discovery/component-discovery.mjs +11 -22
  176. package/foundation/discovery/icon-set-checks.mjs +164 -48
  177. package/foundation/discovery/icon-set-discovery.d.mts +38 -5
  178. package/foundation/discovery/icon-set-discovery.mjs +50 -6
  179. package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
  180. package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
  181. package/foundation/discovery/icon-set-writer.d.mts +2 -3
  182. package/foundation/discovery/icon-set-writer.mjs +58 -17
  183. package/foundation/discovery/module-exports.mjs +1 -15
  184. package/foundation/discovery/template-adapter.mjs +44 -19
  185. package/foundation/discovery/template-icons.d.mts +27 -10
  186. package/foundation/discovery/template-icons.mjs +142 -26
  187. package/foundation/discovery/template-source-tree.mjs +3 -16
  188. package/foundation/discovery/theme-discovery.d.mts +30 -1
  189. package/foundation/discovery/theme-discovery.mjs +109 -50
  190. package/foundation/fs/exact-codec.d.mts +35 -0
  191. package/foundation/fs/exact-codec.mjs +148 -0
  192. package/foundation/fs/gather-cache.d.mts +15 -5
  193. package/foundation/fs/gather-cache.mjs +129 -31
  194. package/foundation/fs/paths.d.mts +39 -0
  195. package/foundation/fs/paths.mjs +44 -11
  196. package/foundation/fs/read-record.mjs +11 -1
  197. package/foundation/integrations/autolink.d.mts +4 -2
  198. package/foundation/integrations/autolink.mjs +4 -2
  199. package/foundation/integrations/cli-requirement.d.mts +16 -5
  200. package/foundation/integrations/cli-requirement.mjs +27 -6
  201. package/foundation/integrations/contribution-fixes.mjs +1 -16
  202. package/foundation/integrations/may-have-integrations.mjs +7 -3
  203. package/foundation/integrations/missing-dependency.d.mts +9 -0
  204. package/foundation/integrations/missing-dependency.mjs +100 -0
  205. package/foundation/integrations/public-imports.mjs +1 -1
  206. package/foundation/render/embedded-imports.mjs +1 -1
  207. package/foundation/render/host-exit.d.mts +8 -0
  208. package/foundation/render/host-exit.mjs +11 -0
  209. package/foundation/render/page-host.mjs +56 -10
  210. package/foundation/render/page-worker.mjs +14 -0
  211. package/foundation/render/render-page.mjs +37 -2
  212. package/foundation/response/error-codes.d.mts +2 -1
  213. package/foundation/response/error-codes.d.ts +1 -0
  214. package/foundation/response/error-codes.doc.mjs +5 -0
  215. package/foundation/response/error-codes.mjs +3 -0
  216. package/foundation/response/json.d.mts +15 -0
  217. package/foundation/response/json.mjs +52 -1
  218. package/foundation/response/response-types.doc.mjs +1 -1
  219. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  220. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  221. package/foundation/xle/browser.d.mts +2 -2
  222. package/package.json +7 -6
@@ -13,7 +13,7 @@ export const doc = {
13
13
  displayName: 'themeEject()',
14
14
  summary: 'Eject an available theme into a project as editable source.',
15
15
  description:
16
- "Resolves a theme from the CLI bundle or an installed integration and ejects it into the consumer project: a bundled theme's source files, or an integration theme's complete directory with its descriptor. Writes are staged and existing files require explicit overwrite. Duplicate slugs fail closed until the caller selects an owner package.",
16
+ "Resolves a theme from the CLI bundle or an installed integration and ejects it into the consumer project: a bundled theme's source files, or an integration theme's complete directory with its descriptor. Writes are staged and existing files require explicit overwrite. A target inside a folder the theme editor made (a subfolder of <slug>/ that holds <slug>.settings.json) is written, and the CLI warns. Duplicate slugs fail closed until the caller selects an owner package.",
17
17
  importPath: '@astryxdesign/cli/api',
18
18
  signature:
19
19
  'themeEject(slug: string, options?: {targetPath?: string, overwrite?: boolean, cwd?: string, package?: string}): Promise<ThemeEjectResponse>',
@@ -68,7 +68,7 @@ export const doc = {
68
68
  {code: 'ERR_FILE_NOT_FOUND', when: 'the config file does not exist'},
69
69
  {
70
70
  code: 'ERR_PALETTE_GENERATION',
71
- when: 'the config is not valid JSON; the request, seed, stop layout, mode or anchor is invalid; out does not end in .ts or .json; or preview does not end in .html',
71
+ when: 'the config is not valid JSON; the request, seed, stop layout, mode, anchor or dark chroma taper is invalid; out does not end in .ts or .json; or preview does not end in .html',
72
72
  },
73
73
  {
74
74
  code: 'ERR_PATH_TRAVERSAL',
@@ -22,7 +22,9 @@ export const doc = {
22
22
  'Read it, copy what you need into your own theme file, delete it. Use `theme add` to ' +
23
23
  'use an installed built theme, extend that theme for ordinary customization, or use ' +
24
24
  '`theme eject` for a complete source fork. This command starts a new blank theme. Refuses to overwrite without ' +
25
- '`overwrite`, so it is safe to re-run.',
25
+ '`overwrite`, so it is safe to re-run. With no package.json at or above cwd, it writes in cwd ' +
26
+ 'and the CLI warns; pass a cwd inside a project, or run `npm init -y` in that folder first, to ' +
27
+ 'write it at a project root.',
26
28
  importPath: '@astryxdesign/cli/api',
27
29
  signature:
28
30
  'themeTemplate(options?: {targetPath?: string, overwrite?: boolean, cwd?: string}): ThemeTemplateResponse',
@@ -31,7 +33,8 @@ export const doc = {
31
33
  {
32
34
  name: 'options.targetPath',
33
35
  type: 'string',
34
- description: 'Destination file. Must resolve within cwd.',
36
+ description:
37
+ 'Destination file, read from cwd. Must resolve within the project root: the nearest folder at or above cwd with a package.json. Left out, the template is written at the project root.',
35
38
  default: "'theme.template.ts'",
36
39
  },
37
40
  {
@@ -55,7 +58,10 @@ export const doc = {
55
58
  },
56
59
  ],
57
60
  throws: [
58
- {code: 'ERR_PATH_TRAVERSAL', when: 'the target path escapes cwd'},
61
+ {
62
+ code: 'ERR_PATH_TRAVERSAL',
63
+ when: 'the target path escapes the project root (the nearest folder at or above cwd with a package.json)',
64
+ },
59
65
  {
60
66
  code: 'ERR_INVALID_ARGUMENT',
61
67
  when: 'the target path is blank, names a folder, or is not a .ts file (with or without overwrite)',
@@ -36,13 +36,17 @@ export function editorThemeRefusal(err: AstryxError, cwd: string): AstryxError |
36
36
  * take an editor theme, and `--check` checks an editor theme by the editor's
37
37
  * own rules (waiting for a change in progress).
38
38
  * @param {string[]} files
39
- * @param {{cwd: string, check?: boolean, family?: boolean}} options
39
+ * @param {{cwd: string, check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}} options
40
+ * `check`, `out` and `iconsSpecifier` are kept in every compile a refusal
41
+ * suggests
40
42
  * @returns {Promise<AstryxError | null>}
41
43
  */
42
- export function editorCompileProblem(files: string[], { cwd, check, family }: {
44
+ export function editorCompileProblem(files: string[], { cwd, check, family, iconsSpecifier, out }: {
43
45
  cwd: string;
44
46
  check?: boolean;
45
47
  family?: boolean;
48
+ iconsSpecifier?: string;
49
+ out?: string;
46
50
  }): Promise<AstryxError | null>;
47
51
  /**
48
52
  * Hold the theme lock of every editor theme among the files while
@@ -55,8 +59,35 @@ export function editorCompileProblem(files: string[], { cwd, check, family }: {
55
59
  export function editorThemeHold(files: string[], { cwd }: {
56
60
  cwd: string;
57
61
  }): Promise<() => Promise<void>>;
62
+ /**
63
+ * For `compile` of a file that is not there: when it is an editor theme's
64
+ * own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
65
+ * that writes it again; null otherwise.
66
+ * @param {string} file the path as given
67
+ * @param {string} cwd
68
+ * @returns {{name: string, reason: string} | null}
69
+ */
70
+ export function editorMissingSource(file: string, cwd: string): {
71
+ name: string;
72
+ reason: string;
73
+ } | null;
74
+ /**
75
+ * `theme template` for the experimental command: in a folder the theme
76
+ * editor made, only the editor's own files are protected.
77
+ * @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} options
78
+ * @returns {import('../theme/theme.type.mjs').ThemeTemplateResponse}
79
+ */
80
+ export function editorThemeTemplate(options: {
81
+ targetPath?: string;
82
+ overwrite?: boolean;
83
+ cwd?: string;
84
+ }): import("../theme/theme.type.mjs").ThemeTemplateResponse;
58
85
  export { parsePoints } from "./_how.mjs";
86
+ export { newFlagList } from "./_edit.mjs";
59
87
  export function builtInThemes(): string[];
88
+ export function editorBaseIn(slug: string | null | undefined, cwd: string): string;
89
+ export function showSections(): string[];
90
+ export { dialValueFits } from "./_settings.mjs";
60
91
  /** @type {typeof edit.themeEditNew} */
61
92
  export const themeEditNew: typeof edit.themeEditNew;
62
93
  /** @type {typeof edit.themeEditSet} */
@@ -31,18 +31,18 @@
31
31
  * @position api/theme-edit — adapter for api/theme-edit/theme-edit.mjs
32
32
  */
33
33
 
34
+ import {writeThemeTemplate} from '../theme/template/template.mjs';
35
+ import {buildSuggestion} from '../theme/build/build.mjs';
34
36
  import {createHash} from 'node:crypto';
35
37
  import * as fs from 'node:fs';
36
38
  import * as path from 'node:path';
37
39
  import * as edit from './_edit.mjs';
38
- import {themeCacheRoot} from './_project.mjs';
40
+ import {baseInstalled, themeCacheRoot} from './_project.mjs';
39
41
  import * as preview from './_preview-app.mjs';
40
42
  import {AstryxError} from '../error.mjs';
41
43
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
42
- import {
43
- findAstryxProject,
44
- findPackageRoot,
45
- } from '../../foundation/fs/paths.mjs';
44
+ import {findPackageRoot} from '../../foundation/fs/paths.mjs';
45
+ import {coreApp} from './_context.mjs';
46
46
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
47
47
  import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
48
48
  import {
@@ -50,10 +50,22 @@ import {
50
50
  quoteCommandArgument,
51
51
  } from '../../foundation/env/package-manager.mjs';
52
52
  import {LIKE, P} from './_tables.mjs';
53
- import {camel} from './_settings.mjs';
53
+ import {setLine} from './_check.mjs';
54
+ import {
55
+ SHOWCASE_GROUPS,
56
+ takeFirstAppCopy,
57
+ writeAppCopy,
58
+ writeAppCopyAt,
59
+ } from './_preview.mjs';
60
+ import {humanWarn} from '../../foundation/response/json.mjs';
61
+ import {folderIsEmpty, setAfterBuild, typedThemeName} from './_settings.mjs';
62
+
63
+ // Every build of a theme writes its app copy (src/themes/<theme>/).
64
+ setAfterBuild(writeAppCopy);
54
65
  import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
55
66
 
56
67
  export {parsePoints} from './_how.mjs';
68
+ export {newFlagList} from './_edit.mjs';
57
69
  import {themeEditHow as howAt} from './_how.mjs';
58
70
 
59
71
  /**
@@ -90,6 +102,22 @@ export async function themeEditHow(subject, options = {}) {
90
102
  /** The built-in themes a theme can build on (`--like`). */
91
103
  export const builtInThemes = () => [...LIKE];
92
104
 
105
+ /**
106
+ * The base the editor can start a theme from in a project: `slug` when it
107
+ * is a built-in base installed there (the check `new --like` makes), else
108
+ * neutral.
109
+ * @param {string | null | undefined} slug
110
+ * @param {string} cwd
111
+ * @returns {string}
112
+ */
113
+ export const editorBaseIn = (slug, cwd) =>
114
+ slug && LIKE.includes(slug) && baseInstalled(cwd, slug) ? slug : 'neutral';
115
+
116
+ /** The sections `show --section` takes. */
117
+ export const showSections = () => [...SHOWCASE_GROUPS];
118
+
119
+ export {dialValueFits} from './_settings.mjs';
120
+
93
121
  /**
94
122
  * The project a command acts on: the Astryx project at or above `cwd`, found
95
123
  * as `upgrade` finds it (the nearest package that declares an Astryx package
@@ -102,7 +130,9 @@ export const builtInThemes = () => [...LIKE];
102
130
  */
103
131
  export function projectRoot(cwd) {
104
132
  const start = path.resolve(cwd);
105
- const project = findAstryxProject(start);
133
+ // One rule: the nearest folder at or above cwd whose package.json lists
134
+ // @astryxdesign/core.
135
+ const project = coreApp(start);
106
136
  const pkg = findPackageRoot(start);
107
137
  const inReach = (/** @type {string} */ dir) =>
108
138
  project ? !path.relative(project, dir).startsWith('..') : true;
@@ -112,13 +142,19 @@ export function projectRoot(cwd) {
112
142
  let json;
113
143
  try {
114
144
  json = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
115
- } catch {
145
+ } catch (e) {
146
+ // Name the file and what the parser says is wrong, with its place.
147
+ const rel = path.relative(start, file) || 'package.json';
148
+ const why = String(/** @type {Error} */ (e).message ?? '').replace(
149
+ /^Unexpected token.*?, /,
150
+ '',
151
+ );
116
152
  throw new AstryxError(
117
- `${path.relative(start, file) || 'package.json'} is not valid JSON, so the app it belongs to is unknown. Fix it, then run the command again. Nothing was written.`,
153
+ `${rel} is not valid JSON (${why}), so the app it belongs to is unknown. Fix it, then run the command again. Nothing was written.`,
118
154
  [
119
155
  {
120
- name: runLine(start, 'doctor'),
121
- reason: 'names the file and what is wrong in it',
156
+ name: `\${EDITOR:-vi} ${quoteCommandArgument(rel)}`,
157
+ reason: 'open the file and fix it',
122
158
  },
123
159
  ],
124
160
  ERROR_CODES.ERR_PROJECT_REQUIRED,
@@ -195,9 +231,15 @@ function lockDir(root) {
195
231
  * @param {boolean} [bestEffort] a command that can run read-only runs
196
232
  * without the lock when it cannot be taken (a read-only node_modules),
197
233
  * told so, and then writes nothing
234
+ * @param {string | null} [again] the command's own words after the CLI
235
+ * name, to suggest running it again (never the host process's argv: an
236
+ * API caller is not a CLI run)
198
237
  * @returns {Promise<T>}
199
238
  */
200
- async function withLock(root, name, fn, bestEffort = false) {
239
+ async function withLock(root, name, fn, bestEffort = false, again = null) {
240
+ // A preview command, which holds the preview lock, suggests the list of
241
+ // previews (what the other command may be changing).
242
+ again ??= name === 'preview' ? 'experimental theme preview list' : null;
201
243
  /** @type {string | null} */
202
244
  let dir;
203
245
  try {
@@ -239,16 +281,17 @@ async function withLock(root, name, fn, bestEffort = false) {
239
281
  {
240
282
  onBusy: (o, held) => {
241
283
  throw new AstryxError(
242
- `Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
243
- // A look that takes no lock: the last build as it is.
244
- [
245
- {
246
- name: name.startsWith('theme-')
247
- ? `${P} show ${name.replace(/^theme-/, '')}`
248
- : 'astryx experimental theme preview list',
249
- reason: 'see it as it is now',
250
- },
251
- ],
284
+ `Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again once the other one ends. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
285
+ // Every editor command (show too) takes this lock, so none of
286
+ // them works meanwhile: this same command, once the other ends.
287
+ again
288
+ ? [
289
+ {
290
+ name: runLine(root, again),
291
+ reason: 'run it again once the other command ends',
292
+ },
293
+ ]
294
+ : [],
252
295
  ERROR_CODES.ERR_THEME_BUSY,
253
296
  );
254
297
  },
@@ -346,9 +389,11 @@ function absolute(result, root, from) {
346
389
  * @param {O} options
347
390
  * @param {string | null} lock
348
391
  * @param {(o: O & {cwd: string}) => Promise<T>} fn
392
+ * @param {boolean} [bestEffort]
393
+ * @param {string | null} [again] the command's own words, for a busy lock
349
394
  * @returns {Promise<T>}
350
395
  */
351
- async function inProject(options, lock, fn, bestEffort = false) {
396
+ async function inProject(options, lock, fn, bestEffort = false, again = null) {
352
397
  const from = options.cwd ?? process.cwd();
353
398
  const o = atRoot(options);
354
399
  try {
@@ -360,6 +405,7 @@ async function inProject(options, lock, fn, bestEffort = false) {
360
405
  lock,
361
406
  locked => fn(locked ? o : {...o, readOnly: true}),
362
407
  bestEffort,
408
+ again,
363
409
  )
364
410
  : await fn(o);
365
411
  return absolute(r, o.cwd, from);
@@ -434,20 +480,74 @@ const withThemeLock = o => ({
434
480
  ) => withLock(o.cwd, lockName(slug), fn),
435
481
  });
436
482
 
483
+ /**
484
+ * A command's own words after the CLI name, from what it was called with,
485
+ * every option kept: set and undo as `set` writes them (scope flags and
486
+ * --only), new with --like and each dial, --png where given.
487
+ * @param {string} line a command as the editor writes one (`astryx …`)
488
+ * @param {{png?: boolean}} [o]
489
+ */
490
+ const words = (line, o = {}) =>
491
+ `${line.replace(/^astryx /, '').trimEnd()}${o.png ? ' --png' : ''}`;
492
+
437
493
  /** @type {typeof edit.themeEditNew} */
438
494
  export const themeEditNew = (name, options = {}) =>
439
- inProject(options, lockName(name), o => edit.themeEditNew(name, o));
495
+ inProject(
496
+ options,
497
+ lockName(name),
498
+ o => edit.themeEditNew(name, o),
499
+ false,
500
+ words(
501
+ `${P} new ${quoteCommandArgument(name)} ${edit
502
+ .newFlagList(
503
+ options.like,
504
+ options.settings ?? {},
505
+ /** @type {boolean} */ (options.png),
506
+ )
507
+ .join(' ')}`,
508
+ ),
509
+ );
440
510
  /** @type {typeof edit.themeEditSet} */
441
511
  export const themeEditSet = (theme, thing, value, options = {}) =>
442
- inProject(options, lockName(theme), o =>
443
- edit.themeEditSet(theme, thing, value, o),
512
+ inProject(
513
+ options,
514
+ lockName(theme),
515
+ o => edit.themeEditSet(theme, thing, value, o),
516
+ false,
517
+ words(setLine(theme, thing, value, options), options),
444
518
  );
445
519
  /** @type {typeof edit.themeEditUndo} */
446
520
  export const themeEditUndo = (theme, options = {}) =>
447
- inProject(options, lockName(theme), o => edit.themeEditUndo(theme, o));
521
+ inProject(
522
+ options,
523
+ lockName(theme),
524
+ o => edit.themeEditUndo(theme, o),
525
+ false,
526
+ words(
527
+ options.thing
528
+ ? setLine(
529
+ theme,
530
+ options.thing,
531
+ /** @type {string} */ (options.value ?? ''),
532
+ options,
533
+ true,
534
+ )
535
+ : `${P} undo ${theme}`,
536
+ options,
537
+ ),
538
+ );
448
539
  /** @type {typeof edit.themeEditShow} */
449
540
  export const themeEditShow = (theme, options = {}) =>
450
- inProject(options, lockName(theme), o => edit.themeEditShow(theme, o), true);
541
+ inProject(
542
+ options,
543
+ lockName(theme),
544
+ o => edit.themeEditShow(theme, o),
545
+ true,
546
+ words(
547
+ `${P} show ${theme}${options.section ? ` --section ${quoteCommandArgument(String(options.section))}` : ''}`,
548
+ options,
549
+ ),
550
+ );
451
551
  /** @type {typeof preview.themeEditPreviewAdd} */
452
552
  export const themeEditPreviewAdd = (description, options = {}) =>
453
553
  inProject(options, 'preview', o =>
@@ -577,20 +677,45 @@ export function editorThemeRefusal(err, cwd) {
577
677
  )
578
678
  return null;
579
679
  const root = projectRoot(cwd);
580
- const named = /"([a-z][a-z0-9-]*)"|'([a-z][a-z0-9-]*)'/.exec(err.message);
581
- const slug = named ? editorThemeOf(root, named[1] ?? named[2]) : null;
680
+ // The name as typed, read the way the editor reads a theme name: a path
681
+ // to its folder or a file in it, in any case, names the theme.
682
+ const named = /"([^"]+)"|'([^']+)'/.exec(err.message);
683
+ const word = named ? typedThemeName(named[1] ?? named[2]) : '';
684
+ const slug = word ? editorThemeOf(root, word) : null;
582
685
  if (!slug) return null;
583
686
  // A local theme of that name (a fork in the app's own themes folder) is
584
687
  // one the stable commands take: their own message stands.
585
- if (fs.existsSync(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
586
- const id = `${camel(slug)}Theme`;
587
- const key = /^[a-z][a-z0-9]*$/i.test(slug) ? slug : JSON.stringify(slug);
688
+ // A folder of only system files (or empty) holds no theme: as absent.
689
+ if (!folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
690
+ // No app copy yet (a theme made before the editor wrote one, or the
691
+ // copy removed): the next build writes it, then the same steps every
692
+ // place gives (`wiring` of new and show).
693
+ // A one-mode theme's mode is a step too, as in `wiring`.
694
+ /** @type {'light' | 'dark' | 'system'} */
695
+ let mode = 'system';
696
+ try {
697
+ const m = JSON.parse(
698
+ fs.readFileSync(
699
+ path.join(root, 'themes', slug, `${slug}.settings.json`),
700
+ 'utf8',
701
+ ),
702
+ ).mode;
703
+ if (m === 'light-only') mode = 'light';
704
+ else if (m === 'dark-only') mode = 'dark';
705
+ } catch {
706
+ // Settings that do not read: both modes.
707
+ }
708
+ const steps = preview.addWiring(root, slug, mode);
588
709
  return new AstryxError(
589
- `${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet in a file of your own (import {${id}} from './themes/${slug}/${slug}.js'; import './themes/${slug}/${slug}.css';) and merge it into the themes there ({...themes, ${key}: ${id}}); do not add it to src/astryx-themes.ts, which add, use and remove write again. Change it with the editor.`,
710
+ `${slug} is a theme the editor made (themes/${slug}/), and it has no app copy yet: list, add, use, remove and eject take the copy every build of it writes in src/themes/${slug}/, a standard local theme. Build it once, then: ${steps.join('; ')}.`,
590
711
  [
591
712
  {
592
713
  name: runLine(cwd, `experimental theme editor show ${slug}`),
593
- reason: 'see the theme',
714
+ reason: `builds it and writes its app copy, src/themes/${slug}/`,
715
+ },
716
+ {
717
+ name: runLine(cwd, `theme add ${slug}`),
718
+ reason: 'then adds it to the app',
594
719
  },
595
720
  ],
596
721
  ERROR_CODES.ERR_UNKNOWN_THEME,
@@ -603,24 +728,62 @@ export function editorThemeRefusal(err, cwd) {
603
728
  * take an editor theme, and `--check` checks an editor theme by the editor's
604
729
  * own rules (waiting for a change in progress).
605
730
  * @param {string[]} files
606
- * @param {{cwd: string, check?: boolean, family?: boolean}} options
731
+ * @param {{cwd: string, check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}} options
732
+ * `check`, `out` and `iconsSpecifier` are kept in every compile a refusal
733
+ * suggests
607
734
  * @returns {Promise<AstryxError | null>}
608
735
  */
609
- export async function editorCompileProblem(files, {cwd, check, family}) {
736
+ export async function editorCompileProblem(
737
+ files,
738
+ {cwd, check, family, iconsSpecifier, out},
739
+ ) {
610
740
  const cwdRoot = projectRoot(cwd);
741
+ const COMPILE = {group: 'experimental theme', build: 'compile'};
742
+ /**
743
+ * The compile of `source` (from `from`) with the caller's mode: a check
744
+ * stays a check, and --out names the same file from there.
745
+ * @param {string} source @param {string} from
746
+ */
747
+ const compileLine = (source, from) =>
748
+ buildSuggestion(
749
+ source,
750
+ {
751
+ check,
752
+ iconsSpecifier,
753
+ out: out
754
+ ? path.relative(from, path.resolve(cwd, out)) || out
755
+ : undefined,
756
+ },
757
+ from,
758
+ COMPILE,
759
+ );
611
760
  for (const file of files) {
612
761
  const at = editorThemeAt(cwdRoot, path.resolve(cwd, file));
613
762
  if (!at || !editorOwnFile(at.slug, file)) continue;
614
763
  const {root, slug} = at;
615
764
  const source = `themes/${slug}/${slug}.theme.ts`;
765
+ // An editor theme is built from its project's root, as every editor
766
+ // command runs there: from a subfolder the build would write outside
767
+ // its working folder. The run names the root.
768
+ if (path.resolve(cwd) !== path.resolve(root))
769
+ return new AstryxError(
770
+ `${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.`,
771
+ [
772
+ {
773
+ name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${compileLine(source, root)}`,
774
+ reason: 'do this instead',
775
+ },
776
+ ],
777
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
778
+ );
616
779
  if (/\.settings\.(ts|json)$/.test(file))
617
780
  return new AstryxError(
618
781
  `${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
619
782
  [
620
783
  {
621
- name: runLine(
784
+ name: compileLine(
785
+ path.relative(cwd, path.join(root, source)) || source,
622
786
  cwd,
623
- `experimental theme compile ${quoteCommandArgument(path.relative(cwd, path.join(root, source)) || source)}`,
624
787
  ),
625
788
  reason: 'do this instead',
626
789
  },
@@ -632,9 +795,9 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
632
795
  `${slug} is a theme the editor made; --family builds package theme families, not editor themes. Compile it on its own.`,
633
796
  [
634
797
  {
635
- name: runLine(
798
+ name: compileLine(
799
+ path.relative(cwd, path.join(root, source)) || source,
636
800
  cwd,
637
- `experimental theme compile ${quoteCommandArgument(path.relative(cwd, path.join(root, source)) || source)}`,
638
801
  ),
639
802
  reason: 'do this instead',
640
803
  },
@@ -661,6 +824,28 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
661
824
  if (e instanceof AstryxError) return e;
662
825
  throw e;
663
826
  }
827
+ // An own change to the theme source is what compile builds (and what
828
+ // --check compares): never a reason to refuse it.
829
+ if (
830
+ why &&
831
+ /\.theme\.ts (or a module it imports )?changed since the last build$/.test(
832
+ why,
833
+ )
834
+ )
835
+ why = null;
836
+ // A missing built output is one compile writes itself.
837
+ if (
838
+ why &&
839
+ !check &&
840
+ /^[^/]+\.(css|js|d\.ts|css\.d\.ts) was missing$/.test(why)
841
+ )
842
+ why = null;
843
+ // Saved settings the editor no longer accepts: show refuses them too,
844
+ // so the refusal names the undo that removes each.
845
+ if (why) {
846
+ const stored = await edit.editorStoredRefusal(root, slug);
847
+ if (stored) return stored;
848
+ }
664
849
  if (why && !check)
665
850
  return new AstryxError(
666
851
  `${slug}'s generated settings do not match its settings (${why}), so compile would build the old ones. The editor builds it from its settings.`,
@@ -683,6 +868,13 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
683
868
  ],
684
869
  ERROR_CODES.ERR_THEME_INVALID,
685
870
  );
871
+ // A [light, dark] pair on a token that is not a color, however the
872
+ // file writes it: what the theme builds now is read (never written
873
+ // beside it), as the editor's own build reads it.
874
+ if (path.basename(file) === `${slug}.theme.ts`) {
875
+ const pairs = await edit.editorPairRefusal(root, slug);
876
+ if (pairs) return pairs;
877
+ }
686
878
  }
687
879
  }
688
880
  return null;
@@ -750,9 +942,52 @@ export async function editorThemeHold(files, {cwd}) {
750
942
  throw err;
751
943
  }
752
944
  releases.push(async () => {
945
+ // A compile that wrote the build refreshes the app's copy too
946
+ // (src/themes/<theme>/), under the same lock; a check writes nothing.
947
+ if (!process.argv.includes('--check')) {
948
+ try {
949
+ writeAppCopyAt(root, slug, null);
950
+ // The first write of the app copy is named once (the compile's
951
+ // own JSON envelope is the stable command's).
952
+ const wrote = takeFirstAppCopy(root, slug);
953
+ if (wrote)
954
+ humanWarn(
955
+ `wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${wrote.join(', ')}`,
956
+ );
957
+ } catch {
958
+ // A theme that does not load keeps its copy as it was.
959
+ }
960
+ }
753
961
  release();
754
962
  await done;
755
963
  });
756
964
  }
757
965
  return releaseAll;
758
966
  }
967
+
968
+ /**
969
+ * For `compile` of a file that is not there: when it is an editor theme's
970
+ * own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
971
+ * that writes it again; null otherwise.
972
+ * @param {string} file the path as given
973
+ * @param {string} cwd
974
+ * @returns {{name: string, reason: string} | null}
975
+ */
976
+ export function editorMissingSource(file, cwd) {
977
+ const at = editorThemeAt(projectRoot(cwd), path.resolve(cwd, file));
978
+ if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
979
+ return {
980
+ name: runLine(cwd, `experimental theme editor show ${at.slug}`),
981
+ reason: `the editor writes ${at.slug}.theme.ts again from its settings`,
982
+ };
983
+ }
984
+
985
+ /**
986
+ * `theme template` for the experimental command: in a folder the theme
987
+ * editor made, only the editor's own files are protected.
988
+ * @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} options
989
+ * @returns {import('../theme/theme.type.mjs').ThemeTemplateResponse}
990
+ */
991
+ export function editorThemeTemplate(options) {
992
+ return writeThemeTemplate(options, true);
993
+ }