-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·58 lines (48 loc) · 1.83 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
#!/usr/bin/env node
const CFonts = require('cfonts')
const chalk = require('chalk')
const got = require('got')
const terminalImage = require('term-image')
const { version } = require('./package.json')
const args = process.argv.slice(2)[0]
const menu = {
main: `
node-gif [gifName]
gifName ............ show gif based on input
version ............ show package version
help ............... show help menu for a command
`
}
if(args === '-v' || args === '--version') {
console.log(`v${version}`)
return
}
if(args === '-h' || args === '--help') {
console.log(menu.main)
return
}
CFonts.say('node-gif', {
font: 'chrome', // define the font face
align: 'left', // define text alignment
colors: ['cyanBright','greenBright','white'], // define all colors
background: 'transparent', // define the background color, you can also use `backgroundColor` here as key
letterSpacing: 1, // define letter spacing
lineHeight: 1, // define the line height
space: true, // define if the output text should have empty lines on top and on the bottom
maxLength: '0', // define how many characters can be on one line
})
const getGif = () => {
(async () => {
const { body } = await got(`https://api.giphy.com/v1/gifs/search?api_key=p1gIrzabo2nzwNhZblbhIp4x9Xp8zYcn&q=${args}&limit=1&offset=0&rating=G&lang=en`);
const json = JSON.parse(body)
console.log(chalk.cyan('Fetching.... 🌍'))
const fetchGif = async () => {
console.log(chalk.yellow('Cooking.... 👨🍳'))
const { body } = await got(json.data[0].images.original.url, { encoding: null })
console.log(chalk.red('Here we go.... 💃'))
console.log(await terminalImage.buffer(body, {height: '50%'}))
};
fetchGif()
})()
}
getGif()