@twin.org/cli-core 0.0.2-next.8 → 0.0.3-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 (38) hide show
  1. package/dist/es/cliBase.js +122 -0
  2. package/dist/es/cliBase.js.map +1 -0
  3. package/dist/es/cliDisplay.js +166 -0
  4. package/dist/es/cliDisplay.js.map +1 -0
  5. package/dist/es/cliOptions.js +36 -0
  6. package/dist/es/cliOptions.js.map +1 -0
  7. package/dist/es/cliParam.js +248 -0
  8. package/dist/es/cliParam.js.map +1 -0
  9. package/dist/es/cliUtils.js +235 -0
  10. package/dist/es/cliUtils.js.map +1 -0
  11. package/dist/es/commands/global.js +61 -0
  12. package/dist/es/commands/global.js.map +1 -0
  13. package/dist/es/index.js +14 -0
  14. package/dist/es/index.js.map +1 -0
  15. package/dist/es/models/ICliOptions.js +2 -0
  16. package/dist/es/models/ICliOptions.js.map +1 -0
  17. package/dist/es/models/ICliOutputOptionsConsole.js +2 -0
  18. package/dist/es/models/ICliOutputOptionsConsole.js.map +1 -0
  19. package/dist/es/models/ICliOutputOptionsEnv.js +2 -0
  20. package/dist/es/models/ICliOutputOptionsEnv.js.map +1 -0
  21. package/dist/es/models/ICliOutputOptionsJson.js +2 -0
  22. package/dist/es/models/ICliOutputOptionsJson.js.map +1 -0
  23. package/dist/es/models/cliOutputOptions.js +2 -0
  24. package/dist/es/models/cliOutputOptions.js.map +1 -0
  25. package/dist/types/cliBase.d.ts +1 -1
  26. package/dist/types/cliDisplay.d.ts +5 -0
  27. package/dist/types/cliParam.d.ts +10 -9
  28. package/dist/types/index.d.ts +11 -11
  29. package/dist/types/models/cliOutputOptions.d.ts +3 -3
  30. package/docs/changelog.md +297 -0
  31. package/docs/reference/classes/CLIDisplay.md +20 -0
  32. package/docs/reference/classes/CLIParam.md +62 -50
  33. package/docs/reference/classes/CLIUtils.md +10 -10
  34. package/locales/.validate-ignore +1 -0
  35. package/locales/en.json +0 -1
  36. package/package.json +25 -14
  37. package/dist/cjs/index.cjs +0 -878
  38. package/dist/esm/index.mjs +0 -849
