@qlover/fe-release 0.1.7 → 1.0.8

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.
@@ -0,0 +1,378 @@
1
+ import { FeScriptContextOptions, Shell, FeReleaseConfig, FeScriptContext } from '@qlover/scripts-context';
2
+ import { AsyncExecutor, ExecutorContext, ExecutorPlugin, Logger } from '@qlover/fe-corekit';
3
+ import { Env } from '@qlover/env-loader';
4
+ import { OptionValues } from 'commander';
5
+
6
+ interface InitOptions {
7
+ token?: string;
8
+ repoName?: string;
9
+ authorName?: string;
10
+ }
11
+ interface PullRequestInterface {
12
+ init(params: InitOptions): Promise<unknown>;
13
+ mergePullRequest(params: unknown): Promise<unknown>;
14
+ /**
15
+ *
16
+ * @param params
17
+ */
18
+ getPullRequest(params: {
19
+ pull_number: number;
20
+ }): Promise<unknown>;
21
+ deleteBranch(params: unknown): Promise<unknown>;
22
+ addPullRequestLabels(params: unknown): Promise<unknown>;
23
+ createPullRequestLabel(params: unknown): Promise<unknown>;
24
+ createPullRequest(params: unknown): Promise<{
25
+ /**
26
+ * pr number
27
+ */
28
+ number: number;
29
+ [key: string]: unknown;
30
+ }>;
31
+ }
32
+
33
+ interface ReleaseItProps extends ReleaseItInstanceOptions {
34
+ /**
35
+ * Receive the `release-it` instance
36
+ */
37
+ releaseIt: ReleaseItInstanceType;
38
+ }
39
+ type ReleaseItInstanceType = (options: ReleaseItInstanceOptions) => Promise<ReleaseItInstanceResult>;
40
+ type ReleaseItInstanceOptions = Record<string, unknown>;
41
+ type ReleaseItInstanceResult = {
42
+ changelog: string;
43
+ version: string;
44
+ };
45
+ declare class ReleaseIt {
46
+ private context;
47
+ private releaseItInstance;
48
+ private templateOptions;
49
+ private templateJson;
50
+ private lastPath;
51
+ constructor(context: ReleaseContext, props?: ReleaseItProps);
52
+ /**
53
+ * Run release-it in the publish path
54
+ *
55
+ * Because `release-it` only support signle publish path,
56
+ * so we need to change the current working directory to the publish path.
57
+ *
58
+ * @note This method will change the current working directory to the publish path.
59
+ * @param options - The options for the release-it process.
60
+ * @returns The output from the release-it process.
61
+ */
62
+ run(options?: ReleaseItInstanceOptions): Promise<ReleaseItInstanceResult>;
63
+ getOptions(context?: SharedReleaseOptions, mergeOptions?: Partial<ReleaseItInstanceOptions>): ReleaseItInstanceOptions;
64
+ publishNpm(): Promise<ReleaseItInstanceResult>;
65
+ createChangelog(): Promise<ReleaseItInstanceResult>;
66
+ }
67
+
68
+ interface PublishNpmProps {
69
+ npmToken?: string;
70
+ /**
71
+ * Whether to skip setting the npmrc file
72
+ *
73
+ * @default `false`
74
+ */
75
+ skipNpmrc?: boolean;
76
+ }
77
+
78
+ type ConstructorType<T, Args extends unknown[]> = (new (...args: Args) => T) | ((...args: Args) => T);
79
+ declare function factory<T, Args extends unknown[]>(Constructor: ConstructorType<T, Args>, ...args: Args): T;
80
+
81
+ declare class ReleaseTask {
82
+ private executor;
83
+ private defaultTuples;
84
+ protected context: ReleaseContext;
85
+ constructor(options?: ReleaseContextOptions, executor?: AsyncExecutor, defaultTuples?: PluginTuple<PluginClass>[]);
86
+ getContext(): ReleaseContext;
87
+ usePlugins(externalTuples?: PluginTuple<PluginClass>[]): Promise<Plugin[]>;
88
+ run(): Promise<unknown>;
89
+ exec(externalTuples?: PluginTuple<PluginClass>[]): Promise<unknown>;
90
+ }
91
+
92
+ interface WorkspacesProps {
93
+ /**
94
+ * Whether to skip workspaces
95
+ *
96
+ * @default `false`
97
+ */
98
+ skip?: boolean;
99
+ /**
100
+ * Whether to skip checking the package.json file
101
+ *
102
+ * @default `false`
103
+ */
104
+ skipCheckPackage?: boolean;
105
+ /**
106
+ * The workspace to publish
107
+ */
108
+ workspace?: WorkspaceValue;
109
+ /**
110
+ * The workspaces to publish
111
+ * @private
112
+ */
113
+ workspaces?: WorkspaceValue[];
114
+ /**
115
+ * The change labels
116
+ *
117
+ * from `changePackagesLabel`
118
+ */
119
+ changeLabels?: string[];
120
+ }
121
+ interface WorkspaceValue {
122
+ name: string;
123
+ version: string;
124
+ /**
125
+ * The relative path of the workspace
126
+ */
127
+ path: string;
128
+ /**
129
+ * The absolute path of the workspace
130
+ */
131
+ root: string;
132
+ /**
133
+ * The package.json of the workspace
134
+ */
135
+ packageJson: PackageJson;
136
+ }
137
+
138
+ type ReleaseParamsConfig = {
139
+ /**
140
+ * Max number of workspaces to include in the release name
141
+ *
142
+ * @default 3
143
+ */
144
+ maxWorkspace?: number;
145
+ /**
146
+ * Multi-workspace separator
147
+ *
148
+ * @default '_'
149
+ */
150
+ multiWorkspaceSeparator?: string;
151
+ /**
152
+ * Workspace version separator
153
+ *
154
+ * @default '@'
155
+ */
156
+ workspaceVersionSeparator?: string;
157
+ /**
158
+ * The branch name for batch release
159
+ *
160
+ * @default `batch-${releaseName}-${length}-packages`
161
+ */
162
+ batchBranchName?: string;
163
+ /**
164
+ * The PR title for batch release
165
+ *
166
+ * default from feConfig.release.PRTitle
167
+ *
168
+ * @default `Release ${env} ${pkgName} ${tagName}`
169
+ */
170
+ PRTitle?: string;
171
+ /**
172
+ * The PR body for batch release
173
+ *
174
+ * default from feConfig.release.PRBody
175
+ */
176
+ PRBody?: string;
177
+ };
178
+
179
+ interface ReleasePullRequestProps extends ReleaseParamsConfig {
180
+ /**
181
+ * The increment of the release
182
+ *
183
+ * @default `patch`
184
+ */
185
+ increment: string;
186
+ /**
187
+ * Whether to dry run the creation of the pull request
188
+ *
189
+ * @default `false`
190
+ */
191
+ dryRunCreatePR?: boolean;
192
+ /**
193
+ * The pull request interface
194
+ */
195
+ pullRequestInterface: ConstructorType<PullRequestInterface, [ReleaseContext]>;
196
+ }
197
+
198
+ interface ExecutorReleaseContext extends ExecutorContext<ReleaseContext> {
199
+ returnValue: ReleaseReturnValue;
200
+ }
201
+ type ReleaseReturnValue = {
202
+ githubToken?: string;
203
+ [key: string]: unknown;
204
+ };
205
+ type DeepPartial<T> = {
206
+ [P in keyof T]?: DeepPartial<T[P]>;
207
+ };
208
+ interface ReleaseConfig {
209
+ publishNpm?: PublishNpmProps;
210
+ githubPR?: ReleasePullRequestProps;
211
+ releaseIt: ReleaseItProps;
212
+ workspaces?: WorkspacesProps;
213
+ }
214
+ interface ReleaseContextOptions<T extends ReleaseConfig = ReleaseConfig> extends Omit<FeScriptContextOptions<T>, 'constructor'> {
215
+ shared?: SharedReleaseOptions;
216
+ }
217
+ type StepOption<T> = {
218
+ label: string;
219
+ task: () => Promise<T>;
220
+ };
221
+ type PackageJson = Record<string, unknown>;
222
+ interface TemplateContext extends SharedReleaseOptions, WorkspaceValue {
223
+ publishPath: string;
224
+ /**
225
+ * @deprecated use `releaseEnv` from `shared`
226
+ */
227
+ env: string;
228
+ /**
229
+ * @deprecated use `sourceBranch` from `shared`
230
+ */
231
+ branch: string;
232
+ }
233
+
234
+ declare abstract class Plugin<Props = unknown> implements ExecutorPlugin<ReleaseContext> {
235
+ protected context: ReleaseContext;
236
+ readonly pluginName: string;
237
+ protected props: Props;
238
+ readonly onlyOne = true;
239
+ constructor(context: ReleaseContext, pluginName: string, props?: Props);
240
+ getInitialProps(props?: Props): Props;
241
+ get logger(): Logger;
242
+ get shell(): Shell;
243
+ get options(): Props;
244
+ getEnv(key: string, defaultValue?: string): string | undefined;
245
+ enabled(): boolean;
246
+ getConfig<T>(keys?: string | string[], defaultValue?: T): T;
247
+ setConfig(config: DeepPartial<Props>): void;
248
+ onBefore?(_context: ExecutorReleaseContext): void | Promise<void>;
249
+ onExec?(_context: ExecutorReleaseContext): void | Promise<void>;
250
+ onSuccess?(_context: ExecutorReleaseContext): void | Promise<void>;
251
+ onError?(_context: ExecutorReleaseContext): void | Promise<void>;
252
+ /**
253
+ * run a step
254
+ *
255
+ * this will log the step and return the result of the task
256
+ *
257
+ * @param label - the label of the step
258
+ * @param task - the task to run
259
+ * @returns the result of the task
260
+ */
261
+ step<T>({ label, task }: StepOption<T>): Promise<T>;
262
+ }
263
+
264
+ /**
265
+ * Represents a class that extends Plugin.
266
+ */
267
+ type PluginClass<T extends unknown[] = any[]> = new (...args: T) => Plugin;
268
+ /**
269
+ * Represents the constructor parameters for a specific Plugin class, excluding the first parameter.
270
+ * This assumes that the constructor parameters are known and can be inferred.
271
+ */
272
+ type PluginConstructorParams<T extends PluginClass> = T extends new (first: any, ...args: infer P) => unknown ? P : never;
273
+ type PluginTuple<T extends PluginClass> = [
274
+ T | string,
275
+ ...PluginConstructorParams<T>
276
+ ];
277
+ declare function tuple<T extends PluginClass>(plugin: T | string, ...args: PluginConstructorParams<T>): PluginTuple<T>;
278
+
279
+ interface SharedReleaseOptions extends FeReleaseConfig {
280
+ /**
281
+ * The source branch of the project
282
+ *
283
+ * default:
284
+ * - first, get from `FE_RELEASE_SOURCE_BRANCH`
285
+ * - second, get from `FE_RELEASE_BRANCH`
286
+ * - `master`
287
+ *
288
+ */
289
+ sourceBranch?: string;
290
+ /**
291
+ * The environment of the project
292
+ *
293
+ * default:
294
+ * - first, get from `FE_RELEASE_ENV`
295
+ * - second, get from `NODE_ENV`
296
+ * - `development`
297
+ */
298
+ releaseEnv?: string;
299
+ /**
300
+ * The root path of the project
301
+ *
302
+ * @default `process.cwd()`
303
+ */
304
+ rootPath?: string;
305
+ /**
306
+ * Whether to publish a PR
307
+ *
308
+ * @default `false`
309
+ */
310
+ releasePR?: boolean;
311
+ /**
312
+ * Plugins
313
+ */
314
+ plugins?: PluginTuple<PluginClass<unknown[]>>[];
315
+ repoName?: string;
316
+ authorName?: string;
317
+ currentBranch?: string;
318
+ /**
319
+ * Merge publish?
320
+ *
321
+ * If true, the PR will be created for all workspaces, instead of creating one PR per workspace.
322
+ *
323
+ * @default `false`
324
+ */
325
+ mergePublish?: boolean;
326
+ }
327
+
328
+ declare class ReleaseContext<T extends ReleaseConfig = ReleaseConfig> extends FeScriptContext<T> {
329
+ protected readonly _env: Env;
330
+ readonly releaseIt: ReleaseIt;
331
+ /**
332
+ * Shared Config
333
+ */
334
+ shared: SharedReleaseOptions;
335
+ constructor(context: ReleaseContextOptions<T>);
336
+ private getDefaultShreadOptions;
337
+ get releasePR(): boolean;
338
+ get rootPath(): string;
339
+ get sourceBranch(): string;
340
+ get releaseEnv(): string;
341
+ get env(): Env;
342
+ get workspaces(): WorkspaceValue[] | undefined;
343
+ get workspace(): WorkspaceValue | undefined;
344
+ setConfig(config: DeepPartial<ReleaseConfig>): void;
345
+ getConfig<T = unknown>(key: string | string[], defaultValue?: T): T;
346
+ setShared(shared: Partial<SharedReleaseOptions>): void;
347
+ getPkg<T>(key?: string, defaultValue?: T): T;
348
+ getTemplateContext(): TemplateContext;
349
+ }
350
+
351
+ type ReleaseLabelCompare = (changedFilePath: string, packagePath: string) => boolean;
352
+ interface ReleaseLabelOptions {
353
+ /**
354
+ * The change packages label
355
+ */
356
+ changePackagesLabel: string;
357
+ /**
358
+ * The packages directories
359
+ */
360
+ packagesDirectories: string[];
361
+ compare?: ReleaseLabelCompare;
362
+ }
363
+ declare class ReleaseLabel {
364
+ private readonly options;
365
+ constructor(options: ReleaseLabelOptions);
366
+ compare(changedFilePath: string, packagePath: string): boolean;
367
+ toChangeLabel(packagePath: string, label?: string): string;
368
+ toChangeLabels(packages: string[], label?: string): string[];
369
+ pick(changedFiles: Array<string> | Set<string>, packages?: string[]): string[];
370
+ }
371
+
372
+ declare function load<T>(pluginName: string): Promise<[string, T]>;
373
+ declare function loaderPluginsFromPluginTuples<T extends Plugin<unknown>>(context: ReleaseContext, pluginsTuples: PluginTuple<PluginClass>[], maxLimit?: number): Promise<T[]>;
374
+
375
+ declare function reduceOptions(opts: OptionValues, commonKey?: string): OptionValues;
376
+
377
+ export { Plugin, ReleaseContext, ReleaseLabel, ReleaseTask, factory, load, loaderPluginsFromPluginTuples, reduceOptions, tuple };
378
+ export type { ConstructorType, DeepPartial, ExecutorReleaseContext, InitOptions, PackageJson, PluginClass, PluginConstructorParams, PluginTuple, PullRequestInterface, ReleaseConfig, ReleaseContextOptions, ReleaseLabelCompare, ReleaseLabelOptions, ReleaseReturnValue, StepOption, TemplateContext };