@astryxdesign/cli 0.7.17 → 0.7.18-canary.g6dfc0b6
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 +1 -1
- package/api/discover/_adapter.d.mts +7 -5
- package/api/discover/_adapter.mjs +12 -11
- package/api/doctor/_adapter.d.mts +11 -62
- package/api/doctor/_adapter.mjs +242 -472
- package/api/doctor/doctor.d.mts +1 -1
- package/api/doctor/doctor.mjs +1 -1
- package/api/doctor/theme-checks.mjs +37 -45
- package/api/error.d.mts +21 -0
- package/api/error.mjs +89 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/icon.doc.mjs +1 -1
- package/api/icon/icon.type.mjs +1 -1
- package/api/icon/search/search.d.mts +4 -1
- package/api/icon/search/search.mjs +41 -4
- package/api/render/_adapter.mjs +233 -40
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/search/ORDERING.md +2 -2
- package/api/search/_candidate-score.mjs +32 -8
- package/api/search/_cards.json +1 -1
- package/api/search/_compound.d.mts +0 -1
- package/api/search/_compound.mjs +93 -2
- package/api/search/_lexical.mjs +177 -17
- package/api/search/_order.d.mts +3 -1
- package/api/search/_order.mjs +16 -5
- package/api/search/_result.d.mts +9 -0
- package/api/search/_result.mjs +10 -0
- package/api/search/_score.mjs +21 -3
- package/api/swizzle/_moduleGraph.d.mts +8 -0
- package/api/swizzle/_moduleGraph.mjs +61 -3
- package/api/template/copy/copy.mjs +5 -3
- package/api/theme/_adapter.mjs +48 -12
- package/api/theme/build/build.d.mts +4 -0
- package/api/theme/build/build.mjs +69 -18
- package/api/theme/build/style-keys.mjs +4 -5
- package/api/theme/build/theme-object.mjs +5 -0
- package/api/theme/palette/generate/color.d.mts +47 -0
- package/api/theme/palette/generate/color.mjs +58 -1
- package/api/theme/palette/generate/derive-look.d.mts +293 -0
- package/api/theme/palette/generate/derive-look.mjs +1362 -0
- package/api/theme/palette/generate/editor-look.d.mts +62 -0
- package/api/theme/palette/generate/editor-look.mjs +550 -0
- package/api/theme/palette/generate/mapping.d.mts +94 -9
- package/api/theme/palette/generate/mapping.mjs +94 -22
- package/api/theme-edit/_adapter.mjs +10 -1
- package/api/theme-edit/_catalog.d.mts +13 -13
- package/api/theme-edit/_catalog.mjs +38 -16
- package/api/theme-edit/_check.d.mts +82 -6
- package/api/theme-edit/_check.mjs +1230 -223
- package/api/theme-edit/_color.d.mts +74 -0
- package/api/theme-edit/_color.mjs +168 -3
- package/api/theme-edit/_compiler.d.mts +3 -5
- package/api/theme-edit/_compiler.mjs +122 -23
- package/api/theme-edit/_context.d.mts +46 -5
- package/api/theme-edit/_context.mjs +97 -49
- package/api/theme-edit/_css.d.mts +11 -0
- package/api/theme-edit/_css.mjs +40 -0
- package/api/theme-edit/_edit.d.mts +13 -0
- package/api/theme-edit/_edit.mjs +1450 -128
- package/api/theme-edit/_how-commands.d.mts +12 -0
- package/api/theme-edit/_how-commands.mjs +96 -14
- package/api/theme-edit/_how-question.d.mts +73 -29
- package/api/theme-edit/_how-question.mjs +8131 -1209
- package/api/theme-edit/_how-sides.d.mts +22 -0
- package/api/theme-edit/_how-sides.mjs +173 -0
- package/api/theme-edit/_how-steps.d.mts +42 -0
- package/api/theme-edit/_how-steps.mjs +208 -0
- package/api/theme-edit/_how-values.d.mts +29 -0
- package/api/theme-edit/_how-values.mjs +111 -0
- package/api/theme-edit/_how-words.d.mts +15 -0
- package/api/theme-edit/_how-words.mjs +239 -0
- package/api/theme-edit/_how.d.mts +1 -1
- package/api/theme-edit/_how.mjs +412 -37
- package/api/theme-edit/_missed.d.mts +2 -1
- package/api/theme-edit/_missed.mjs +125 -13
- package/api/theme-edit/_normal.d.mts +5 -3
- package/api/theme-edit/_normal.mjs +54 -14
- package/api/theme-edit/_palette.d.mts +204 -4
- package/api/theme-edit/_palette.mjs +901 -25
- package/api/theme-edit/_part-pieces.d.mts +54 -0
- package/api/theme-edit/_part-pieces.mjs +179 -0
- package/api/theme-edit/_part-words.mjs +33 -5
- package/api/theme-edit/_parts.d.mts +133 -0
- package/api/theme-edit/_parts.mjs +599 -10
- package/api/theme-edit/_picture-traits.d.mts +259 -0
- package/api/theme-edit/_picture-traits.mjs +1030 -0
- package/api/theme-edit/_preview.d.mts +84 -4
- package/api/theme-edit/_preview.mjs +260 -24
- package/api/theme-edit/_project.d.mts +14 -4
- package/api/theme-edit/_project.mjs +95 -26
- package/api/theme-edit/_set-line.d.mts +29 -0
- package/api/theme-edit/_set-line.mjs +100 -0
- package/api/theme-edit/_settings.d.mts +625 -28
- package/api/theme-edit/_settings.mjs +4587 -880
- package/api/theme-edit/_tables.d.mts +25 -1
- package/api/theme-edit/_tables.mjs +115 -11
- package/api/theme-edit/_text-looks.d.mts +78 -0
- package/api/theme-edit/_text-looks.mjs +376 -0
- package/api/theme-edit/_vet.d.mts +3 -26
- package/api/theme-edit/_vet.mjs +5 -89
- package/api/theme-edit/how/how.d.mts +1 -1
- package/api/theme-edit/how/how.mjs +1 -1
- package/api/theme-edit/theme-edit.type.d.mts +54 -1
- package/api/theme-edit/theme-edit.type.mjs +17 -2
- package/api/theme-edit/themeEditHow.doc.mjs +3 -3
- package/api/theme-edit/themeEditNew.doc.mjs +4 -0
- package/api/theme-edit/themeEditSet.doc.mjs +6 -2
- package/api/theme-edit/themeEditShow.doc.mjs +4 -0
- package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/author-a-theme.doc.mjs +7 -4
- package/assets/docs/tree/export-pages.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +89 -17
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/article.doc.mjs +9 -0
- package/assets/icons/template-icons.json +5 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ide/page.tsx +5 -10
- package/assets/templates/pages/payment-form/page.tsx +16 -60
- package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
- package/authoring/debug/parse.d.mts +1 -1
- package/authoring/doctypes/_schema.d.mts +13 -13
- package/authoring/gap-report/parse.d.mts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/ensure-core-built.mjs +17 -10
- package/clients/cli/commands/experimental/theme.mjs +46 -6
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/hook.mjs +7 -0
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/index.mjs +6 -2
- package/clients/cli/lib/hook-format.mjs +41 -1
- package/clients/cli/lib/json-shim.mjs +34 -14
- package/clients/cli/lib/other-cli-words.mjs +7 -0
- package/clients/cli/lib/unknown-command.mjs +345 -46
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +11 -2
- package/foundation/agent-docs/agent-docs.mjs +51 -8
- package/foundation/config/project.d.mts +11 -1
- package/foundation/config/project.mjs +11 -2
- package/foundation/discovery/component-replacement.d.mts +5 -8
- package/foundation/discovery/component-replacement.mjs +12 -14
- package/foundation/discovery/core-augmentation-points.d.mts +35 -0
- package/foundation/discovery/core-augmentation-points.mjs +410 -9
- package/foundation/discovery/core-elements.d.mts +6 -0
- package/foundation/discovery/core-elements.mjs +10 -2
- package/foundation/discovery/core-prop-types.d.mts +5 -0
- package/foundation/discovery/core-prop-types.mjs +10 -3
- package/foundation/discovery/core-props.d.mts +8 -0
- package/foundation/discovery/core-props.mjs +29 -13
- package/foundation/discovery/official-list.d.mts +17 -0
- package/foundation/discovery/official-list.mjs +77 -0
- package/foundation/discovery/unknown-core-props.d.mts +130 -0
- package/foundation/discovery/unknown-core-props.mjs +601 -0
- package/foundation/discovery/written-prop-values.d.mts +35 -0
- package/foundation/discovery/written-prop-values.mjs +258 -0
- package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
- package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
- package/foundation/fs/package-name.d.mts +10 -0
- package/foundation/fs/package-name.mjs +37 -0
- package/foundation/fs/project-source-files.d.mts +27 -0
- package/foundation/fs/project-source-files.mjs +115 -0
- package/foundation/fs/project-sources.d.mts +25 -0
- package/foundation/fs/project-sources.mjs +83 -0
- package/foundation/fs/read-record.d.mts +18 -0
- package/foundation/fs/read-record.mjs +36 -2
- package/foundation/integrations/integration-warnings.d.mts +39 -7
- package/foundation/integrations/integration-warnings.mjs +141 -19
- package/foundation/integrations/missing-dependency.d.mts +11 -0
- package/foundation/integrations/missing-dependency.mjs +20 -5
- package/foundation/release/folder-lock.d.mts +5 -2
- package/foundation/release/folder-lock.mjs +9 -3
- package/foundation/release/notices.mjs +2 -8
- package/foundation/render/cut-short.d.mts +8 -2
- package/foundation/render/cut-short.mjs +50 -5
- package/foundation/render/drawn-contrast.d.mts +38 -0
- package/foundation/render/drawn-contrast.mjs +237 -0
- package/foundation/render/file-header.mjs +4 -0
- package/foundation/render/layers.d.mts +2 -1
- package/foundation/render/layers.mjs +22 -1
- package/foundation/render/page-worker.mjs +83 -18
- package/foundation/render/part-boxes.d.mts +27 -0
- package/foundation/render/part-boxes.mjs +45 -0
- package/foundation/render/picture-chrome.mjs +36 -4
- package/foundation/render/picture-playwright.mjs +26 -2
- package/foundation/render/picture-window.d.mts +29 -2
- package/foundation/render/picture-window.mjs +99 -1
- package/foundation/render/render-page.d.mts +39 -6
- package/foundation/render/render-page.mjs +26 -10
- package/foundation/render/ts-paths.mjs +2 -1
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/text/written-string.d.mts +4 -1
- package/foundation/text/written-string.mjs +4 -1
- package/package.json +8 -7
|
@@ -6,19 +6,33 @@
|
|
|
6
6
|
* as one word, another command line's word order (a verb before its group),
|
|
7
7
|
* a word from the table in other-cli-words.mjs, a command's plural, an option
|
|
8
8
|
* some commands take, a command deeper in the tree, or a name another command
|
|
9
|
-
* reads
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* reads; an icon word (`icon`, `icons`) points at the icons guide. With no
|
|
10
|
+
* such run, it names the commands a typo of the word could be, else the
|
|
11
|
+
* help, never a list of every command. A word that names one of the
|
|
12
|
+
* project's own package.json scripts names that script's run first, with the
|
|
13
|
+
* project's package manager. Every help run it names keeps the program
|
|
14
|
+
* options typed (`--json`). It only suggests: it runs nothing, and it names no
|
|
15
|
+
* experimental command except the ones spec:AST-017 FR27's shareable-page
|
|
16
|
+
* exception lets a share word or a way-back word name, and the icon finder
|
|
17
|
+
* for an icon word where icon features are on (spec:AST-084).
|
|
13
18
|
*
|
|
14
19
|
* @input the program and the words of the run after the program name
|
|
15
20
|
* @output the message and the suggestions the unknown-command error prints
|
|
16
21
|
* @position packages/cli/clients/cli/lib — read by the program's own action
|
|
17
|
-
* in index.mjs and by
|
|
22
|
+
* in index.mjs and by json-shim.mjs
|
|
18
23
|
*/
|
|
19
24
|
|
|
25
|
+
import * as path from 'node:path';
|
|
20
26
|
import {levenshteinDistance} from '../../../foundation/text/levenshtein.mjs';
|
|
21
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
commandInFolder,
|
|
29
|
+
detectPackageManager,
|
|
30
|
+
quoteCommandArgument,
|
|
31
|
+
} from '../../../foundation/env/package-manager.mjs';
|
|
32
|
+
import {
|
|
33
|
+
findDeclaringPackage,
|
|
34
|
+
readJson,
|
|
35
|
+
} from '../../../foundation/release/project.mjs';
|
|
22
36
|
import {optionsInReach, runParses} from './stray-option.mjs';
|
|
23
37
|
import {
|
|
24
38
|
ADD_WORDS as ADD_TABLE,
|
|
@@ -50,6 +64,17 @@ import {
|
|
|
50
64
|
* @typedef {(name: string) => Promise<{command: string, name: string} | null>} FindEntry
|
|
51
65
|
*/
|
|
52
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Whether icon features are on where the run is.
|
|
69
|
+
* @typedef {() => Promise<boolean>} IconFeatures
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The run of the project's own package.json script that a word names, or
|
|
74
|
+
* null when it names none.
|
|
75
|
+
* @typedef {(word: string) => Promise<string | null>} ProjectScript
|
|
76
|
+
*/
|
|
77
|
+
|
|
53
78
|
/**
|
|
54
79
|
* The commands below `cmd` that people and agents see, `help` aside: the
|
|
55
80
|
* run's base serves each one.
|
|
@@ -148,10 +173,11 @@ function everyCommand(program) {
|
|
|
148
173
|
|
|
149
174
|
/**
|
|
150
175
|
* The first word that is not an option or the value of one of the program's
|
|
151
|
-
* options, with the words before and after it.
|
|
176
|
+
* options, with the words before and after it. `operands` when it follows
|
|
177
|
+
* `--`, after which every word is a word.
|
|
152
178
|
* @param {string[]} words
|
|
153
179
|
* @param {CommandLike} program
|
|
154
|
-
* @returns {{word: string, before: string[], after: string[]} | null}
|
|
180
|
+
* @returns {{word: string, before: string[], after: string[], operands?: true} | null}
|
|
155
181
|
*/
|
|
156
182
|
export function firstWord(words, program) {
|
|
157
183
|
for (let i = 0; i < words.length; i += 1) {
|
|
@@ -163,6 +189,7 @@ export function firstWord(words, program) {
|
|
|
163
189
|
word: words[i + 1],
|
|
164
190
|
before: words.slice(0, i),
|
|
165
191
|
after: words.slice(i + 2),
|
|
192
|
+
operands: true,
|
|
166
193
|
}
|
|
167
194
|
: null;
|
|
168
195
|
if (word.startsWith('-')) {
|
|
@@ -177,6 +204,20 @@ export function firstWord(words, program) {
|
|
|
177
204
|
return null;
|
|
178
205
|
}
|
|
179
206
|
|
|
207
|
+
/**
|
|
208
|
+
* The words after the word that a help run takes the program options from:
|
|
209
|
+
* those before a `--`, and none when the word itself follows `--`, since
|
|
210
|
+
* every word after `--` is a word.
|
|
211
|
+
* @param {{operands?: true}} first
|
|
212
|
+
* @param {string[]} words
|
|
213
|
+
* @returns {string[]}
|
|
214
|
+
*/
|
|
215
|
+
function optionWords(first, words) {
|
|
216
|
+
if (first.operands) return [];
|
|
217
|
+
const end = words.indexOf('--');
|
|
218
|
+
return end < 0 ? words : words.slice(0, end);
|
|
219
|
+
}
|
|
220
|
+
|
|
180
221
|
/**
|
|
181
222
|
* The options the program lists in its help, its help option included.
|
|
182
223
|
* @param {CommandLike} program
|
|
@@ -215,22 +256,26 @@ function takesWords(cmd, words) {
|
|
|
215
256
|
}
|
|
216
257
|
|
|
217
258
|
/**
|
|
218
|
-
* The
|
|
219
|
-
*
|
|
220
|
-
*
|
|
259
|
+
* The command names a typo of the word could be: one edit away for a word of
|
|
260
|
+
* up to four letters, two for a longer one, two letters swapped counting as
|
|
261
|
+
* one edit. A looser likeness is no typo (`edit` is two edits from `init`),
|
|
262
|
+
* and naming it sends a reader to a command they did not mean, one that may
|
|
263
|
+
* write files. Best first, three at most.
|
|
221
264
|
* @param {string} word
|
|
222
265
|
* @param {string[]} names
|
|
223
266
|
* @returns {string[]}
|
|
224
267
|
*/
|
|
225
268
|
function nearNames(word, names) {
|
|
226
269
|
const typed = word.toLowerCase();
|
|
270
|
+
const allowed = typed.length <= 4 ? 1 : 2;
|
|
227
271
|
return names
|
|
228
|
-
.map(name => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
272
|
+
.map(name => ({
|
|
273
|
+
name,
|
|
274
|
+
distance: levenshteinDistance(typed, name.toLowerCase(), allowed, {
|
|
275
|
+
swaps: true,
|
|
276
|
+
}),
|
|
277
|
+
}))
|
|
278
|
+
.filter(s => s.distance <= allowed)
|
|
234
279
|
.sort((a, b) => a.distance - b.distance)
|
|
235
280
|
.slice(0, 3)
|
|
236
281
|
.map(s => s.name);
|
|
@@ -255,6 +300,12 @@ const PATH_OPTIONS = wordsOf(PATH_TABLE);
|
|
|
255
300
|
/** Words that ask to run the command after them (`add template settings`). */
|
|
256
301
|
const RUN_WORDS = new Set([...READ_WORDS, ...ADD_WORDS]);
|
|
257
302
|
|
|
303
|
+
/**
|
|
304
|
+
* Words after an icon word that only ask to look (`icon search arrow`): the
|
|
305
|
+
* icon finder reads the words after them.
|
|
306
|
+
*/
|
|
307
|
+
const LOOK_WORDS = new Set(['search', 'find', ...READ_WORDS]);
|
|
308
|
+
|
|
258
309
|
/**
|
|
259
310
|
* Whether a word names an input to fill (`<old-version>`), not a value.
|
|
260
311
|
* @param {string} word
|
|
@@ -492,12 +543,147 @@ async function otherCliWords({word, before, after: rest}, program, findEntry) {
|
|
|
492
543
|
return [run(filled(template, fitted), job.reason)];
|
|
493
544
|
}
|
|
494
545
|
|
|
546
|
+
/**
|
|
547
|
+
* The words of a run that are neither options of `cmd` nor their values.
|
|
548
|
+
* @param {CommandLike} cmd
|
|
549
|
+
* @param {string[]} words
|
|
550
|
+
* @returns {string[]}
|
|
551
|
+
*/
|
|
552
|
+
function plainWords(cmd, words) {
|
|
553
|
+
return plainAt(cmd, words).map(i => words[i]);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Where the words of a run that are neither options of `cmd` nor their
|
|
558
|
+
* values stand in it.
|
|
559
|
+
* @param {CommandLike} cmd
|
|
560
|
+
* @param {string[]} words
|
|
561
|
+
* @returns {number[]}
|
|
562
|
+
*/
|
|
563
|
+
function plainAt(cmd, words) {
|
|
564
|
+
const options = optionsInReach(
|
|
565
|
+
/** @type {any} */ (cmd),
|
|
566
|
+
(/** @type {OptionLike} */ o) => !o.hidden,
|
|
567
|
+
);
|
|
568
|
+
/** @type {number[]} */
|
|
569
|
+
const plain = [];
|
|
570
|
+
for (let i = 0; i < words.length; i += 1) {
|
|
571
|
+
const word = words[i];
|
|
572
|
+
if (!word.startsWith('-')) {
|
|
573
|
+
plain.push(i);
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
const [flag, inline] = word.split(/=(.*)/s);
|
|
577
|
+
const option = options.find(o => o.long === flag || o.short === flag);
|
|
578
|
+
const next = words[i + 1];
|
|
579
|
+
if (
|
|
580
|
+
option &&
|
|
581
|
+
(option.required || option.optional) &&
|
|
582
|
+
inline === undefined &&
|
|
583
|
+
next !== undefined &&
|
|
584
|
+
!next.startsWith('-')
|
|
585
|
+
)
|
|
586
|
+
i += 1;
|
|
587
|
+
}
|
|
588
|
+
return plain;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* The runs an icon word (`icon`, `icons`) points at: the stable icons guide
|
|
593
|
+
* (`docs icons`), and where icon features are on, the icon finder. With
|
|
594
|
+
* words to look for, the finder run comes first, with those words and the
|
|
595
|
+
* options given (`icon search arrow` is `experimental icon arrow`); a leading
|
|
596
|
+
* word that only asks to look or list is left out, and so is `--list`, which
|
|
597
|
+
* takes no words (`icon list arrows` is `experimental icon arrows`). A list
|
|
598
|
+
* word or `--list` with nothing to look for asks for `experimental icon
|
|
599
|
+
* --list`, and a first word to look for that names a subcommand of the
|
|
600
|
+
* finder asks for that subcommand's help. With neither, the guide comes first, then the finder's
|
|
601
|
+
* help. Where icon features are off, the answer names no experimental
|
|
602
|
+
* command (spec:AST-084 FR0).
|
|
603
|
+
* @param {{word: string, before: string[], after: string[], operands?: true}} first
|
|
604
|
+
* the word, the words of the run before and after it, and whether it
|
|
605
|
+
* follows `--`
|
|
606
|
+
* @param {CommandLike} program
|
|
607
|
+
* @param {IconFeatures} iconFeatures
|
|
608
|
+
* @returns {Promise<Array<{words: string[], reason: string}>>}
|
|
609
|
+
*/
|
|
610
|
+
async function iconRuns(first, program, iconFeatures) {
|
|
611
|
+
const {before, after: rest} = first;
|
|
612
|
+
/** @param {string[]} parts @param {string} reason */
|
|
613
|
+
const run = (parts, reason) => ({words: [...before, ...parts], reason});
|
|
614
|
+
// The guide keeps only the program's own options written after the word
|
|
615
|
+
// (`icons --json`): the finder's (`--list`, `--set`) are not the guide's,
|
|
616
|
+
// and `docs icons --list` fails.
|
|
617
|
+
const guide = run(
|
|
618
|
+
['docs', 'icons', ...fitWords(program, rest)],
|
|
619
|
+
'the guide to icons in Astryx',
|
|
620
|
+
);
|
|
621
|
+
const finder = ['experimental', 'icon'];
|
|
622
|
+
if (!served(program, finder) || !(await iconFeatures().catch(() => false)))
|
|
623
|
+
return [guide];
|
|
624
|
+
const finderCmd = /** @type {CommandLike} */ (
|
|
625
|
+
visible(
|
|
626
|
+
/** @type {CommandLike} */ (
|
|
627
|
+
visible(program).find(c => c.name() === finder[0])
|
|
628
|
+
),
|
|
629
|
+
).find(c => c.name() === finder[1])
|
|
630
|
+
);
|
|
631
|
+
// The first plain word decides, wherever the options stand (`icon --json
|
|
632
|
+
// list` asks for the list as `icon list --json` does).
|
|
633
|
+
const [at] = plainAt(finderCmd, rest);
|
|
634
|
+
const lower = at === undefined ? '' : rest[at].toLowerCase();
|
|
635
|
+
const listWord = LIST_WORDS.has(lower);
|
|
636
|
+
const words =
|
|
637
|
+
listWord || LOOK_WORDS.has(lower)
|
|
638
|
+
? [...rest.slice(0, at), ...rest.slice(at + 1)]
|
|
639
|
+
: rest;
|
|
640
|
+
// A first word to look for that names one of the finder's subcommands
|
|
641
|
+
// (`icon add trash`, `icon search use lucide`, `icon --json map pin`) runs
|
|
642
|
+
// that subcommand, which may need inputs or write files: the answer names
|
|
643
|
+
// its help, never a run of it.
|
|
644
|
+
const lookFor = plainWords(finderCmd, words)[0]?.toLowerCase();
|
|
645
|
+
const sub = visible(finderCmd).find(c => c.name() === lookFor);
|
|
646
|
+
if (sub)
|
|
647
|
+
return [
|
|
648
|
+
run(
|
|
649
|
+
[
|
|
650
|
+
...finder,
|
|
651
|
+
sub.name(),
|
|
652
|
+
'--help',
|
|
653
|
+
...fitWords(program, optionWords(first, rest)),
|
|
654
|
+
],
|
|
655
|
+
`the command is experimental icon ${sub.name()} (experimental); its help says what it takes`,
|
|
656
|
+
),
|
|
657
|
+
guide,
|
|
658
|
+
];
|
|
659
|
+
const reason =
|
|
660
|
+
'the command is experimental icon (experimental): it finds the icon for what you mean in your icon sets';
|
|
661
|
+
if (plainWords(finderCmd, words).length > 0)
|
|
662
|
+
return [
|
|
663
|
+
run([...finder, ...words.filter(w => w !== '--list')], reason),
|
|
664
|
+
guide,
|
|
665
|
+
];
|
|
666
|
+
if (listWord || words.includes('--list'))
|
|
667
|
+
return [
|
|
668
|
+
run([...finder, '--list', ...fitWords(program, words)], reason),
|
|
669
|
+
guide,
|
|
670
|
+
];
|
|
671
|
+
return [
|
|
672
|
+
guide,
|
|
673
|
+
run(
|
|
674
|
+
[...finder, '--help', ...fitWords(program, optionWords(first, rest))],
|
|
675
|
+
reason,
|
|
676
|
+
),
|
|
677
|
+
];
|
|
678
|
+
}
|
|
679
|
+
|
|
495
680
|
/**
|
|
496
681
|
* The commands the words point at, as runs (`astryx …`), best first, with
|
|
497
682
|
* the reason each is offered; empty when they point at none. Rules, in
|
|
498
683
|
* order: the word is an option of the program written after `--`
|
|
499
684
|
* (`astryx -- --help`); the word holds a whole command (`"component Table"`
|
|
500
|
-
* passed as one word); the
|
|
685
|
+
* passed as one word); the word asks for icons ({@link iconRuns}); the
|
|
686
|
+
* words come from another command line (see
|
|
501
687
|
* {@link otherCliWords}: `add theme matcha` is `theme add matcha`); the
|
|
502
688
|
* word, or its singular, is a command (`components Button`), a group named
|
|
503
689
|
* alone is its list (`themes` is `theme list`), and a list word or a read
|
|
@@ -508,17 +694,28 @@ async function otherCliWords({word, before, after: rest}, program, findEntry) {
|
|
|
508
694
|
* the tree (`verify` is `integration verify`, `themes` is `theme list`), or its hyphenated parts name that command (`validate-integration`
|
|
509
695
|
* is `doctor integration validate`); the next word, else the word itself,
|
|
510
696
|
* is a name another command reads (`info Text` is `component Text`).
|
|
511
|
-
* @param {{word: string, before: string[], after: string[]}}
|
|
512
|
-
*
|
|
697
|
+
* @param {{word: string, before: string[], after: string[], operands?: true}} first
|
|
698
|
+
* the word, the words of the run before and after it, and whether it
|
|
699
|
+
* follows `--`
|
|
513
700
|
* @param {CommandLike} program
|
|
514
701
|
* @param {FindEntry} findEntry
|
|
702
|
+
* @param {IconFeatures} iconFeatures
|
|
515
703
|
* @returns {Promise<Array<{words: string[], reason: string}>>}
|
|
516
704
|
*/
|
|
517
|
-
async function pointed(
|
|
705
|
+
async function pointed(first, program, findEntry, iconFeatures) {
|
|
706
|
+
const {word, before, after: rest} = first;
|
|
518
707
|
const top = visible(program);
|
|
519
708
|
const topNames = top.map(c => c.name());
|
|
520
709
|
/** @param {string[]} parts @param {string} reason */
|
|
521
710
|
const run = (parts, reason) => ({words: [...before, ...parts], reason});
|
|
711
|
+
// A command's help keeps the program options the reader typed (`--json`),
|
|
712
|
+
// so it answers in the form they asked for.
|
|
713
|
+
/** @param {string[]} command @param {string[]} [given] */
|
|
714
|
+
const help = (command, given = rest) => [
|
|
715
|
+
...command,
|
|
716
|
+
'--help',
|
|
717
|
+
...fitWords(program, optionWords(first, given)),
|
|
718
|
+
];
|
|
522
719
|
// An option written after `--`, where it reads as a word
|
|
523
720
|
// (`astryx -- --help`).
|
|
524
721
|
if (
|
|
@@ -531,6 +728,8 @@ async function pointed({word, before, after: rest}, program, findEntry) {
|
|
|
531
728
|
return [
|
|
532
729
|
run([...parts, ...rest], 'the words of one command, passed as one word'),
|
|
533
730
|
];
|
|
731
|
+
if (spellings(word).includes('icon'))
|
|
732
|
+
return iconRuns(first, program, iconFeatures);
|
|
534
733
|
// A borrowed run that does not parse leaves the word to the rules below
|
|
535
734
|
// (`info theme` names a group alone, so it is `component Theme`).
|
|
536
735
|
const borrowed = (
|
|
@@ -559,9 +758,7 @@ async function pointed({word, before, after: rest}, program, findEntry) {
|
|
|
559
758
|
),
|
|
560
759
|
];
|
|
561
760
|
if (visible(named).length > 0)
|
|
562
|
-
return [
|
|
563
|
-
run([named.name(), '--help'], `the commands of ${named.name()}`),
|
|
564
|
-
];
|
|
761
|
+
return [run(help([named.name()]), `the commands of ${named.name()}`)];
|
|
565
762
|
}
|
|
566
763
|
if (named && takesWords(named, rest)) {
|
|
567
764
|
// A read word after the command only asks to read the name after it
|
|
@@ -637,9 +834,7 @@ async function pointed({word, before, after: rest}, program, findEntry) {
|
|
|
637
834
|
const asRun = c => {
|
|
638
835
|
const words = [...c.words, ...listing(c), ...rest];
|
|
639
836
|
return run(
|
|
640
|
-
runParses(program, [...before, ...words])
|
|
641
|
-
? words
|
|
642
|
-
: [...c.words, '--help'],
|
|
837
|
+
runParses(program, [...before, ...words]) ? words : help(c.words),
|
|
643
838
|
`the command is ${c.words.join(' ')}`,
|
|
644
839
|
);
|
|
645
840
|
};
|
|
@@ -670,7 +865,7 @@ async function pointed({word, before, after: rest}, program, findEntry) {
|
|
|
670
865
|
run(
|
|
671
866
|
runParses(program, [...before, ...asked.words, ...carried])
|
|
672
867
|
? [...asked.words, ...carried]
|
|
673
|
-
:
|
|
868
|
+
: help(asked.words, carried),
|
|
674
869
|
asked.reason,
|
|
675
870
|
),
|
|
676
871
|
];
|
|
@@ -703,27 +898,39 @@ async function pointed({word, before, after: rest}, program, findEntry) {
|
|
|
703
898
|
|
|
704
899
|
/**
|
|
705
900
|
* The answer to a word the CLI has no command for: `unknown command
|
|
706
|
-
* '<word>'`, with the
|
|
707
|
-
*
|
|
708
|
-
*
|
|
901
|
+
* '<word>'`, with the run of the project's own script the word names first
|
|
902
|
+
* ({@link projectScript}), then the runs the words point at ({@link pointed}),
|
|
903
|
+
* else the commands a typo of the word could be, else the help. Suggestion
|
|
904
|
+
* names are bare `astryx …` runs, a script run with the project's package
|
|
905
|
+
* manager, or command names, as cliError prints them.
|
|
709
906
|
* @param {CommandLike} program
|
|
710
907
|
* @param {string[]} words the words of the run after the program name
|
|
711
|
-
* @param {{findEntry?: FindEntry}} [context]
|
|
712
|
-
* command reads a name; without it, no name
|
|
713
|
-
*
|
|
714
|
-
*
|
|
908
|
+
* @param {{findEntry?: FindEntry, iconFeatures?: IconFeatures, projectScript?: ProjectScript}} [context]
|
|
909
|
+
* `findEntry` finds which lookup command reads a name; without it, no name
|
|
910
|
+
* points at a command. `iconFeatures` says whether icon features are on;
|
|
911
|
+
* without it, they are off. `projectScript` finds the project's own script
|
|
912
|
+
* the word names; without it, no word names one
|
|
913
|
+
* @returns {Promise<{word: string, message: string, suggestions: Array<{name: string, reason: string}>, help: {name: string, reason: string}, near?: string[], fallback?: true} | null>}
|
|
914
|
+
* null when no word names a command; `help`: the help run, with the
|
|
915
|
+
* program options typed; `near`: the suggestions that are names of
|
|
916
|
+
* commands the word is a typo of, not runs; `fallback` when nothing fits
|
|
917
|
+
* and the one suggestion is the help
|
|
715
918
|
*/
|
|
716
919
|
export async function unknownCommandAnswer(
|
|
717
920
|
program,
|
|
718
921
|
words,
|
|
719
|
-
{
|
|
922
|
+
{
|
|
923
|
+
findEntry = async () => null,
|
|
924
|
+
iconFeatures = async () => false,
|
|
925
|
+
projectScript = async () => null,
|
|
926
|
+
} = {},
|
|
720
927
|
) {
|
|
721
928
|
const first = firstWord(words, program);
|
|
722
929
|
if (!first) return null;
|
|
723
930
|
const {word} = first;
|
|
724
931
|
const message = `unknown command '${word}'`;
|
|
725
932
|
// Only runs that parse: a line that fails again names nothing that works.
|
|
726
|
-
const runs = (await pointed(first, program, findEntry))
|
|
933
|
+
const runs = (await pointed(first, program, findEntry, iconFeatures))
|
|
727
934
|
.filter(r => runParses(program, r.words))
|
|
728
935
|
.map(r => ({
|
|
729
936
|
name: [
|
|
@@ -732,19 +939,96 @@ export async function unknownCommandAnswer(
|
|
|
732
939
|
].join(' '),
|
|
733
940
|
reason: r.reason,
|
|
734
941
|
}));
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
const
|
|
942
|
+
// The help keeps the program options the reader typed (`--json`), so it
|
|
943
|
+
// answers in the form they asked for.
|
|
944
|
+
const help = {
|
|
945
|
+
name: [
|
|
946
|
+
'astryx',
|
|
947
|
+
...[
|
|
948
|
+
...fitWords(program, first.before),
|
|
949
|
+
'help',
|
|
950
|
+
...fitWords(program, optionWords(first, first.after)),
|
|
951
|
+
].map(w => quoteCommandArgument(w)),
|
|
952
|
+
].join(' '),
|
|
953
|
+
reason: 'every command, with what it does',
|
|
954
|
+
};
|
|
955
|
+
// `help` travels with the answer so a printer that shows only runs can
|
|
956
|
+
// name it in place of a typo's command names.
|
|
957
|
+
const answer = {
|
|
958
|
+
...withoutScript(word, message, runs, program, help),
|
|
959
|
+
help,
|
|
960
|
+
};
|
|
961
|
+
// A word that names one of the project's own package.json scripts (`test`,
|
|
962
|
+
// `dev`) is most likely that script, typed through the CLI: its run comes
|
|
963
|
+
// first.
|
|
964
|
+
const script = await projectScript(word).catch(() => null);
|
|
965
|
+
if (!script) return answer;
|
|
966
|
+
// The script's run is a run, so the answer is no longer only the help.
|
|
967
|
+
const {fallback: _fallback, ...rest} = answer;
|
|
738
968
|
return {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
: names.map(name => ({name, reason: 'available command'})),
|
|
969
|
+
...rest,
|
|
970
|
+
suggestions: [
|
|
971
|
+
{name: script, reason: `the project's own ${word} script`},
|
|
972
|
+
...answer.suggestions,
|
|
973
|
+
],
|
|
745
974
|
};
|
|
746
975
|
}
|
|
747
976
|
|
|
977
|
+
/**
|
|
978
|
+
* The answer the word gets when it names no project script: the runs the
|
|
979
|
+
* words point at, else the commands a typo of the word could be, else the
|
|
980
|
+
* help.
|
|
981
|
+
* @param {string} word
|
|
982
|
+
* @param {string} message
|
|
983
|
+
* @param {Array<{name: string, reason: string}>} runs
|
|
984
|
+
* @param {CommandLike} program
|
|
985
|
+
* @param {{name: string, reason: string}} help
|
|
986
|
+
* @returns {{word: string, message: string, suggestions: Array<{name: string, reason: string}>, near?: string[], fallback?: true}}
|
|
987
|
+
*/
|
|
988
|
+
function withoutScript(word, message, runs, program, help) {
|
|
989
|
+
if (runs.length > 0) return {word, message, suggestions: runs};
|
|
990
|
+
const near = nearNames(
|
|
991
|
+
word,
|
|
992
|
+
visible(program).map(c => c.name()),
|
|
993
|
+
);
|
|
994
|
+
if (near.length > 0)
|
|
995
|
+
return {
|
|
996
|
+
word,
|
|
997
|
+
message,
|
|
998
|
+
suggestions: near.map(name => ({name, reason: 'did you mean this?'})),
|
|
999
|
+
near,
|
|
1000
|
+
};
|
|
1001
|
+
// When nothing fits, the help lists every command with what it does. A
|
|
1002
|
+
// bare list of names would put the first one (`init`, which writes files)
|
|
1003
|
+
// where a reader looks for the answer.
|
|
1004
|
+
return {word, message, suggestions: [help], fallback: true};
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* The run of the project's own package.json script named `word`, with the
|
|
1009
|
+
* package manager the project uses (`pnpm run test`), from the folder of
|
|
1010
|
+
* that package.json when the run starts elsewhere. Null outside a project,
|
|
1011
|
+
* or when no script has that name.
|
|
1012
|
+
* @type {ProjectScript}
|
|
1013
|
+
*/
|
|
1014
|
+
export async function projectScript(word) {
|
|
1015
|
+
const project = findDeclaringPackage(process.cwd());
|
|
1016
|
+
if (!project) return null;
|
|
1017
|
+
const scripts = readJson(path.join(project.dir, 'package.json'))?.scripts;
|
|
1018
|
+
if (
|
|
1019
|
+
!scripts ||
|
|
1020
|
+
typeof scripts !== 'object' ||
|
|
1021
|
+
!Object.hasOwn(scripts, word) ||
|
|
1022
|
+
typeof scripts[word] !== 'string'
|
|
1023
|
+
)
|
|
1024
|
+
return null;
|
|
1025
|
+
const pm = detectPackageManager(project.dir);
|
|
1026
|
+
const run = `${pm === 'npx' ? 'npm' : pm} run ${quoteCommandArgument(word)}`;
|
|
1027
|
+
return path.resolve(project.dir) === path.resolve(process.cwd())
|
|
1028
|
+
? run
|
|
1029
|
+
: commandInFolder(project.dir, run);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
748
1032
|
/**
|
|
749
1033
|
* Which lookup command reads `name` in the project the run is in, from the
|
|
750
1034
|
* lookups' shared other-command hint (foundation/suggest/other-command.mjs),
|
|
@@ -765,3 +1049,18 @@ export async function findEntry(name) {
|
|
|
765
1049
|
? {command: words[1], name: words.slice(2).join(' ')}
|
|
766
1050
|
: null;
|
|
767
1051
|
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Whether icon features are on in the project the run is in, by the one gate
|
|
1055
|
+
* that decides it (spec:AST-084), loaded only when an icon word needs it.
|
|
1056
|
+
* @type {IconFeatures}
|
|
1057
|
+
*/
|
|
1058
|
+
export async function iconFeaturesOn() {
|
|
1059
|
+
const [{Project}, {iconFeatureGate}] = await Promise.all([
|
|
1060
|
+
import('../../../foundation/config/project.mjs'),
|
|
1061
|
+
import('../../../foundation/integrations/icon-features.mjs'),
|
|
1062
|
+
]);
|
|
1063
|
+
const cwd = process.cwd();
|
|
1064
|
+
const project = Project.lastLoaded(cwd) ?? (await Project.load(cwd));
|
|
1065
|
+
return iconFeatureGate(project).on;
|
|
1066
|
+
}
|