@astryxdesign/cli 0.7.14-canary.gfb823d9 → 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.
- package/CHANGELOG.md +197 -0
- package/api/component/_adapter.d.mts +15 -0
- package/api/component/_adapter.mjs +76 -0
- package/api/component/component.mjs +8 -1
- package/api/search/_named-keywords.d.mts +31 -0
- package/api/search/_named-keywords.mjs +177 -0
- package/api/search/search-index.mjs +8 -1
- package/api/search/search.d.mts +6 -1
- package/api/search/search.mjs +49 -8
- package/api/theme/_adapter.d.mts +33 -0
- package/api/theme/_adapter.mjs +352 -16
- package/api/theme/build/build.mjs +261 -10
- package/api/theme/eject/eject.mjs +13 -1
- package/api/theme/list/list.mjs +11 -2
- package/api/theme/palette/generate/color.d.mts +2 -0
- package/api/theme/palette/generate/color.mjs +1 -1
- package/api/theme/template/template.mjs +139 -6
- package/api/theme/theme.type.d.mts +15 -1
- package/api/theme/theme.type.mjs +9 -3
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeBuild.doc.mjs +10 -2
- package/api/theme/themeEject.doc.mjs +2 -2
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +8 -0
- package/api/theme/themeUse.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +36 -2
- package/api/theme-edit/_adapter.mjs +340 -12
- package/api/theme-edit/_check.d.mts +28 -25
- package/api/theme-edit/_check.mjs +876 -308
- package/api/theme-edit/_color.d.mts +53 -4
- package/api/theme-edit/_color.mjs +406 -79
- package/api/theme-edit/_compiler.d.mts +14 -6
- package/api/theme-edit/_compiler.mjs +89 -59
- package/api/theme-edit/_context.d.mts +28 -8
- package/api/theme-edit/_context.mjs +142 -19
- package/api/theme-edit/_edit.d.mts +3 -1
- package/api/theme-edit/_edit.mjs +746 -76
- package/api/theme-edit/_how-commands.d.mts +91 -0
- package/api/theme-edit/_how-commands.mjs +269 -0
- package/api/theme-edit/_how-question.d.mts +57 -0
- package/api/theme-edit/_how-question.mjs +2574 -0
- package/api/theme-edit/_how.d.mts +27 -8
- package/api/theme-edit/_how.mjs +776 -175
- package/api/theme-edit/_overview.d.mts +9 -0
- package/api/theme-edit/_overview.mjs +296 -0
- package/api/theme-edit/_palette.d.mts +155 -15
- package/api/theme-edit/_palette.mjs +1446 -262
- package/api/theme-edit/_parts.mjs +61 -5
- package/api/theme-edit/_png.d.mts +18 -6
- package/api/theme-edit/_png.mjs +135 -25
- package/api/theme-edit/_preview-app.d.mts +32 -11
- package/api/theme-edit/_preview-app.mjs +1976 -285
- package/api/theme-edit/_preview.d.mts +39 -8
- package/api/theme-edit/_preview.mjs +367 -41
- package/api/theme-edit/_settings.d.mts +147 -11
- package/api/theme-edit/_settings.mjs +908 -99
- package/api/theme-edit/_tables.d.mts +4 -16
- package/api/theme-edit/_tables.mjs +51 -117
- package/api/theme-edit/theme-edit.type.d.mts +102 -66
- package/api/theme-edit/theme-edit.type.mjs +58 -40
- package/api/theme-edit/themeEditHow.doc.mjs +17 -6
- package/api/theme-edit/themeEditNew.doc.mjs +21 -5
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +18 -5
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -9
- package/api/theme-edit/themeEditPreviewList.doc.mjs +11 -2
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +29 -3
- package/api/theme-edit/themeEditSet.doc.mjs +14 -8
- package/api/theme-edit/themeEditShow.doc.mjs +10 -5
- package/api/theme-edit/themeEditUndo.doc.mjs +9 -4
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/icon-sets.doc.mjs +3 -3
- package/assets/docs.generated.json +1 -0
- package/assets/icons/definitions/bookmarkAdd.doc.mjs +9 -0
- package/assets/icons/definitions/documentSearch.doc.mjs +9 -0
- package/assets/icons/definitions/keyboard.doc.mjs +9 -0
- package/assets/icons/definitions/paintBrush.doc.mjs +9 -0
- package/assets/icons/definitions/wallet.doc.mjs +9 -0
- package/assets/preview-app/gitignore +3 -0
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Lightbox/LightboxGallery.tsx +1 -1
- package/assets/templates/components.generated.json +1 -0
- package/assets/templates/pages/gallery-hero/page.tsx +8 -2
- package/assets/templates/pages/settings-dialog/template.doc.mjs +3 -3
- package/assets/templates/pages/side-gallery/page.tsx +1 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +2 -2
- package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -1
- package/clients/cli/bin/astryx.mjs +37 -5
- package/clients/cli/commands/experimental/theme.mjs +422 -57
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +22 -9
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +103 -4
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +13 -8
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +5 -5
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +5 -5
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +3 -4
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/commands/theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/theme-remove.doc.mjs +2 -2
- package/clients/cli/commands/theme-template.doc.mjs +11 -4
- package/clients/cli/commands/theme.mjs +145 -46
- package/clients/cli/commands.generated.json +1 -0
- package/clients/cli/index.mjs +96 -5
- package/clients/cli/lib/json-shim.mjs +29 -1
- package/foundation/config/project.d.mts +16 -2
- package/foundation/config/project.mjs +40 -6
- package/foundation/config/theme-state.d.mts +9 -0
- package/foundation/config/theme-state.mjs +20 -1
- package/foundation/discovery/template-adapter.d.mts +12 -1
- package/foundation/discovery/template-adapter.mjs +29 -4
- package/foundation/discovery/template-icons.d.mts +13 -0
- package/foundation/discovery/template-icons.mjs +76 -0
- package/foundation/discovery/template-needs.d.mts +7 -0
- package/foundation/discovery/template-needs.mjs +117 -8
- package/foundation/discovery/template-source-tree.d.mts +5 -1
- package/foundation/discovery/template-source-tree.mjs +6 -4
- package/foundation/discovery/theme-discovery.d.mts +14 -3
- package/foundation/discovery/theme-discovery.mjs +45 -12
- package/foundation/doc-compiler/import.mjs +68 -3
- package/foundation/doc-compiler/stored-docs.d.mts +27 -0
- package/foundation/doc-compiler/stored-docs.mjs +65 -0
- package/foundation/fs/fs-error.d.mts +17 -0
- package/foundation/fs/fs-error.mjs +34 -0
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.doc.mjs +13 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +6 -6
- package/package.json +6 -7
- package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +0 -73
- package/clients/cli/commands/experimental-theme-palette.doc.mjs +0 -37
package/api/theme/theme.type.mjs
CHANGED
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
* @typedef {object} ThemeListResponse
|
|
80
80
|
* @property {'theme.list'} type
|
|
81
81
|
* @property {ThemeListEntry[]} data
|
|
82
|
-
* @property {{unmigratedCopies: ThemeUnmigratedCopy[]}} [meta] descriptor-less released copies that are not listed as themes
|
|
82
|
+
* @property {{unmigratedCopies: ThemeUnmigratedCopy[], skippedThemes?: Array<{slug: string, path: string, reason: string}>}} [meta] descriptor-less released copies that are not listed as themes; local theme folders left out because they are broken
|
|
83
83
|
*/
|
|
84
84
|
|
|
85
85
|
/**
|
|
@@ -99,7 +99,10 @@
|
|
|
99
99
|
* @property {'theme.app'} type
|
|
100
100
|
* @property {string} [package] npm package that owns the theme `theme add`
|
|
101
101
|
* added. Omitted for a local theme, and for remove and use.
|
|
102
|
-
*
|
|
102
|
+
* `notes` is present only when the command did more than its change says:
|
|
103
|
+
* it chose between a local and a package theme with one slug, replaced a
|
|
104
|
+
* recorded owner, or dropped a recorded theme whose source is gone.
|
|
105
|
+
* @property {{themes: ThemeAppEntry[], default: string, modulePath: string, change: {action: 'add'|'remove'|'use', slug: string, changed: boolean, firstAdd: boolean}, notes?: string[]}} data
|
|
103
106
|
*/
|
|
104
107
|
|
|
105
108
|
/**
|
|
@@ -109,7 +112,10 @@
|
|
|
109
112
|
* `maintained` describes the selected source theme. The ejected descriptor is
|
|
110
113
|
* always written with `maintained: false` because the app owns the fork.
|
|
111
114
|
* `package` is the source selector; bundled themes retain `@astryxdesign/cli`.
|
|
112
|
-
*
|
|
115
|
+
* `missingPackages` names the packages the fork imports that the app does not
|
|
116
|
+
* declare (empty when none); `installCommand` installs them, and is null when
|
|
117
|
+
* none are missing or the package manager is undetermined.
|
|
118
|
+
* @property {{slug: string, displayName: string, maintained: boolean, package: string, outputDir: string, entry: string, exportName: string, files: string[], missingPackages: string[], installCommand: string | null}} data
|
|
113
119
|
*/
|
|
114
120
|
|
|
115
121
|
/**
|
|
@@ -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
|
|
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: [
|
|
@@ -1,6 +1,40 @@
|
|
|
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
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The project a command acts on: the Astryx project at or above `cwd`, found
|
|
6
|
+
* as `upgrade` finds it (the nearest package that declares an Astryx package
|
|
7
|
+
* in any dependency list; the search stops at a repository root and never
|
|
8
|
+
* counts the home folder or above), else `cwd` itself. A package nearer
|
|
9
|
+
* than that project that does not use Astryx is refused with the folder to
|
|
10
|
+
* run from, and a nearest package.json that does not parse is never walked
|
|
11
|
+
* past.
|
|
12
|
+
* @param {string} cwd
|
|
13
|
+
*/
|
|
14
|
+
export function projectRoot(cwd: string): string;
|
|
15
|
+
export function isHowPicture(word: string, cwd?: string): boolean;
|
|
16
|
+
export function fileExists(file: string, cwd?: string): boolean;
|
|
17
|
+
/** @type {typeof edit.themeEditNew} */
|
|
18
|
+
export const themeEditNew: typeof edit.themeEditNew;
|
|
19
|
+
/** @type {typeof edit.themeEditSet} */
|
|
20
|
+
export const themeEditSet: typeof edit.themeEditSet;
|
|
21
|
+
/** @type {typeof edit.themeEditUndo} */
|
|
22
|
+
export const themeEditUndo: typeof edit.themeEditUndo;
|
|
23
|
+
/** @type {typeof edit.themeEditShow} */
|
|
24
|
+
export const themeEditShow: typeof edit.themeEditShow;
|
|
25
|
+
/** @type {typeof preview.themeEditPreviewAdd} */
|
|
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;
|
|
34
|
+
/** @type {typeof preview.themeEditPreviewList} */
|
|
35
|
+
export const themeEditPreviewList: typeof preview.themeEditPreviewList;
|
|
36
|
+
/** @type {typeof preview.themeEditPreviewRemove} */
|
|
37
|
+
export const themeEditPreviewRemove: typeof preview.themeEditPreviewRemove;
|
|
38
|
+
import * as edit from './_edit.mjs';
|
|
39
|
+
import * as preview from './_preview-app.mjs';
|
|
6
40
|
export { themeEditHow, parsePoints } from "./_how.mjs";
|
|
@@ -31,16 +31,344 @@
|
|
|
31
31
|
* @position api/theme-edit — adapter for api/theme-edit/theme-edit.mjs
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
import {createHash} from 'node:crypto';
|
|
35
|
+
import * as fs from 'node:fs';
|
|
36
|
+
import * as os from 'node:os';
|
|
37
|
+
import * as path from 'node:path';
|
|
38
|
+
import * as edit from './_edit.mjs';
|
|
39
|
+
import * as preview from './_preview-app.mjs';
|
|
40
|
+
import {AstryxError} from '../error.mjs';
|
|
41
|
+
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
42
|
+
import {
|
|
43
|
+
findAstryxProject,
|
|
44
|
+
findPackageRoot,
|
|
45
|
+
findProjectCoreDir,
|
|
46
|
+
} from '../../foundation/fs/paths.mjs';
|
|
47
|
+
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
48
|
+
import {tryLock} from '../../foundation/release/cache.mjs';
|
|
49
|
+
import {q} from './_settings.mjs';
|
|
50
|
+
|
|
46
51
|
export {themeEditHow, parsePoints} from './_how.mjs';
|
|
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));
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The project a command acts on: the Astryx project at or above `cwd`, found
|
|
73
|
+
* as `upgrade` finds it (the nearest package that declares an Astryx package
|
|
74
|
+
* in any dependency list; the search stops at a repository root and never
|
|
75
|
+
* counts the home folder or above), else `cwd` itself. A package nearer
|
|
76
|
+
* than that project that does not use Astryx is refused with the folder to
|
|
77
|
+
* run from, and a nearest package.json that does not parse is never walked
|
|
78
|
+
* past.
|
|
79
|
+
* @param {string} cwd
|
|
80
|
+
*/
|
|
81
|
+
export function projectRoot(cwd) {
|
|
82
|
+
const start = path.resolve(cwd);
|
|
83
|
+
const project = findAstryxProject(start);
|
|
84
|
+
const pkg = findPackageRoot(start);
|
|
85
|
+
const inReach = (/** @type {string} */ dir) =>
|
|
86
|
+
project ? !path.relative(project, dir).startsWith('..') : true;
|
|
87
|
+
if (pkg && inReach(pkg) && pkg !== project) {
|
|
88
|
+
const file = path.join(pkg, 'package.json');
|
|
89
|
+
/** @type {any} */
|
|
90
|
+
let json;
|
|
91
|
+
try {
|
|
92
|
+
json = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
93
|
+
} catch {
|
|
94
|
+
throw new AstryxError(
|
|
95
|
+
`${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.`,
|
|
96
|
+
[],
|
|
97
|
+
ERROR_CODES.ERR_PROJECT_REQUIRED,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
// A package.json that only sets the module type (no name, no
|
|
101
|
+
// dependencies) is a folder setting, not another package.
|
|
102
|
+
const trivial =
|
|
103
|
+
json?.name == null &&
|
|
104
|
+
!['dependencies', 'devDependencies', 'peerDependencies'].some(
|
|
105
|
+
k => json?.[k] != null,
|
|
106
|
+
);
|
|
107
|
+
if (project && !trivial)
|
|
108
|
+
throw new AstryxError(
|
|
109
|
+
`${path.relative(start, file) || 'package.json'} is a package that does not use Astryx; the app that does is ${path.relative(start, project) || '.'}. Run the command from there, so the theme lands in that app. Nothing was written.`,
|
|
110
|
+
[
|
|
111
|
+
{
|
|
112
|
+
name: `cd ${q(path.relative(start, project))}`,
|
|
113
|
+
reason: 'do this first',
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
ERROR_CODES.ERR_PROJECT_REQUIRED,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return project ?? start;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The locks this process holds now. */
|
|
123
|
+
const HELD = new Set();
|
|
124
|
+
|
|
125
|
+
/** @param {number} ms */
|
|
126
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
127
|
+
|
|
128
|
+
/**
|
|
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
|
|
131
|
+
* every shell and user that can change the project, outside the source
|
|
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
|
|
134
|
+
* cannot be written is refused, naming it.
|
|
135
|
+
* @param {string} root
|
|
136
|
+
* @returns {string | null}
|
|
137
|
+
*/
|
|
138
|
+
function lockDir(root) {
|
|
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));
|
|
145
|
+
const dir = path.join(modules, '.cache', 'astryx-theme', 'locks');
|
|
146
|
+
try {
|
|
147
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
148
|
+
fs.accessSync(dir, fs.constants.W_OK);
|
|
149
|
+
return dir;
|
|
150
|
+
} catch (e) {
|
|
151
|
+
throw new AstryxError(
|
|
152
|
+
`Could not write ${path.relative(root, dir)} (${/** @type {any} */ (e).code ?? String(e)}), where the lock that keeps two commands on one theme apart is kept. Fix its permission, then run the command again. Nothing was changed.`,
|
|
153
|
+
[],
|
|
154
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Run `fn` holding a lock named `name` for the project at `root`, so two
|
|
161
|
+
* commands on one theme (or one preview) run one after the other: each one
|
|
162
|
+
* reads what the other wrote. The lock is a folder in the project's
|
|
163
|
+
* node_modules/.cache; a lock left by a command that is no longer running
|
|
164
|
+
* is taken over.
|
|
165
|
+
* @template T
|
|
166
|
+
* @param {string} root
|
|
167
|
+
* @param {string} name
|
|
168
|
+
* @param {() => Promise<T>} fn
|
|
169
|
+
* @returns {Promise<T>}
|
|
170
|
+
*/
|
|
171
|
+
async function withLock(root, name, fn) {
|
|
172
|
+
const dir = lockDir(root);
|
|
173
|
+
if (!dir) return fn();
|
|
174
|
+
const key = createHash('sha256').update(root).digest('hex').slice(0, 16);
|
|
175
|
+
const lock = path.join(dir, `${key}-${name}.lock`);
|
|
176
|
+
const ownerFile = path.join(lock, 'owner.json');
|
|
177
|
+
/** @returns {any} */
|
|
178
|
+
const owner = () => {
|
|
179
|
+
try {
|
|
180
|
+
return JSON.parse(fs.readFileSync(ownerFile, 'utf8'));
|
|
181
|
+
} catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
// A lock naming this very process on this computer, that this process
|
|
186
|
+
// does not hold, is left from a process that had this pid before (a
|
|
187
|
+
// container restarted).
|
|
188
|
+
const held = owner();
|
|
189
|
+
if (
|
|
190
|
+
held?.pid === process.pid &&
|
|
191
|
+
held?.host === os.hostname() &&
|
|
192
|
+
!HELD.has(lock)
|
|
193
|
+
)
|
|
194
|
+
fs.rmSync(lock, {recursive: true, force: true});
|
|
195
|
+
try {
|
|
196
|
+
// The release cache's lock: made with mkdir (one taker wins), and a
|
|
197
|
+
// holder that stopped is taken over by a rename (one taker wins).
|
|
198
|
+
for (let waited = 0; !tryLock(lock); waited += 50) {
|
|
199
|
+
if (waited > 30_000) {
|
|
200
|
+
const o = owner();
|
|
201
|
+
throw new AstryxError(
|
|
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
|
+
[],
|
|
204
|
+
ERROR_CODES.ERR_THEME_BUSY,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
await sleep(50);
|
|
208
|
+
}
|
|
209
|
+
} catch (e) {
|
|
210
|
+
if (e instanceof AstryxError) throw e;
|
|
211
|
+
throw new AstryxError(
|
|
212
|
+
`Could not take the lock ${lock} (${/** @type {any} */ (e).code ?? String(e)}). Nothing was changed; fix the folder, then run the command again.`,
|
|
213
|
+
[],
|
|
214
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
HELD.add(lock);
|
|
218
|
+
const mine = fs.existsSync(ownerFile)
|
|
219
|
+
? fs.readFileSync(ownerFile, 'utf8')
|
|
220
|
+
: null;
|
|
221
|
+
// Only this command's own lock is removed, never one another took over.
|
|
222
|
+
const release = () => {
|
|
223
|
+
try {
|
|
224
|
+
const now = fs.existsSync(ownerFile)
|
|
225
|
+
? fs.readFileSync(ownerFile, 'utf8')
|
|
226
|
+
: null;
|
|
227
|
+
if (now === mine) fs.rmSync(lock, {recursive: true, force: true});
|
|
228
|
+
} catch {
|
|
229
|
+
// Gone already.
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
// Stopped by a signal, the lock still goes.
|
|
233
|
+
const onSignal = (/** @type {NodeJS.Signals} */ sig) => {
|
|
234
|
+
release();
|
|
235
|
+
process.kill(process.pid, sig);
|
|
236
|
+
};
|
|
237
|
+
process.once('exit', release);
|
|
238
|
+
process.once('SIGINT', onSignal);
|
|
239
|
+
process.once('SIGTERM', onSignal);
|
|
240
|
+
try {
|
|
241
|
+
return await fn();
|
|
242
|
+
} catch (e) {
|
|
243
|
+
// A folder that cannot be written (no permission, a full or read-only
|
|
244
|
+
// disk) is a documented refusal, not a crash.
|
|
245
|
+
const code = /** @type {any} */ (e)?.code;
|
|
246
|
+
if (['EACCES', 'EPERM', 'ENOSPC', 'EROFS'].includes(code))
|
|
247
|
+
throw new AstryxError(
|
|
248
|
+
`Could not write ${path.relative(root, /** @type {any} */ (e).path ?? '') || 'the theme files'}: ${code === 'ENOSPC' ? 'the disk is full' : code === 'EROFS' ? 'the disk is read-only' : 'no permission'}. Free the space or fix the permission, then run the command again; a refused change is undone.`,
|
|
249
|
+
[],
|
|
250
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
251
|
+
);
|
|
252
|
+
throw e;
|
|
253
|
+
} finally {
|
|
254
|
+
release();
|
|
255
|
+
HELD.delete(lock);
|
|
256
|
+
process.removeListener('exit', release);
|
|
257
|
+
process.removeListener('SIGINT', onSignal);
|
|
258
|
+
process.removeListener('SIGTERM', onSignal);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Options with `cwd` moved to the project root, and a `--path` given from a
|
|
264
|
+
* subfolder kept pointing where it was given.
|
|
265
|
+
* @template {{cwd?: string, path?: string}} O
|
|
266
|
+
* @param {O} options
|
|
267
|
+
* @returns {O & {cwd: string}}
|
|
268
|
+
*/
|
|
269
|
+
function atRoot(options) {
|
|
270
|
+
const from = options.cwd ?? process.cwd();
|
|
271
|
+
const cwd = projectRoot(from);
|
|
272
|
+
return {
|
|
273
|
+
...options,
|
|
274
|
+
cwd,
|
|
275
|
+
...(options.path != null && options.path !== ''
|
|
276
|
+
? {path: path.relative(cwd, path.resolve(from, options.path)) || '.'}
|
|
277
|
+
: {}),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** @param {any} name */
|
|
282
|
+
const lockName = name =>
|
|
283
|
+
`theme-${String(name ?? '')
|
|
284
|
+
.replace(/[^a-z0-9-]/gi, '_')
|
|
285
|
+
.slice(0, 80)}`;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* A result whose theme paths read from the project root, made absolute when
|
|
289
|
+
* the command ran in a folder below that root, so a path in the reply
|
|
290
|
+
* points at the file wherever the person is.
|
|
291
|
+
* @template T
|
|
292
|
+
* @param {T} result
|
|
293
|
+
* @param {string} root
|
|
294
|
+
* @param {string} from
|
|
295
|
+
* @returns {T}
|
|
296
|
+
*/
|
|
297
|
+
function absolute(result, root, from) {
|
|
298
|
+
if (path.resolve(from) === root) return result;
|
|
299
|
+
/** @param {any} v @returns {any} */
|
|
300
|
+
const map = v =>
|
|
301
|
+
typeof v === 'string'
|
|
302
|
+
? /^themes\//.test(v)
|
|
303
|
+
? path.join(root, v)
|
|
304
|
+
: v
|
|
305
|
+
: Array.isArray(v)
|
|
306
|
+
? v.map(map)
|
|
307
|
+
: v && typeof v === 'object'
|
|
308
|
+
? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, map(x)]))
|
|
309
|
+
: v;
|
|
310
|
+
return map(result);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Run an editor command at the project root, holding `lock` when one is
|
|
315
|
+
* named, with paths in the reply that work from where it ran.
|
|
316
|
+
* @template {{cwd?: string, path?: string}} O
|
|
317
|
+
* @template T
|
|
318
|
+
* @param {O} options
|
|
319
|
+
* @param {string | null} lock
|
|
320
|
+
* @param {(o: O & {cwd: string}) => Promise<T>} fn
|
|
321
|
+
* @returns {Promise<T>}
|
|
322
|
+
*/
|
|
323
|
+
async function inProject(options, lock, fn) {
|
|
324
|
+
const from = options.cwd ?? process.cwd();
|
|
325
|
+
const o = atRoot(options);
|
|
326
|
+
const r = lock ? await withLock(o.cwd, lock, () => fn(o)) : await fn(o);
|
|
327
|
+
return absolute(r, o.cwd, from);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** @type {typeof edit.themeEditNew} */
|
|
331
|
+
export const themeEditNew = (name, options = {}) =>
|
|
332
|
+
inProject(options, lockName(name), o => edit.themeEditNew(name, o));
|
|
333
|
+
/** @type {typeof edit.themeEditSet} */
|
|
334
|
+
export const themeEditSet = (theme, thing, value, options = {}) =>
|
|
335
|
+
inProject(options, lockName(theme), o =>
|
|
336
|
+
edit.themeEditSet(theme, thing, value, o),
|
|
337
|
+
);
|
|
338
|
+
/** @type {typeof edit.themeEditUndo} */
|
|
339
|
+
export const themeEditUndo = (theme, options = {}) =>
|
|
340
|
+
inProject(options, lockName(theme), o => edit.themeEditUndo(theme, o));
|
|
341
|
+
/** @type {typeof edit.themeEditShow} */
|
|
342
|
+
export const themeEditShow = (theme, options = {}) =>
|
|
343
|
+
inProject(options, lockName(theme), o => edit.themeEditShow(theme, o));
|
|
344
|
+
/** @type {typeof preview.themeEditPreviewAdd} */
|
|
345
|
+
export const themeEditPreviewAdd = (description, options = {}) =>
|
|
346
|
+
inProject(options, 'preview', o =>
|
|
347
|
+
preview.themeEditPreviewAdd(description, o),
|
|
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
|
+
};
|
|
369
|
+
/** @type {typeof preview.themeEditPreviewList} */
|
|
370
|
+
export const themeEditPreviewList = (options = {}) =>
|
|
371
|
+
inProject(options, null, async o => preview.themeEditPreviewList(o));
|
|
372
|
+
/** @type {typeof preview.themeEditPreviewRemove} */
|
|
373
|
+
export const themeEditPreviewRemove = (page, options = {}) =>
|
|
374
|
+
inProject(options, 'preview', o => preview.themeEditPreviewRemove(page, 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 = {
|