forked from matiassingers/ipa-metadata
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·113 lines (89 loc) · 2.5 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
#!/usr/bin/env node
'use strict';
var pkg = require('./package.json');
var ipaMetadata = require('./');
var meow = require('meow');
var Table = require('cli-table');
var _ = require('lodash');
var chalk = require('chalk');
var cli = meow({
help: [
'Example',
' ipa Facebook.ipa',
'',
' ipa Facebook.ipa --verbose',
'',
' ipa Facebook.ipa --verify',
' (verifies entitlements between `.app` bundle and `embedded.mobileprovision`)',
'',
' => data displayed in a table'
].join('\n')
});
var verificationFailed;
function format(value, compare) {
if(!_.isPlainObject(value)) {
return value;
}
var string = [];
_.each(value, function(value, key) {
var shouldCompareEquality = cli.flags.verify && compare;
if(!shouldCompareEquality){
return string.push(key, ': ', format(value), '\n');
}
if(key === 'keychain-access-groups'){
return string.push(compareKeychainEntitlement(value, key, compare[key]), '\n');
}
return string.push(compareOutputString(value, compare[key], key), '\n');
});
string.pop();
return string.join('');
}
function compareKeychainEntitlement(value, key, compare) {
function splitKeychain(value) {
return value[0].split('.')[0];
}
return compareOutputString(splitKeychain(value), splitKeychain(compare), key);
}
function compareOutputString(value, target, key) {
var match = value === target;
if(!match){
verificationFailed = true;
}
return chalk[match ? 'green' : 'red'](key + ': ' + format(value));
}
function verboseFormatting(data){
var types = Object.keys(data);
_.each(types, function(type){
var table = new Table();
_.each(data[type], function(value, key){
table.push([key, format(value)]) ;
});
console.log(table.toString());
});
}
if(!cli.input[0]){
return cli.showHelp();
}
ipaMetadata(cli.input[0], function(error, data){
if(error){
return console.log(error.message);
}
if(cli.flags.verbose){
return verboseFormatting(data);
}
var types = {
metadata: ['CFBundleDisplayName', 'CFBundleIdentifier', 'CFBundleShortVersionString', 'CFBundleVersion'],
provisioning: ['Name', 'TeamIdentifier', 'TeamName', 'Entitlements']
};
var table = new Table();
_.each(types, function(keys, type) {
if(data[type]){
_.each(keys, function(key) {
var value = data[type][key];
table.push([key, format(value, data.entitlements)]);
});
}
});
console.log(table.toString());
process.exit(verificationFailed);
});