@qodalis/cli-core 0.0.9 → 0.0.11

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.
@@ -1,127 +1,7 @@
1
- import { Terminal } from '@xterm/xterm';
2
- import { Observable, Subject } from 'rxjs';
3
- import { CliBackgroundColor, CliForegroundColor, CliOptions, CliProcessCommand, CliProcessorMetadata, ICliUser, ICliUserSession } from '../models';
4
- export interface ICliCommandAuthor {
5
- /**
6
- * The name of the author
7
- */
8
- name: string;
9
- /**
10
- * The email of the author
11
- */
12
- email: string;
13
- }
14
- /**
15
- * Represents a command processor
16
- */
17
- export interface ICliCommandProcessor {
18
- /**
19
- * The command that this processor handles
20
- */
21
- command: string;
22
- /**
23
- * A description of the command
24
- */
25
- description?: string;
26
- /**
27
- * The author of the command
28
- */
29
- author?: ICliCommandAuthor;
30
- /**
31
- * If true, the processor can handle unlisted commands
32
- */
33
- allowUnlistedCommands?: boolean;
34
- /**
35
- * If true, the value is required
36
- */
37
- valueRequired?: boolean;
38
- /**
39
- * The version of the command processor
40
- * @default '1.0.0'
41
- */
42
- version?: string;
43
- /**
44
- * The metadata for the command processor
45
- */
46
- metadata?: CliProcessorMetadata;
47
- /**
48
- * Processors that are nested under this processor
49
- */
50
- processors?: ICliCommandProcessor[];
51
- /**
52
- * Parameters that the command accepts
53
- */
54
- parameters?: ICliCommandParameterDescriptor[];
55
- /**
56
- * Process the command
57
- * @param command The command to process
58
- * @param context The context in which the command is executed
59
- */
60
- processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
61
- /**
62
- * Write the description of the command
63
- * @param context The context in which the command is executed
64
- */
65
- writeDescription?(context: ICliExecutionContext): void;
66
- /**
67
- * A function that validates the command before execution
68
- * @param value The value to validate
69
- * @returns An object with a valid property that indicates if the value is valid and an optional message property that contains a message to display if the value is not valid
70
- */
71
- validateBeforeExecution?: (command: CliProcessCommand, context: ICliExecutionContext) => {
72
- valid: boolean;
73
- message?: string;
74
- };
75
- /**
76
- * Initialize the command processor
77
- * @param context The context in which the command is executed
78
- */
79
- initialize?(context: ICliExecutionContext): Promise<void>;
80
- }
81
- /**
82
- * Represents a command parameter
83
- */
84
- export interface ICliCommandParameterDescriptor {
85
- /**
86
- * The name of the parameter
87
- */
88
- name: string;
89
- /**
90
- * Aliases for the parameter
91
- */
92
- aliases?: string[];
93
- /**
94
- * A description of the parameter
95
- */
96
- description: string;
97
- /**
98
- * If true, the parameter is required
99
- */
100
- required: boolean;
101
- /**
102
- * The type of the parameter
103
- */
104
- type: string;
105
- /**
106
- * The default value of the parameter
107
- */
108
- defaultValue?: any;
109
- /**
110
- * A validator function that validates the value of the parameter
111
- * @param value The value to validate
112
- * @returns An object with a valid property that indicates if the value is valid and an optional message property that contains a message to display if the value is not valid
113
- */
114
- validator?: (value: any) => {
115
- /**
116
- * Indicates if the value is valid
117
- */
118
- valid: boolean;
119
- /**
120
- * An optional message to display if the value is not valid
121
- */
122
- message?: string;
123
- };
124
- }
1
+ import { Observable } from 'rxjs';
2
+ import { CliBackgroundColor, CliForegroundColor, CliLogLevel, CliProcessCommand, CliProvider, ICliUser, ICliUserSession } from '../models';
3
+ import { ICliExecutionContext } from './execution-context';
4
+ import { ICliCommandProcessor } from './command-processor';
125
5
  export interface ICliTerminalWriter {
126
6
  /**
127
7
  * Write text to the terminal
@@ -132,7 +12,7 @@ export interface ICliTerminalWriter {
132
12
  * Write text to the terminal followed by a newline
133
13
  * @param text The text to write
134
14
  */
135
- writeln(text: string): void;
15
+ writeln(text?: string): void;
136
16
  /**
137
17
  * Write a success message to the terminal
138
18
  * @param messag The message to write
@@ -197,58 +77,16 @@ export interface ICliTerminalWriter {
197
77
  * @returns void
198
78
  */
199
79
  writeTable(headers: string[], rows: string[][]): void;
200
- }
201
- export interface ICliProgressBar {
202
- /**
203
- * Indicates if the progress bar is running
204
- */
205
- isRunning: boolean;
206
- /**
207
- * Show the progress bar
208
- */
209
- show: () => void;
210
- /**
211
- * Hide the progress bar
212
- */
213
- hide: () => void;
214
- }
215
- /**
216
- * Represents a spinner for the CLI
217
- */
218
- export interface ICliSpinner extends ICliProgressBar {
219
- /**
220
- * Set the text of the spinner
221
- * @param text The text to set
222
- */
223
- setText: (text: string) => void;
224
- }
225
- export type CliPercentageProgressBarUpdateValueOptions = {
226
80
  /**
227
- * The type of update to perform
228
- * @default 'replace'
229
- */
230
- type?: 'replace' | 'increment';
231
- };
232
- /**
233
- * Represents a progress bar for the CLI
234
- */
235
- export interface ICliPercentageProgressBar extends ICliProgressBar {
236
- /**
237
- * Update the progress of the progress bar
238
- * @param progress The progress to update to
239
- * @returns void
240
- */
241
- update: (progress: number, options?: CliPercentageProgressBarUpdateValueOptions) => void;
242
- /**
243
- * Complete the progress bar
81
+ * Write a divider to the terminal
82
+ * @param options The options for the divider
244
83
  * @returns void
245
84
  */
246
- complete: () => void;
247
- /**
248
- * Set the text of the spinner
249
- * @param text The text to set
250
- */
251
- setText: (text: string) => void;
85
+ writeDivider(options?: {
86
+ color?: CliForegroundColor;
87
+ length?: number;
88
+ char?: string;
89
+ }): void;
252
90
  }
