UNPKG

4.5 kBTypeScriptView Raw
1import type {
2 BaseGenerator,
3 ComposeOptions as EnvironmentComposeOptions,
4 GeneratorFeatures as FeaturesApi,
5 GeneratorOptions as OptionsApi,
6 ProgressOptions,
7} from '@yeoman/types';
8import type { JSONSchema7Type } from 'json-schema';
9import type { PipelineOptions } from 'mem-fs';
10import type { MemFsEditorFile } from 'mem-fs-editor';
11import type Storage from './util/storage.js';
12import type Generator from './index.js';
13
14export type StorageValue = JSONSchema7Type;
15export type StorageRecord = Record<string, StorageValue>;
16export type GeneratorPipelineOptions = PipelineOptions<MemFsEditorFile> & ProgressOptions & { pendingFiles?: boolean };
17
18/**
19 * Queue options.
20 */
21type QueueOptions = {
22 /** Name of the queue. */
23 queueName?: string;
24
25 /** Execute only once by namespace and taskName. */
26 once?: boolean;
27
28 /** Run the queue if not running yet. */
29 run?: boolean;
30
31 /** Edit a priority */
32 edit?: boolean;
33
34 /** Queued manually only */
35 skip?: boolean;
36
37 /** Arguments to pass to tasks */
38 args?: any[] | ((generator: Generator) => any[]);
39};
40
41/**
42 * Task options.
43 */
44export type TaskOptions = QueueOptions & {
45 /** Reject callback. */
46 reject?: (error: unknown) => void;
47
48 taskPrefix?: string;
49
50 auto?: boolean;
51
52 taskOrigin?: any;
53
54 cancellable?: boolean;
55};
56
57/**
58 * Priority object.
59 */
60export type Priority = QueueOptions & {
61 /** Name of the priority. */
62 priorityName: string;
63 /** The queue which this priority should be added before. */
64 before?: string;
65};
66
67/**
68 * Complete Task object.
69 */
70export type Task<TaskContext = any> = TaskOptions & {
71 /** Function to be queued. */
72
73 method: (this: TaskContext, ...args: any[]) => unknown | Promise<unknown>;
74
75 /** Name of the task. */
76 taskName: string;
77};
78
79export type BaseFeatures = FeaturesApi & {
80 /** The Generator instance unique identifier. The Environment will ignore duplicated identifiers. */
81 uniqueBy?: string;
82
83 /** UniqueBy calculation method */
84 unique?: true | 'argument' | 'namespace';
85
86 /** Only queue methods that matches a priority. */
87 tasksMatchingPriority?: boolean;
88
89 /** Tasks methods starts with prefix. Allows api methods (non tasks) without prefix. */
90 taskPrefix?: string;
91
92 /** Provides a custom install task. Environment built-in task will not be executed */
93 customInstallTask?: boolean | ((...args: any[]) => void | Promise<void>);
94
95 /** Provides a custom commit task. */
96 customCommitTask?: boolean | ((...args: any[]) => void | Promise<void>);
97
98 /** Disable args/options parsing. Whenever options/arguments are provided parsed like using commander based parsing. */
99 skipParseOptions?: boolean;
100
101 /** Custom priorities for more fine tuned workflows. */
102 customPriorities?: Priority[];
103
104 /** Inherit tasks from parent prototypes, implies tasksMatchingPriority */
105 inheritTasks?: boolean;
106};
107
108export type BaseOptions = OptionsApi & {
109 destinationRoot?: string;
110
111 skipInstall?: boolean;
112
113 skipCheckEnv?: boolean;
114
115 ignoreVersionCheck?: boolean;
116
117 askAnswered?: boolean;
118
119 localConfigOnly?: boolean;
120
121 skipCache?: boolean;
122
123 skipLocalCache?: boolean;
124
125 description?: string;
126
127 /** @deprecated moved to features */
128 skipParseOptions?: boolean;
129
130 /** @deprecated moved to features */
131 customPriorities?: Priority[];
132};
133
134export type ArgumentSpec = {
135 name: string;
136
137 /** Description for the argument. */
138 description?: string;
139
140 /** A value indicating whether the argument is required. */
141 required?: boolean;
142
143 /** A value indicating whether the argument is optional. */
144 optional?: boolean;
145
146 /** The type of the argument. */
147 type: typeof String | typeof Number | typeof Array | typeof Object;
148
149 /** The default value of the argument. */
150 default?: any;
151};
152
153export type CliOptionSpec = {
154 name: string;
155
156 /** The type of the option. */
157 type: typeof Boolean | typeof String | typeof Number | ((opt: string) => any);
158
159 required?: boolean;
160
161 /** The option name alias (example `-h` and --help`). */
162 alias?: string;
163
164 /** The default value. */
165 default?: any;
166
167 /** The description for the option. */
168 description?: string;
169
170 /** A value indicating whether the option should be hidden from the help output. */
171 hide?: boolean;
172
173 /** The storage to persist the option */
174 storage?: string | Storage;
175};
176
177export type ComposeOptions<G extends BaseGenerator = BaseGenerator> = EnvironmentComposeOptions<G> & {
178 destinationRoot?: string;
179 skipEnvRegister?: boolean;
180 forceResolve?: boolean;
181 forwardOptions?: boolean;
182};
183
\No newline at end of file