@astryxdesign/cli 0.7.15-canary.gf890983 → 0.7.15

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 (115) hide show
  1. package/CHANGELOG.md +353 -3
  2. package/api/doctor/_adapter.d.mts +2 -1
  3. package/api/doctor/_adapter.mjs +6 -1
  4. package/api/doctor/doctor.mjs +2 -2
  5. package/api/doctor/theme-checks.mjs +56 -21
  6. package/api/integration/add-helpers.mjs +5 -0
  7. package/api/integration/add-theme.mjs +15 -110
  8. package/api/theme/_adapter.d.mts +37 -5
  9. package/api/theme/_adapter.mjs +363 -50
  10. package/api/theme/_fork.d.mts +90 -0
  11. package/api/theme/_fork.mjs +246 -0
  12. package/api/theme/build/build.d.mts +25 -1
  13. package/api/theme/build/build.mjs +352 -41
  14. package/api/theme/eject/eject.mjs +36 -15
  15. package/api/theme/list/list.mjs +3 -6
  16. package/api/theme/palette/generate/generator.d.mts +13 -0
  17. package/api/theme/palette/generate/generator.mjs +32 -2
  18. package/api/theme/targets/targets.mjs +10 -3
  19. package/api/theme/template/template.mjs +48 -2
  20. package/api/theme/theme.type.d.mts +8 -0
  21. package/api/theme/theme.type.mjs +5 -1
  22. package/api/theme/themeBuild.doc.mjs +2 -2
  23. package/api/theme/themeRemove.doc.mjs +5 -2
  24. package/api/theme/themeTemplate.doc.mjs +2 -2
  25. package/api/theme/themeUse.doc.mjs +8 -2
  26. package/api/theme-edit/_adapter.mjs +157 -36
  27. package/api/theme-edit/_catalog.d.mts +1 -6
  28. package/api/theme-edit/_catalog.mjs +5 -268
  29. package/api/theme-edit/_check.d.mts +3 -1
  30. package/api/theme-edit/_check.mjs +733 -308
  31. package/api/theme-edit/_color.d.mts +19 -0
  32. package/api/theme-edit/_color.mjs +277 -33
  33. package/api/theme-edit/_compiler.d.mts +1 -0
  34. package/api/theme-edit/_compiler.mjs +25 -0
  35. package/api/theme-edit/_context.d.mts +2 -0
  36. package/api/theme-edit/_context.mjs +83 -9
  37. package/api/theme-edit/_css.d.mts +84 -0
  38. package/api/theme-edit/_css.mjs +700 -0
  39. package/api/theme-edit/_edit.mjs +370 -85
  40. package/api/theme-edit/_how-commands.d.mts +5 -0
  41. package/api/theme-edit/_how-commands.mjs +20 -13
  42. package/api/theme-edit/_how-question.d.mts +29 -0
  43. package/api/theme-edit/_how-question.mjs +1573 -182
  44. package/api/theme-edit/_how.mjs +306 -22
  45. package/api/theme-edit/_overview.mjs +2 -7
  46. package/api/theme-edit/_palette.d.mts +27 -5
  47. package/api/theme-edit/_palette.mjs +231 -97
  48. package/api/theme-edit/_parts.d.mts +42 -10
  49. package/api/theme-edit/_parts.mjs +224 -69
  50. package/api/theme-edit/_preview-app.d.mts +8 -0
  51. package/api/theme-edit/_preview-app.mjs +549 -96
  52. package/api/theme-edit/_preview.d.mts +7 -16
  53. package/api/theme-edit/_preview.mjs +77 -84
  54. package/api/theme-edit/_project.d.mts +20 -1
  55. package/api/theme-edit/_project.mjs +43 -13
  56. package/api/theme-edit/_settings.d.mts +96 -20
  57. package/api/theme-edit/_settings.mjs +646 -141
  58. package/api/theme-edit/_tables.d.mts +18 -12
  59. package/api/theme-edit/_tables.mjs +144 -147
  60. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  61. package/api/theme-edit/theme-edit.type.mjs +3 -1
  62. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  63. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  64. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  65. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  66. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  67. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  68. package/assets/docs/tree/publishing.doc.mjs +1 -0
  69. package/assets/docs.generated.json +2 -2
  70. package/assets/self-audit.generated.json +1 -1
  71. package/clients/cli/build-id.generated.json +1 -1
  72. package/clients/cli/commands/experimental/index.mjs +10 -10
  73. package/clients/cli/commands/experimental/theme.mjs +22 -3
  74. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  75. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  76. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  77. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  78. package/clients/cli/commands/integration.mjs +8 -0
  79. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  80. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  81. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  82. package/clients/cli/commands/theme.mjs +325 -48
  83. package/clients/cli/index.mjs +18 -3
  84. package/clients/cli/lib/cli-error.mjs +118 -3
  85. package/clients/cli/manifest.generated.json +1 -1
  86. package/foundation/config/project.mjs +34 -8
  87. package/foundation/config/theme-state.d.mts +16 -0
  88. package/foundation/config/theme-state.mjs +84 -13
  89. package/foundation/discovery/template-needs.d.mts +13 -0
  90. package/foundation/discovery/template-needs.mjs +30 -15
  91. package/foundation/discovery/theme-discovery.mjs +14 -2
  92. package/foundation/discovery/theme-imports.d.mts +16 -0
  93. package/foundation/discovery/theme-imports.mjs +30 -2
  94. package/foundation/doc-compiler/import.mjs +10 -4
  95. package/foundation/fs/gather-cache.mjs +82 -23
  96. package/foundation/fs/jiti-cache.d.mts +21 -0
  97. package/foundation/fs/jiti-cache.mjs +66 -0
  98. package/foundation/fs/module-loader.mjs +7 -2
  99. package/foundation/integrations/autolink.d.mts +1 -24
  100. package/foundation/integrations/autolink.mjs +7 -60
  101. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  102. package/foundation/integrations/declared-dependencies.mjs +73 -0
  103. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  104. package/foundation/integrations/may-have-integrations.mjs +47 -0
  105. package/foundation/release/cache.d.mts +21 -2
  106. package/foundation/release/cache.mjs +48 -8
  107. package/foundation/release/folder-lock.d.mts +7 -0
  108. package/foundation/release/folder-lock.mjs +60 -26
  109. package/foundation/release/lock-lease.d.mts +2 -1
  110. package/foundation/release/lock-lease.mjs +7 -2
  111. package/foundation/response/error-codes.doc.mjs +1 -1
  112. package/foundation/response/response-types.doc.mjs +4 -4
  113. package/package.json +6 -6
  114. package/api/theme-edit/_css-properties.d.mts +0 -10
  115. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -18,7 +18,6 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
