forked from jasonkneen/TiCons-CLI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·145 lines (115 loc) · 4.24 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
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
#!/usr/bin/env node
// jscs:disable jsDoc
'use strict';
var _ = require('underscore'),
program = require('commander'),
updateNotifier = require('update-notifier'),
pkg = require('./package.json'),
ticons = require('./'),
constants = require('./lib/constants'),
logger = require('./lib/logger');
var notifier = updateNotifier({
pkg: pkg
});
program
.version(pkg.version, '-v, --version')
.description(pkg.description)
.usage('command <args> [options]')
.option('-m, --min-dpi <dpi>', 'minimum density to generate (default: `160` or `mdpi`)')
.option('-M, --max-dpi <dpi>', 'maximum density to generate, (default e.g. `480` or `xxhdpi`)')
.option('-d, --output-dir <path>', 'directory to write to')
.option('-a, --alloy', 'force Alloy paths, even if not detected')
.option('-b, --alloy-base <directory>', 'select a different alloy base directory instead of app, e.g. src')
.option('-p, --platforms <platforms>', 'none to detect, `all` or some of: ' + constants.platforms.join(','))
.option('-L, --label', 'draws the spec-name on each image for debugging')
.option('-s, --sdk-version <semver>', 'Titanium SDK version, overriding detected')
.option('-t, --trace', 'shows initialized config and actual imagemagick commands');
program.command('icons [input]')
.description('generate icons')
.option('-r, --radius <percentage>', 'percentage between 0 and 50 (all platforms except iOS)')
.action(icons);
program.command('adaptiveicons [input]')
.description('generate foregrounds')
.option('-r, --radius <percentage>', 'percentage between 0 and 50 (all platforms except iOS)')
.action(adaptiveicons);
program.command('splashes [input]')
.description('generate splash screens (aka launch images)')
.option('-l, --locale <code>', 'outputs to i18n folders')
.option('-o, --orientation <orientation>', 'none to detect, `all` or one of: ' + constants.orientations.join(','))
.option('-W, --width <width>', 'width from center that may not be cropped')
.option('-H, --height <width>', 'height from center that may not be cropped')
.option('-S, --storyboard', 'generate LaunchLogo.png for iOS to use with storyboards')
.option('-n, --no-nine', 'do NOT generate 9-patch images (Android)')
.option('-c, --no-crop', 'do NOT crop splashes but contain and fill')
.option('-f, --no-fix', 'do NOT fix errors in Appcelerator specs')
.action(splashes);
program.command('assets [input]')
.description('generate missing densities for input asset(s)')
.option('-O, --orig-dpi <code>', 'input density (default: detect by file path and name)')
.action(assets);
program.parse(process.argv);
if (program.args.length === 0 || typeof program.args[program.args.length - 1] === 'string') {
notifier.update && notifier.notify();
program.help();
}
function assets(input, env) {
notifier.update && notifier.notify();
var options = _filterOptions(env);
options.cli = true;
options.input = input;
ticons.assets(options, function (err, output) {
if (err) {
logger.error(err);
} else {
logger.ok('Generated ' + _.size(_.filter(output, _.identity)) + ' assets');
}
});
}
function icons(input, env) {
notifier.update && notifier.notify();
var options = _filterOptions(env);
options.cli = true;
options.input = input;
ticons.icons(options, function (err, output) {
if (err) {
logger.error(err);
} else {
logger.ok('Generated ' + _.size(_.filter(output, _.identity)) + ' icons');
}
});
}
function adaptiveicons(input, env) {
notifier.update && notifier.notify();
var options = _filterOptions(env);
options.cli = true;
options.input = input;
ticons.adaptiveicons(options, function (err, output) {
if (err) {
logger.error(err);
} else {
logger.ok('Generated ' + _.size(_.filter(output, _.identity)) + ' icon_foreground');
}
});
}
function splashes(input, env) {
notifier.update && notifier.notify();
var options = _filterOptions(env);
options.cli = true;
options.input = input;
ticons.splashes(options, function (err, output) {
if (err) {
logger.error(err);
} else {
logger.ok('Generated ' + _.size(_.filter(output, _.identity)) + ' splashes');
}
});
}
function _filterOptions(o) {
var opts = o.parent ? _filterOptions(o.parent) : {};
_.each(o, function (v, k) {
if (k[0] !== '_' && !_.isObject(v)) {
opts[k] = v;
}
});
return opts;
}