forked from tidev/ioslib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
199 lines (183 loc) · 6.29 KB
/
index.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
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
/**
* Main namespace for the ioslib.
*
* @copyright
* Copyright (c) 2014-2015 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License.
* Please see the LICENSE included with this distribution for details.
*/
const
async = require('async'),
certs = exports.certs = require('./lib/certs'),
device = exports.device = require('./lib/device'),
env = exports.env = require('./lib/env'),
magik = exports.magik = require('./lib/utilities').magik,
provisioning = exports.provisioning = require('./lib/provisioning'),
simulator = exports.simulator = require('./lib/simulator'),
utilities = exports.utilities = require('./lib/utilities'),
xcode = exports.xcode = require('./lib/xcode');
var cache;
exports.detect = detect;
exports.findValidDeviceCertProfileCombos = findValidDeviceCertProfileCombos;
/**
* Detects the entire iOS environment information.
*
* @param {Object} [options] - An object containing various settings.
* @param {Boolean} [options.bypassCache=false] - When true, re-detects the all iOS information.
* @param {String} [options.minIosVersion] - The minimum iOS SDK to detect.
* @param {String} [options.minWatchosVersion] - The minimum WatchOS SDK to detect.
* @param {String} [options.profileDir=~/Library/MobileDevice/Provisioning Profiles] - The path to search for provisioning profiles.
* @param {String} [options.security] - Path to the <code>security</code> executable
* @param {String} [options.supportedVersions] - A string with a version number or range to check if an Xcode install is supported.
* @param {String} [options.type] - The type of emulators to return. Can be either "iphone" or "ipad". Defaults to all types.
* @param {Boolean} [options.validOnly=true] - When true, only returns non-expired, valid certificates.
* @param {String} [options.xcodeSelect] - Path to the <code>xcode-select</code> executable
* @param {Function} [callback(err, info)] - A function to call when all detection tasks have completed.
*/
function detect(options, callback) {
return magik(options, callback, function (emitter, options, callback) {
if (cache && !options.bypassCache) {
emitter.emit('detected', cache);
return callback(null, cache);
}
var results = {
detectVersion: '4.0',
issues: []
};
function mix(src, dest) {
Object.keys(src).forEach(function (name) {
if (Array.isArray(src[name])) {
if (Array.isArray(dest[name])) {
dest[name] = dest[name].concat(src[name]);
} else {
dest[name] = src[name];
}
} else if (src[name] !== null && typeof src[name] === 'object') {
dest[name] || (dest[name] = {});
Object.keys(src[name]).forEach(function (key) {
dest[name][key] = src[name][key];
});
} else {
dest[name] = src[name];
}
});
}
async.parallel([
function certificates(done) {
certs.detect(options, function (err, result) {
err || mix(result, results);
done(err);
});
},
function devices(done) {
device.detect(options, function (err, result) {
err || mix(result, results);
done(err);
});
},
function environment(done) {
env.detect(options, function (err, result) {
err || mix(result, results);
done(err);
});
},
function provisioningProfiles(done) {
provisioning.detect(options, function (err, result) {
err || mix(result, results);
done(err);
});
},
function simulators(done) {
simulator.detect(options, function (err, result) {
err || mix(result, results);
done(err);
});
},
function xcodes(done) {
xcode.detect(options, function (err, result) {
err || mix(result, results);
done(err);
});
}
], function (err) {
if (err) {
emitter.emit('error', err);
return callback(err);
} else {
cache = results;
emitter.emit('detected', results);
return callback(null, results);
}
});
});
};
/**
* Finds all valid device/cert/provisioning profile combinations. This is handy for quickly
* finding valid parameters for building an app for an iOS device.
*
* @param {Object} [options] - An object containing various settings.
* @param {String} [options.appId] - The app identifier (com.domain.app) to filter provisioning profiles by.
* @param {Boolean} [options.bypassCache=false] - When true, re-detects the all iOS information.
* @param {Function} [callback(err, info)] - A function to call when the simulator has launched.
*/
function findValidDeviceCertProfileCombos(options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
} else if (!options) {
options = {};
}
typeof callback === 'function' || (callback = function () {});
// find us a device
device.detect(function (err, deviceResults) {
if (!deviceResults.devices.length) {
// no devices connected
return callback(new Error('No iOS devices connected'));
}
// next find us some certs
certs.detect(function (err, certResults) {
var certs = [];
Object.keys(certResults.certs.keychains).forEach(function (keychain) {
var types = certResults.certs.keychains[keychain];
Object.keys(types).forEach(function (type) {
certs = certs.concat(types[type]);
});
});
if (!certs.length) {
return callback(new Error('No iOS certificates'));
}
// find us a provisioning profile
provisioning.find({
appId: options.appId,
certs: certs,
devicesUDIDs: deviceResults.devices.map(function (device) { return device.udid; })
}, function (err, profiles) {
if (!profiles.length) {
return callback(new Error('No provisioning profiles found'));
}
var combos = [];
profiles.forEach(function (profile) {
deviceResults.devices.forEach(function (device) {
if (profile.devices && profile.devices.indexOf(device.udid) !== -1) {
certs.forEach(function (cert) {
var prefix = cert.pem.replace(/^-----BEGIN CERTIFICATE-----\n/, '').substring(0, 60);
profile.certs.forEach(function (pcert) {
if (pcert.indexOf(prefix) === 0) {
combos.push({
ppUUID: profile.uuid,
certName: cert.name,
deviceUDID: device.udid
});
}
});
});
}
});
});
callback(null, combos);
});
});
});
}