-
Notifications
You must be signed in to change notification settings - Fork 11
/
cli.js
executable file
·83 lines (73 loc) · 1.84 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
#!/usr/bin/env node
'use strict';
const path = require('path');
const updateNotifier = require('update-notifier');
const meow = require('meow');
const mobicon = require('mobicon');
const logSymbols = require('log-symbols');
const cli = meow(`
Usage
$ mobicon <file>
Options
--platform, -p Platform to generate icons for
--background, -b Color of the icon background if the icon is transparant [Default: white]
--contentRatio, -r Logo-icon ratio [Default: 1]
--roundedCorners Generate icons with rounded corners [Default: true for pwa and Android]
--borderRadius Border radius percentage [Default: 0.0909]
--out, -o Output directory [Default: cwd]
Examples
$ mobicon icon.png -p=android
✔ success
$ mobicon icon.png -p=android -p=ios
✔ success
$ mobicon icon.svg -p=ios -o=resources
✔ success
`, {
flags: {
platform: {
type: 'string',
alias: 'p'
},
background: {
type: 'string',
alias: 'b',
default: 'white'
},
contentRatio: {
type: 'number',
alias: 'r',
default: '1'
},
out: {
type: 'string',
alias: 'o',
default: process.cwd()
}
}
});
updateNotifier({pkg: cli.pkg}).notify();
if (cli.input.length === 0) {
console.error('Please provide an input file.');
process.exit(1);
}
if (!cli.flags.platform) {
console.error('Please provide at least one platform.');
process.exit(1);
}
const platforms = [].concat(cli.flags.platform);
Promise.all(platforms.map(platform => {
let dest = cli.flags.out;
if (platforms.length > 1) {
dest = path.join(dest, platform);
}
return mobicon(cli.input[0], {
platform,
dest,
background: cli.flags.background,
contentRatio: cli.flags.contentRatio
});
})).then(() => {
console.log(` ${logSymbols.success} success`);
}).catch(error => {
console.log(` ${logSymbols.error} ${error.message}`);
});