UNPKG

4.28 kBPlain TextView Raw
1import { ExecaError, ExecaReturnValue } from 'execa';
2import {
3 Arguments,
4 Argv,
5 Command,
6 MapOptionConfig,
7 MapParamConfig,
8 OptionConfigMap,
9 ParserOptions,
10 PrimitiveType,
11} from '@boost/args';
12import { Path, PortablePath } from '@boost/common';
13import { PluginsSetting } from '@boost/config';
14import { Pluggable } from '@boost/plugin';
15import type { Context } from './contexts/Context';
16import type { ScriptContext } from './contexts/ScriptContext';
17import type { Tool } from './Tool';
18
19export type { Arguments, Argv, ParserOptions };
20
21export type BeemoTool = Tool;
22
23export interface BeemoProcess<C extends Context = Context> {
24 context: C;
25 tool: BeemoTool;
26}
27
28export type UnknownSettings = Record<string, unknown>;
29
30export interface BootstrapFile {
31 (tool: BeemoTool): Promise<void> | void;
32 bootstrap?: (tool: BeemoTool) => Promise<void> | void;
33 default?: (tool: BeemoTool) => Promise<void> | void;
34}
35
36export type Execution = ExecaReturnValue;
37
38export type ExecutionError = ExecaError;
39
40// DRIVERS
41
42export type DriverConfigStrategy = 'copy' | 'create' | 'native' | 'none' | 'reference' | 'template';
43
44export type DriverOutputStrategy = 'buffer' | 'none' | 'pipe' | 'stream';
45
46export interface DriverOptions {
47 args?: string[];
48 configStrategy?: DriverConfigStrategy;
49 dependencies?: string[];
50 env?: Record<string, string>;
51 expandGlobs?: boolean;
52 outputStrategy?: DriverOutputStrategy;
53 template?: string;
54}
55
56export interface DriverMetadata {
57 bin: string;
58 commandOptions: OptionConfigMap;
59 configName: string;
60 configOption: string;
61 configStrategy: 'copy' | 'create' | 'reference' | 'template';
62 dependencies: string[];
63 description: string;
64 filterOptions: boolean;
65 helpOption: string;
66 title: string;
67 useConfigOption: boolean;
68 versionOption: string;
69 watchOptions: string[];
70 workspaceStrategy: 'copy' | 'reference';
71}
72
73export interface DriverOutput {
74 stderr: string;
75 stdout: string;
76}
77
78export interface Driverable extends Pluggable<BeemoTool> {
79 metadata: DriverMetadata;
80}
81
82// DRIVER COMMANDS
83
84export interface DriverCommandConfig<O extends object, P extends PrimitiveType[]>
85 extends Omit<Command, 'category'> {
86 allowUnknownOptions?: boolean;
87 allowVariadicParams?: boolean | string;
88 options?: MapOptionConfig<O>;
89 params?: MapParamConfig<P>;
90}
91
92export type DriverCommandRunner<O extends object, P extends PrimitiveType[]> = (
93 tool: Tool,
94 options: O,
95 params: P,
96 rest: string[],
97) => Promise<string | undefined | void> | string | undefined | void;
98
99export interface DriverCommandRegistration<O extends object, P extends PrimitiveType[]> {
100 path: string;
101 config: DriverCommandConfig<O, P>;
102 runner: DriverCommandRunner<O, P>;
103}
104
105// SCRIPTS
106
107export interface Scriptable<O extends object> extends Pluggable<BeemoTool> {
108 parse: () => ParserOptions<O>;
109 execute: (context: ScriptContext, args: Arguments<O>) => Promise<unknown>;
110}
111
112// ROUTINES
113
114export interface RoutineOptions {
115 tool: BeemoTool;
116}
117
118// CONFIG
119
120export type ConfigExecuteStrategy = DriverOutputStrategy | '';
121
122export interface ConfigFile<T extends object = UnknownSettings> {
123 configure: {
124 cleanup: boolean;
125 parallel: boolean;
126 };
127 debug: boolean;
128 drivers: PluginsSetting;
129 execute: {
130 concurrency: number;
131 graph: boolean;
132 output: ConfigExecuteStrategy;
133 };
134 module: string;
135 scripts: PluginsSetting;
136 settings: T;
137}
138
139export interface BeemoConfig<T extends object = UnknownSettings> {
140 configure?: {
141 cleanup?: boolean;
142 parallel?: boolean;
143 };
144 debug?: boolean;
145 drivers?: PluginsSetting;
146 execute?: {
147 concurrency?: number;
148 graph?: boolean;
149 output?: ConfigExecuteStrategy;
150 };
151 module?: string;
152 scripts?: PluginsSetting;
153 settings?: T;
154}
155
156export type ConfigObject = Record<string, unknown>;
157
158export interface ConfigTemplateOptions {
159 configModule: string;
160 consumerConfigPath: Path | null;
161 context: Context;
162 driver: Driverable;
163 driverConfigPath: Path;
164 driverName: string;
165 providerConfigPath: Path | null;
166 templatePath: Path;
167 tool: BeemoTool;
168}
169
170export interface ConfigTemplateResult {
171 config: ConfigObject | string;
172 path?: PortablePath;
173}
174
175export type ConfigTemplate = (
176 configs: ConfigObject[],
177 options: ConfigTemplateOptions,
178) => ConfigTemplateResult;
179
180// OTHER
181
182declare global {
183 namespace NodeJS {
184 interface Process {
185 beemo: BeemoProcess;
186 }
187 }
188}