@twin.org/crypto-cli 0.0.1-next.3 → 0.0.1-next.7

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.
@@ -126,7 +126,8 @@ function buildCommandMnemonic() {
126
126
  .default("256"))
127
127
  .addOption(new commander.Option(core.I18n.formatMessage("commands.mnemonic.options.seed-format.param"), core.I18n.formatMessage("commands.mnemonic.options.seed-format.description"))
128
128
  .choices(["hex", "base64"])
129
- .default("hex"));
129
+ .default("hex"))
130
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.mnemonic.options.env-prefix.param"), core.I18n.formatMessage("commands.mnemonic.options.env-prefix.description")));
130
131
  cliCore.CLIOptions.output(command, {
131
132
  noConsole: true,
132
133
  json: true,
@@ -147,17 +148,21 @@ async function actionCommandMnemonic(opts) {
147
148
  const strength = cliCore.CLIParam.integer("strength", opts.strength, false, 128, 256);
148
149
  const mnemonic = crypto.Bip39.randomMnemonic(strength);
149
150
  const seed = crypto.Bip39.mnemonicToSeed(mnemonic);
151
+ const envPrefix = core.Is.stringValue(opts.envPrefix) ? opts.envPrefix : "";
150
152
  const seedFormatted = opts.seedFormat === "hex" ? core.Converter.bytesToHex(seed, true) : core.Converter.bytesToBase64(seed);
151
153
  if (opts.console) {
152
154
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.mnemonic.labels.mnemonic"), mnemonic);
153
155
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.mnemonic.labels.seed"), seedFormatted);
156
+ if (core.Is.stringValue(opts.envPrefix)) {
157
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.mnemonic.labels.envPrefix"), envPrefix);
158
+ }
154
159
  cliCore.CLIDisplay.break();
155
160
  }
156
161
  if (core.Is.stringValue(opts?.json)) {
157
162
  await cliCore.CLIUtils.writeJsonFile(opts.json, { mnemonic, seed: seedFormatted }, opts.mergeJson);
158
163
  }
159
164
  if (core.Is.stringValue(opts?.env)) {
160
- await cliCore.CLIUtils.writeEnvFile(opts.env, [`MNEMONIC="${mnemonic}"`, `SEED="${seedFormatted}"`], opts.mergeEnv);
165
+ await cliCore.CLIUtils.writeEnvFile(opts.env, [`${envPrefix}MNEMONIC="${mnemonic}"`, `${envPrefix}SEED="${seedFormatted}"`], opts.mergeEnv);
161
166
  }
162
167
  cliCore.CLIDisplay.done();
163
168
  }
@@ -172,16 +177,19 @@ class CLI extends cliCore.CLIBase {
172
177
  * Run the app.
173
178
  * @param argv The process arguments.
174
179
  * @param localesDirectory The directory for the locales, default to relative to the script.
180
+ * @param options Additional options.
181
+ * @param options.overrideOutputWidth Override the output width.
175
182
  * @returns The exit code.
176
183
  */
177
- async run(argv, localesDirectory) {
184
+ async run(argv, localesDirectory, options) {
178
185
  return this.execute({
179
186
  title: "TWIN Crypto",
180
187
  appName: "twin-crypto",
181
- version: "0.0.1-next.3",
188
+ version: "0.0.1-next.7",
182
189
  icon: "🌍",
183
- supportsEnvFiles: true
184
- }, localesDirectory ?? path.join(path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))), "../locales"), argv);
190
+ supportsEnvFiles: true,
191
+ overrideOutputWidth: options?.overrideOutputWidth
192
+ }, localesDirectory ?? path.join(path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))), "../locales"), argv);
185
193
  }
