1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { logging } from '@angular-devkit/core';
|
9 | import { ArgumentsCamelCase, Argv, CamelCaseKey, CommandModule as YargsCommandModule } from 'yargs';
|
10 | import { AnalyticsCollector } from '../analytics/analytics-collector';
|
11 | import { EventCustomDimension, EventCustomMetric } from '../analytics/analytics-parameters';
|
12 | import { AngularWorkspace } from '../utilities/config';
|
13 | import { PackageManagerUtils } from '../utilities/package-manager';
|
14 | import { Option } from './utilities/json-schema';
|
15 | export type Options<T> = {
|
16 | [key in keyof T as CamelCaseKey<key>]: T[key];
|
17 | };
|
18 | export declare enum CommandScope {
|
19 |
|
20 | In = 0,
|
21 |
|
22 | Out = 1,
|
23 |
|
24 | Both = 2
|
25 | }
|
26 | export interface CommandContext {
|
27 | currentDirectory: string;
|
28 | root: string;
|
29 | workspace?: AngularWorkspace;
|
30 | globalConfiguration: AngularWorkspace;
|
31 | logger: logging.Logger;
|
32 | packageManager: PackageManagerUtils;
|
33 |
|
34 | args: {
|
35 | positional: string[];
|
36 | options: {
|
37 | help: boolean;
|
38 | jsonHelp: boolean;
|
39 | getYargsCompletions: boolean;
|
40 | } & Record<string, unknown>;
|
41 | };
|
42 | }
|
43 | export type OtherOptions = Record<string, unknown>;
|
44 | export interface CommandModuleImplementation<T extends {} = {}> extends Omit<YargsCommandModule<{}, T>, 'builder' | 'handler'> {
|
45 |
|
46 | scope: CommandScope;
|
47 |
|
48 | longDescriptionPath?: string;
|
49 |
|
50 | builder(argv: Argv): Promise<Argv<T>> | Argv<T>;
|
51 |
|
52 | run(options: Options<T> & OtherOptions): Promise<number | void> | number | void;
|
53 | }
|
54 | export interface FullDescribe {
|
55 | describe?: string;
|
56 | longDescription?: string;
|
57 | longDescriptionRelativePath?: string;
|
58 | }
|
59 | export declare abstract class CommandModule<T extends {} = {}> implements CommandModuleImplementation<T> {
|
60 | protected readonly context: CommandContext;
|
61 | abstract readonly command: string;
|
62 | abstract readonly describe: string | false;
|
63 | abstract readonly longDescriptionPath?: string;
|
64 | protected readonly shouldReportAnalytics: boolean;
|
65 | readonly scope: CommandScope;
|
66 | private readonly optionsWithAnalytics;
|
67 | constructor(context: CommandContext);
|
68 | /**
|
69 | * Description object which contains the long command descroption.
|
70 | * This is used to generate JSON help wich is used in AIO.
|
71 | *
|
72 | * `false` will result in a hidden command.
|
73 | */
|
74 | get fullDescribe(): FullDescribe | false;
|
75 | protected get commandName(): string;
|
76 | abstract builder(argv: Argv): Promise<Argv<T>> | Argv<T>;
|
77 | abstract run(options: Options<T> & OtherOptions): Promise<number | void> | number | void;
|
78 | handler(args: ArgumentsCamelCase<T> & OtherOptions): Promise<void>;
|
79 | protected getAnalytics(): Promise<AnalyticsCollector | undefined>;
|
80 | /**
|
81 | * Adds schema options to a command also this keeps track of options that are required for analytics.
|
82 | * **Note:** This method should be called from the command bundler method.
|
83 | */
|
84 | protected addSchemaOptionsToCommand<T>(localYargs: Argv<T>, options: Option[]): Argv<T>;
|
85 | protected getWorkspaceOrThrow(): AngularWorkspace;
|
86 | /**
|
87 | * Flush on an interval (if the event loop is waiting).
|
88 | *
|
89 | * @returns a method that when called will terminate the periodic
|
90 | * flush and call flush one last time.
|
91 | */
|
92 | protected getAnalyticsParameters(options: (Options<T> & OtherOptions) | OtherOptions): Partial<Record<EventCustomDimension | EventCustomMetric, string | boolean | number>>;
|
93 | private reportCommandRunAnalytics;
|
94 | private reportWorkspaceInfoAnalytics;
|
95 | }
|
96 | /**
|
97 | * Creates an known command module error.
|
98 | * This is used so during executation we can filter between known validation error and real non handled errors.
|
99 | */
|
100 | export declare class CommandModuleError extends Error {
|
101 | }
|