-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
59 lines (44 loc) · 1.39 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
'use strict';
var async = require('async');
var plist = require('simple-plist');
var decompress = require('decompress-zip');
var provisioning = require('provisioning');
var entitlements = require('entitlements');
var rimraf = require('rimraf');
var tmp = require('temporary');
var glob = require("glob");
var output = new tmp.Dir();
module.exports = function (file, callback){
var data = {};
var unzipper = new decompress(file);
unzipper.extract({
path: output.path
});
unzipper.on('error', cleanUp);
unzipper.on('extract', function() {
var path = glob.sync(output.path + '/Payload/*/')[0];
data.metadata = plist.readFileSync(path + 'Info.plist');
var tasks = [
async.apply(provisioning, path + 'embedded.mobileprovision')
];
// `entitlements` relies on a OS X only CLI tool called `codesign`
if(process.platform === 'darwin'){
tasks.push(async.apply(entitlements, path));
}
async.parallel(tasks, function(error, results){
if(error){
return cleanUp(error);
}
data.provisioning = results[0];
// Hard to serialize and it looks messy in output
delete data.provisioning.DeveloperCertificates;
// Will be undefined on non-OSX platforms
data.entitlements = results[1];
return cleanUp();
});
});
function cleanUp(error){
rimraf.sync(output.path);
return callback(error, data);
}
};