186
194
  /**
187
195
  * Get the commands for the CLI.
@@ -123,7 +123,8 @@ function buildCommandMnemonic() {
123
123
  .default("256"))
124
124
  .addOption(new Option(I18n.formatMessage("commands.mnemonic.options.seed-format.param"), I18n.formatMessage("commands.mnemonic.options.seed-format.description"))
125
125
  .choices(["hex", "base64"])
126
- .default("hex"));
126
+ .default("hex"))
127
+ .addOption(new Option(I18n.formatMessage("commands.mnemonic.options.env-prefix.param"), I18n.formatMessage("commands.mnemonic.options.env-prefix.description")));
127
128
  CLIOptions.output(command, {
128
129
  noConsole: true,
129
130
  json: true,
@@ -144,17 +145,21 @@ async function actionCommandMnemonic(opts) {
144
145
  const strength = CLIParam.integer("strength", opts.strength, false, 128, 256);
145
146
  const mnemonic = Bip39.randomMnemonic(strength);
146
147
  const seed = Bip39.mnemonicToSeed(mnemonic);
148
+ const envPrefix = Is.stringValue(opts.envPrefix) ? opts.envPrefix : "";
147
149
  const seedFormatted = opts.seedFormat === "hex" ? Converter.bytesToHex(seed, true) : Converter.bytesToBase64(seed);
148
150
  if (opts.console) {
149
151
  CLIDisplay.value(I18n.formatMessage("commands.mnemonic.labels.mnemonic"), mnemonic);
150
152
  CLIDisplay.value(I18n.formatMessage("commands.mnemonic.labels.seed"), seedFormatted);
153
+ if (Is.stringValue(opts.envPrefix)) {
154
+ CLIDisplay.value(I18n.formatMessage("commands.mnemonic.labels.envPrefix"), envPrefix);
155
+ }
151
156
  CLIDisplay.break();
152
157
  }
153
158
  if (Is.stringValue(opts?.json)) {
154
159
  await CLIUtils.writeJsonFile(opts.json, { mnemonic, seed: seedFormatted }, opts.mergeJson);
155
160
  }
156
161
  if (Is.stringValue(opts?.env)) {
157
- await CLIUtils.writeEnvFile(opts.env, [`MNEMONIC="${mnemonic}"`, `SEED="${seedFormatted}"`], opts.mergeEnv);
162
+ await CLIUtils.writeEnvFile(opts.env, [`${envPrefix}MNEMONIC="${mnemonic}"`, `${envPrefix}SEED="${seedFormatted}"`], opts.mergeEnv);
158
163
  }
159
164
  CLIDisplay.done();
160
165
  }
@@ -169,15 +174,18 @@ class CLI extends CLIBase {
169
174
  * Run the app.
170
175
  * @param argv The process arguments.
171
176
  * @param localesDirectory The directory for the locales, default to relative to the script.
177
+ * @param options Additional options.
178
+ * @param options.overrideOutputWidth Override the output width.
172
179
  * @returns The exit code.
173
180
  */
174
- async run(argv, localesDirectory) {
181
+ async run(argv, localesDirectory, options) {
175
182
  return this.execute({
176
183
  title: "TWIN Crypto",
177
184
  appName: "twin-crypto",
178
- version: "0.0.1-next.3",
185
+ version: "0.0.1-next.7",
179
186
  icon: "🌍",
180
- supportsEnvFiles: true
187
+ supportsEnvFiles: true,
188
+ overrideOutputWidth: options?.overrideOutputWidth
181
189
  }, localesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), "../locales"), argv);
182
190
  }
183
191
  /**
@@ -185,6 +185,10 @@
185
185
  "env": {
186
186
  "param": "--env '<'filename'>'",
187
187
  "description": "Creates an env file containing the mnemonic and seed."
188
+ },
189
+ "env-prefix": {
190
+ "param": "--env-prefix '<'prefix'>'",
191
+ "description": "Prefixes the env variables with the value."
188
192
  }
189
193
  },
190
194
  "progress": {
@@ -193,7 +197,8 @@
193
197
  },
194
198
  "labels": {
195
199
  "mnemonic": "Mnemonic",
196
- "seed": "Seed"
200
+ "seed": "Seed",
201
+ "envPrefix": "Env Prefix"
197
202
  }
198
203
  },
199
204
  "address": {
@@ -7,7 +7,11 @@ export declare class CLI extends CLIBase {
7
7
  * Run the app.
8
8
  * @param argv The process arguments.
9
9
  * @param localesDirectory The directory for the locales, default to relative to the script.
10
+ * @param options Additional options.
11
+ * @param options.overrideOutputWidth Override the output width.
10
12
  * @returns The exit code.
11
13
  */
12
- run(argv: string[], localesDirectory?: string): Promise<number>;
14
+ run(argv: string[], localesDirectory?: string, options?: {
15
+ overrideOutputWidth?: number;
16
+ }): Promise<number>;
13
17
  }
@@ -14,4 +14,5 @@ export declare function buildCommandMnemonic(): Command;
14
14
  export declare function actionCommandMnemonic(opts: {
15
15
  strength: string;
16
16
  seedFormat: "hex" | "base64";
17
+ envPrefix?: string;
17
18
  } & CliOutputOptions): Promise<void>;
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/crypto-cli - Changelog
2
2
 
3
- ## 0.0.1-next.3
3
+ ## 0.0.1-next.7
4
4
 
5
5
  - Initial Release
package/docs/examples.md CHANGED
@@ -1,22 +1,21 @@
1
1
  # @twin.org/crypto-cli - Examples
2
2
 
3
- ## Command Line Tool
3
+ ## Running
4
4
 
5
- First install the tool with the following script.
5
+ To install and run the CLI locally use the following commands:
6
6
 
7
7
  ```shell
8
- npm install @twin.org/crypto-cli
8
+ npm install @twin.org/crypto-cli -g
9
+ twin-crypto
9
10
  ```
10
11
 
11
- ## Running
12
-
13
- If you run the tool with no command line options:
12
+ or run directly using NPX:
14
13
 
