@twin.org/cli-core 0.0.1-next.1

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.
Files changed (33) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -0
  3. package/dist/cjs/index.cjs +848 -0
  4. package/dist/esm/index.mjs +819 -0
  5. package/dist/types/cliBase.d.ts +26 -0
  6. package/dist/types/cliDisplay.d.ts +74 -0
  7. package/dist/types/cliOptions.d.ts +23 -0
  8. package/dist/types/cliParam.d.ts +110 -0
  9. package/dist/types/cliUtils.d.ts +81 -0
  10. package/dist/types/commands/global.d.ts +13 -0
  11. package/dist/types/index.d.ts +11 -0
  12. package/dist/types/models/ICliOptions.d.ts +29 -0
  13. package/dist/types/models/ICliOutputOptionsConsole.d.ts +9 -0
  14. package/dist/types/models/ICliOutputOptionsEnv.d.ts +13 -0
  15. package/dist/types/models/ICliOutputOptionsJson.d.ts +13 -0
  16. package/dist/types/models/cliOutputOptions.d.ts +7 -0
  17. package/docs/changelog.md +5 -0
  18. package/docs/examples.md +1 -0
  19. package/docs/reference/classes/CLIBase.md +83 -0
  20. package/docs/reference/classes/CLIDisplay.md +259 -0
  21. package/docs/reference/classes/CLIOptions.md +59 -0
  22. package/docs/reference/classes/CLIParam.md +393 -0
  23. package/docs/reference/classes/CLIUtils.md +289 -0
  24. package/docs/reference/functions/addGlobalOptions.md +27 -0
  25. package/docs/reference/functions/initGlobalOptions.md +19 -0
  26. package/docs/reference/globals.md +29 -0
  27. package/docs/reference/interfaces/ICliOptions.md +55 -0
  28. package/docs/reference/interfaces/ICliOutputOptionsConsole.md +15 -0
  29. package/docs/reference/interfaces/ICliOutputOptionsEnv.md +23 -0
  30. package/docs/reference/interfaces/ICliOutputOptionsJson.md +23 -0
  31. package/docs/reference/type-aliases/CliOutputOptions.md +9 -0
  32. package/locales/en.json +57 -0
  33. package/package.json +70 -0
