-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathbackend.ts
More file actions
113 lines (109 loc) · 3.5 KB
/
Copy pathbackend.ts
File metadata and controls
113 lines (109 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { loadPluginConfig } from "../../config.js";
import type { PluginConfig } from "../../types.js";
import { UI_COPY } from "../../ui/ui-copy.js";
import { getUiRuntimeOptions } from "../../ui/runtime.js";
import { select } from "../../ui/select.js";
import { promptBackendCategorySettingsEntry } from "../backend-category-entry.js";
import {
applyBackendCategoryDefaults,
getBackendCategory,
getBackendCategoryInitialFocus,
resolveFocusedBackendNumberKey,
} from "../backend-category-helpers.js";
import { promptBackendCategorySettingsMenu } from "../backend-category-prompt.js";
import { configureBackendSettingsController } from "../backend-settings-controller.js";
import { configureBackendSettingsEntry } from "../backend-settings-entry.js";
import {
backendSettingsEqual,
buildBackendSettingsPreview,
cloneBackendPluginConfig,
formatBackendNumberValue,
} from "../backend-settings-helpers.js";
import { promptBackendSettingsMenu } from "../backend-settings-prompt.js";
import {
BACKEND_CATEGORY_OPTIONS,
BACKEND_DEFAULTS,
BACKEND_NUMBER_OPTION_BY_KEY,
BACKEND_TOGGLE_OPTION_BY_KEY,
type BackendCategoryOption,
type BackendSettingFocusKey,
} from "../backend-settings-schema.js";
import { formatDashboardSettingState } from "../dashboard-formatters.js";
import { highlightPreviewToken } from "../settings-preview.js";
import {
clampBackendNumber,
isTtyInteractive,
persistBackendConfigSelection,
} from "./shared.js";
/* c8 ignore start - interactive prompt flows are covered by integration tests */
async function promptBackendCategorySettings(
initial: PluginConfig,
category: BackendCategoryOption,
initialFocus: BackendSettingFocusKey,
): Promise<{ draft: PluginConfig; focusKey: BackendSettingFocusKey }> {
return promptBackendCategorySettingsEntry({
initial,
category,
initialFocus,
promptBackendCategorySettingsMenu,
ui: getUiRuntimeOptions(),
cloneBackendPluginConfig,
buildBackendSettingsPreview,
highlightPreviewToken,
resolveFocusedBackendNumberKey,
clampBackendNumber,
formatBackendNumberValue,
formatDashboardSettingState,
applyBackendCategoryDefaults: (config, selectedCategory) =>
applyBackendCategoryDefaults(config, selectedCategory, {
backendDefaults: BACKEND_DEFAULTS,
numberOptionByKey: BACKEND_NUMBER_OPTION_BY_KEY,
}),
getBackendCategoryInitialFocus,
backendDefaults: BACKEND_DEFAULTS,
toggleOptionByKey: BACKEND_TOGGLE_OPTION_BY_KEY,
numberOptionByKey: BACKEND_NUMBER_OPTION_BY_KEY,
select,
copy: UI_COPY.settings,
});
}
export async function promptBackendSettings(
initial: PluginConfig,
): Promise<PluginConfig | null> {
const interactive = isTtyInteractive();
if (!interactive) {
return null;
}
return promptBackendSettingsMenu({
initial,
isInteractive: () => interactive,
ui: getUiRuntimeOptions(),
cloneBackendPluginConfig,
backendCategoryOptions: BACKEND_CATEGORY_OPTIONS,
getBackendCategoryInitialFocus,
buildBackendSettingsPreview,
highlightPreviewToken,
select,
getBackendCategory,
promptBackendCategorySettings,
backendDefaults: BACKEND_DEFAULTS,
copy: UI_COPY.settings,
});
}
export async function configureBackendSettings(
currentConfig?: PluginConfig,
): Promise<PluginConfig> {
return configureBackendSettingsEntry(currentConfig, {
configureBackendSettingsController,
cloneBackendPluginConfig,
loadPluginConfig,
promptBackendSettings,
backendSettingsEqual,
persistBackendConfigSelection,
isInteractive: isTtyInteractive,
writeLine: (message) => {
console.log(message);
},
});
}
/* c8 ignore stop */