15
14
  ```shell
16
- twin-crypto
15
+ npx "@twin.org/crypto-cli"
17
16
  ```
18
17
 
19
- You should see output similar to the following
18
+ You should see output similar to the following:
20
19
 
21
20
  ```shell
22
21
  🌍 TWIN Crypto v1.0.0
@@ -22,63 +22,9 @@ The main entry point for the CLI.
22
22
 
23
23
  ## Methods
24
24
 
25
- ### execute()
26
-
27
- > **execute**(`options`, `localesDirectory`, `argv`): `Promise`\<`number`\>
28
-
29
- Execute the command line processing.
30
-
31
- #### Parameters
32
-
33
- • **options**: `ICliOptions`
34
-
35
- The options for the CLI.
36
-
37
- • **localesDirectory**: `string`
38
-
39
- The path to load the locales from.
40
-
41
- • **argv**: `string`[]
42
-
43
- The process arguments.
44
-
45
- #### Returns
46
-
47
- `Promise`\<`number`\>
48
-
49
- The exit code.
50
-
51
- #### Inherited from
52
-
53
- `CLIBase.execute`
54
-
55
- ***
56
-
57
- ### configureRoot()
58
-
59
- > `protected` **configureRoot**(`program`): `void`
60
-
61
- Configure any options or actions at the root program level.
62
-
63
- #### Parameters
64
-
65
- • **program**: `Command`
66
-
67
- The root program command.
68
-
69
- #### Returns
70
-
71
- `void`
72
-
73
- #### Inherited from
74
-
75
- `CLIBase.configureRoot`
76
-
77
- ***
78
-
79
25
  ### run()
80
26
 
81
- > **run**(`argv`, `localesDirectory`?): `Promise`\<`number`\>
27
+ > **run**(`argv`, `localesDirectory`?, `options`?): `Promise`\<`number`\>
82
28
 
83
29
  Run the app.
84
30
 
@@ -92,6 +38,14 @@ The process arguments.
92
38
 
93
39
  The directory for the locales, default to relative to the script.
94
40
 
41
+ • **options?**
42
+
43
+ Additional options.
44
+
45
+ • **options.overrideOutputWidth?**: `number`
46
+
47
+ Override the output width.
48
+
95
49
  #### Returns
96
50
 
97
51
  `Promise`\<`number`\>
package/locales/en.json CHANGED
@@ -32,6 +32,10 @@
32
32
  "env": {
33
33
  "param": "--env '<'filename'>'",
34
34
  "description": "Creates an env file containing the mnemonic and seed."
35
+ },
36
+ "env-prefix": {
37
+ "param": "--env-prefix '<'prefix'>'",
38
+ "description": "Prefixes the env variables with the value."
35
39
  }
36
40
  },
37
41
  "progress": {
@@ -40,7 +44,8 @@
40
44
  },
41
45
  "labels": {
42
46
  "mnemonic": "Mnemonic",
43
- "seed": "Seed"
47
+ "seed": "Seed",
48
+ "envPrefix": "Env Prefix"
44
49
  }
45
50
  },
46
51
  "address": {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@twin.org/crypto-cli",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.7",
4
4
  "description": "A command line interface for interacting with the crypto tools",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/twinfoundation/framework.git",
8
- "directory": "packages/crypto-cli"
8
+ "directory": "apps/crypto-cli"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
11
11
  "license": "Apache-2.0",
@@ -13,42 +13,13 @@
13
13
  "engines": {
14
14
  "node": ">=20.0.0"
15
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
16
  "dependencies": {
31
- "@twin.org/cli-core": "0.0.1-next.3",
32
- "@twin.org/core": "0.0.1-next.3",
33
- "@twin.org/crypto": "0.0.1-next.3",
17
+ "@twin.org/cli-core": "0.0.1-next.7",
18
+ "@twin.org/core": "0.0.1-next.7",
19
+ "@twin.org/crypto": "0.0.1-next.7",
34
20
  "@twin.org/nameof": "next",
35
21
  "commander": "12.1.0"
36
22
  },
37
- "devDependencies": {
38
- "@twin.org/merge-locales": "next",
39
- "@twin.org/nameof-transformer": "next",
40
- "@types/node": "22.5.5",
41
- "@vitest/coverage-v8": "2.1.1",
42
- "copyfiles": "2.4.1",
43
- "rimraf": "6.0.1",
44
- "rollup": "4.21.3",
45
- "rollup-plugin-typescript2": "0.36.0",
46
- "ts-patch": "3.2.1",
47
- "typedoc": "0.26.7",
48
- "typedoc-plugin-markdown": "4.2.7",
49
- "typescript": "5.6.2",
50
- "vitest": "2.1.1"
51
- },
52
23
  "main": "./dist/cjs/index.cjs",
53
24
  "module": "./dist/esm/index.mjs",
54
25
  "types": "./dist/types/index.d.ts",