-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.ts
215 lines (182 loc) · 5.32 KB
/
cli.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import {
readFileSync
} from 'fs';
import {
argv,
end,
options as readOptions
} from 'argue-cli';
import Table from 'easy-table';
import vfs from 'vinyl-fs';
import getRc from 'rcfile';
import omit from 'omit-empty';
import stream from './stream';
import {
IIconConfig
} from './';
const {
help,
verbose,
path,
background,
manifest,
headers,
dest,
skipFavicon,
skipAndroid,
skipApple,
skipAppleStartup,
androidBackground,
androidOffset,
appleBackground,
appleOffset,
appleStartupBackground,
appleStartupOffset
}: any = readOptions([
['help', 'h'],
['verbose', 'v'],
['headers', 'H']
], [
{ 'path': 'p' },
{ 'background': 'b' },
{ 'manifest': 'm' },
{ 'dest': 'd' },
'skipFavicon',
'skipAndroid',
'skipApple',
'skipAppleStartup',
'androidBackground',
'androidOffset',
'appleBackground',
'appleOffset',
'appleStartupBackground',
'appleStartupOffset'
]);
if (help) {
end();
const optionsTable = new Table();
optionsTable.cell('Option', 'sources');
optionsTable.cell('Description', 'Source icon(s) glob patterns.');
optionsTable.newRow();
optionsTable.cell('Option', '--help, -h');
optionsTable.cell('Description', 'Print this message.');
optionsTable.newRow();
optionsTable.cell('Option', '--verbose, -v');
optionsTable.cell('Description', 'Print additional info about progress.');
optionsTable.newRow();
optionsTable.cell('Option', '--path, -p');
optionsTable.cell('Description', 'Relative public path to use in webmanifest and html-headers.');
optionsTable.newRow();
optionsTable.cell('Option', '--background, -b');
optionsTable.cell('Description', 'Background color for icons and startup images.');
optionsTable.cell('Default', 'white');
optionsTable.newRow();
optionsTable.cell('Option', '--manifest, -m');
optionsTable.cell('Description', 'Path to webmanifest file to add icons. Also can use it to get background color.');
optionsTable.newRow();
optionsTable.cell('Option', '--headers, -H');
optionsTable.cell('Description', 'Create html-file with headers for icons.');
optionsTable.cell('Default', 'false');
optionsTable.newRow();
optionsTable.cell('Option', '--skipFavicon');
optionsTable.cell('Description', 'Do not create favicon.');
optionsTable.cell('Default', 'false');
optionsTable.newRow();
optionsTable.cell('Option', '--skipAndroid');
optionsTable.cell('Description', 'Do not create icons for Android.');
optionsTable.cell('Default', 'false');
optionsTable.newRow();
optionsTable.cell('Option', '--skipApple');
optionsTable.cell('Description', 'Do not create icons for iOS.');
optionsTable.cell('Default', 'false');
optionsTable.newRow();
optionsTable.cell('Option', '--skipAppleStartup');
optionsTable.cell('Description', 'Do not create startup screens for iOS.');
optionsTable.cell('Default', 'false');
optionsTable.newRow();
optionsTable.cell('Option', '--androidBackground');
optionsTable.cell('Description', 'Background color for Android icons.');
optionsTable.newRow();
optionsTable.cell('Option', '--androidOffset');
optionsTable.cell('Description', 'Offset size in percents for Android icons.');
optionsTable.cell('Default', '0');
optionsTable.newRow();
optionsTable.cell('Option', '--appleBackground');
optionsTable.cell('Description', 'Background color for iOS icons.');
optionsTable.newRow();
optionsTable.cell('Option', '--appleOffset');
optionsTable.cell('Description', 'Offset size in percents for iOS icons.');
optionsTable.cell('Default', '0');
optionsTable.newRow();
optionsTable.cell('Option', '--appleStartupBackground');
optionsTable.cell('Description', 'Background color for iOS startup screens.');
optionsTable.newRow();
optionsTable.cell('Option', '--appleStartupOffset');
optionsTable.cell('Description', 'Offset size in percents for iOS startup screens.');
optionsTable.cell('Default', '0');
optionsTable.newRow();
optionsTable.cell('Option', '--dest, -d');
optionsTable.cell('Description', 'Destination directory.');
optionsTable.newRow();
console.log(`\nfavicons [...sources] [...options]\n\n${optionsTable.toString()}`);
process.exit(0);
}
function configIcon(
icon: boolean|IIconConfig,
skip: boolean,
background: string,
offset: string|number
) {
if (skip || !background && !offset && icon === false) {
return false;
}
const config: IIconConfig = typeof icon !== 'boolean'
? { ...icon }
: {};
if (background) {
config.background = background;
}
if (offset) {
config.offset = Number(offset);
}
if (!Object.keys(config).length) {
return true;
}
return config;
}
const rc = {
icons: {},
...getRc('favicons')
};
const icons = {
...rc.icons,
favicon: !skipFavicon,
android: configIcon(rc.icons.android, skipAndroid, androidBackground, androidOffset),
apple: configIcon(rc.icons.apple, skipApple, appleBackground, appleOffset),
appleStartup: configIcon(rc.icons.appleStartup, skipAppleStartup, appleStartupBackground, appleStartupOffset)
};
const params = {
...rc,
...omit({
src: argv.length
? argv
: rc.src,
path,
verbose,
background,
icons,
manifest: manifest
? JSON.parse(readFileSync(manifest, 'utf8'))
: typeof rc.manifest === 'string'
? JSON.parse(readFileSync(rc.manifest, 'utf8'))
: rc.manifest,
headers,
dest
})
};
if (!params.src || !params.src.length) {
throw new Error('No any sources');
}
vfs.src(params.src)
.pipe(stream(params))
.pipe(vfs.dest(params.dest));