@astryxdesign/cli 0.7.14 → 0.7.15-canary.g061b2fa
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/README.md +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +3 -1
- package/api/doctor/_adapter.mjs +14 -1
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.d.mts +17 -1
- package/api/theme/_adapter.mjs +185 -40
- package/api/theme/build/build.d.mts +29 -1
- package/api/theme/build/build.mjs +426 -65
- package/api/theme/eject/eject.mjs +10 -6
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +24 -4
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +7 -4
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +372 -109
- package/api/theme-edit/_check.d.mts +6 -3
- package/api/theme-edit/_check.mjs +665 -87
- package/api/theme-edit/_color.mjs +4 -2
- package/api/theme-edit/_compiler.d.mts +2 -1
- package/api/theme-edit/_compiler.mjs +27 -13
- package/api/theme-edit/_context.d.mts +2 -1
- package/api/theme-edit/_context.mjs +47 -8
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +484 -66
- package/api/theme-edit/_how-commands.d.mts +33 -7
- package/api/theme-edit/_how-commands.mjs +57 -45
- package/api/theme-edit/_how-question.d.mts +4 -0
- package/api/theme-edit/_how-question.mjs +1004 -223
- package/api/theme-edit/_how.mjs +96 -9
- package/api/theme-edit/_palette.d.mts +38 -13
- package/api/theme-edit/_palette.mjs +620 -223
- package/api/theme-edit/_parts.mjs +63 -7
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +6 -0
- package/api/theme-edit/_preview-app.mjs +1194 -207
- package/api/theme-edit/_preview.mjs +2 -2
- package/api/theme-edit/_project.d.mts +12 -1
- package/api/theme-edit/_project.mjs +37 -6
- package/api/theme-edit/_settings.d.mts +104 -33
- package/api/theme-edit/_settings.mjs +818 -118
- package/api/theme-edit/_tables.d.mts +7 -0
- package/api/theme-edit/_tables.mjs +61 -0
- package/api/theme-edit/theme-edit.type.d.mts +11 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs/tree/checks.doc.mjs +22 -1
- package/assets/docs.generated.json +2 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/theme.mjs +178 -78
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/manifest.mjs +5 -2
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +374 -42
- package/clients/cli/index.mjs +9 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +19 -0
- package/foundation/discovery/template-needs.mjs +50 -16
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +2 -8
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +22 -15
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +741 -0
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +14 -3
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- package/foundation/integrations/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +476 -40
- package/foundation/release/cache.d.mts +11 -2
- package/foundation/release/cache.mjs +59 -10
- package/foundation/release/folder-lock.d.mts +21 -0
- package/foundation/release/folder-lock.mjs +171 -0
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +8 -6
package/api/search/_words.mjs
CHANGED
|
@@ -136,14 +136,34 @@ export function sameTermWord(t, w) {
|
|
|
136
136
|
* @returns {string[]}
|
|
137
137
|
*/
|
|
138
138
|
export function wordsOf(text) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.
|
|
143
|
-
.
|
|
144
|
-
.
|
|
139
|
+
const key = String(text);
|
|
140
|
+
let words = splitWords.get(key);
|
|
141
|
+
if (words === undefined) {
|
|
142
|
+
// A long-running caller ranks many queries; start over rather than grow.
|
|
143
|
+
if (splitWords.size >= SPLIT_WORDS_LIMIT) splitWords.clear();
|
|
144
|
+
words = Object.freeze(
|
|
145
|
+
key
|
|
146
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
147
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1 $2')
|
|
148
|
+
.toLowerCase()
|
|
149
|
+
.split(/[^a-z0-9]+/)
|
|
150
|
+
.filter(Boolean),
|
|
151
|
+
);
|
|
152
|
+
splitWords.set(key, words);
|
|
153
|
+
}
|
|
154
|
+
return /** @type {string[]} */ (words);
|
|
145
155
|
}
|
|
146
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Each text's words, split once per process: a search splits the same names
|
|
159
|
+
* and keywords for every term of every query.
|
|
160
|
+
* @type {Map<string, readonly string[]>}
|
|
161
|
+
*/
|
|
162
|
+
const splitWords = new Map();
|
|
163
|
+
|
|
164
|
+
/** How many texts' words are kept before the cache starts over. */
|
|
165
|
+
const SPLIT_WORDS_LIMIT = 100_000;
|
|
166
|
+
|
|
147
167
|
/**
|
|
148
168
|
* Whether a term is found inside a name or keyword: it is one of its words, or
|
|
149
169
|
* the start of one (a truncation), and covers at least half of the whole
|
|
@@ -554,7 +554,7 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
554
554
|
for (const dir of [...createdDirs].reverse()) {
|
|
555
555
|
fs.rmSync(dir, {recursive: true, force: true});
|
|
556
556
|
}
|
|
557
|
-
if (!outputDirExisted) {
|
|
557
|
+
if (!outputDirExisted && fs.existsSync(outputDir)) {
|
|
558
558
|
fs.rmSync(outputDir, {recursive: true, force: true});
|
|
559
559
|
}
|
|
560
560
|
throw writeFailed(output.dest, cwd, err, unrestored);
|
package/api/theme/_adapter.d.mts
CHANGED
|
@@ -91,14 +91,30 @@ export function forkNeeds(outputDir: string, files: string[], cwd: string): {
|
|
|
91
91
|
* Without an explicit package, a local theme shadows package themes that share
|
|
92
92
|
* its slug. Other duplicate slugs fail closed until the caller selects an owner.
|
|
93
93
|
* @param {string} [slug]
|
|
94
|
-
* @param {{cwd?: string, package?: string, includeLocal?: boolean}} [options]
|
|
94
|
+
* @param {{cwd?: string, package?: string, includeLocal?: boolean, command?: string}} [options]
|
|
95
|
+
* `command`: the command a refusal suggests running with `--package`,
|
|
96
|
+
* `theme add` by default
|
|
95
97
|
* @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme | undefined>}
|
|
96
98
|
*/
|
|
97
99
|
export function findTheme(slug?: string, options?: {
|
|
98
100
|
cwd?: string;
|
|
99
101
|
package?: string;
|
|
100
102
|
includeLocal?: boolean;
|
|
103
|
+
command?: string;
|
|
101
104
|
}): Promise<import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme | undefined>;
|
|
105
|
+
/**
|
|
106
|
+
* Runnable `<command> <slug>` suggestions for an unknown slug, closest names
|
|
107
|
+
* first; `--package` is named only where packages share a slug.
|
|
108
|
+
* @param {string} command such as `theme add`
|
|
109
|
+
* @param {string} slug what the person typed
|
|
110
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} available
|
|
111
|
+
* @param {string} cwd
|
|
112
|
+
* @returns {Array<{theme: import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme, name: string}>}
|
|
113
|
+
*/
|
|
114
|
+
export function themeCommandsFor(command: string, slug: string, available: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme[], cwd: string): Array<{
|
|
115
|
+
theme: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme;
|
|
116
|
+
name: string;
|
|
117
|
+
}>;
|
|
102
118
|
/**
|
|
103
119
|
* Read the generated module's app-theme record with stable CLI errors.
|
|
104
120
|
* @param {string} [cwd]
|
package/api/theme/_adapter.mjs
CHANGED
|
@@ -51,8 +51,12 @@ import {stripCopyrightHeader} from '../../foundation/text/copyright-header.mjs';
|
|
|
51
51
|
import {loadIntegrations} from '../../foundation/integrations/integrations.mjs';
|
|
52
52
|
import {importThemeArtifact} from '../../foundation/fs/module-loader.mjs';
|
|
53
53
|
import {applyWrites} from '../integration/add-helpers.mjs';
|
|
54
|
-
import {
|
|
54
|
+
import {
|
|
55
|
+
formatCliCommand,
|
|
56
|
+
quoteCommandArgument,
|
|
57
|
+
} from '../../foundation/env/package-manager.mjs';
|
|
55
58
|
import {fsErrorMessage} from '../../foundation/fs/fs-error.mjs';
|
|
59
|
+
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
56
60
|
import {analyzeTemplateNeeds} from '../../foundation/discovery/template-needs.mjs';
|
|
57
61
|
|
|
58
62
|
export {BUNDLED_THEME_PACKAGE, THEMES_DIR};
|
|
@@ -168,11 +172,60 @@ const skippedLocalThemesOf = new WeakMap();
|
|
|
168
172
|
function brokenLocalThemeError(broken) {
|
|
169
173
|
return new AstryxError(
|
|
170
174
|
`Local theme "${broken.slug}" in ${broken.path} is broken: ${broken.reason}`,
|
|
171
|
-
|
|
175
|
+
[
|
|
176
|
+
{
|
|
177
|
+
name: formatCliCommand('theme list'),
|
|
178
|
+
reason: 'the themes that load, and the broken folders it skips',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
172
181
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
173
182
|
);
|
|
174
183
|
}
|
|
175
184
|
|
|
185
|
+
/**
|
|
186
|
+
* A slug that is not in the app's record. When a theme by that name is
|
|
187
|
+
* available, the refusal names `theme add`; otherwise `theme list`, since
|
|
188
|
+
* adding it would fail too.
|
|
189
|
+
* @param {string} slug
|
|
190
|
+
* @param {{projectDir: string}} state
|
|
191
|
+
*/
|
|
192
|
+
async function notAddedError(slug, state) {
|
|
193
|
+
let match;
|
|
194
|
+
try {
|
|
195
|
+
match = await findTheme(slug, {cwd: state.projectDir});
|
|
196
|
+
} catch (error) {
|
|
197
|
+
// More than one package provides the slug: adding it names one.
|
|
198
|
+
if (
|
|
199
|
+
error instanceof AstryxError &&
|
|
200
|
+
error.code === ERROR_CODES.ERR_AMBIGUOUS_THEME
|
|
201
|
+
) {
|
|
202
|
+
return new AstryxError(
|
|
203
|
+
`Theme "${slug}" is not added, and more than one package provides it. Add it from one of them with --package first.`,
|
|
204
|
+
error.suggestions,
|
|
205
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
const list = {
|
|
211
|
+
name: formatCliCommand('theme list', state.projectDir),
|
|
212
|
+
reason: 'the themes you can add',
|
|
213
|
+
};
|
|
214
|
+
if (!match) {
|
|
215
|
+
return new AstryxError(
|
|
216
|
+
`Theme "${slug}" is not added, and no theme by that name is available. Run \`${list.name}\` for the themes you can add.`,
|
|
217
|
+
[list],
|
|
218
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
const add = formatCliCommand(`theme add ${match.slug}`, state.projectDir);
|
|
222
|
+
return new AstryxError(
|
|
223
|
+
`Theme "${slug}" is not added. Run \`${add}\` first.`,
|
|
224
|
+
[{name: add, reason: 'add it to the app'}],
|
|
225
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
176
229
|
/** @param {unknown} error */
|
|
177
230
|
function isMissingThemeArtifact(error) {
|
|
178
231
|
return (
|
|
@@ -403,8 +456,9 @@ export default {
|
|
|
403
456
|
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
|
|
404
457
|
* @param {string} dir
|
|
405
458
|
* @param {string} cwd
|
|
459
|
+
* @param {string} projectDir the project root the default target is in
|
|
406
460
|
*/
|
|
407
|
-
function assertEjectTargetFree(theme, dir, cwd) {
|
|
461
|
+
function assertEjectTargetFree(theme, dir, cwd, projectDir) {
|
|
408
462
|
/** @type {string[]} */
|
|
409
463
|
let entries;
|
|
410
464
|
try {
|
|
@@ -415,7 +469,8 @@ function assertEjectTargetFree(theme, dir, cwd) {
|
|
|
415
469
|
}
|
|
416
470
|
const rel = path.relative(cwd, dir) || '.';
|
|
417
471
|
const isDefault =
|
|
418
|
-
path.resolve(
|
|
472
|
+
path.resolve(projectDir, defaultEjectTarget(theme.slug)) ===
|
|
473
|
+
path.resolve(dir);
|
|
419
474
|
const suggestion = isDefault
|
|
420
475
|
? undefined
|
|
421
476
|
: [
|
|
@@ -472,18 +527,32 @@ function themeDescriptorName(file) {
|
|
|
472
527
|
* @returns {string} project-relative output directory
|
|
473
528
|
*/
|
|
474
529
|
export function ejectThemeFiles(theme, {cwd, targetPath, overwrite = false}) {
|
|
530
|
+
// The fork lands in the project, as list and add read it: the default root
|
|
531
|
+
// is the project's, and a relative [path] is read from the working folder
|
|
532
|
+
// but must stay inside the project.
|
|
533
|
+
const projectDir = findPackageRoot(cwd) ?? path.resolve(cwd);
|
|
534
|
+
const target = !targetPath
|
|
535
|
+
? defaultEjectTarget(theme.slug)
|
|
536
|
+
: path.isAbsolute(targetPath)
|
|
537
|
+
? targetPath
|
|
538
|
+
: path.relative(projectDir, path.resolve(cwd, targetPath)) || '.';
|
|
475
539
|
let resolvedDir;
|
|
476
540
|
try {
|
|
477
|
-
resolvedDir = assertWithin(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
{label: 'theme target path'},
|
|
481
|
-
);
|
|
541
|
+
resolvedDir = assertWithin(target, projectDir, {
|
|
542
|
+
label: 'theme target path',
|
|
543
|
+
});
|
|
482
544
|
} catch (error) {
|
|
483
545
|
if (error instanceof PathSafetyError) {
|
|
484
546
|
throw new AstryxError(
|
|
485
|
-
|
|
486
|
-
|
|
547
|
+
targetPath
|
|
548
|
+
? error.message.replace(`"${target}"`, `"${targetPath}"`)
|
|
549
|
+
: error.message,
|
|
550
|
+
[
|
|
551
|
+
{
|
|
552
|
+
name: formatCliCommand(`theme eject ${theme.slug}`, cwd),
|
|
553
|
+
reason: `fork into ${defaultEjectTarget(theme.slug).split(path.sep).join('/')}`,
|
|
554
|
+
},
|
|
555
|
+
],
|
|
487
556
|
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
488
557
|
);
|
|
489
558
|
}
|
|
@@ -521,7 +590,7 @@ export function ejectThemeFiles(theme, {cwd, targetPath, overwrite = false}) {
|
|
|
521
590
|
}
|
|
522
591
|
}
|
|
523
592
|
|
|
524
|
-
assertEjectTargetFree(theme, resolvedDir, cwd);
|
|
593
|
+
assertEjectTargetFree(theme, resolvedDir, cwd, projectDir);
|
|
525
594
|
|
|
526
595
|
if (!overwrite) {
|
|
527
596
|
const existing = writes.find(write => fs.existsSync(write.dest));
|
|
@@ -530,7 +599,23 @@ export function ejectThemeFiles(theme, {cwd, targetPath, overwrite = false}) {
|
|
|
530
599
|
throw new AstryxError(
|
|
531
600
|
`Refusing to overwrite existing file ${rel}. ` +
|
|
532
601
|
'Re-run with --overwrite (or -f) to replace it.',
|
|
533
|
-
|
|
602
|
+
[
|
|
603
|
+
{
|
|
604
|
+
name: formatCliCommand(
|
|
605
|
+
[
|
|
606
|
+
'theme eject',
|
|
607
|
+
theme.slug,
|
|
608
|
+
...(targetPath ? [quoteCommandArgument(targetPath)] : []),
|
|
609
|
+
...(theme.source === 'bundled'
|
|
610
|
+
? []
|
|
611
|
+
: ['--package', quoteCommandArgument(theme.package)]),
|
|
612
|
+
'--overwrite',
|
|
613
|
+
].join(' '),
|
|
614
|
+
cwd,
|
|
615
|
+
),
|
|
616
|
+
reason: 'replace the earlier fork of this theme',
|
|
617
|
+
},
|
|
618
|
+
],
|
|
534
619
|
ERROR_CODES.ERR_FILE_EXISTS,
|
|
535
620
|
);
|
|
536
621
|
}
|
|
@@ -606,7 +691,9 @@ function asThemeError(error) {
|
|
|
606
691
|
message.startsWith('Refusing to replace')
|
|
607
692
|
? ERROR_CODES.ERR_FILE_EXISTS
|
|
608
693
|
: ERROR_CODES.ERR_THEME_INVALID;
|
|
609
|
-
|
|
694
|
+
const suggestions =
|
|
695
|
+
error instanceof ThemeStateError ? error.suggestions : undefined;
|
|
696
|
+
return new AstryxError(message, suggestions, code);
|
|
610
697
|
}
|
|
611
698
|
|
|
612
699
|
/**
|
|
@@ -614,7 +701,9 @@ function asThemeError(error) {
|
|
|
614
701
|
* Without an explicit package, a local theme shadows package themes that share
|
|
615
702
|
* its slug. Other duplicate slugs fail closed until the caller selects an owner.
|
|
616
703
|
* @param {string} [slug]
|
|
617
|
-
* @param {{cwd?: string, package?: string, includeLocal?: boolean}} [options]
|
|
704
|
+
* @param {{cwd?: string, package?: string, includeLocal?: boolean, command?: string}} [options]
|
|
705
|
+
* `command`: the command a refusal suggests running with `--package`,
|
|
706
|
+
* `theme add` by default
|
|
618
707
|
* @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme | undefined>}
|
|
619
708
|
*/
|
|
620
709
|
export async function findTheme(slug, options = {}) {
|
|
@@ -657,7 +746,10 @@ export async function findTheme(slug, options = {}) {
|
|
|
657
746
|
throw new AstryxError(
|
|
658
747
|
`Theme "${slug}" is provided by more than one package. Select one with --package.`,
|
|
659
748
|
matches.map(theme => ({
|
|
660
|
-
name:
|
|
749
|
+
name: formatCliCommand(
|
|
750
|
+
`${options.command ?? 'theme add'} ${theme.slug} --package ${quoteCommandArgument(theme.package)}`,
|
|
751
|
+
options.cwd ?? process.cwd(),
|
|
752
|
+
),
|
|
661
753
|
reason:
|
|
662
754
|
theme.source === 'bundled'
|
|
663
755
|
? 'bundled theme'
|
|
@@ -671,6 +763,36 @@ export async function findTheme(slug, options = {}) {
|
|
|
671
763
|
return matches[0];
|
|
672
764
|
}
|
|
673
765
|
|
|
766
|
+
/**
|
|
767
|
+
* Runnable `<command> <slug>` suggestions for an unknown slug, closest names
|
|
768
|
+
* first; `--package` is named only where packages share a slug.
|
|
769
|
+
* @param {string} command such as `theme add`
|
|
770
|
+
* @param {string} slug what the person typed
|
|
771
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} available
|
|
772
|
+
* @param {string} cwd
|
|
773
|
+
* @returns {Array<{theme: import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme, name: string}>}
|
|
774
|
+
*/
|
|
775
|
+
export function themeCommandsFor(command, slug, available, cwd) {
|
|
776
|
+
const needle = String(slug).toLowerCase();
|
|
777
|
+
const shared = (/** @type {string} */ other) =>
|
|
778
|
+
available.filter(theme => theme.slug === other).length > 1;
|
|
779
|
+
return [...available]
|
|
780
|
+
.sort(
|
|
781
|
+
(a, b) =>
|
|
782
|
+
levenshteinDistance(needle, a.slug.toLowerCase()) -
|
|
783
|
+
levenshteinDistance(needle, b.slug.toLowerCase()) ||
|
|
784
|
+
a.slug.localeCompare(b.slug),
|
|
785
|
+
)
|
|
786
|
+
.slice(0, 5)
|
|
787
|
+
.map(theme => ({
|
|
788
|
+
theme,
|
|
789
|
+
name: formatCliCommand(
|
|
790
|
+
`${command} ${theme.slug}${shared(theme.slug) ? ` --package ${quoteCommandArgument(theme.package)}` : ''}`,
|
|
791
|
+
cwd,
|
|
792
|
+
),
|
|
793
|
+
}));
|
|
794
|
+
}
|
|
795
|
+
|
|
674
796
|
/**
|
|
675
797
|
* Read the generated module's app-theme record with stable CLI errors.
|
|
676
798
|
* @param {string} [cwd]
|
|
@@ -730,7 +852,12 @@ export function resolveRecordedThemes(state, available) {
|
|
|
730
852
|
if (!theme) {
|
|
731
853
|
throw new AstryxError(
|
|
732
854
|
`Added theme "${slug}" from ${owner} is unavailable. Reinstall the package or restore the local theme, or drop it with \`${formatCliCommand(`theme remove ${slug}`, state.projectDir)}\`.`,
|
|
733
|
-
|
|
855
|
+
[
|
|
856
|
+
{
|
|
857
|
+
name: formatCliCommand(`theme remove ${slug}`, state.projectDir),
|
|
858
|
+
reason: 'drop it from the app',
|
|
859
|
+
},
|
|
860
|
+
],
|
|
734
861
|
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
735
862
|
);
|
|
736
863
|
}
|
|
@@ -985,15 +1112,17 @@ async function addThemeToAppLocked(slug, cwd, options) {
|
|
|
985
1112
|
const available = await listAvailableThemes(cwd);
|
|
986
1113
|
throw new AstryxError(
|
|
987
1114
|
`Unknown theme "${slug}"${options.package ? ` in package "${options.package}"` : ''}.`,
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1115
|
+
themeCommandsFor('theme add', slug, available, cwd).map(
|
|
1116
|
+
({theme, name}) => ({
|
|
1117
|
+
name,
|
|
1118
|
+
reason:
|
|
1119
|
+
theme.source === 'bundled'
|
|
1120
|
+
? 'bundled theme'
|
|
1121
|
+
: theme.source === 'local'
|
|
1122
|
+
? 'local theme'
|
|
1123
|
+
: `provided by ${theme.package}`,
|
|
1124
|
+
}),
|
|
1125
|
+
),
|
|
997
1126
|
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
998
1127
|
);
|
|
999
1128
|
}
|
|
@@ -1066,16 +1195,28 @@ async function removeThemeFromAppLocked(slug, cwd) {
|
|
|
1066
1195
|
const state = readAppThemeState(cwd);
|
|
1067
1196
|
const recordedSlug = recordedThemeSlug(state, slug);
|
|
1068
1197
|
if (!state.configured || recordedSlug == null) {
|
|
1069
|
-
throw
|
|
1070
|
-
`Theme "${slug}" is not added. Run \`${formatCliCommand(`theme add ${slug}`, state.projectDir)}\` first.`,
|
|
1071
|
-
undefined,
|
|
1072
|
-
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
1073
|
-
);
|
|
1198
|
+
throw await notAddedError(slug, state);
|
|
1074
1199
|
}
|
|
1075
1200
|
if (state.defaultSlug === recordedSlug) {
|
|
1201
|
+
const others = Object.keys(state.themes).filter(
|
|
1202
|
+
other => other !== recordedSlug,
|
|
1203
|
+
);
|
|
1204
|
+
const uses = others.slice(0, 3).map(other => ({
|
|
1205
|
+
name: formatCliCommand(`theme use ${other}`, state.projectDir),
|
|
1206
|
+
reason: `make ${other} the default`,
|
|
1207
|
+
}));
|
|
1076
1208
|
throw new AstryxError(
|
|
1077
|
-
|
|
1078
|
-
|
|
1209
|
+
uses.length > 0
|
|
1210
|
+
? `Theme "${recordedSlug}" is the default. Run \`${uses[0].name}\` before removing it.`
|
|
1211
|
+
: `Theme "${recordedSlug}" is the default and the only added theme. Add another theme and make it the default before removing it.`,
|
|
1212
|
+
uses.length > 0
|
|
1213
|
+
? uses
|
|
1214
|
+
: [
|
|
1215
|
+
{
|
|
1216
|
+
name: formatCliCommand('theme list', state.projectDir),
|
|
1217
|
+
reason: 'the themes you can add',
|
|
1218
|
+
},
|
|
1219
|
+
],
|
|
1079
1220
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
1080
1221
|
);
|
|
1081
1222
|
}
|
|
@@ -1083,8 +1224,16 @@ async function removeThemeFromAppLocked(slug, cwd) {
|
|
|
1083
1224
|
delete themes[recordedSlug];
|
|
1084
1225
|
if (state.defaultSlug == null) {
|
|
1085
1226
|
throw new AstryxError(
|
|
1086
|
-
`The generated theme module has no default theme. Run \`${formatCliCommand(
|
|
1087
|
-
|
|
1227
|
+
`The generated theme module has no default theme. Run \`${formatCliCommand(`theme use ${Object.keys(themes)[0] ?? recordedSlug}`, state.projectDir)}\` first.`,
|
|
1228
|
+
[
|
|
1229
|
+
{
|
|
1230
|
+
name: formatCliCommand(
|
|
1231
|
+
`theme use ${Object.keys(themes)[0] ?? recordedSlug}`,
|
|
1232
|
+
state.projectDir,
|
|
1233
|
+
),
|
|
1234
|
+
reason: 'choose a default',
|
|
1235
|
+
},
|
|
1236
|
+
],
|
|
1088
1237
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
1089
1238
|
);
|
|
1090
1239
|
}
|
|
@@ -1116,11 +1265,7 @@ async function useThemeInAppLocked(slug, cwd) {
|
|
|
1116
1265
|
const state = readAppThemeState(cwd);
|
|
1117
1266
|
const recordedSlug = recordedThemeSlug(state, slug);
|
|
1118
1267
|
if (!state.configured || recordedSlug == null) {
|
|
1119
|
-
throw
|
|
1120
|
-
`Theme "${slug}" is not added. Run \`${formatCliCommand(`theme add ${slug}`, state.projectDir)}\` first.`,
|
|
1121
|
-
undefined,
|
|
1122
|
-
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
1123
|
-
);
|
|
1268
|
+
throw await notAddedError(slug, state);
|
|
1124
1269
|
}
|
|
1125
1270
|
const available = await listAvailableThemes(state.projectDir);
|
|
1126
1271
|
return writeThemeApp(
|
|
@@ -48,6 +48,24 @@ export function coreUnavailableMessage(cwd: string, importError: any): string;
|
|
|
48
48
|
* @returns {string}
|
|
49
49
|
*/
|
|
50
50
|
export function normalizeThemeBuildForCompare(content: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Theme sources a missing build input probably meant, relative to `cwd`: the
|
|
53
|
+
* same path with `/` for `\`; or, for a bare theme name, the theme sources in
|
|
54
|
+
* `themes/<name>/` and `src/themes/<name>/` of the project, and `<name>` with a
|
|
55
|
+
* theme source extension. A build output is never offered.
|
|
56
|
+
* @param {string} file the input as given
|
|
57
|
+
* @param {string} cwd
|
|
58
|
+
* @returns {string[]} at most three paths
|
|
59
|
+
*/
|
|
60
|
+
export function themeSourceGuesses(file: string, cwd: string): string[];
|
|
61
|
+
/**
|
|
62
|
+
* Publish the outputs a batch deferred, one theme at a time, in build order.
|
|
63
|
+
* @param {Array<Array<{dest: string, content: string}>>} deferred
|
|
64
|
+
*/
|
|
65
|
+
export function writeDeferredBuildOutputs(deferred: Array<Array<{
|
|
66
|
+
dest: string;
|
|
67
|
+
content: string;
|
|
68
|
+
}>>): void;
|
|
51
69
|
/**
|
|
52
70
|
* Import specifier for install/scaffold instructions. Drops a leading `src/`
|
|
53
71
|
* from the cwd-relative dir (most consumers import from a file under src/) but
|
|
@@ -58,6 +76,12 @@ export function normalizeThemeBuildForCompare(content: string): string;
|
|
|
58
76
|
* @returns {string}
|
|
59
77
|
*/
|
|
60
78
|
export function importSpecifier(relDir: string, base: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* The package a theme load failed on because it is not installed.
|
|
81
|
+
* @param {unknown} error
|
|
82
|
+
* @returns {string | null}
|
|
83
|
+
*/
|
|
84
|
+
export function missingThemePackage(error: unknown): string | null;
|
|
61
85
|
/**
|
|
62
86
|
* Load one theme through the build's real module loader and validate the raw
|
|
63
87
|
* input captured from its defineTheme lineage. Used by doctor so it applies the
|
|
@@ -144,12 +168,16 @@ export function themeBuild(file: string, options?: {
|
|
|
144
168
|
cwd?: string;
|
|
145
169
|
projectCore?: boolean;
|
|
146
170
|
}): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
|
|
147
|
-
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void}} options @param {{cwd?: string}} [ctx] */
|
|
171
|
+
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
|
|
148
172
|
export function themeBuildFamily(files: string[], options: {
|
|
149
173
|
familyKey: string;
|
|
150
174
|
check?: boolean;
|
|
151
175
|
iconsSpecifier?: string;
|
|
152
176
|
__onPrivateVarError?: () => void;
|
|
177
|
+
__commandWords?: {
|
|
178
|
+
group: string;
|
|
179
|
+
build: string;
|
|
180
|
+
};
|
|
153
181
|
}, { cwd }?: {
|
|
154
182
|
cwd?: string;
|
|
155
183
|
}): Promise<{
|