forked from SamVerschueren/gulp-cordova-build-ios
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
50 lines (44 loc) · 1.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
'use strict';
var path = require('path');
var fs = require('fs');
var through = require('through2');
var gutil = require('gulp-util');
var Promise = require('pinkie-promise');
var cordovaLib = require('cordova-lib').cordova;
var cordova = cordovaLib.raw;
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 exists = fs.existsSync(path.join(cordovaLib.findProjectRoot(), 'platforms', 'ios'));
Promise.resolve()
.then(function () {
if (options.reAdd) {
// First remove the platform if we have to re-add it
return cordova.platforms('rm', 'ios');
}
})
.then(function () {
if (exists === false || options.reAdd) {
// Add the iOS platform if it does not exist or we have to re-add it
return cordova.platforms('add', 'ios' + (options.version ? ('@' + options.version) : ''));
}
})
.then(function () {
// Build the platform
return cordova.build({platforms: ['ios']});
})
.then(function () {
cb();
})
.catch(function (err) {
// Return an error if something happened
cb(new gutil.PluginError('gulp-cordova-build-ios', err.message));
});
});
};