18
18
  import {
19
19
  assertWithin,
20
20
  PathSafetyError,
21
- sanitizeName,
22
21
  } from '../../foundation/fs/path-safety.mjs';
23
22
  import {
24
23
  discoverBundledThemes,
@@ -46,47 +45,14 @@ import {
46
45
  projectPath,
47
46
  } from './add-helpers.mjs';
48
47
 
49
- const DEFAULT_THEMES_ROOT = './themes';
48
+ import {
49
+ renameDefinedTheme,
50
+ renameThemeFile,
51
+ rewriteThemeSource,
52
+ themeIdentity,
53
+ } from '../theme/_fork.mjs';
50
54
 
51
- /** @param {string} slug */
52
- function themeIdentity(slug) {
53
- try {
54
- sanitizeName(slug, {label: 'theme name'});
55
- } catch (error) {
56
- if (error instanceof PathSafetyError) {
57
- throw new AstryxError(
58
- error.message,
59
- undefined,
60
- ERROR_CODES.ERR_INVALID_ARGUMENT,
61
- );
62
- }
63
- throw error;
64
- }
65
- if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(slug)) {
66
- throw new AstryxError(
67
- `Invalid theme name "${slug}": use lowercase kebab-case starting with a letter.`,
68
- undefined,
69
- ERROR_CODES.ERR_INVALID_ARGUMENT,
70
- );
71
- }
72
- const identifier = slug.replace(/-([a-z0-9])/gu, (_, character) =>
73
- character.toUpperCase(),
74
- );
75
- const displayName = slug
76
- .split('-')
77
- .map(part =>
78
- part === 'y2k' ? 'Y2K' : part[0].toUpperCase() + part.slice(1),
79
- )
80
- .join(' ');
81
- return {
82
- slug,
83
- identifier,
84
- displayName,
85
- exportName: `${identifier}Theme`,
86
- entry: `${identifier}Theme.ts`,
87
- descriptor: `${identifier}Theme.doc.mjs`,
88
- };
89
- }
55
+ const DEFAULT_THEMES_ROOT = './themes';
90
56
 