253
91
  /**
254
92
  * Represents a clipboard for the CLI
@@ -277,10 +115,16 @@ export interface ICliCommandExecutorService {
277
115
  */
278
116
  showHelp(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
279
117
  /**
280
- * List all commands
281
- * @returns An array of all commands
118
+ * Execute a command
119
+ * @param command The command to execute
120
+ * @param context The context in which the command is executed
282
121
  */
283
- listCommands(): string[];
122
+ executeCommand(command: string, context: ICliExecutionContext): Promise<void>;
123
+ }
124
+ /**
125
+ * Represents a registry for command processors
126
+ */
127
+ export interface ICliCommandProcessorRegistry {
284
128
  /**
285
129
  * Find a processor for a command
286
130
  * @param mainCommand
@@ -314,86 +158,31 @@ export interface ICliExecutionProcess {
314
158
  /**
315
159
  * The data of the process
316
160
  */
317
- data: string | undefined;
161
+ data: any | undefined;
318
162
  /**
319
163
  * Exit the process
320
164
  * @param code The exit code
321
165
  * @returns void
322
166
  */
323
- exit: (code?: number) => void;
167
+ exit: (
324
168
  /**
325
- * Output data from the process
326
- * @param data The data to output
169
+ * The exit code
327
170
  */
328
- output(data: string): void;
171
+ code?: number,
329
172
  /**
330
- * Start the process
331
- * @returns void
332
- */
333
- start: () => void;
334
- /**
335
- * End the process
336
- * @returns void
173
+ * Options for exiting the process
337
174
  */
338
- end: () => void;
339
- }
340
- /**
341
- * Represents the context in which a command is executed
342
- */
343
- export interface ICliExecutionContext {
344
- /**
345
- * The current user session
346
- */
347
- userSession?: ICliUserSession;
348
- /**
349
- * The spinner to use for showing/hiding the loader
350
- */
351
- spinner?: ICliSpinner;
352
- /**
353
- * The progress bar to use for showing progress
354
- */
355
- progressBar: ICliPercentageProgressBar;
356
- /**
357
- * A subject that emits when the command is aborted
358
- */
359
- onAbort: Subject<void>;
360
- /**
361
- * The terminal to use for writing
362
- */
363
- terminal: Terminal;
364
- /**
365
- * The writer to use for writing to the terminal
366
- */
367
- writer: ICliTerminalWriter;
368
- /**
369
- * The command executor to use for executing commands
370
- */
371
- executor: ICliCommandExecutorService;
372
- /**
373
- * The clipboard to use for copying/pasting
374
- */
375
- clipboard: ICliClipboard;
376
- /**
377
- * The data store to use for storing data
378
- */
379
- dataStore: ICliCommandDataStore;
380
- /**
381
- * The options for the CLI
382
- */
383
- options?: CliOptions;
384
- /**
385
- * The prompt to use for prompting the user for input
386
- */
387
- showPrompt: () => void;
388
- /**
389
- * Set the current main processor
390
- * @param processor The processor to set
391
- */
392
- setMainProcessor(processor: ICliCommandProcessor): void;
175
+ options?: {
176
+ /**
177
+ * Indicates if the exit should be silent, i.e. not throw an error
178
+ */
179
+ silent?: boolean;
180
+ }) => void;
393
181
  /**
394
- * The process to use for exiting the CLI
182
+ * Output data from the process
183
+ * @param data The data to output
395
184
  */
396
- process: ICliExecutionProcess;
185
+ output(data: any): void;
397
186
  }
