@astryxdesign/cli 0.7.14-canary.gfdb9213 → 0.7.14

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 (95) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/api/theme/_adapter.d.mts +33 -0
  3. package/api/theme/_adapter.mjs +352 -16
  4. package/api/theme/build/build.mjs +261 -10
  5. package/api/theme/eject/eject.mjs +13 -1
  6. package/api/theme/list/list.mjs +11 -2
  7. package/api/theme/template/template.mjs +139 -6
  8. package/api/theme/theme.type.d.mts +15 -1
  9. package/api/theme/theme.type.mjs +9 -3
  10. package/api/theme/themeAdd.doc.mjs +1 -1
  11. package/api/theme/themeBuild.doc.mjs +10 -2
  12. package/api/theme/themeEject.doc.mjs +2 -2
  13. package/api/theme/themeListAvailable.doc.mjs +1 -1
  14. package/api/theme/themeRemove.doc.mjs +1 -1
  15. package/api/theme/themeTemplate.doc.mjs +8 -0
  16. package/api/theme/themeUse.doc.mjs +1 -1
  17. package/api/theme-edit/_adapter.d.mts +10 -2
  18. package/api/theme-edit/_adapter.mjs +52 -31
  19. package/api/theme-edit/_check.d.mts +28 -25
  20. package/api/theme-edit/_check.mjs +586 -548
  21. package/api/theme-edit/_color.d.mts +28 -2
  22. package/api/theme-edit/_color.mjs +306 -68
  23. package/api/theme-edit/_compiler.d.mts +8 -4
  24. package/api/theme-edit/_compiler.mjs +30 -27
  25. package/api/theme-edit/_context.d.mts +10 -4
  26. package/api/theme-edit/_context.mjs +21 -4
  27. package/api/theme-edit/_edit.mjs +300 -43
  28. package/api/theme-edit/_how-commands.d.mts +91 -0
  29. package/api/theme-edit/_how-commands.mjs +269 -0
  30. package/api/theme-edit/_how-question.d.mts +57 -0
  31. package/api/theme-edit/_how-question.mjs +2574 -0
  32. package/api/theme-edit/_how.d.mts +25 -17
  33. package/api/theme-edit/_how.mjs +727 -305
  34. package/api/theme-edit/_palette.d.mts +127 -19
  35. package/api/theme-edit/_palette.mjs +1313 -399
  36. package/api/theme-edit/_parts.mjs +36 -3
  37. package/api/theme-edit/_png.d.mts +18 -6
  38. package/api/theme-edit/_png.mjs +135 -25
  39. package/api/theme-edit/_preview-app.d.mts +26 -7
  40. package/api/theme-edit/_preview-app.mjs +1611 -280
  41. package/api/theme-edit/_preview.d.mts +4 -2
  42. package/api/theme-edit/_preview.mjs +18 -7
  43. package/api/theme-edit/_settings.d.mts +56 -5
  44. package/api/theme-edit/_settings.mjs +197 -49
  45. package/api/theme-edit/_tables.d.mts +0 -12
  46. package/api/theme-edit/_tables.mjs +24 -97
  47. package/api/theme-edit/theme-edit.type.d.mts +22 -5
  48. package/api/theme-edit/theme-edit.type.mjs +17 -6
  49. package/api/theme-edit/themeEditHow.doc.mjs +13 -3
  50. package/api/theme-edit/themeEditNew.doc.mjs +2 -1
  51. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +16 -4
  52. package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -4
  53. package/api/theme-edit/themeEditPreviewList.doc.mjs +9 -1
  54. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +27 -2
  55. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  56. package/assets/docs.generated.json +1 -0
  57. package/assets/preview-app/gitignore +3 -0
  58. package/assets/templates/components.generated.json +1 -0
  59. package/clients/cli/bin/astryx.mjs +37 -5
  60. package/clients/cli/commands/experimental/theme.mjs +231 -31
  61. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +14 -5
  62. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -1
  63. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  64. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
  65. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -2
  66. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
  67. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  68. package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
  69. package/clients/cli/commands/experimental-theme.doc.mjs +2 -2
  70. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  71. package/clients/cli/commands/theme-eject.doc.mjs +3 -3
  72. package/clients/cli/commands/theme-remove.doc.mjs +2 -2
  73. package/clients/cli/commands/theme-template.doc.mjs +11 -4
  74. package/clients/cli/commands/theme.mjs +104 -40
  75. package/clients/cli/commands.generated.json +1 -0
  76. package/clients/cli/index.mjs +96 -4
  77. package/clients/cli/lib/json-shim.mjs +29 -1
  78. package/foundation/config/project.d.mts +16 -2
  79. package/foundation/config/project.mjs +40 -6
  80. package/foundation/config/theme-state.d.mts +9 -0
  81. package/foundation/config/theme-state.mjs +20 -1
  82. package/foundation/discovery/template-adapter.d.mts +12 -1
  83. package/foundation/discovery/template-adapter.mjs +24 -1
  84. package/foundation/discovery/template-needs.d.mts +7 -0
  85. package/foundation/discovery/template-needs.mjs +117 -8
  86. package/foundation/discovery/template-source-tree.d.mts +5 -1
  87. package/foundation/discovery/template-source-tree.mjs +6 -4
  88. package/foundation/discovery/theme-discovery.d.mts +14 -3
  89. package/foundation/discovery/theme-discovery.mjs +45 -12
  90. package/foundation/doc-compiler/import.mjs +68 -3
  91. package/foundation/doc-compiler/stored-docs.d.mts +27 -0
  92. package/foundation/doc-compiler/stored-docs.mjs +65 -0
  93. package/foundation/fs/fs-error.d.mts +17 -0
  94. package/foundation/fs/fs-error.mjs +34 -0
  95. package/package.json +6 -6
