-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcli.js
executable file
·61 lines (51 loc) · 1.35 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
import path from 'node:path';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import meow from 'meow';
import terminalImage from 'terminal-image';
import termImg from 'term-img';
import chalk from 'chalk';
import boxen from 'boxen';
import uniqueRandomArray from 'unique-random-array';
import dogeSeed from 'doge-seed';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const isIterm = process.env.TERM_PROGRAM === 'iTerm.app';
const dogeImage = path.join(__dirname, 'doge.png');
const randomColor = uniqueRandomArray([
'red',
'green',
'yellow',
'blue',
'magenta',
'cyan',
]);
const cli = meow(`
Usage
$ doge-seed [bits]
The first argument is the number of bits to derive a BIP39 mnemonic from.
Must be an integer, divisible by 32, in the range 128...256.
The default value is 128.
`, {
importMeta: import.meta,
});
(async () => {
const bits = cli.input[0];
const seed = (bits ? dogeSeed(Number(bits)) : dogeSeed())
.split(' ')
.map(word => chalk[randomColor()](word))
.join(' ');
const seedBox = boxen(seed, {
float: 'center',
padding: 1,
borderStyle: 'round',
borderColor: 'yellow',
dimBorder: true,
});
if (isIterm) {
console.log(termImg(dogeImage, {width: '100%'}));
} else {
console.log(await terminalImage.file(dogeImage));
}
console.log(seedBox, '\n\n\n');
})();