@astryxdesign/cli 0.7.14-canary.gfdb9213 → 0.7.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +197 -0
- 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/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 +10 -2
- package/api/theme-edit/_adapter.mjs +52 -31
- package/api/theme-edit/_check.d.mts +28 -25
- package/api/theme-edit/_check.mjs +586 -548
- package/api/theme-edit/_color.d.mts +28 -2
- package/api/theme-edit/_color.mjs +306 -68
- package/api/theme-edit/_compiler.d.mts +8 -4
- package/api/theme-edit/_compiler.mjs +30 -27
- package/api/theme-edit/_context.d.mts +10 -4
- package/api/theme-edit/_context.mjs +21 -4
- package/api/theme-edit/_edit.mjs +300 -43
- 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 +25 -17
- package/api/theme-edit/_how.mjs +727 -305
- package/api/theme-edit/_palette.d.mts +127 -19
- package/api/theme-edit/_palette.mjs +1313 -399
- package/api/theme-edit/_parts.mjs +36 -3
- 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 +26 -7
- package/api/theme-edit/_preview-app.mjs +1611 -280
- package/api/theme-edit/_preview.d.mts +4 -2
- package/api/theme-edit/_preview.mjs +18 -7
- package/api/theme-edit/_settings.d.mts +56 -5
- package/api/theme-edit/_settings.mjs +197 -49
- package/api/theme-edit/_tables.d.mts +0 -12
- package/api/theme-edit/_tables.mjs +24 -97
- package/api/theme-edit/theme-edit.type.d.mts +22 -5
- package/api/theme-edit/theme-edit.type.mjs +17 -6
- package/api/theme-edit/themeEditHow.doc.mjs +13 -3
- package/api/theme-edit/themeEditNew.doc.mjs +2 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +16 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -4
- package/api/theme-edit/themeEditPreviewList.doc.mjs +9 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +27 -2
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs.generated.json +1 -0
- package/assets/preview-app/gitignore +3 -0
- package/assets/templates/components.generated.json +1 -0
- package/clients/cli/bin/astryx.mjs +37 -5
- package/clients/cli/commands/experimental/theme.mjs +231 -31
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +14 -5
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -1
- package/clients/cli/commands/experimental-theme-editor-undo.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 -2
- 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 +2 -2
- 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 +104 -40
- package/clients/cli/commands.generated.json +1 -0
- package/clients/cli/index.mjs +96 -4
- 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 +24 -1
- 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/package.json +6 -6
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The theme an answer's commands are for: the one named, the only one, or
|
|
6
|
+
* the one changed last; with none, a theme the answer first makes.
|
|
7
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
8
|
+
* @param {string} cwd
|
|
9
|
+
* @param {string | undefined} name
|
|
10
|
+
* @returns {Promise<HowTheme>}
|
|
11
|
+
*/
|
|
12
|
+
export function howTheme(ctx: import("./_settings.mjs").Ctx, cwd: string, name: string | undefined): Promise<HowTheme>;
|
|
13
|
+
/**
|
|
14
|
+
* One word of a command as a shell takes it: plain when it is only safe
|
|
15
|
+
* characters, otherwise in double quotes with the characters a shell
|
|
16
|
+
* expands escaped.
|
|
17
|
+
* @param {string} v
|
|
18
|
+
*/
|
|
19
|
+
export function shellWord(v: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* A step as the command a person runs.
|
|
22
|
+
* @param {Step} st
|
|
23
|
+
* @param {string} slug
|
|
24
|
+
*/
|
|
25
|
+
export function render(st: Step, slug: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Parse a dial example (`set my corners pill --on button`) into a step.
|
|
28
|
+
* @param {string} example
|
|
29
|
+
* @returns {Step | null}
|
|
30
|
+
*/
|
|
31
|
+
export function exampleStep(example: string): Step | null;
|
|
32
|
+
/**
|
|
33
|
+
* Keep the alternatives that pass, and render them for the theme.
|
|
34
|
+
* @param {HowTheme} env
|
|
35
|
+
* @param {Step[][]} options each a list of steps run in order
|
|
36
|
+
* @returns {{commands: string[], refused: Array<{command: string, why: string}>}}
|
|
37
|
+
*/
|
|
38
|
+
export function checked(env: HowTheme, options: Step[][]): {
|
|
39
|
+
commands: string[];
|
|
40
|
+
refused: Array<{
|
|
41
|
+
command: string;
|
|
42
|
+
why: string;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
/** The theme name commands use when the app has no theme yet. */
|
|
46
|
+
export const EXAMPLE_THEME: "my-theme";
|
|
47
|
+
/**
|
|
48
|
+
* One change a command makes.
|
|
49
|
+
*/
|
|
50
|
+
export type Step = {
|
|
51
|
+
verb: "set" | "undo";
|
|
52
|
+
thing: string;
|
|
53
|
+
value?: string | undefined;
|
|
54
|
+
on?: string | undefined;
|
|
55
|
+
when?: string | undefined;
|
|
56
|
+
state?: string | undefined;
|
|
57
|
+
mode?: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The theme the commands of one answer are for, and the checks they pass.
|
|
61
|
+
*/
|
|
62
|
+
export type HowTheme = {
|
|
63
|
+
slug: string;
|
|
64
|
+
/**
|
|
65
|
+
* - false when the app has no theme: the commands name {@link EXAMPLE_THEME} and the answer starts with `new`.
|
|
66
|
+
*/
|
|
67
|
+
exists: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* - Every theme the editor made in the app.
|
|
70
|
+
*/
|
|
71
|
+
themes: string[];
|
|
72
|
+
/**
|
|
73
|
+
* - Which theme the commands are for when the app has several, or that it has none.
|
|
74
|
+
*/
|
|
75
|
+
note: string | null;
|
|
76
|
+
/**
|
|
77
|
+
* - How the theme was picked.
|
|
78
|
+
*/
|
|
79
|
+
chosenBy: "named" | "only" | "last-changed" | "none";
|
|
80
|
+
data: import("./_settings.mjs").ThemeData;
|
|
81
|
+
base: {
|
|
82
|
+
light: Record<string, string>;
|
|
83
|
+
dark: Record<string, string>;
|
|
84
|
+
};
|
|
85
|
+
check: (steps: Step[]) => {
|
|
86
|
+
ok: true;
|
|
87
|
+
} | {
|
|
88
|
+
ok: false;
|
|
89
|
+
why: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The commands `how` suggests: written for the user's theme, quoted so
|
|
5
|
+
* a shell runs them as printed, and each one checked as `set` checks it and
|
|
6
|
+
* compiled, so an answer names only commands that are accepted and change
|
|
7
|
+
* the theme. Nothing is written.
|
|
8
|
+
* @position api/theme-edit — imported by _how.mjs and _how-question.mjs
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as fs from 'node:fs';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import {AstryxError} from '../error.mjs';
|
|
14
|
+
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
15
|
+
import {checkSetting} from './_check.mjs';
|
|
16
|
+
import {baseResolved} from './_project.mjs';
|
|
17
|
+
import {compileTheme, keyOf, loadTheme, themeFiles} from './_settings.mjs';
|
|
18
|
+
import {LIKE, P} from './_tables.mjs';
|
|
19
|
+
|
|
20
|
+
/** The theme name commands use when the app has no theme yet. */
|
|
21
|
+
export const EXAMPLE_THEME = 'my-theme';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One change a command makes.
|
|
25
|
+
* @typedef {object} Step
|
|
26
|
+
* @property {'set' | 'undo'} verb
|
|
27
|
+
* @property {string} thing
|
|
28
|
+
* @property {string} [value]
|
|
29
|
+
* @property {string} [on]
|
|
30
|
+
* @property {string} [when]
|
|
31
|
+
* @property {string} [state]
|
|
32
|
+
* @property {string} [mode]
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The theme the commands of one answer are for, and the checks they pass.
|
|
37
|
+
* @typedef {object} HowTheme
|
|
38
|
+
* @property {string} slug
|
|
39
|
+
* @property {boolean} exists - false when the app has no theme: the commands name {@link EXAMPLE_THEME} and the answer starts with `new`.
|
|
40
|
+
* @property {string[]} themes - Every theme the editor made in the app.
|
|
41
|
+
* @property {string | null} note - Which theme the commands are for when the app has several, or that it has none.
|
|
42
|
+
* @property {'named' | 'only' | 'last-changed' | 'none'} chosenBy - How the theme was picked.
|
|
43
|
+
* @property {import('./_settings.mjs').ThemeData} data
|
|
44
|
+
* @property {{light: Record<string, string>, dark: Record<string, string>}} base
|
|
45
|
+
* @property {(steps: Step[]) => {ok: true} | {ok: false, why: string}} check
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The themes the editor made in the app, the one an editor command changed
|
|
50
|
+
* last first.
|
|
51
|
+
* @param {string} cwd
|
|
52
|
+
* @returns {string[]}
|
|
53
|
+
*/
|
|
54
|
+
function editorThemes(cwd) {
|
|
55
|
+
const root = path.join(cwd, 'themes');
|
|
56
|
+
if (!fs.existsSync(root)) return [];
|
|
57
|
+
return (
|
|
58
|
+
fs
|
|
59
|
+
.readdirSync(root)
|
|
60
|
+
.filter(d => fs.existsSync(themeFiles(cwd, d).settings))
|
|
61
|
+
// The undo history is written only by an editor command, so its time is
|
|
62
|
+
// the last change made here; a checkout or touch of the settings file
|
|
63
|
+
// does not move it.
|
|
64
|
+
.map(d => {
|
|
65
|
+
const f = themeFiles(cwd, d);
|
|
66
|
+
const t =
|
|
67
|
+
[f.history, f.settingsTs, f.settings].find(x => fs.existsSync(x)) ??
|
|
68
|
+
f.settings;
|
|
69
|
+
return {d, t: fs.statSync(t).mtimeMs};
|
|
70
|
+
})
|
|
71
|
+
.sort((a, b) => b.t - a.t || a.d.localeCompare(b.d))
|
|
72
|
+
.map(x => x.d)
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The theme an answer's commands are for: the one named, the only one, or
|
|
78
|
+
* the one changed last; with none, a theme the answer first makes.
|
|
79
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
80
|
+
* @param {string} cwd
|
|
81
|
+
* @param {string | undefined} name
|
|
82
|
+
* @returns {Promise<HowTheme>}
|
|
83
|
+
*/
|
|
84
|
+
export async function howTheme(ctx, cwd, name) {
|
|
85
|
+
const themes = editorThemes(cwd);
|
|
86
|
+
/** @type {import('./_settings.mjs').ThemeData | null} */
|
|
87
|
+
let data = null;
|
|
88
|
+
let slug = name ?? themes[0] ?? EXAMPLE_THEME;
|
|
89
|
+
let note = null;
|
|
90
|
+
if (name === '')
|
|
91
|
+
throw new AstryxError(
|
|
92
|
+
'--theme was given no name.',
|
|
93
|
+
[{name: `${P} how --list kinds`, reason: 'or leave --theme out'}],
|
|
94
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
95
|
+
);
|
|
96
|
+
if (name) data = loadTheme(cwd, name);
|
|
97
|
+
else if (themes.length) {
|
|
98
|
+
try {
|
|
99
|
+
data = loadTheme(cwd, slug);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
if (!(e instanceof AstryxError)) throw e;
|
|
102
|
+
note = `${slug} cannot be read (${e.message}); the commands are checked against a new theme instead`;
|
|
103
|
+
}
|
|
104
|
+
if (themes.length > 1 && !note)
|
|
105
|
+
note = `the commands are for ${slug}, the theme changed last; --theme picks another of: ${themes.join(', ')}`;
|
|
106
|
+
} else
|
|
107
|
+
note = `the app has no theme yet; the commands are for a theme named ${EXAMPLE_THEME}, made first with: ${P} new ${EXAMPLE_THEME} --like ${LIKE[0]}`;
|
|
108
|
+
const exists = Boolean(data);
|
|
109
|
+
if (!data) {
|
|
110
|
+
if (!themes.length) slug = EXAMPLE_THEME;
|
|
111
|
+
data = {name: slug, like: LIKE[0], mode: 'both', settings: []};
|
|
112
|
+
}
|
|
113
|
+
const theme = /** @type {import('./_settings.mjs').ThemeData} */ (data);
|
|
114
|
+
const base = await baseResolved(ctx.project, theme.like);
|
|
115
|
+
const compiled = (/** @type {import('./_settings.mjs').ThemeData} */ d) =>
|
|
116
|
+
JSON.stringify([d.mode, compileTheme(ctx, d, base)]);
|
|
117
|
+
const before = compiled(theme);
|
|
118
|
+
return {
|
|
119
|
+
slug,
|
|
120
|
+
exists,
|
|
121
|
+
themes,
|
|
122
|
+
note,
|
|
123
|
+
chosenBy: name
|
|
124
|
+
? 'named'
|
|
125
|
+
: !themes.length
|
|
126
|
+
? 'none'
|
|
127
|
+
: themes.length === 1
|
|
128
|
+
? 'only'
|
|
129
|
+
: 'last-changed',
|
|
130
|
+
data: theme,
|
|
131
|
+
base,
|
|
132
|
+
check(steps) {
|
|
133
|
+
/** @type {import('./_settings.mjs').ThemeData} */
|
|
134
|
+
const d = JSON.parse(JSON.stringify(theme));
|
|
135
|
+
try {
|
|
136
|
+
for (const st of steps) apply(ctx, slug, d, st);
|
|
137
|
+
if (compiled(d) === before)
|
|
138
|
+
return {
|
|
139
|
+
ok: false,
|
|
140
|
+
why: 'it changes nothing: the theme already looks that way',
|
|
141
|
+
};
|
|
142
|
+
return {ok: true};
|
|
143
|
+
} catch (e) {
|
|
144
|
+
if (e instanceof AstryxError)
|
|
145
|
+
return {
|
|
146
|
+
ok: false,
|
|
147
|
+
why: e.message.replace(/ Nothing was changed\.$/, ''),
|
|
148
|
+
};
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Apply one step to theme data in memory, as `set` and `undo` do.
|
|
157
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
158
|
+
* @param {string} slug
|
|
159
|
+
* @param {import('./_settings.mjs').ThemeData} d
|
|
160
|
+
* @param {Step} st
|
|
161
|
+
*/
|
|
162
|
+
function apply(ctx, slug, d, st) {
|
|
163
|
+
const unset = st.verb === 'undo';
|
|
164
|
+
const s = checkSetting(
|
|
165
|
+
ctx,
|
|
166
|
+
slug,
|
|
167
|
+
d,
|
|
168
|
+
st.thing,
|
|
169
|
+
st.value,
|
|
170
|
+
{on: st.on, when: st.when, state: st.state, mode: st.mode},
|
|
171
|
+
unset,
|
|
172
|
+
);
|
|
173
|
+
if (!unset && s.thing === 'mode') {
|
|
174
|
+
d.mode = /** @type {'both' | 'light-only' | 'dark-only'} */ (s.value);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (!unset && s.thing === 'base')
|
|
178
|
+
throw new AstryxError(
|
|
179
|
+
'how does not check a change of base',
|
|
180
|
+
[],
|
|
181
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
182
|
+
);
|
|
183
|
+
const k = keyOf(s);
|
|
184
|
+
const i = d.settings.findIndex(x => keyOf(x) === k);
|
|
185
|
+
if (unset) {
|
|
186
|
+
if (i < 0)
|
|
187
|
+
throw new AstryxError(
|
|
188
|
+
`the theme does not set ${st.thing}${st.on ? ` on ${st.on}` : ''}`,
|
|
189
|
+
[],
|
|
190
|
+
ERROR_CODES.ERR_THEME_NOT_SET,
|
|
191
|
+
);
|
|
192
|
+
d.settings.splice(i, 1);
|
|
193
|
+
} else if (i >= 0) d.settings[i] = s;
|
|
194
|
+
else d.settings.push(s);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* One word of a command as a shell takes it: plain when it is only safe
|
|
199
|
+
* characters, otherwise in double quotes with the characters a shell
|
|
200
|
+
* expands escaped.
|
|
201
|
+
* @param {string} v
|
|
202
|
+
*/
|
|
203
|
+
export function shellWord(v) {
|
|
204
|
+
if (/^[A-Za-z0-9_.,:%+\-/=@]+$/.test(v)) return v;
|
|
205
|
+
return `"${v.replace(/["\\$`]/g, c => `\\${c}`)}"`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* A step as the command a person runs.
|
|
210
|
+
* @param {Step} st
|
|
211
|
+
* @param {string} slug
|
|
212
|
+
*/
|
|
213
|
+
export function render(st, slug) {
|
|
214
|
+
return [
|
|
215
|
+
P,
|
|
216
|
+
st.verb,
|
|
217
|
+
slug,
|
|
218
|
+
shellWord(st.thing),
|
|
219
|
+
...(st.value != null ? [shellWord(st.value)] : []),
|
|
220
|
+
...(st.on ? ['--on', st.on] : []),
|
|
221
|
+
...(st.when ? ['--when', st.when] : []),
|
|
222
|
+
...(st.state ? ['--state', st.state] : []),
|
|
223
|
+
...(st.mode ? ['--mode', st.mode] : []),
|
|
224
|
+
].join(' ');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Parse a dial example (`set my corners pill --on button`) into a step.
|
|
229
|
+
* @param {string} example
|
|
230
|
+
* @returns {Step | null}
|
|
231
|
+
*/
|
|
232
|
+
export function exampleStep(example) {
|
|
233
|
+
const words = [...example.matchAll(/"((?:[^"\\]|\\.)*)"|(\S+)/g)].map(
|
|
234
|
+
m => m[1] ?? m[2],
|
|
235
|
+
);
|
|
236
|
+
const [verb, , thing, ...rest] = words;
|
|
237
|
+
if (verb !== 'set' || !thing) return null;
|
|
238
|
+
/** @type {Step} */
|
|
239
|
+
const st = {verb: 'set', thing};
|
|
240
|
+
const flag = rest.findIndex(w => w.startsWith('--'));
|
|
241
|
+
const value = (flag < 0 ? rest : rest.slice(0, flag)).join(' ');
|
|
242
|
+
if (value) st.value = value;
|
|
243
|
+
for (let i = flag < 0 ? rest.length : flag; i < rest.length; i += 2) {
|
|
244
|
+
const k = rest[i].slice(2);
|
|
245
|
+
if (k === 'on' || k === 'when' || k === 'state' || k === 'mode')
|
|
246
|
+
st[k] = rest[i + 1];
|
|
247
|
+
}
|
|
248
|
+
return st;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Keep the alternatives that pass, and render them for the theme.
|
|
253
|
+
* @param {HowTheme} env
|
|
254
|
+
* @param {Step[][]} options each a list of steps run in order
|
|
255
|
+
* @returns {{commands: string[], refused: Array<{command: string, why: string}>}}
|
|
256
|
+
*/
|
|
257
|
+
export function checked(env, options) {
|
|
258
|
+
/** @type {string[]} */
|
|
259
|
+
const commands = [];
|
|
260
|
+
/** @type {Array<{command: string, why: string}>} */
|
|
261
|
+
const refused = [];
|
|
262
|
+
for (const steps of options) {
|
|
263
|
+
const text = steps.map(st => render(st, env.slug));
|
|
264
|
+
const r = env.check(steps);
|
|
265
|
+
if (r.ok) commands.push(...text.filter(c => !commands.includes(c)));
|
|
266
|
+
else refused.push({command: text.join(' && '), why: r.why});
|
|
267
|
+
}
|
|
268
|
+
return {commands, refused};
|
|
269
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Answer a plain-words question with drafts of commands.
|
|
6
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
7
|
+
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
8
|
+
* @param {string} question
|
|
9
|
+
* @returns {{parts: string[], aspects: string[], drafts: Draft[]}}
|
|
10
|
+
*/
|
|
11
|
+
export function draftAnswer(ctx: import("./_settings.mjs").Ctx, env: import("./_how-commands.mjs").HowTheme, question: string): {
|
|
12
|
+
parts: string[];
|
|
13
|
+
aspects: string[];
|
|
14
|
+
drafts: Draft[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* One clause, read.
|
|
18
|
+
*/
|
|
19
|
+
export type Clause = {
|
|
20
|
+
text: string;
|
|
21
|
+
parts: Array<{
|
|
22
|
+
on: string;
|
|
23
|
+
when?: string;
|
|
24
|
+
role?: string;
|
|
25
|
+
level?: string;
|
|
26
|
+
}>;
|
|
27
|
+
aspects: string[];
|
|
28
|
+
neg: boolean;
|
|
29
|
+
dir: "more" | "less" | null;
|
|
30
|
+
colors: string[];
|
|
31
|
+
/**
|
|
32
|
+
* - a hex color written with the wrong number of digits
|
|
33
|
+
*/
|
|
34
|
+
bad: string | null;
|
|
35
|
+
lengths: string[];
|
|
36
|
+
state: string | null;
|
|
37
|
+
mode: "light" | "dark" | null;
|
|
38
|
+
/**
|
|
39
|
+
* - "but not on X": X keeps what the clause before does
|
|
40
|
+
*/
|
|
41
|
+
except: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* - CSS written as `prop: value`
|
|
44
|
+
*/
|
|
45
|
+
decl: Record<string, string>;
|
|
46
|
+
};
|
|
47
|
+
export type Step = import("./_how-commands.mjs").Step;
|
|
48
|
+
/**
|
|
49
|
+
* One answer: what it does, and the ways to do it. Each option is a list of
|
|
50
|
+
* steps run in order; most options are one step.
|
|
51
|
+
*/
|
|
52
|
+
export type Draft = {
|
|
53
|
+
text: string;
|
|
54
|
+
options: Step[][];
|
|
55
|
+
sequence?: boolean;
|
|
56
|
+
lookup?: string;
|
|
57
|
+
};
|