-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
48 lines (42 loc) · 1.14 KB
/
index.ts
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
#!/usr/bin/env node
import program from 'commander';
import Canvas from './lib/Canvas';
import PKG from './package.json';
program
.version(PKG.version)
.parse(process.argv);
program
.command('create <name>')
.description('Generate image')
.usage('[options] <file ...>')
.option('-s, --size <size>', 'Image size', /^\d+x\d+$/i, '200x200')
.option('-t, --text <text>', 'Text')
.option('-o, --out <path>', 'Out path')
.option('-f, --filetype <png|jpe?g|svg|gif>', 'File type', /^(png|jpe?g|svg|gif)/i, 'png')
.option('-b, --background <color>', 'Background color', '#000000')
.option('-c, --color <color>', 'Font color', '#FFFFFF')
.action((name, cmd) => {
const { size, text, out, filetype, background, color } = cmd;
const canvas = new Canvas(name, {
size,
text,
out,
type: filetype,
background,
color,
});
canvas.genarator();
})
.parse(process.argv);
program
.command('help')
.description('Print this help')
.action(() => {
program.outputHelp();
})
.parse(process.argv);
program
.parse(process.argv);
if (process.argv.length === 2) {
program.outputHelp();
}