@@ -59,7 +59,7 @@ export const doc = {
59
59
  {
60
60
  type: 'theme.app',
61
61
  description:
62
- 'The complete generated-module state and add change. Its envelope package names the npm package that owns the added theme, except for a local theme.',
62
+ 'The complete generated-module state and add change. Its envelope package names the npm package that owns the added theme, except for a local theme. data.notes, present only when needed, says which owner was chosen when a local theme shadows a package theme with the same slug, names a replaced recorded owner, and names added themes left out because their local folder or package is gone (a theme that is only broken or not installed yet still fails the command).',
63
63
  },
64
64
  ],
65
65
  throws: [
@@ -58,7 +58,7 @@ export const doc = {
58
58
  name: 'options.out',
59
59
  type: 'string',
60
60
  description:
61
- 'Override the output CSS path, relative or absolute; a build refuses a path outside cwd, and check mode refuses only a relative path that escapes cwd. The .js, .d.ts and any .variants.d.ts are written in the same directory, named after the theme (<name>.js), not after the CSS file.',
61
+ 'Override the output CSS path, relative or absolute; a build refuses a path outside cwd, and check mode refuses only a relative path that escapes cwd. The .js, .d.ts and any .variants.d.ts are written in the same directory, named after the theme (<name>.js), not after the CSS file. An existing folder, or a path that ends in a separator, names the folder: the CSS is written there as <name>.css.',
62
62
  },
63
63
  {
64
64
  name: 'options.check',
@@ -101,7 +101,15 @@ export const doc = {
101
101
  },
102
102
  {
103
103
  code: 'ERR_THEME_INVALID',
104
- when: 'the resolved theme is invalid, for example it has no name, a custom Heading type has no standalone rule with a declaration the compiler can emit, or its icon registry cannot be preserved through an import (also rejected in check mode)',
104
+ when: 'the resolved theme is invalid, for example it has no name, a custom Heading type has no standalone rule with a declaration the compiler can emit, or its icon registry cannot be preserved through an import (also rejected in check mode); or an output would replace the theme source, two outputs share one path, or the file is itself an output of a build',
105
+ },
106
+ {
107
+ code: 'ERR_FILE_EXISTS',
108
+ when: 'a path that out names holds a non-empty file without the generated header, such as package.json, app source, or an output from a CLI before 0.6.7; nothing is written. Delete the file and run the same build again (the suggestion), or pick another out path. At the default paths beside the source, and at family output paths, a header-less file is an output of a CLI before 0.6.7 and is replaced',
109
+ },
110
+ {
111
+ code: 'ERR_INVALID_ARGUMENT',
112
+ when: 'the theme file is a folder',
105
113
  },
106
114
  {
107
115
  code: 'ERR_PATH_TRAVERSAL',
@@ -56,7 +56,7 @@ export const doc = {
56
56
  {
57
57
  type: 'theme.eject',
58
58
  description:
59
- 'Eject receipt with slug, displayName, the source theme maintained flag, source-selector package, outputDir, entry, exportName, and files. The written local descriptor always uses maintained: false.',
59
+ 'Eject receipt with slug, displayName, the source theme maintained flag, source-selector package, outputDir, entry, exportName, files, missingPackages (packages the fork imports that the app does not declare), and installCommand (installs them; null when none are missing or the package manager is undetermined). The written local descriptor always uses maintained: false.',
60
60
  },
61
61
  ],
62
62
  throws: [
@@ -73,7 +73,7 @@ export const doc = {
73
73
  {code: 'ERR_NO_SOURCE', when: 'a theme file to eject is missing'},
74
74
  {
75
75
  code: 'ERR_FILE_EXISTS',
76
- when: 'a destination exists and overwrite is not set',
76
+ when: 'a destination exists and overwrite is not set, or the target folder holds another theme or a theme the theme editor made',
77
77
  },
78
78
  {code: 'ERR_WRITE_FAILED', when: 'writing files fails'},
79
79
  ],
@@ -36,7 +36,7 @@ export const doc = {
36
36
  {
37
37
  type: 'theme.list',
38
38
  description:
39
- 'Every available theme as ThemeListEntry[], plus optional meta.unmigratedCopies entries with the source path, missing descriptor, and upgrade command. Unmigrated copies are not included in data.',
39
+ 'Every available theme as ThemeListEntry[], plus optional meta.unmigratedCopies entries with the source path, missing descriptor, and upgrade command. Unmigrated copies are not included in data. A broken local theme folder is left out of data and listed in meta.skippedThemes ({slug, path, reason}); the other themes are still listed.',
40
40
  },
41
41
  ],
42
42
  throws: [
@@ -33,7 +33,7 @@ export const doc = {
33
33
  {
34
34
  type: 'theme.app',
35
35
  description:
36
- 'Every remaining theme and its imports, the default slug, the generated module path, and the remove change.',
36
+ 'Every remaining theme and its imports, the default slug, the generated module path, and the remove change. The default is never removed: choose another with themeUse first, which also works when the folder or package of the default is gone. Other added themes whose local folder or package is gone are left out, with a note in data.notes.',
37
37
  },
38
38
  ],
39
39
  throws: [
@@ -56,6 +56,14 @@ export const doc = {
56
56
  ],
57
57
  throws: [
58
58
  {code: 'ERR_PATH_TRAVERSAL', when: 'the target path escapes cwd'},
59
+ {
60
+ code: 'ERR_INVALID_ARGUMENT',
61
+ when: 'the target path is blank, names a folder, or is not a .ts file',
62
+ },
63
+ {
64
+ code: 'ERR_FILE_EXISTS',
65
+ when: 'overwrite names a file that is not a copy of the template or a theme source, or a file in a folder the theme editor made (folder <slug>/ holds <slug>.settings.json)',
66
+ },
59
67
  {code: 'ERR_WRITE_FAILED', when: 'the template file cannot be written'},
60
68
  ],
61
69
  examples: [
@@ -33,7 +33,7 @@ export const doc = {
33
33
  {
34
34
  type: 'theme.app',
35
35
  description:
36
- 'Every added theme and its imports, the selected default, the generated module path, and the use change.',
36
+ 'Every added theme and its imports, the selected default, the generated module path, and the use change. Added themes whose local folder or package is gone are left out of the record, and data.notes names each one. A theme that is only broken, or whose package is declared but not installed, still fails the command.',
37
37
  },
38
38
  ],
39
39
  throws: [
@@ -12,7 +12,8 @@
12
12
  * @param {string} cwd
13
13
  */
14
14
  export function projectRoot(cwd: string): string;
15
- export const themeEditPreviewApp: typeof preview.themeEditPreviewApp;
15
+ export function isHowPicture(word: string, cwd?: string): boolean;
16
+ export function fileExists(file: string, cwd?: string): boolean;
16
17
  /** @type {typeof edit.themeEditNew} */
17
18
  export const themeEditNew: typeof edit.themeEditNew;
18
19
  /** @type {typeof edit.themeEditSet} */
@@ -23,10 +24,17 @@ export const themeEditUndo: typeof edit.themeEditUndo;
23
24
  export const themeEditShow: typeof edit.themeEditShow;
24
25
  /** @type {typeof preview.themeEditPreviewAdd} */
25
26
  export const themeEditPreviewAdd: typeof preview.themeEditPreviewAdd;
27
+ /**
28
+ * `preview app` runs from the project root, with `dir` kept pointing where
29
+ * it was given. With a theme it holds that theme's lock, since it may build
30
+ * the theme and copies its files: a `set` beside it waits.
31
+ * @type {typeof preview.themeEditPreviewApp}
32
+ */
33
+ export const themeEditPreviewApp: typeof preview.themeEditPreviewApp;
26
34
  /** @type {typeof preview.themeEditPreviewList} */
27
35
  export const themeEditPreviewList: typeof preview.themeEditPreviewList;
28
36
  /** @type {typeof preview.themeEditPreviewRemove} */
29
37
  export const themeEditPreviewRemove: typeof preview.themeEditPreviewRemove;
30
- import * as preview from './_preview-app.mjs';
31
38
  import * as edit from './_edit.mjs';
39
+ import * as preview from './_preview-app.mjs';
32
40
  export { themeEditHow, parsePoints } from "./_how.mjs";
@@ -42,12 +42,31 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
42
42
  import {
43
43
  findAstryxProject,
44
44
  findPackageRoot,
45
+ findProjectCoreDir,
45
46
  } from '../../foundation/fs/paths.mjs';
47
+ import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
46
48
  import {tryLock} from '../../foundation/release/cache.mjs';
47
49
  import {q} from './_settings.mjs';
48
50
 
49
51
  export {themeEditHow, parsePoints} from './_how.mjs';
50
- export const {themeEditPreviewApp} = preview;
52
+ import {isPicture as howPicture} from './_how.mjs';
53
+
54
+ /**
55
+ * Whether `how`'s first word names a picture, as the API decides it, for
56
+ * the command line's own argument checks. The file system is read here.
57
+ * @param {string} word
58
+ * @param {string} [cwd]
59
+ */
60
+ export const isHowPicture = (word, cwd = process.cwd()) =>
61
+ howPicture(word, cwd);
62
+
63
+ /**
64
+ * Whether a file named on the command line exists, read here.
65
+ * @param {string} file
66
+ * @param {string} [cwd]
67
+ */
68
+ export const fileExists = (file, cwd = process.cwd()) =>
69
+ fs.existsSync(path.resolve(cwd, file));
51
70
 
52
71
  /**
53
72
  * The project a command acts on: the Astryx project at or above `cwd`, found
@@ -100,23 +119,6 @@ export function projectRoot(cwd) {
100
119
  return project ?? start;
101
120
  }
102
121
 
103
- /**
104
- * The node_modules folder Core resolves from for `root` (its own, or one
105
- * above it, as Node finds packages), or null when Core is not installed.
106
- * @param {string} root
107
- * @returns {string | null}
108
- */
109
- function coreModules(root) {
110
- for (let d = root; ; d = path.dirname(d)) {
111
- const modules = path.join(d, 'node_modules');
112
- if (
113
- fs.existsSync(path.join(modules, '@astryxdesign', 'core', 'package.json'))
114
- )
115
- return modules;
116
- if (path.dirname(d) === d) return null;
117
- }
118
- }
119
-
120
122
  /** The locks this process holds now. */
121
123
  const HELD = new Set();
122
124
 
@@ -124,18 +126,22 @@ const HELD = new Set();
124
126
  const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
125
127
 
126
128
  /**
127
- * Where a project's locks are: the `.cache` of the node_modules its Core
128
- * is installed in (the project's own, or a workspace root's), shared by
129
+ * Where a project's locks are: the `.cache` of the node_modules holding
130
+ * the Core the command reads (the project's own, or a workspace root's), shared by
129
131
  * every shell and user that can change the project, outside the source
130
- * tree. Null when Core is not installed for it (nothing can be written
131
- * without Core, so there is nothing to keep apart). A folder that
132
+ * tree. Null outside a project or without Core (nothing can be written
133
+ * then, so there is nothing to keep apart). A folder that
132
134
  * cannot be written is refused, naming it.
133
135
  * @param {string} root
134
136
  * @returns {string | null}
135
137
  */
136
138
  function lockDir(root) {
137
- const modules = coreModules(root);
138
- if (!modules) return null;
139
+ // The Core the command reads decides where; outside a project there is
140
+ // none, and no lock.
141
+ if (isOutsideProject(root)) return null;
142
+ const core = findProjectCoreDir(root);
143
+ if (!core) return null;
144
+ const modules = path.dirname(path.dirname(core));
139
145
  const dir = path.join(modules, '.cache', 'astryx-theme', 'locks');
140
146
  try {
141
147
  fs.mkdirSync(dir, {recursive: true});
@@ -193,13 +199,8 @@ async function withLock(root, name, fn) {
193
199
  if (waited > 30_000) {
194
200
  const o = owner();
195
201
  throw new AstryxError(
196
- `Another command is changing ${name.replace(/^theme-/, '')} and did not finish within 30 seconds${o ? ` (process ${o.pid} on ${o.host}, for ${Math.round((Date.now() - Number(o.at)) / 1000)} s)` : ''}. Nothing was changed; run this command again. If no astryx command is running, remove the lock ${lock}.`,
197
- [
198
- {
199
- name: `rm -r ${q(lock)}`,
200
- reason: 'only when no astryx command is running',
201
- },
202
- ],
202
+ `Another command is changing ${name.replace(/^theme-/, '')} and did not finish within 30 seconds${o ? ` (process ${o.pid} on ${o.host}, for ${Math.round((Date.now() - Number(o.at)) / 1000)} 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}.`,
203
+ [],
203
204
  ERROR_CODES.ERR_THEME_BUSY,
204
205
  );
205
206
  }
@@ -345,6 +346,26 @@ export const themeEditPreviewAdd = (description, options = {}) =>
345
346
  inProject(options, 'preview', o =>
346
347
  preview.themeEditPreviewAdd(description, o),
347
348
  );
349
+ /**
350
+ * `preview app` runs from the project root, with `dir` kept pointing where
351
+ * it was given. With a theme it holds that theme's lock, since it may build
352
+ * the theme and copies its files: a `set` beside it waits.
353
+ * @type {typeof preview.themeEditPreviewApp}
354
+ */
355
+ export const themeEditPreviewApp = (dir, options = {}) => {
356
+ const from = options.cwd ?? process.cwd();
357
+ return inProject(
358
+ options,
359
+ options.theme == null ? null : lockName(options.theme),
360
+ o =>
361
+ preview.themeEditPreviewApp(
362
+ typeof dir === 'string' && dir.trim() && dir === dir.trim()
363
+ ? path.relative(o.cwd, path.resolve(from, dir)) || '.'
364
+ : dir,
365
+ o,
366
+ ),
367
+ );
368
+ };
348
369
  /** @type {typeof preview.themeEditPreviewList} */
349
370
  export const themeEditPreviewList = (options = {}) =>
350
371
  inProject(options, null, async o => preview.themeEditPreviewList(o));
@@ -1,6 +1,34 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * @typedef {object} SetFlags
6
+ * @property {string} [on]
7
+ * @property {string} [when]
8
+ * @property {string} [state]
9
+ * @property {string} [mode]
10
+ * @property {boolean} [only]
11
+ */
12
+ /**
13
+ * The first exact token setting whose value the type rules refuse now (a
14
+ * hand edit, or a value an earlier release took), with why; null when all
15
+ * pass. `skip` is the thing the command changes or removes.
16
+ * @param {import('./_settings.mjs').Ctx} ctx
17
+ * @param {string} slug
18
+ * @param {import('./_settings.mjs').ThemeData} data
19
+ * @param {string} [skip]
20
+ * @returns {{setting: import('./_settings.mjs').Setting, why: string} | null}
21
+ */
22
+ export function storedTokenProblem(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, skip?: string): {
23
+ setting: import("./_settings.mjs").Setting;
24
+ why: string;
25
+ } | null;
26
+ /**
27
+ * A value of a type to put in a suggestion, so a suggested command runs.
28
+ * @param {string} type
29
+ * @param {string} name
30
+ */
31
+ export function exampleOf(type: string, name: string): string;
4
32
  /**
5
33
  * Check one setting and give it back ready to store, or refuse.
6
34
  * @param {import('./_settings.mjs').Ctx} ctx
@@ -13,31 +41,6 @@
13
41
  * @returns {import('./_settings.mjs').Setting}
14
42
  */
15
43
  export function checkSetting(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, thing: string, value: string | undefined, flags: SetFlags, unset?: boolean): import("./_settings.mjs").Setting;
16
- /**
17
- * Answer a plain-words question with exact commands: the parts it names,
18
- * the aspects it asks about, and what each part really reads for them.
19
- * @param {import('./_settings.mjs').Ctx} ctx
20
- * @param {string} question
21
- * @returns {{parts: string[], aspects: string[], results: Array<{text: string, commands: string[]}>}}
22
- */
23
- export function answerHow(ctx: import("./_settings.mjs").Ctx, question: string): {
24
- parts: string[];
25
- aspects: string[];
26
- results: Array<{
27
- text: string;
28
- commands: string[];
29
- }>;
30
- };
31
- /**
32
- * The tokens most parts read for one aspect, for a whole-theme change.
33
- * @param {import('./_settings.mjs').Ctx} ctx
34
- * @param {string} aspect
35
- * @returns {Array<{text: string, commands: string[]}>}
36
- */
37
- export function wholeThemeTokens(ctx: import("./_settings.mjs").Ctx, aspect: string): Array<{
38
- text: string;
39
- commands: string[];
40
- }>;
41
44
  /** The aspects `how` answers at the whole-theme level. */
42
45
  export const ASPECTS: string[];
43
46
  export type SetFlags = {