91
57
  /** @param {{slug: string, exportName: string}} identity */
92
58
  function themeSource(identity) {
@@ -129,7 +95,10 @@ function resolveBaseTheme(slug, packageDir, owner, themesRoot) {
129
95
  // Also check the package's own themes root.
130
96
  if (themesRoot && fs.existsSync(themesRoot)) {
131
97
  try {
132
- candidates = [...candidates, ...discoverThemeDirectory(themesRoot, owner)];
98
+ candidates = [
99
+ ...candidates,
100
+ ...discoverThemeDirectory(themesRoot, owner),
101
+ ];
133
102
  } catch {
134
103
  // A broken local root is not the caller's problem here.
135
104
  }
@@ -149,74 +118,6 @@ function resolveBaseTheme(slug, packageDir, owner, themesRoot) {
149
118
  return match;
150
119
  }
151
120
 
152
- /**
153
- * Rename a file from the base theme's namespace to the new theme's namespace.
154
- * Files whose name starts with the base identifier get the new identifier;
155
- * others keep their name as-is.
156
- * @param {string} file POSIX relative path inside the theme directory
157
- * @param {string} baseIdentifier
158
- * @param {string} newIdentifier
159
- * @returns {string}
160
- */
161
- function renameThemeFile(file, baseIdentifier, newIdentifier) {
162
- const basename = path.posix.basename(file);
163
- const dir = path.posix.dirname(file);
164
- if (!basename.startsWith(baseIdentifier)) return file;
165
- const renamed = newIdentifier + basename.slice(baseIdentifier.length);
166
- return dir === '.' ? renamed : `${dir}/${renamed}`;
167
- }
168
-
169
- /**
170
- * Rewrite a source file's contents from the base theme's names to the new
171
- * theme's names. This replaces:
172
- * 1. Identifier prefixes (camelCase variables, import paths): baseIdentifier
173
- * followed by an uppercase letter.
174
- * 2. The theme slug in string literals: 'baseSlug' → 'newSlug' and
175
- * 'astryx-baseSlug' → 'astryx-newSlug'.
176
- * 3. CSS custom properties scoped to the theme: --astryx-theme-baseSlug-.
177
- * @param {string} source
178
- * @param {string} baseSlug
179
- * @param {string} baseIdentifier
180
- * @param {string} newSlug
181
- * @param {string} newIdentifier
182
- * @returns {string}
183
- */
184
- function rewriteThemeSource(
185
- source,
186
- baseSlug,
187
- baseIdentifier,
188
- newSlug,
189
- newIdentifier,
190
- ) {
191
- let result = source;
192
- // 1. Identifier prefixes: neutralPalettes → oceanPalettes, neutralTheme → oceanTheme
193
- const identRe = new RegExp(`${escapeRegExp(baseIdentifier)}(?=[A-Z])`, 'gu');
194
- result = result.replace(identRe, newIdentifier);
195
- // 2. String-literal theme names
196
- result = result.replace(
197
- new RegExp(`'astryx-${escapeRegExp(baseSlug)}'`, 'gu'),
198
- `'astryx-${newSlug}'`,
199
- );
200
- result = result.replace(
201
- new RegExp(`'${escapeRegExp(baseSlug)}'`, 'gu'),
202
- `'${newSlug}'`,
203
- );
204
- // 3. CSS custom properties scoped to the base theme
205
- result = result.replace(
206
- new RegExp(
207
- `--astryx-theme-${escapeRegExp(baseSlug)}-`,
208
- 'gu',
209
- ),
210
- `--astryx-theme-${newSlug}-`,
211
- );
212
- return result;
213
- }
214
-
215
- /** @param {string} s */
216
- function escapeRegExp(s) {
217
- return s.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
218
- }
219
-
220
121
  /** What every app that uses Astryx already has: Core, and React through Core's peers. */
221
122
  const APP_PROVIDED = new Set(['@astryxdesign/core', 'react', 'react-dom']);
222
123
 
@@ -332,6 +233,10 @@ function forkThemePlans(base, identity, themeDir) {
332
233
  identity.slug,
333
234
  identity.identifier,
334
235
  );
236
+ // The entry's defineTheme name, wherever it sits (a double-quoted name,
237
+ // one after `extends`), is the fork's, as the build names its files.
238
+ if (file === base.files[0])
239
+ contents = renameDefinedTheme(contents, identity.slug) ?? contents;
335
240
  } else {
336
241
  contents = bytes;
337
242
  }
@@ -6,6 +6,15 @@
6
6
  * @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
7
7
  */
8
8
  export function themeRecordOwner(theme: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme): string;
9
+ /**
10
+ * Whether `--package <name>` selects a theme. It takes either name the CLI
11
+ * shows for it: the package that provides it (`@astryxdesign/cli` for a
12
+ * bundled theme) or the package the app imports it from, which the record
13
+ * holds (`@astryxdesign/theme-butter`).
14
+ * @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
15
+ * @param {string | undefined} name
16
+ */
17
+ export function themeInPackage(theme: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme, name: string | undefined): boolean;
9
18
  /**
10
19
  * A bundled theme entry kept for the historical public `listThemes()` helper.
11
20
  * @typedef {Pick<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme, 'slug' | 'displayName' | 'description' | 'maintained' | 'entry' | 'exportName' | 'files'>} BundledTheme
@@ -66,14 +75,21 @@ export function listUnmigratedThemeCopies(cwd: string): import("../../foundation
66
75
  /**
67
76
  * Publish one theme's complete source inventory as an atomic local fork.
68
77
  * @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
69
- * @param {{cwd: string, targetPath?: string, overwrite?: boolean}} options
70
- * @returns {string} project-relative output directory
78
+ * @param {{cwd: string, targetPath?: string, overwrite?: boolean, takenSlugs?: Set<string>}} options
79
+ * `takenSlugs`: the slugs of the themes the project can use, which a fork's
80
+ * new folder name may not take
81
+ * @returns {{outputDir: string, files: string[]}} the project-relative output
82
+ * directory and the files written, named as the fork names them
71
83
  */
72
- export function ejectThemeFiles(theme: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme, { cwd, targetPath, overwrite }: {
84
+ export function ejectThemeFiles(theme: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme, { cwd, targetPath: typedPath, overwrite, takenSlugs }: {
73
85
  cwd: string;
74
86
  targetPath?: string;
75
87
  overwrite?: boolean;
76
- }): string;
88
+ takenSlugs?: Set<string>;
89
+ }): {
90
+ outputDir: string;
91
+ files: string[];
92
+ };
77
93
  /**
78
94
  * The packages the fork imports that the app does not declare. A fork that
79
95
  * imports a missing package (bundled icon sets use `lucide-react`) fails to
@@ -91,14 +107,30 @@ export function forkNeeds(outputDir: string, files: string[], cwd: string): {
91
107
  * Without an explicit package, a local theme shadows package themes that share
92
108
  * its slug. Other duplicate slugs fail closed until the caller selects an owner.
93
109
  * @param {string} [slug]
94
- * @param {{cwd?: string, package?: string, includeLocal?: boolean}} [options]
110
+ * @param {{cwd?: string, package?: string, includeLocal?: boolean, command?: string}} [options]
111
+ * `command`: the command a refusal suggests running with `--package`,
112
+ * `theme add` by default
95
113
  * @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme | undefined>}
96
114
  */
97
115
  export function findTheme(slug?: string, options?: {
98
116
  cwd?: string;
99
117
  package?: string;
100
118
  includeLocal?: boolean;
119
+ command?: string;
101
120
  }): Promise<import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme | undefined>;
121
+ /**
122
+ * Runnable `<command> <slug>` suggestions for an unknown slug, closest names
123
+ * first; `--package` is named only where packages share a slug.
124
+ * @param {string} command such as `theme add`
125
+ * @param {string} slug what the person typed
126
+ * @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} available
127
+ * @param {string} cwd
128
+ * @returns {Array<{theme: import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme, name: string}>}
129
+ */
130
+ export function themeCommandsFor(command: string, slug: string, available: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme[], cwd: string): Array<{
131
+ theme: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme;
132
+ name: string;
133
+ }>;
102
134
  /**
103
135
  * Read the generated module's app-theme record with stable CLI errors.
104
136
  * @param {string} [cwd]