@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,289 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Class: CLIUtils
6
+
7
+ Utilities function for helping in the CLI.
8
+
9
+ ## Constructors
10
+
11
+ ### new CLIUtils()
12
+
13
+ > **new CLIUtils**(): [`CLIUtils`](CLIUtils.md)
14
+
15
+ #### Returns
16
+
17
+ [`CLIUtils`](CLIUtils.md)
18
+
19
+ ## Methods
20
+
21
+ ### fileExists()
22
+
23
+ > `static` **fileExists**(`filename`): `Promise`\<`boolean`\>
24
+
25
+ Does the specified file exist.
26
+
27
+ #### Parameters
28
+
29
+ • **filename**: `string`
30
+
31
+ The filename to check for existence.
32
+
33
+ #### Returns
34
+
35
+ `Promise`\<`boolean`\>
36
+
37
+ True if the file exists.
38
+
39
+ ***
40
+
41
+ ### fileExistsSync()
42
+
43
+ > `static` **fileExistsSync**(`filename`): `boolean`
44
+
45
+ Does the specified file exist, synchronously.
46
+
47
+ #### Parameters
48
+
49
+ • **filename**: `string`
50
+
51
+ The filename to check for existence.
52
+
53
+ #### Returns
54
+
55
+ `boolean`
56
+
57
+ True if the file exists.
58
+
59
+ ***
60
+
61
+ ### dirExists()
62
+
63
+ > `static` **dirExists**(`dir`): `Promise`\<`boolean`\>
64
+
65
+ Check if the dir exists.
66
+
67
+ #### Parameters
68
+
69
+ • **dir**: `string`
70
+
71
+ The directory to check.
72
+
73
+ #### Returns
74
+
75
+ `Promise`\<`boolean`\>
76
+
77
+ True if the dir exists.
78
+
79
+ ***
80
+
81
+ ### dirExistsSync()
82
+
83
+ > `static` **dirExistsSync**(`dir`): `boolean`
84
+
85
+ Check if the dir exists, synchronously.
86
+
87
+ #### Parameters
88
+
89
+ • **dir**: `string`
90
+
91
+ The directory to check.
92
+
93
+ #### Returns
94
+
95
+ `boolean`
96
+
97
+ True if the dir exists.
98
+
99
+ ***
100
+
101
+ ### readJsonFile()
102
+
103
+ > `static` **readJsonFile**\<`T`\>(`filename`): `Promise`\<`undefined` \| `T`\>
104
+
105
+ Read a JSON file and parse it.
106
+
107
+ #### Type parameters
108
+
109
+ • **T** = `unknown`
110
+
111
+ #### Parameters
112
+
113
+ • **filename**: `string`
114
+
115
+ The filename to read.
116
+
117
+ #### Returns
118
+
119
+ `Promise`\<`undefined` \| `T`\>
120
+
121
+ The parsed JSON.
122
+
123
+ ***
124
+
125
+ ### readJsonFileSync()
126
+
127
+ > `static` **readJsonFileSync**\<`T`\>(`filename`): `undefined` \| `T`
128
+
129
+ Read a JSON file and parse it, synchronously.
130
+
131
+ #### Type parameters
132
+
133
+ • **T** = `unknown`
134
+
135
+ #### Parameters
136
+
137
+ • **filename**: `string`
138
+
139
+ The filename to read.
140
+
141
+ #### Returns
142
+
143
+ `undefined` \| `T`
144
+
145
+ The parsed JSON.
146
+
147
+ ***
148
+
149
+ ### readLinesFile()
150
+
151
+ > `static` **readLinesFile**(`filename`): `Promise`\<`undefined` \| `string`[]\>
152
+
153
+ Read a file as lines.
154
+
155
+ #### Parameters
156
+
157
+ • **filename**: `string`
158
+
159
+ The filename to read.
160
+
161
+ #### Returns
162
+
163
+ `Promise`\<`undefined` \| `string`[]\>
164
+
165
+ The lines.
166
+
167
+ ***
168
+
169
+ ### readLinesFileSync()
170
+
171
+ > `static` **readLinesFileSync**(`filename`): `undefined` \| `string`[]
172
+
173
+ Read a file as lines, synchronously.
174
+
175
+ #### Parameters
176
+
177
+ • **filename**: `string`
178
+
179
+ The filename to read.
180
+
181
+ #### Returns
182
+
183
+ `undefined` \| `string`[]
184
+
185
+ The lines.
186
+
187
+ ***
188
+
189
+ ### findNpmRoot()
190
+
191
+ > `static` **findNpmRoot**(`rootFolder`): `Promise`\<`string`\>
192
+
193
+ Find the NPM root based on a package.json path.
194
+
195
+ #### Parameters
196
+
197
+ • **rootFolder**: `string`
198
+
199
+ The path to the package.json.
200
+
201
+ #### Returns
202
+
203
+ `Promise`\<`string`\>
204
+
205
+ The root path.
206
+
207
+ ***
208
+
209
+ ### runShellCmd()
210
+
211
+ > `static` **runShellCmd**(`app`, `args`, `cwd`): `Promise`\<`void`\>
212
+
213
+ Run a shell app.
214
+
215
+ #### Parameters
216
+
217
+ • **app**: `string`
218
+
219
+ The app to run in the shell.
220
+
221
+ • **args**: `string`[]
222
+
223
+ The args for the app.
224
+
225
+ • **cwd**: `string`
226
+
227
+ The working directory to execute the command in.
228
+
229
+ #### Returns
230
+
231
+ `Promise`\<`void`\>
232
+
233
+ Promise to wait for command execution to complete.
234
+
235
+ ***
236
+
237
+ ### writeJsonFile()
238
+
239
+ > `static` **writeJsonFile**\<`T`\>(`jsonFilename`, `data`, `append`): `Promise`\<`void`\>
240
+
241
+ Write a JSON file.
242
+
243
+ #### Type parameters
244
+
245
+ • **T** = `unknown`
246
+
247
+ #### Parameters
248
+
249
+ • **jsonFilename**: `undefined` \| `string`
250
+
251
+ The filename to write.
252
+
253
+ • **data**: `T`
254
+
255
+ The data to write.
256
+
257
+ • **append**: `boolean`
258
+
259
+ Append to the file.
260
+
261
+ #### Returns
262
+
263
+ `Promise`\<`void`\>
264
+
265
+ ***
266
+
267
+ ### writeEnvFile()
268
+
269
+ > `static` **writeEnvFile**(`envFilename`, `data`, `append`): `Promise`\<`void`\>
270
+
271
+ Write an env file.
272
+
273
+ #### Parameters
274
+
275
+ • **envFilename**: `undefined` \| `string`
276
+
277
+ The filename to write.
278
+
279
+ • **data**: `string`[]
280
+
281
+ The data to write.
282
+
283
+ • **append**: `boolean`
284
+
285
+ Append to the file.
286
+
287
+ #### Returns
288
+
289
+ `Promise`\<`void`\>
@@ -0,0 +1,27 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Function: addGlobalOptions()
6
+
7
+ > **addGlobalOptions**(`program`, `supportsLang`, `supportsEnvFiles`): `void`
8
+
9
+ Add the global options.
10
+
11
+ ## Parameters
12
+
13
+ • **program**: `Command`
14
+
15
+ The program to add the options to.
16
+
17
+ • **supportsLang**: `boolean`
18
+
19
+ Whether the CLI supports different languages.
20
+
21
+ • **supportsEnvFiles**: `boolean`
22
+
23
+ Whether the CLI supports loading env files
24
+
25
+ ## Returns
26
+
27
+ `void`
@@ -0,0 +1,19 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Function: initGlobalOptions()
6
+
7
+ > **initGlobalOptions**(`localesDirectory`): `void`
8
+
9
+ Initialize the global options.
10
+
11
+ ## Parameters
12
+
13
+ • **localesDirectory**: `string`
14
+
15
+ The path to load the locales from.
16
+
17
+ ## Returns
18
+
19
+ `void`
@@ -0,0 +1,29 @@
1
+ [**@twin.org/cli-core**](overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # @twin.org/cli-core
6
+
7
+ ## Classes
8
+
9
+ - [CLIBase](classes/CLIBase.md)
10
+ - [CLIDisplay](classes/CLIDisplay.md)
11
+ - [CLIOptions](classes/CLIOptions.md)
12
+ - [CLIParam](classes/CLIParam.md)
13
+ - [CLIUtils](classes/CLIUtils.md)
14
+
15
+ ## Interfaces
16
+
17
+ - [ICliOptions](interfaces/ICliOptions.md)
18
+ - [ICliOutputOptionsConsole](interfaces/ICliOutputOptionsConsole.md)
19
+ - [ICliOutputOptionsEnv](interfaces/ICliOutputOptionsEnv.md)
20
+ - [ICliOutputOptionsJson](interfaces/ICliOutputOptionsJson.md)
21
+
22
+ ## Type Aliases
23
+
24
+ - [CliOutputOptions](type-aliases/CliOutputOptions.md)
25
+
26
+ ## Functions
27
+
28
+ - [initGlobalOptions](functions/initGlobalOptions.md)
29
+ - [addGlobalOptions](functions/addGlobalOptions.md)
@@ -0,0 +1,55 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Interface: ICliOptions
6
+
7
+ Options for the CLI.
8
+
9
+ ## Properties
10
+
11
+ ### title
12
+
13
+ > **title**: `string`
14
+
15
+ The title of the CLI.
16
+
17
+ ***
18
+
19
+ ### appName
20
+
21
+ > **appName**: `string`
22
+
23
+ The name of the app used to execute it.
24
+
25
+ ***
26
+
27
+ ### version
28
+
29
+ > **version**: `string`
30
+
31
+ The version of the app.
32
+
33
+ ***
34
+
35
+ ### icon
36
+
37
+ > **icon**: `string`
38
+
39
+ The icon for the CLI as an emoji character.
40
+
41
+ ***
42
+
43
+ ### supportsLang?
44
+
45
+ > `optional` **supportsLang**: `boolean`
46
+
47
+ Supports different languages.
48
+
49
+ ***
50
+
51
+ ### supportsEnvFiles?
52
+
53
+ > `optional` **supportsEnvFiles**: `boolean`
54
+
55
+ Supports the loading of env files.
@@ -0,0 +1,15 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Interface: ICliOutputOptionsConsole
6
+
7
+ Options for the CLI Output for console.
8
+
9
+ ## Properties
10
+
11
+ ### console
12
+
13
+ > **console**: `boolean`
14
+
15
+ Flag to display on the console.
@@ -0,0 +1,23 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Interface: ICliOutputOptionsEnv
6
+
7
+ Options for the CLI Output for env.
8
+
9
+ ## Properties
10
+
11
+ ### env?
12
+
13
+ > `optional` **env**: `string`
14
+
15
+ Output the data to an environment file.
16
+
17
+ ***
18
+
19
+ ### mergeEnv
20
+
21
+ > **mergeEnv**: `boolean`
22
+
23
+ Merge the data to an environment file.
@@ -0,0 +1,23 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Interface: ICliOutputOptionsJson
6
+
7
+ Options for the CLI Output for JSON.
8
+
9
+ ## Properties
10
+
11
+ ### json?
12
+
13
+ > `optional` **json**: `string`
14
+
15
+ Output the data to an JSON file.
16
+
17
+ ***
18
+
19
+ ### mergeJson
20
+
21
+ > **mergeJson**: `boolean`
22
+
23
+ Merge the data to a JSON file.
@@ -0,0 +1,9 @@
1
+ [**@twin.org/cli-core**](../overview.md) • **Docs**
2
+
3
+ ***
4
+
5
+ # Type alias: CliOutputOptions
6
+
7
+ > **CliOutputOptions**: [`ICliOutputOptionsConsole`](../interfaces/ICliOutputOptionsConsole.md) & [`ICliOutputOptionsEnv`](../interfaces/ICliOutputOptionsEnv.md) & [`ICliOutputOptionsJson`](../interfaces/ICliOutputOptionsJson.md)
8
+
9
+ Options for the CLI Output.
@@ -0,0 +1,57 @@
1
+ {
2
+ "error": {
3
+ "commands": {
4
+ "common": {
5
+ "missingEnv": "The \"{option}\" option is configured as an environment variable, but there is no environment variable with the name \"{value}\" set.",
6
+ "optionInvalidHex": "The \"{option}\" does not appear to be hex. \"{value}\"",
7
+ "optionInvalidBase64": "The \"{option}\" does not appear to be base64. \"{value}\"",
8
+ "optionInvalidHexBase64": "The \"{option}\" does not appear to be hex or base64. \"{value}\"",
9
+ "optionInvalidBech32": "The \"{option}\" does not appear to be bech32. \"{value}\"",
10
+ "optionMinValue": "The \"{option}\" option must be greater than or equal to {minValue}, it is {value}.",
11
+ "optionMaxValue": "The \"{option}\" option must be less than or equal to {maxValue}, it is {value}."
12
+ }
13
+ }
14
+ },
15
+ "cli": {
16
+ "progress": {
17
+ "done": "Done.",
18
+ "error": "Error",
19
+ "loadingEnvFiles": "Loading env files",
20
+ "pleaseWait": "Please wait...",
21
+ "writingJsonFile": "Writing JSON file",
22
+ "writingEnvFile": "Writing env file",
23
+ "readingJsonFile": "Reading JSON file",
24
+ "readingEnvFile": "Reading env file"
25
+ },
26
+ "options": {
27
+ "lang": {
28
+ "param": "--lang '<'lang'>'",
29
+ "description": "The language to display the output in."
30
+ },
31
+ "load-env": {
32
+ "param": "--load-env [env...]",
33
+ "description": "Load the env files to initialise any environment variables."
34
+ },
35
+ "no-console": {
36
+ "param": "--no-console",
37
+ "description": "Hides the output in the console."
38
+ },
39
+ "json": {
40
+ "param": "--json '<'filename'>'",
41
+ "description": "Creates a JSON file containing the output."
42
+ },
43
+ "env": {
44
+ "param": "--env '<'filename'>'",
45
+ "description": "Creates an env file containing the output."
46
+ },
47
+ "merge-json": {
48
+ "param": "--merge-json",
49
+ "description": "If the JSON file already exists merge the data instead of overwriting."
50
+ },
51
+ "merge-env": {
52
+ "param": "--merge-env",
53
+ "description": "If the env file already exists merge the data instead of overwriting."
54
+ }
55
+ }
56
+ }
57
+ }
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@twin.org/cli-core",
3
+ "version": "0.0.1-next.1",
4
+ "description": "Core classes for building a CLI",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/twinfoundation/framework.git",
8
+ "directory": "packages/cli-core"
9
+ },
10
+ "author": "martyn.janes@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "scripts": {
17
+ "clean": "rimraf dist coverage",
18
+ "build": "tspc",
19
+ "merge-locales": "merge-locales",
20
+ "test": "vitest --run --config ./vitest.config.ts --no-cache",
21
+ "coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
22
+ "bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
23
+ "bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
24
+ "bundle": "npm run bundle:esm && npm run bundle:cjs",
25
+ "docs:clean": "rimraf docs/reference",
26
+ "docs:generate": "typedoc",
27
+ "docs": "npm run docs:clean && npm run docs:generate",
28
+ "dist": "npm run clean && npm run build && npm run merge-locales && npm run test && npm run bundle && npm run docs"
29
+ },
30
+ "dependencies": {
31
+ "@twin.org/core": "0.0.1-next.1",
32
+ "@twin.org/crypto": "0.0.1-next.1",
33
+ "@twin.org/nameof": "next",
34
+ "chalk": "5.3.0",
35
+ "commander": "12.1.0",
36
+ "dotenv": "16.4.5"
37
+ },
38
+ "devDependencies": {
39
+ "@gtsc/merge-locales": "next",
40
+ "@twin.org/nameof-transformer": "next",
41
+ "@types/node": "22.5.5",
42
+ "@vitest/coverage-v8": "2.1.1",
43
+ "copyfiles": "2.4.1",
44
+ "rimraf": "6.0.1",
45
+ "rollup": "4.21.3",
46
+ "rollup-plugin-typescript2": "0.36.0",
47
+ "ts-patch": "3.2.1",
48
+ "typedoc": "0.26.7",
49
+ "typedoc-plugin-markdown": "4.2.7",
50
+ "typescript": "5.6.2",
51
+ "vitest": "2.1.1"
52
+ },
53
+ "main": "./dist/cjs/index.cjs",
54
+ "module": "./dist/esm/index.mjs",
55
+ "types": "./dist/types/index.d.ts",
56
+ "exports": {
57
+ ".": {
58
+ "require": "./dist/cjs/index.cjs",
59
+ "import": "./dist/esm/index.mjs",
60
+ "types": "./dist/types/index.d.ts"
61
+ }
62
+ },
63
+ "files": [
64
+ "dist/cjs",
65
+ "dist/esm",
66
+ "dist/types",
67
+ "locales",
68
+ "docs"
69
+ ]
70
+ }