forked from arusanov/avatar-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·45 lines (41 loc) · 1.08 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
#! /usr/bin/env node
const AvatarGenerator = require('./lib')
const program = require('commander')
const generator = new AvatarGenerator()
const variants = generator.variants
function checkDiscriminator(value) {
return variants.indexOf(value) !== -1
}
program
.version(require('./package').version)
.option('-I, --id <id>', 'id for avatar. any string')
.option(
'-D, --discriminator [value]',
'avatar discriminator (one of: ' + variants.join(', ') + ')',
variants[0],
checkDiscriminator
)
.option('-S, --size <width>', 'avatar size', parseInt, 400)
.option('*')
.parse(process.argv)
try {
let out = process.stdout
if (program['*'] && Array.isArray(program['*']) && program['*'].length > 0) {
out = require('fs').createWriteStream(program['*'][0])
}
generator
.generate(program.id || '', program.discriminator)
.then((image) =>
image
.resize(program.size, program.size)
.png()
.pipe(out)
)
.catch((err) => {
console.error(err)
program.help()
})
} catch (err) {
console.error(err)
program.help()
}