forked from sindresorhus/emoj
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·86 lines (70 loc) · 1.73 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const importJsx = require('import-jsx');
const {h, render} = require('ink');
const clipboardy = require('clipboardy');
const skinTone = require('skin-tone');
const Conf = require('conf');
const emoj = require('.');
const ui = importJsx('./ui');
const cli = meow(`
Usage
$ emoj [text]
Example
$ emoj 'i love unicorns'
🦄 🎠 🐴 🐎 ❤ ✨ 🌈
Options
--copy -c Copy the first emoji to the clipboard
--skin-tone -s Set and persist the default emoji skin tone (0 to 5)
Run it without arguments to enter the live search
Use the up/down keys during live search to change the skin tone
Use the left/right or 1..9 keys during live search to select the emoji
`, {
boolean: [
'copy'
],
alias: {
c: 'copy',
s: 'skinTone'
}
});
const config = new Conf({
defaults: {
skinNumber: 0
}
});
if (cli.flags.skinTone !== undefined) {
config.set('skinNumber', Math.max(0, Math.min(5, Number(cli.flags.skinTone) || 0)));
}
const skinNumber = config.get('skinNumber');
const main = () => {
const onSelectEmoji = emoji => {
clipboardy.writeSync(emoji);
process.exit();
};
let unmount; // eslint-disable-line prefer-const
const onError = () => {
unmount();
process.exit(1);
};
const onExit = () => {
unmount();
process.exit();
};
// Uses `h` instead of JSX to avoid transpiling this file
unmount = render(h(ui, {skinNumber, onSelectEmoji, onError, onExit}));
};
if (cli.input.length > 0) {
(async () => {
const emojis = (await emoj(cli.input[0]))
.slice(0, 7)
.map(emoji => skinTone(emoji, skinNumber));
console.log(emojis.join(' '));
if (cli.flags.copy) {
clipboardy.writeSync(emojis[0]);
}
})();
} else {
main();
}