398
187
  /**
399
188
  * Represents a data store for storing data associated with commands
@@ -479,3 +268,58 @@ export interface ICliUmdModule {
479
268
  */
480
269
  processors: ICliCommandProcessor[];
481
270
  }
271
+ /**
272
+ * Represents a logger for the CLI
273
+ */
274
+ export interface ICliLogger {
275
+ /**
276
+ * Set the log level of the logger
277
+ * @param level The log level to set
278
+ * @returns void
279
+ * @default CliLogLevel.ERROR
280
+ */
281
+ setCliLogLevel(level: CliLogLevel): void;
282
+ /**
283
+ * Log a message
284
+ * @param args The arguments to log
285
+ */
286
+ log(...args: any[]): void;
287
+ /**
288
+ * Log a message
289
+ * @param args The arguments to log
290
+ */
291
+ info(...args: any[]): void;
292
+ /**
293
+ * Log a message
294
+ * @param args The arguments to log
295
+ */
296
+ warn(...args: any[]): void;
297
+ /**
298
+ * Log a message
299
+ * @param args The arguments to log
300
+ */
301
+ error(...args: any[]): void;
302
+ /**
303
+ * Log a message
304
+ * @param args The arguments to log
305
+ */
306
+ debug(...args: any[]): void;
307
+ }
308
+ /**
309
+ * Represents a services for the CLI context
310
+ */
311
+ export interface ICliContextServices {
312
+ /**
313
+ * Get a service
314
+ * @param service The service to get
315
+ */
316
+ get<T>(service: any): T;
317
+ /**
318
+ * Set a service
319
+ * @param definition The definition of the service
320
+ */
321
+ set(definition: CliProvider | CliProvider[]): void;
322
+ }
323
+ export * from './execution-context';
324
+ export * from './command-processor';
325
+ export * from './progress-bars';
@@ -0,0 +1,52 @@
1
+ export interface ICliProgressBar {
2
+ /**
3
+ * Indicates if the progress bar is running
4
+ */
5
+ isRunning: boolean;
6
+ /**
7
+ * Show the progress bar
8
+ */
9
+ show: () => void;
10
+ /**
11
+ * Hide the progress bar
12
+ */
13
+ hide: () => void;
14
+ }
15
+ /**
16
+ * Represents a spinner for the CLI
17
+ */
18
+ export interface ICliSpinner extends ICliProgressBar {
19
+ /**
20
+ * Set the text of the spinner
21
+ * @param text The text to set
22
+ */
23
+ setText: (text: string) => void;
24
+ }
25
+ export type CliPercentageProgressBarUpdateValueOptions = {
26
+ /**
27
+ * The type of update to perform
28
+ * @default 'replace'
29
+ */
30
+ type?: 'replace' | 'increment';
31
+ };
32
+ /**
33
+ * Represents a progress bar for the CLI
34
+ */
35
+ export interface ICliPercentageProgressBar extends ICliProgressBar {
36
+ /**
37
+ * Update the progress of the progress bar
38
+ * @param progress The progress to update to
39
+ * @returns void
40
+ */
41
+ update: (progress: number, options?: CliPercentageProgressBarUpdateValueOptions) => void;
42
+ /**
43
+ * Complete the progress bar
44
+ * @returns void
45
+ */
46
+ complete: () => void;
47
+ /**
48
+ * Set the text of the spinner
49
+ * @param text The text to set
50
+ */
51
+ setText: (text: string) => void;
52
+ }
@@ -7,7 +7,7 @@ export type CliProcessCommand = {
7
7
  /**
8
8
  * The data that was entered
9
9
  */
10
- data?: string;
10
+ data?: any;
11
11
  /**
12
12
  * The chain of commands that were entered
13
13
  */
@@ -196,9 +196,19 @@ export interface ICliUserSession {
196
196
  */
197
197
  export type CliOptions = Record<string, any> & {
198
198
  /**
199
- * The welcome message to display when the CLI starts
199
+ * The welcome message options
200
200
  */
201
- welcomeMessage?: string;
201
+ welcomeMessage?: {
202
+ /**
203
+ * The message to display
204
+ */
205
+ message?: string;
206
+ /**
207
+ * When to show the welcome message
208
+ * @default 'always'
209
+ */
210
+ show?: 'always' | 'once' | 'daily' | 'never';
211
+ };
202
212
  /**
203
213
  * If true, the welcome message is hidden
204
214
  * @default false
@@ -225,6 +235,10 @@ export type CliOptions = Record<string, any> & {
225
235
  * Custom terminal options
226
236
  */
227
237
  terminalOptions?: ITerminalOptions & ITerminalInitOnlyOptions;
238
+ /**
239
+ * The minimum log level to display
240
+ */
241
+ logLevel?: CliLogLevel;
228
242
  };
229
243
  /**
230
244
  * Represents a package that can be installed
@@ -272,8 +286,21 @@ export type CliProcessorMetadata = Record<string, any> & {
272
286
  */
273
287
  icon?: CliIcon | string;
274
288
  };
289
+ /**
290
+ * Represents a log level for the CLI
291
+ */
292
+ export declare enum CliLogLevel {
293
+ None = 0,
294
+ DEBUG = 1,
295
+ LOG = 2,
296
+ INFO = 3,
297
+ WARN = 4,
298
+ ERROR = 5
299
+ }
275
300
  export declare const enums: {
276
301
  CliForegroundColor: typeof CliForegroundColor;
277
302
  CliBackgroundColor: typeof CliBackgroundColor;
278
303
  CliIcon: typeof CliIcon;
304
+ CliLogLevel: typeof CliLogLevel;
279
305
  };
306
+ export * from './services';
@@ -0,0 +1,20 @@
1
+ type MultiServices = {
2
+ /**
3
+ * When true, injector returns an array of instances. This is useful to allow multiple
4
+ * providers spread across many files to provide configuration information to a common token.
5
+ */
6
+ multi?: boolean;
7
+ };
8
+ export type CliValueProvider = MultiServices & {
9
+ useValue: any;
10
+ };
11
+ export type CliTypeProvider = MultiServices & {
12
+ useClass: any;
13
+ };
14
+ export type CliFactoryProvider = MultiServices & {
15
+ useFactory: Function;
16
+ };
17
+ export type CliProvider = {
18
+ provide: any;
19
+ } & (CliValueProvider | CliTypeProvider | CliFactoryProvider) & Record<string, any>;
20
+ export {};
@@ -1,5 +1,6 @@
1
- import { ICliUmdModule } from '../interfaces';
2
- export declare const initializeBrowserEnvironment: ({ handlers, }: {
1
+ import { ICliExecutionContext, ICliUmdModule } from '../interfaces';
2
+ export declare const initializeBrowserEnvironment: ({ context, handlers, }: {
3
+ context: ICliExecutionContext;
3
4
  handlers: ((module: ICliUmdModule) => Promise<void>)[];
4
5
  }) => void;
5
6
  export declare const bootUmdModule: (module: ICliUmdModule) => Promise<void>;
@@ -0,0 +1 @@
1
+ export declare const delay: (ms: number) => Promise<void>;
@@ -8,6 +8,7 @@ export declare const toQueryString: (params: Record<string, any>) => string;
8
8
  export declare const highlightTextWithBg: (text: string, pattern: RegExp, bgColor?: CliBackgroundColor) => string;
9
9
  export declare const getRightOfWord: (command: string, word: string) => string | undefined;
10
10
  export * from './object-describer';
11
+ export * from './delay';
11
12
  export declare const utils: {
12
13
  getParameterValue: (p: ICliCommandParameterDescriptor, args: Record<string, any>) => any | undefined;
13
14
  formatJson: (json: any) => string;
@@ -16,4 +17,5 @@ export declare const utils: {
16
17
  highlightTextWithBg: (text: string, pattern: RegExp, bgColor?: CliBackgroundColor) => string;
17
18
  getRightOfWord: (command: string, word: string) => string | undefined;
18
19
  ObjectDescriber: typeof ObjectDescriber;
20
+ delay: (ms: number) => Promise<void>;
19
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qodalis/cli-core",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Core Angular CLI for @qodalis extensions.",
5
5
  "author": "Nicolae Lupei, Qodalis Solutions",
6
6
  "license": "MIT",