@@ -0,0 +1,235 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { exec, spawn } from "node:child_process";
4
+ import { accessSync, readFileSync, statSync } from "node:fs";
5
+ import { access, mkdir, readFile, stat, writeFile } from "node:fs/promises";
6
+ import path from "node:path";
7
+ import { Coerce, I18n, Is, ObjectHelper } from "@twin.org/core";
8
+ import { CLIDisplay } from "./cliDisplay.js";
9
+ /**
10
+ * Utilities function for helping in the CLI.
11
+ */
12
+ export class CLIUtils {
13
+ /**
14
+ * Does the specified file exist.
15
+ * @param filename The filename to check for existence.
16
+ * @returns True if the file exists.
17
+ */
18
+ static async fileExists(filename) {
19
+ try {
20
+ const stats = await stat(filename);
21
+ return stats.isFile();
22
+ }
23
+ catch {
24
+ return false;
25
+ }
26
+ }
27
+ /**
28
+ * Does the specified file exist, synchronously.
29
+ * @param filename The filename to check for existence.
30
+ * @returns True if the file exists.
31
+ */
32
+ static fileExistsSync(filename) {
33
+ try {
34
+ const stats = statSync(filename);
35
+ return stats.isFile();
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ }
41
+ /**
42
+ * Check if the dir exists.
43
+ * @param dir The directory to check.
44
+ * @returns True if the dir exists.
45
+ */
46
+ static async dirExists(dir) {
47
+ try {
48
+ await access(dir);
49
+ return true;
50
+ }
51
+ catch {
52
+ return false;
53
+ }
54
+ }
55
+ /**
56
+ * Check if the dir exists, synchronously.
57
+ * @param dir The directory to check.
58
+ * @returns True if the dir exists.
59
+ */
60
+ static dirExistsSync(dir) {
61
+ try {
62
+ accessSync(dir);
63
+ return true;
64
+ }
65
+ catch {
66
+ return false;
67
+ }
68
+ }
69
+ /**
70
+ * Read a JSON file and parse it.
71
+ * @param filename The filename to read.
72
+ * @returns The parsed JSON.
73
+ */
74
+ static async readJsonFile(filename) {
75
+ if (await CLIUtils.fileExists(filename)) {
76
+ const content = await readFile(filename, "utf8");
77
+ return JSON.parse(content);
78
+ }
79
+ }
80
+ /**
81
+ * Read a JSON file and parse it, synchronously.
82
+ * @param filename The filename to read.
83
+ * @returns The parsed JSON.
84
+ */
85
+ static readJsonFileSync(filename) {
86
+ if (CLIUtils.fileExistsSync(filename)) {
87
+ const content = readFileSync(filename, "utf8");
88
+ return JSON.parse(content);
89
+ }
90
+ }
91
+ /**
92
+ * Read a file as lines.
93
+ * @param filename The filename to read.
94
+ * @returns The lines.
95
+ */
96
+ static async readLinesFile(filename) {
97
+ if (await CLIUtils.fileExists(filename)) {
98
+ const content = await readFile(filename, "utf8");
99
+ return content.split("\n");
100
+ }
101
+ }
102
+ /**
103
+ * Read a file as lines, synchronously.
104
+ * @param filename The filename to read.
105
+ * @returns The lines.
106
+ */
107
+ static readLinesFileSync(filename) {
108
+ if (CLIUtils.fileExistsSync(filename)) {
109
+ const content = readFileSync(filename, "utf8");
110
+ return content.split("\n");
111
+ }
112
+ }
113
+ /**
114
+ * Find the NPM root based on a package.json path.
115
+ * @param rootFolder The path to the package.json.
116
+ * @returns The root path.
117
+ */
118
+ static async findNpmRoot(rootFolder) {
119
+ return new Promise((resolve, reject) => {
120
+ exec("npm root", { cwd: rootFolder }, (error, stdout, stderr) => {
121
+ if (error) {
122
+ reject(error);
123
+ }
124
+ else {
125
+ resolve(stdout.trim());
126
+ }
127
+ });
128
+ });
129
+ }
130
+ /**
131
+ * Run a shell command.
132
+ * @param command The app to run in the shell.
133
+ * @param args The args for the app.
134
+ * @param cwd The working directory to execute the command in.
135
+ * @returns Promise to wait for command execution to complete.
136
+ */
137
+ static async runShellCmd(command, args, cwd) {
138
+ const osCommand = process.platform.startsWith("win") ? `${command}.cmd` : command;
139
+ return CLIUtils.runShellApp(osCommand, args, cwd);
140
+ }
141
+ /**
142
+ * Run a shell app.
143
+ * @param app The app to run in the shell.
144
+ * @param args The args for the app.
145
+ * @param cwd The working directory to execute the command in.
146
+ * @returns Promise to wait for command execution to complete.
147
+ */
148
+ static async runShellApp(app, args, cwd) {
149
+ return new Promise((resolve, reject) => {
150
+ const sp = spawn(app, args, {
151
+ shell: true,
152
+ cwd
153
+ });
154
+ sp.stdout?.on("data", data => {
155
+ CLIDisplay.write(data);
156
+ });
157
+ sp.stderr?.on("data", data => {
158
+ CLIDisplay.writeError(data);
159
+ });
160
+ sp.on("exit", (exitCode, signals) => {
161
+ if (Coerce.number(exitCode) !== 0 || signals?.length) {
162
+ // eslint-disable-next-line no-restricted-syntax
163
+ reject(new Error("Run failed"));
164
+ }
165
+ else {
166
+ resolve();
167
+ }
168
+ });
169
+ });
170
+ }
171
+ /**
172
+ * Write a JSON file.
173
+ * @param jsonFilename The filename to write.
174
+ * @param data The data to write.
175
+ * @param append Append to the file.
176
+ */
177
+ static async writeJsonFile(jsonFilename, data, append) {
178
+ if (Is.stringValue(jsonFilename)) {
179
+ const filename = path.resolve(jsonFilename);
180
+ let currentJson = {};
181
+ if (append) {
182
+ CLIDisplay.task(I18n.formatMessage("cli.progress.readingJsonFile"), filename);
183
+ currentJson = (await CLIUtils.readJsonFile(filename)) ?? {};
184
+ }
185
+ CLIDisplay.task(I18n.formatMessage("cli.progress.writingJsonFile"), filename);
186
+ CLIDisplay.break();
187
+ await mkdir(path.dirname(filename), { recursive: true });
188
+ await writeFile(filename, `${JSON.stringify(ObjectHelper.merge(currentJson, data), undefined, "\t")}\n`);
189
+ }
190
+ }
191
+ /**
192
+ * Write an env file.
193
+ * @param envFilename The filename to write.
194
+ * @param data The data to write.
195
+ * @param append Append to the file.
196
+ */
197
+ static async writeEnvFile(envFilename, data, append) {
198
+ if (Is.stringValue(envFilename)) {
199
+ const filename = path.resolve(envFilename);
200
+ const outputKeys = [];
201
+ const outputDict = {};
202
+ if (append) {
203
+ CLIDisplay.task(I18n.formatMessage("cli.progress.readingEnvFile"), filename);
204
+ const lines = await CLIUtils.readLinesFile(filename);
205
+ if (Is.arrayValue(lines)) {
206
+ for (const line of lines) {
207
+ const parts = line.split("=");
208
+ outputKeys.push(parts[0]);
209
+ outputDict[parts[0]] = parts.slice(1).join("=");
210
+ }
211
+ }
212
+ }
213
+ CLIDisplay.task(I18n.formatMessage("cli.progress.writingEnvFile"), filename);
214
+ CLIDisplay.break();
215
+ if (Is.arrayValue(data)) {
216
+ for (const line of data) {
217
+ const parts = line.split("=");
218
+ const currentIndex = outputKeys.indexOf(parts[0]);
219
+ if (currentIndex !== -1) {
220
+ outputKeys.splice(currentIndex, 1);
221
+ }
222
+ outputKeys.push(parts[0]);
223
+ outputDict[parts[0]] = parts.slice(1).join("=");
224
+ }
225
+ }
226
+ const output = [];
227
+ for (const outputKey of outputKeys) {
228
+ output.push(`${outputKey}=${outputDict[outputKey]}`);
229
+ }
230
+ await mkdir(path.dirname(filename), { recursive: true });
231
+ await writeFile(filename, output.join("\n"));
232
+ }
233
+ }
234
+ }
235
+ //# sourceMappingURL=cliUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliUtils.js","sourceRoot":"","sources":["../../src/cliUtils.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,QAAQ;IACpB;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAgB;QAC9C,IAAI,CAAC;YAC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,IAAI,CAAC,GAAG,CAAC,CAAC;gBACjD,CAAC;YACF,CAAC;YAED,MAAM,MAAM,GAAa,EAAE,CAAC;YAC5B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACpC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YACtD,CAAC;YAED,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACzD,MAAM,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { exec, spawn } from \"node:child_process\";\nimport { accessSync, readFileSync, statSync } from \"node:fs\";\nimport { access, mkdir, readFile, stat, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Coerce, I18n, Is, ObjectHelper } from \"@twin.org/core\";\nimport { CLIDisplay } from \"./cliDisplay.js\";\n\n/**\n * Utilities function for helping in the CLI.\n */\nexport class CLIUtils {\n\t/**\n\t * Does the specified file exist.\n\t * @param filename The filename to check for existence.\n\t * @returns True if the file exists.\n\t */\n\tpublic static async fileExists(filename: string): Promise<boolean> {\n\t\ttry {\n\t\t\tconst stats = await stat(filename);\n\t\t\treturn stats.isFile();\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Does the specified file exist, synchronously.\n\t * @param filename The filename to check for existence.\n\t * @returns True if the file exists.\n\t */\n\tpublic static fileExistsSync(filename: string): boolean {\n\t\ttry {\n\t\t\tconst stats = statSync(filename);\n\t\t\treturn stats.isFile();\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Check if the dir exists.\n\t * @param dir The directory to check.\n\t * @returns True if the dir exists.\n\t */\n\tpublic static async dirExists(dir: string): Promise<boolean> {\n\t\ttry {\n\t\t\tawait access(dir);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Check if the dir exists, synchronously.\n\t * @param dir The directory to check.\n\t * @returns True if the dir exists.\n\t */\n\tpublic static dirExistsSync(dir: string): boolean {\n\t\ttry {\n\t\t\taccessSync(dir);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Read a JSON file and parse it.\n\t * @param filename The filename to read.\n\t * @returns The parsed JSON.\n\t */\n\tpublic static async readJsonFile<T = unknown>(filename: string): Promise<T | undefined> {\n\t\tif (await CLIUtils.fileExists(filename)) {\n\t\t\tconst content = await readFile(filename, \"utf8\");\n\t\t\treturn JSON.parse(content);\n\t\t}\n\t}\n\n\t/**\n\t * Read a JSON file and parse it, synchronously.\n\t * @param filename The filename to read.\n\t * @returns The parsed JSON.\n\t */\n\tpublic static readJsonFileSync<T = unknown>(filename: string): T | undefined {\n\t\tif (CLIUtils.fileExistsSync(filename)) {\n\t\t\tconst content = readFileSync(filename, \"utf8\");\n\t\t\treturn JSON.parse(content);\n\t\t}\n\t}\n\n\t/**\n\t * Read a file as lines.\n\t * @param filename The filename to read.\n\t * @returns The lines.\n\t */\n\tpublic static async readLinesFile(filename: string): Promise<string[] | undefined> {\n\t\tif (await CLIUtils.fileExists(filename)) {\n\t\t\tconst content = await readFile(filename, \"utf8\");\n\t\t\treturn content.split(\"\\n\");\n\t\t}\n\t}\n\n\t/**\n\t * Read a file as lines, synchronously.\n\t * @param filename The filename to read.\n\t * @returns The lines.\n\t */\n\tpublic static readLinesFileSync(filename: string): string[] | undefined {\n\t\tif (CLIUtils.fileExistsSync(filename)) {\n\t\t\tconst content = readFileSync(filename, \"utf8\");\n\t\t\treturn content.split(\"\\n\");\n\t\t}\n\t}\n\n\t/**\n\t * Find the NPM root based on a package.json path.\n\t * @param rootFolder The path to the package.json.\n\t * @returns The root path.\n\t */\n\tpublic static async findNpmRoot(rootFolder: string): Promise<string> {\n\t\treturn new Promise<string>((resolve, reject) => {\n\t\t\texec(\"npm root\", { cwd: rootFolder }, (error, stdout, stderr) => {\n\t\t\t\tif (error) {\n\t\t\t\t\treject(error);\n\t\t\t\t} else {\n\t\t\t\t\tresolve(stdout.trim());\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Run a shell command.\n\t * @param command The app to run in the shell.\n\t * @param args The args for the app.\n\t * @param cwd The working directory to execute the command in.\n\t * @returns Promise to wait for command execution to complete.\n\t */\n\tpublic static async runShellCmd(command: string, args: string[], cwd: string): Promise<void> {\n\t\tconst osCommand = process.platform.startsWith(\"win\") ? `${command}.cmd` : command;\n\n\t\treturn CLIUtils.runShellApp(osCommand, args, cwd);\n\t}\n\n\t/**\n\t * Run a shell app.\n\t * @param app The app to run in the shell.\n\t * @param args The args for the app.\n\t * @param cwd The working directory to execute the command in.\n\t * @returns Promise to wait for command execution to complete.\n\t */\n\tpublic static async runShellApp(app: string, args: string[], cwd: string): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst sp = spawn(app, args, {\n\t\t\t\tshell: true,\n\t\t\t\tcwd\n\t\t\t});\n\n\t\t\tsp.stdout?.on(\"data\", data => {\n\t\t\t\tCLIDisplay.write(data);\n\t\t\t});\n\n\t\t\tsp.stderr?.on(\"data\", data => {\n\t\t\t\tCLIDisplay.writeError(data);\n\t\t\t});\n\n\t\t\tsp.on(\"exit\", (exitCode, signals) => {\n\t\t\t\tif (Coerce.number(exitCode) !== 0 || signals?.length) {\n\t\t\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\t\t\treject(new Error(\"Run failed\"));\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Write a JSON file.\n\t * @param jsonFilename The filename to write.\n\t * @param data The data to write.\n\t * @param append Append to the file.\n\t */\n\tpublic static async writeJsonFile<T = unknown>(\n\t\tjsonFilename: string | undefined,\n\t\tdata: T,\n\t\tappend: boolean\n\t): Promise<void> {\n\t\tif (Is.stringValue(jsonFilename)) {\n\t\t\tconst filename = path.resolve(jsonFilename);\n\t\t\tlet currentJson = {};\n\t\t\tif (append) {\n\t\t\t\tCLIDisplay.task(I18n.formatMessage(\"cli.progress.readingJsonFile\"), filename);\n\t\t\t\tcurrentJson = (await CLIUtils.readJsonFile(filename)) ?? {};\n\t\t\t}\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"cli.progress.writingJsonFile\"), filename);\n\t\t\tCLIDisplay.break();\n\n\t\t\tawait mkdir(path.dirname(filename), { recursive: true });\n\t\t\tawait writeFile(\n\t\t\t\tfilename,\n\t\t\t\t`${JSON.stringify(ObjectHelper.merge(currentJson, data), undefined, \"\\t\")}\\n`\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Write an env file.\n\t * @param envFilename The filename to write.\n\t * @param data The data to write.\n\t * @param append Append to the file.\n\t */\n\tpublic static async writeEnvFile(\n\t\tenvFilename: string | undefined,\n\t\tdata: string[],\n\t\tappend: boolean\n\t): Promise<void> {\n\t\tif (Is.stringValue(envFilename)) {\n\t\t\tconst filename = path.resolve(envFilename);\n\n\t\t\tconst outputKeys: string[] = [];\n\t\t\tconst outputDict: { [key: string]: string } = {};\n\n\t\t\tif (append) {\n\t\t\t\tCLIDisplay.task(I18n.formatMessage(\"cli.progress.readingEnvFile\"), filename);\n\t\t\t\tconst lines = await CLIUtils.readLinesFile(filename);\n\t\t\t\tif (Is.arrayValue(lines)) {\n\t\t\t\t\tfor (const line of lines) {\n\t\t\t\t\t\tconst parts = line.split(\"=\");\n\t\t\t\t\t\toutputKeys.push(parts[0]);\n\t\t\t\t\t\toutputDict[parts[0]] = parts.slice(1).join(\"=\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"cli.progress.writingEnvFile\"), filename);\n\t\t\tCLIDisplay.break();\n\n\t\t\tif (Is.arrayValue(data)) {\n\t\t\t\tfor (const line of data) {\n\t\t\t\t\tconst parts = line.split(\"=\");\n\t\t\t\t\tconst currentIndex = outputKeys.indexOf(parts[0]);\n\t\t\t\t\tif (currentIndex !== -1) {\n\t\t\t\t\t\toutputKeys.splice(currentIndex, 1);\n\t\t\t\t\t}\n\t\t\t\t\toutputKeys.push(parts[0]);\n\t\t\t\t\toutputDict[parts[0]] = parts.slice(1).join(\"=\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output: string[] = [];\n\t\t\tfor (const outputKey of outputKeys) {\n\t\t\t\toutput.push(`${outputKey}=${outputDict[outputKey]}`);\n\t\t\t}\n\n\t\t\tawait mkdir(path.dirname(filename), { recursive: true });\n\t\t\tawait writeFile(filename, output.join(\"\\n\"));\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,61 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import path from "node:path";
4
+ import { I18n, Is } from "@twin.org/core";
5
+ import * as dotenv from "dotenv";
6
+ import { CLIDisplay } from "../cliDisplay.js";
7
+ import { CLIUtils } from "../cliUtils.js";
8
+ let localesDir;
9
+ /**
10
+ * Initialize the global options.
11
+ * @param localesDirectory The path to load the locales from.
12
+ */
13
+ export function initGlobalOptions(localesDirectory) {
14
+ localesDir = localesDirectory;
15
+ }
16
+ /**
17
+ * Add the global options.
18
+ * @param program The program to add the options to.
19
+ * @param supportsLang Whether the CLI supports different languages.
20
+ * @param supportsEnvFiles Whether the CLI supports loading env files
21
+ */
22
+ export function addGlobalOptions(program, supportsLang, supportsEnvFiles) {
23
+ if (supportsLang) {
24
+ program.option(I18n.formatMessage("cli.options.lang.param"), I18n.formatMessage("cli.options.lang.description"), "en");
25
+ }
26
+ if (supportsEnvFiles) {
27
+ program.option(I18n.formatMessage("cli.options.load-env.param"), I18n.formatMessage("cli.options.load-env.description"));
28
+ }
29
+ }
30
+ /**
31
+ * Handle the global options.
32
+ * @param command The command to use for context.
33
+ * @internal
34
+ */
35
+ export function handleGlobalOptions(command) {
36
+ const globalOpts = command.optsWithGlobals();
37
+ if (Is.stringValue(globalOpts?.lang)) {
38
+ initLocales(globalOpts.lang);
39
+ }
40
+ const loadEnv = globalOpts?.loadEnv;
41
+ if (Is.arrayValue(loadEnv)) {
42
+ const resolvedEnv = loadEnv.map(e => path.resolve(e));
43
+ CLIDisplay.task(I18n.formatMessage("cli.progress.loadingEnvFiles"), resolvedEnv.join(", "));
44
+ CLIDisplay.break();
45
+ dotenv.config({ path: resolvedEnv, quiet: true });
46
+ }
47
+ }
48
+ /**
49
+ * Initialize the locales for the CLI.
50
+ * @param locale The locale to use.
51
+ * @internal
52
+ */
53
+ export function initLocales(locale) {
54
+ const localePath = path.join(localesDir, `${locale}.json`);
55
+ const localeContent = CLIUtils.readJsonFileSync(localePath);
56
+ if (Is.objectValue(localeContent)) {
57
+ I18n.addDictionary(locale, localeContent);
58
+ I18n.setLocale(locale);
59
+ }
60
+ }
61
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/commands/global.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,EAAE,EAA0B,MAAM,gBAAgB,CAAC;AAElE,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,IAAI,UAAkB,CAAC;AAEvB;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,gBAAwB;IACzD,UAAU,GAAG,gBAAgB,CAAC;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU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IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,MAAM,OAAO,CAAC,CAAC;IAC3D,MAAM,aAAa,GAAG,QAAQ,CAAC,gBAAgB,CAAoB,UAAU,CAAC,CAAC;IAC/E,IAAI,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;QACnC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport { I18n, Is, type ILocaleDictionary } from \"@twin.org/core\";\nimport type { Command } from \"commander\";\nimport * as dotenv from \"dotenv\";\nimport { CLIDisplay } from \"../cliDisplay.js\";\nimport { CLIUtils } from \"../cliUtils.js\";\n\nlet localesDir: string;\n\n/**\n * Initialize the global options.\n * @param localesDirectory The path to load the locales from.\n */\nexport function initGlobalOptions(localesDirectory: string): void {\n\tlocalesDir = localesDirectory;\n}\n\n/**\n * Add the global options.\n * @param program The program to add the options to.\n * @param supportsLang Whether the CLI supports different languages.\n * @param supportsEnvFiles Whether the CLI supports loading env files\n */\nexport function addGlobalOptions(\n\tprogram: Command,\n\tsupportsLang: boolean,\n\tsupportsEnvFiles: boolean\n): void {\n\tif (supportsLang) {\n\t\tprogram.option(\n\t\t\tI18n.formatMessage(\"cli.options.lang.param\"),\n\t\t\tI18n.formatMessage(\"cli.options.lang.description\"),\n\t\t\t\"en\"\n\t\t);\n\t}\n\n\tif (supportsEnvFiles) {\n\t\tprogram.option(\n\t\t\tI18n.formatMessage(\"cli.options.load-env.param\"),\n\t\t\tI18n.formatMessage(\"cli.options.load-env.description\")\n\t\t);\n\t}\n}\n\n/**\n * Handle the global options.\n * @param command The command to use for context.\n * @internal\n */\nexport function handleGlobalOptions(command: Command): void {\n\tconst globalOpts = command.optsWithGlobals();\n\n\tif (Is.stringValue(globalOpts?.lang)) {\n\t\tinitLocales(globalOpts.lang);\n\t}\n\n\tconst loadEnv: string[] = globalOpts?.loadEnv;\n\tif (Is.arrayValue(loadEnv)) {\n\t\tconst resolvedEnv = loadEnv.map(e => path.resolve(e));\n\t\tCLIDisplay.task(I18n.formatMessage(\"cli.progress.loadingEnvFiles\"), resolvedEnv.join(\", \"));\n\t\tCLIDisplay.break();\n\t\tdotenv.config({ path: resolvedEnv, quiet: true });\n\t}\n}\n\n/**\n * Initialize the locales for the CLI.\n * @param locale The locale to use.\n * @internal\n */\nexport function initLocales(locale: string): void {\n\tconst localePath = path.join(localesDir, `${locale}.json`);\n\tconst localeContent = CLIUtils.readJsonFileSync<ILocaleDictionary>(localePath);\n\tif (Is.objectValue(localeContent)) {\n\t\tI18n.addDictionary(locale, localeContent);\n\t\tI18n.setLocale(locale);\n\t}\n}\n"]}
@@ -0,0 +1,14 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./cliBase.js";
4
+ export * from "./cliDisplay.js";
5
+ export * from "./cliOptions.js";
6
+ export * from "./cliParam.js";
7
+ export * from "./cliUtils.js";
8
+ export * from "./commands/global.js";
9
+ export * from "./models/cliOutputOptions.js";
10
+ export * from "./models/ICliOptions.js";
11
+ export * from "./models/ICliOutputOptionsConsole.js";
12
+ export * from "./models/ICliOutputOptionsEnv.js";
13
+ export * from "./models/ICliOutputOptionsJson.js";
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./cliBase.js\";\nexport * from \"./cliDisplay.js\";\nexport * from \"./cliOptions.js\";\nexport * from \"./cliParam.js\";\nexport * from \"./cliUtils.js\";\nexport * from \"./commands/global.js\";\nexport * from \"./models/cliOutputOptions.js\";\nexport * from \"./models/ICliOptions.js\";\nexport * from \"./models/ICliOutputOptionsConsole.js\";\nexport * from \"./models/ICliOutputOptionsEnv.js\";\nexport * from \"./models/ICliOutputOptionsJson.js\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ICliOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICliOptions.js","sourceRoot":"","sources":["../../../src/models/ICliOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Options for the CLI.\n */\nexport interface ICliOptions {\n\t/**\n\t * The title of the CLI.\n\t */\n\ttitle: string;\n\n\t/**\n\t * The name of the app used to execute it.\n\t */\n\tappName: string;\n\n\t/**\n\t * The version of the app.\n\t */\n\tversion: string;\n\n\t/**\n\t * The icon for the CLI as an emoji character.\n\t */\n\ticon: string;\n\n\t/**\n\t * Supports different languages.\n\t */\n\tsupportsLang?: boolean;\n\n\t/**\n\t * Supports the loading of env files.\n\t */\n\tsupportsEnvFiles?: boolean;\n\n\t/**\n\t * Override the default output width.\n\t */\n\toverrideOutputWidth?: number;\n\n\t/**\n\t * Show a warning that this is a dev tool and not for production use.\n\t */\n\tshowDevToolWarning?: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ICliOutputOptionsConsole.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICliOutputOptionsConsole.js","sourceRoot":"","sources":["../../../src/models/ICliOutputOptionsConsole.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Options for the CLI Output for console.\n */\nexport interface ICliOutputOptionsConsole {\n\t/**\n\t * Flag to display on the console.\n\t */\n\tconsole: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ICliOutputOptionsEnv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICliOutputOptionsEnv.js","sourceRoot":"","sources":["../../../src/models/ICliOutputOptionsEnv.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Options for the CLI Output for env.\n */\nexport interface ICliOutputOptionsEnv {\n\t/**\n\t * Output the data to an environment file.\n\t */\n\tenv?: string;\n\n\t/**\n\t * Merge the data to an environment file.\n\t */\n\tmergeEnv: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ICliOutputOptionsJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICliOutputOptionsJson.js","sourceRoot":"","sources":["../../../src/models/ICliOutputOptionsJson.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n/**\n * Options for the CLI Output for JSON.\n */\nexport interface ICliOutputOptionsJson {\n\t/**\n\t * Output the data to an JSON file.\n\t */\n\tjson?: string;\n\n\t/**\n\t * Merge the data to a JSON file.\n\t */\n\tmergeJson: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cliOutputOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliOutputOptions.js","sourceRoot":"","sources":["../../../src/models/cliOutputOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ICliOutputOptionsConsole } from \"./ICliOutputOptionsConsole.js\";\nimport type { ICliOutputOptionsEnv } from \"./ICliOutputOptionsEnv.js\";\nimport type { ICliOutputOptionsJson } from \"./ICliOutputOptionsJson.js\";\n\n/**\n * Options for the CLI Output.\n */\nexport type CliOutputOptions = ICliOutputOptionsConsole &\n\tICliOutputOptionsEnv &\n\tICliOutputOptionsJson;\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Command } from "commander";
2
- import type { ICliOptions } from "./models/ICliOptions";
2
+ import type { ICliOptions } from "./models/ICliOptions.js";
3
3
  /**
4
4
  * The main entry point for the CLI.
5
5
  */
@@ -29,6 +29,11 @@ export declare class CLIDisplay {
29
29
  * @param lineBreaks Whether to add a line break after the error.
30
30
  */
31
31
  static error(error: unknown, lineBreaks?: boolean): void;
32
+ /**
33
+ * Display an error message in simple form.
34
+ * @param error The error to display.
35
+ */
36
+ static errorMessage(error: string): void;
32
37
  /**
33
38
  * Display a section.
34
39
  * @param label The label for the section.
@@ -20,6 +20,16 @@ export declare class CLIParam {
20
20
  * @throws An error if the option is invalid.
21
21
  */
22
22
  static stringValue(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): string;
23
+ /**
24
+ * Check the option to see if the value exists in the specific array.
25
+ * @param optionName The name of the option.
26
+ * @param optionValue The option value.
27
+ * @param validValues The valid values.
28
+ * @param allowEnvVar Allow the option to be read from an env var.
29
+ * @returns The final option value.
30
+ * @throws An error if the option is invalid.
31
+ */
32
+ static arrayOneOf<T = string>(optionName: string, optionValue: string | undefined, validValues: T[], allowEnvVar?: boolean): T;
23
33
  /**
24
34
  * Check the option to see if it is a url.
25
35
  * @param optionName The name of the option.
@@ -98,13 +108,4 @@ export declare class CLIParam {
98
108
  * @throws An error if the option is invalid.
99
109
  */
100
110
  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
111
  }
@@ -1,11 +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/cliOutputOptions";
8
- export * from "./models/ICliOptions";
9
- export * from "./models/ICliOutputOptionsConsole";
10
- export * from "./models/ICliOutputOptionsEnv";
11
- export * from "./models/ICliOutputOptionsJson";
1
+ export * from "./cliBase.js";
2
+ export * from "./cliDisplay.js";
3
+ export * from "./cliOptions.js";
4
+ export * from "./cliParam.js";
5
+ export * from "./cliUtils.js";
6
+ export * from "./commands/global.js";
7
+ export * from "./models/cliOutputOptions.js";
8
+ export * from "./models/ICliOptions.js";
9
+ export * from "./models/ICliOutputOptionsConsole.js";
10
+ export * from "./models/ICliOutputOptionsEnv.js";
11
+ export * from "./models/ICliOutputOptionsJson.js";
@@ -1,6 +1,6 @@
1
- import type { ICliOutputOptionsConsole } from "./ICliOutputOptionsConsole";
2
- import type { ICliOutputOptionsEnv } from "./ICliOutputOptionsEnv";
3
- import type { ICliOutputOptionsJson } from "./ICliOutputOptionsJson";
1
+ import type { ICliOutputOptionsConsole } from "./ICliOutputOptionsConsole.js";
2
+ import type { ICliOutputOptionsEnv } from "./ICliOutputOptionsEnv.js";
3
+ import type { ICliOutputOptionsJson } from "./ICliOutputOptionsJson.js";
4
4
  /**
5
5
  * Options for the CLI Output.
6
6
  */