This repository has been archived by the owner on May 15, 2024. It is now read-only.
forked from SamVerschueren/gulp-cordova-build-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (65 loc) · 2.31 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
'use strict';
/**
* Builds the cordova project for the iOS platform.
*
* @author Sam Verschueren <[email protected]>
* @since 30 April 2015
*/
// module dependencies
var path = require('path'),
fs = require('fs'),
through = require('through2'),
gutil = require('gulp-util'),
Q = require('q'),
cordovaLib = require('cordova-lib').cordova,
cordova = cordovaLib.raw;
// export the module
module.exports = function(options) {
options = options || {};
return through.obj(function(file, enc, cb) {
// Change the working directory
process.env.PWD = file.path;
// Pipe the file to the next step
this.push(file);
cb();
}, function(cb) {
var iosPath = path.join(cordovaLib.findProjectRoot(), 'platforms', 'ios');
var exists = fs.existsSync(iosPath),
reAdd = exists === true && options.rm === true;
Q.fcall(function() {
if(reAdd) {
// First remove the platform if we have to re-add it
return cordova.platforms('rm', 'ios');
}
}).then(function() {
if(exists === false || reAdd) {
// Add the iOS platform if it does not exist or we have to re-add it
return cordova.platforms('add', 'ios');
}
}).then(function() {
var buildOptions = {
codeSignIdentity: options.codeSignIdentity,
provisioningProfile: options.provisioningProfile,
device: options.device,
release: options.release
};
// Build the platform
return cordova.build({platforms: ['ios'], options: buildOptions});
}).then(function() {
var base = path.join(iosPath, 'build/device'),
cwd = process.env.PWD;
var filePath = path.join(base, '*.ipa');
// Push the file to the result set
self.push(new gutil.File({
base: base,
cwd: cwd,
path: filePath,
contents: fs.readFileSync(filePath)
}));
cb();
}).catch(function(err) {
// Return an error if something happened
cb(new gutil.PluginError('gulp-cordova-build-ios', err.message));
});
});
};