@@ -0,0 +1,26 @@
1
+ import { Command } from "commander";
2
+ import type { ICliOptions } from "./models/ICliOptions";
3
+ /**
4
+ * The main entry point for the CLI.
5
+ */
6
+ export declare abstract class CLIBase {
7
+ /**
8
+ * Execute the command line processing.
9
+ * @param options The options for the CLI.
10
+ * @param localesDirectory The path to load the locales from.
11
+ * @param argv The process arguments.
12
+ * @returns The exit code.
13
+ */
14
+ execute(options: ICliOptions, localesDirectory: string, argv: string[]): Promise<number>;
15
+ /**
16
+ * Configure any options or actions at the root program level.
17
+ * @param program The root program command.
18
+ */
19
+ protected configureRoot(program: Command): void;
20
+ /**
21
+ * Get the commands for the CLI, override in derived class to supply your own.
22
+ * @param program The main program that the commands will be added to.
23
+ * @returns The commands for the CLI.
24
+ */
25
+ protected getCommands(program: Command): Command[];
26
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Display utilities for the CLI.
3
+ */
4
+ export declare class CLIDisplay {
5
+ /**
6
+ * The default output method for writing standard messages.
7
+ * @param buffer The message to output.
8
+ */
9
+ static write: (buffer: string | Uint8Array) => void;
10
+ /**
11
+ * The default output method for writing error messages.
12
+ * @param buffer The message to output.
13
+ */
14
+ static writeError: (buffer: string | Uint8Array) => void;
15
+ /**
16
+ * The default output method for clearing the current line.
17
+ */
18
+ static clearLine: () => void;
19
+ /**
20
+ * Display the header for the CLI.
21
+ * @param title The title of the CLI.
22
+ * @param version The version of the CLI.
23
+ * @param icon The icon for the CLI.
24
+ */
25
+ static header(title: string, version: string, icon: string): void;
26
+ /**
27
+ * Display an error message.
28
+ * @param error The error to display.
29
+ * @param lineBreaks Whether to add a line break after the error.
30
+ */
31
+ static error(error: unknown, lineBreaks?: boolean): void;
32
+ /**
33
+ * Display a section.
34
+ * @param label The label for the section.
35
+ */
36
+ static section(label: string): void;
37
+ /**
38
+ * Display a value with a label.
39
+ * @param label The label for the value.
40
+ * @param value The value to display.
41
+ * @param indentLevel The level of indentation.
42
+ */
43
+ static value(label: string, value: unknown, indentLevel?: number): void;
44
+ /**
45
+ * Display a task with a label.
46
+ * @param label The label for the value.
47
+ * @param task The task to display.
48
+ */
49
+ static task(label: string, task?: string): void;
50
+ /**
51
+ * Display a break.
52
+ */
53
+ static break(): void;
54
+ /**
55
+ * Display formatted and colorized JSON.
56
+ * @param obj The object to display.
57
+ */
58
+ static json(obj: unknown): void;
59
+ /**
60
+ * Display the processing is done.
61
+ */
62
+ static done(): void;
63
+ /**
64
+ * Start the spinner.
65
+ * @param i18nMessage The message to display with the spinner.
66
+ * @param spinnerCharacters The characters to use in the spinner.
67
+ * @param interval The interval for the spinner.
68
+ */
69
+ static spinnerStart(i18nMessage?: string, spinnerCharacters?: string[], interval?: number): void;
70
+ /**
71
+ * Stop the spinner.
72
+ */
73
+ static spinnerStop(): void;
74
+ }
@@ -0,0 +1,23 @@
1
+ import type { Command } from "commander";
2
+ /**
3
+ * Utilities for getting standard options.
4
+ */
5
+ export declare class CLIOptions {
6
+ /**
7
+ * Get the options for output.
8
+ * @param command The command to add the options to.
9
+ * @param opts The options of what to include.
10
+ * @param opts.noConsole Do not output to the console.
11
+ * @param opts.json Output to a JSON file.
12
+ * @param opts.env Output to an environment file.
13
+ * @param opts.mergeJson Merge existing JSON file.
14
+ * @param opts.mergeEnv Merge existing environment file.
15
+ */
16
+ static output(command: Command, opts: {
17
+ noConsole: boolean;
18
+ json: boolean;
19
+ env: boolean;
20
+ mergeJson: boolean;
21
+ mergeEnv: boolean;
22
+ }): void;
23
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Parameter utilities for the CLI.
3
+ */
4
+ export declare class CLIParam {
5
+ /**
6
+ * Check the option to see if it exists.
7
+ * @param optionName The name of the option.
8
+ * @param optionValue The option value.
9
+ * @param allowEnvVar Allow the option to be read from an env var.
10
+ * @returns The final option value.
11
+ * @throws An error if the option is invalid.
12
+ */
13
+ static env(optionName: string, optionValue: string | undefined, allowEnvVar: boolean): string | undefined;
14
+ /**
15
+ * Check the option to see if it exists.
16
+ * @param optionName The name of the option.
17
+ * @param optionValue The option value.
18
+ * @param allowEnvVar Allow the option to be read from an env var.
19
+ * @returns The final option value.
20
+ * @throws An error if the option is invalid.
21
+ */
22
+ static stringValue(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): string;
23
+ /**
24
+ * Check the option to see if it a url.
25
+ * @param optionName The name of the option.
26
+ * @param optionValue The option value.
27
+ * @param allowEnvVar Allow the option to be read from an env var.
28
+ * @returns The final option value.
29
+ * @throws An error if the option is invalid.
30
+ */
31
+ static url(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): string;
32
+ /**
33
+ * Check the option to see if it exists and is a number.
34
+ * @param optionName The name of the option.
35
+ * @param optionValue The option value.
36
+ * @param allowEnvVar Allow the option to be read from an env var.
37
+ * @param minValue The minimum value.
38
+ * @param maxValue The maximum value.
39
+ * @returns The final option value.
40
+ * @throws An error if the option is invalid.
41
+ */
42
+ static number(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean, minValue?: number, maxValue?: number): number;
43
+ /**
44
+ * Check the option to see if it exists and is an integer.
45
+ * @param optionName The name of the option.
46
+ * @param optionValue The option value.
47
+ * @param allowEnvVar Allow the option to be read from an env var.
48
+ * @param minValue The minimum value.
49
+ * @param maxValue The maximum value.
50
+ * @returns The final option value.
51
+ * @throws An error if the option is invalid.
52
+ */
53
+ static integer(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean, minValue?: number, maxValue?: number): number;
54
+ /**
55
+ * Check the option to see if it exists and is a big number.
56
+ * @param optionName The name of the option.
57
+ * @param optionValue The option value.
58
+ * @param allowEnvVar Allow the option to be read from an env var.
59
+ * @param minValue The minimum value.
60
+ * @param maxValue The maximum value.
61
+ * @returns The final option value.
62
+ * @throws An error if the option is invalid.
63
+ */
64
+ static bigint(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean, minValue?: bigint, maxValue?: bigint): bigint;
65
+ /**
66
+ * Check the option to see if it exists and is a boolean.
67
+ * @param optionName The name of the option.
68
+ * @param optionValue The option value.
69
+ * @param allowEnvVar Allow the option to be read from an env var.
70
+ * @returns The final option value.
71
+ * @throws An error if the option is invalid.
72
+ */
73
+ static boolean(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): boolean;
74
+ /**
75
+ * Check the option to see if it exists and is hex.
76
+ * @param optionName The name of the option.
77
+ * @param optionValue The option value.
78
+ * @param allowEnvVar Allow the option to be read from an env var.
79
+ * @returns The final option value.
80
+ * @throws An error if the option is invalid.
81
+ */
82
+ static hex(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): Uint8Array;
83
+ /**
84
+ * Check the option to see if it exists and is base64.
85
+ * @param optionName The name of the option.
86
+ * @param optionValue The option value.
87
+ * @param allowEnvVar Allow the option to be read from an env var.
88
+ * @returns The final option value.
89
+ * @throws An error if the option is invalid.
90
+ */
91
+ static base64(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): Uint8Array;
92
+ /**
93
+ * Check the option to see if it exists and is hex or base64.
94
+ * @param optionName The name of the option.
95
+ * @param optionValue The option value.
96
+ * @param allowEnvVar Allow the option to be read from an env var.
97
+ * @returns The final option value.
98
+ * @throws An error if the option is invalid.
99
+ */
100
+ static hexBase64(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): Uint8Array;
101
+ /**
102
+ * Check the option to see if it exists and is bech32.
103
+ * @param optionName The name of the option.
104
+ * @param optionValue The option value.
105
+ * @param allowEnvVar Allow the option to be read from an env var.
106
+ * @returns The final option value.
107
+ * @throws An error if the option is invalid.
108
+ */
109
+ static bech32(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): string;
110
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Utilities function for helping in the CLI.
3
+ */
4
+ export declare class CLIUtils {
5
+ /**
6
+ * Does the specified file exist.
7
+ * @param filename The filename to check for existence.
8
+ * @returns True if the file exists.
9
+ */
10
+ static fileExists(filename: string): Promise<boolean>;
11
+ /**
12
+ * Does the specified file exist, synchronously.
13
+ * @param filename The filename to check for existence.
14
+ * @returns True if the file exists.
15
+ */
16
+ static fileExistsSync(filename: string): boolean;
17
+ /**
18
+ * Check if the dir exists.
19
+ * @param dir The directory to check.
20
+ * @returns True if the dir exists.
21
+ */
22
+ static dirExists(dir: string): Promise<boolean>;
23
+ /**
24
+ * Check if the dir exists, synchronously.
25
+ * @param dir The directory to check.
26
+ * @returns True if the dir exists.
27
+ */
28
+ static dirExistsSync(dir: string): boolean;
29
+ /**
30
+ * Read a JSON file and parse it.
31
+ * @param filename The filename to read.
32
+ * @returns The parsed JSON.
33
+ */
34
+ static readJsonFile<T = unknown>(filename: string): Promise<T | undefined>;
35
+ /**
36
+ * Read a JSON file and parse it, synchronously.
37
+ * @param filename The filename to read.
38
+ * @returns The parsed JSON.
39
+ */
40
+ static readJsonFileSync<T = unknown>(filename: string): T | undefined;
41
+ /**
42
+ * Read a file as lines.
43
+ * @param filename The filename to read.
44
+ * @returns The lines.
45
+ */
46
+ static readLinesFile(filename: string): Promise<string[] | undefined>;
47
+ /**
48
+ * Read a file as lines, synchronously.
49
+ * @param filename The filename to read.
50
+ * @returns The lines.
51
+ */
52
+ static readLinesFileSync(filename: string): string[] | undefined;
53
+ /**
54
+ * Find the NPM root based on a package.json path.
55
+ * @param rootFolder The path to the package.json.
56
+ * @returns The root path.
57
+ */
58
+ static findNpmRoot(rootFolder: string): Promise<string>;
59
+ /**
60
+ * Run a shell app.
61
+ * @param app The app to run in the shell.
62
+ * @param args The args for the app.
63
+ * @param cwd The working directory to execute the command in.
64
+ * @returns Promise to wait for command execution to complete.
65
+ */
66
+ static runShellCmd(app: string, args: string[], cwd: string): Promise<void>;
67
+ /**
68
+ * Write a JSON file.
69
+ * @param jsonFilename The filename to write.
70
+ * @param data The data to write.
71
+ * @param append Append to the file.
72
+ */
73
+ static writeJsonFile<T = unknown>(jsonFilename: string | undefined, data: T, append: boolean): Promise<void>;
74
+ /**
75
+ * Write an env file.
76
+ * @param envFilename The filename to write.
77
+ * @param data The data to write.
78
+ * @param append Append to the file.
79
+ */
80
+ static writeEnvFile(envFilename: string | undefined, data: string[], append: boolean): Promise<void>;
81
+ }
@@ -0,0 +1,13 @@
1
+ import type { Command } from "commander";
2
+ /**
3
+ * Initialize the global options.
4
+ * @param localesDirectory The path to load the locales from.
5
+ */
6
+ export declare function initGlobalOptions(localesDirectory: string): void;
7
+ /**
8
+ * Add the global options.
9
+ * @param program The program to add the options to.
10
+ * @param supportsLang Whether the CLI supports different languages.
11
+ * @param supportsEnvFiles Whether the CLI supports loading env files
12
+ */
13
+ export declare function addGlobalOptions(program: Command, supportsLang: boolean, supportsEnvFiles: boolean): void;
@@ -0,0 +1,11 @@
1
+ export * from "./cliBase";
2
+ export * from "./cliDisplay";
3
+ export * from "./cliOptions";
4
+ export * from "./cliParam";
5
+ export * from "./cliUtils";
6
+ export * from "./commands/global";
7
+ export * from "./models/ICliOptions";
8
+ export * from "./models/ICliOutputOptionsConsole";
9
+ export * from "./models/ICliOutputOptionsEnv";
10
+ export * from "./models/ICliOutputOptionsJson";
11
+ export * from "./models/cliOutputOptions";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Options for the CLI.
3
+ */
4
+ export interface ICliOptions {
5
+ /**
6
+ * The title of the CLI.
7
+ */
8
+ title: string;
9
+ /**
10
+ * The name of the app used to execute it.
11
+ */
12
+ appName: string;
13
+ /**
14
+ * The version of the app.
15
+ */
16
+ version: string;
17
+ /**
18
+ * The icon for the CLI as an emoji character.
19
+ */
20
+ icon: string;
21
+ /**
22
+ * Supports different languages.
23
+ */
24
+ supportsLang?: boolean;
25
+ /**
26
+ * Supports the loading of env files.
27
+ */
28
+ supportsEnvFiles?: boolean;
29
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Options for the CLI Output for console.
3
+ */
4
+ export interface ICliOutputOptionsConsole {
5
+ /**
6
+ * Flag to display on the console.
7
+ */
8
+ console: boolean;
9
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Options for the CLI Output for env.
3
+ */
4
+ export interface ICliOutputOptionsEnv {
5
+ /**
6
+ * Output the data to an environment file.
7
+ */
8
+ env?: string;
9
+ /**
10
+ * Merge the data to an environment file.
11
+ */
12
+ mergeEnv: boolean;
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Options for the CLI Output for JSON.
3
+ */
4
+ export interface ICliOutputOptionsJson {
5
+ /**
6
+ * Output the data to an JSON file.
7
+ */
8
+ json?: string;
9
+ /**
10
+ * Merge the data to a JSON file.
11
+ */
12
+ mergeJson: boolean;
13
+ }
@@ -0,0 +1,7 @@
1
+ import type { ICliOutputOptionsConsole } from "./ICliOutputOptionsConsole";
2
+ import type { ICliOutputOptionsEnv } from "./ICliOutputOptionsEnv";
3
+ import type { ICliOutputOptionsJson } from "./ICliOutputOptionsJson";
4
+ /**
5
+ * Options for the CLI Output.
6
+ */
7
+ export type CliOutputOptions = ICliOutputOptionsConsole & ICliOutputOptionsEnv & ICliOutputOptionsJson;
@@ -0,0 +1,5 @@
1
+ # @twin.org/cli-core - Changelog
2
+
3
+ ## v0.0.1
4
+
5
+ - Initial Release
@@ -0,0 +1 @@
1
+ # @twin.org/cli-core - Examples
@@ -0,0 +1,83 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Class: `abstract` CLIBase
6
+
7
+ The main entry point for the CLI.
8
+
9
+ ## Constructors
10
+
11
+ ### new CLIBase()
12
+
13
+ > **new CLIBase**(): [`CLIBase`](CLIBase.md)
14
+
15
+ #### Returns
16
+
17
+ [`CLIBase`](CLIBase.md)
18
+
19
+ ## Methods
20
+
21
+ ### execute()
22
+
23
+ > **execute**(`options`, `localesDirectory`, `argv`): `Promise`\<`number`\>
24
+
25
+ Execute the command line processing.
26
+
27
+ #### Parameters
28
+
29
+ • **options**: [`ICliOptions`](../interfaces/ICliOptions.md)
30
+
31
+ The options for the CLI.
32
+
33
+ • **localesDirectory**: `string`
34
+
35
+ The path to load the locales from.
36
+
37
+ • **argv**: `string`[]
38
+
39
+ The process arguments.
40
+
41
+ #### Returns
42
+
43
+ `Promise`\<`number`\>
44
+
45
+ The exit code.
46
+
47
+ ***
48
+
49
+ ### configureRoot()
50
+
51
+ > `protected` **configureRoot**(`program`): `void`
52
+
53
+ Configure any options or actions at the root program level.
54
+
55
+ #### Parameters
56
+
57
+ • **program**: `Command`
58
+
59
+ The root program command.
60
+
61
+ #### Returns
62
+
63
+ `void`
64
+
65
+ ***
66
+
67
+ ### getCommands()
68
+
69
+ > `protected` **getCommands**(`program`): `Command`[]
70
+
71
+ Get the commands for the CLI, override in derived class to supply your own.
72
+
73
+ #### Parameters
74
+
75
+ • **program**: `Command`
76
+
77
+ The main program that the commands will be added to.
78
+
79
+ #### Returns
80
+
81
+ `Command`[]
82
+
83
+ The commands for the CLI.