This repository was archived by the owner on May 15, 2024. It is now read-only.
forked from SamVerschueren/gulp-cordova-build-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
99 lines (85 loc) · 3.23 KB
/
Copy pathindex.js
File metadata and controls
99 lines (85 loc) · 3.23 KB
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
'use strict';
/**
* Builds the cordova project for the Android platform.
*
* @author Sam Verschueren <sam.verschueren@gmail.com>
* @since 25 April 2015
*/
// module dependencies
var path = require('path'),
fs = require('fs'),
os = require('os'),
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;
cb();
}, function(cb) {
var self = this,
androidPath = path.join(cordovaLib.findProjectRoot(), 'platforms', 'android'),
sign = !!(options.storeFile && options.keyAlias),
release = options.release;
Q.fcall(function() {
return fs.existsSync(androidPath);
}).then(function(exists) {
if(!exists) {
// Add the android platform if it does not exist
return cordova.platforms('add', 'android');
}
}).then(function() {
if(sign) {
var data = [];
// Add all the options related to key signing to the array to be added to 'release-signing.properties'
data.push('storeFile=' + options.storeFile);
data.push('keyAlias=' + options.keyAlias);
if(options.storePassword) {
data.push('storePassword=' + options.storePassword);
}
if(options.keyPassword) {
data.push('keyPassword=' + options.keyPassword);
}
if(options.storeType) {
data.push('storeType=' + options.storeType);
}
// Write the release-signing.properties file
fs.writeFileSync(path.join(androidPath, 'release-signing.properties'), data.join(os.EOL));
}
}).then(function() {
var options = {};
options.release = release;
// Build the platform
return cordova.build({platforms: ['android'], options: options});
}).then(function() {
var base = path.join(androidPath, 'build/outputs/apk'),
cwd = process.env.PWD;
var filePath;
if (release) {
if (sign)
filePath = path.join(base, 'android-release.apk');
else
filePath = path.join(base, 'android-release-unsigned.apk');
} else {
filePath = path.join(base, 'android-debug.apk');
}
// 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) {
console.log(err);
// Return an error if something happened
cb(new gutil.PluginError('gulp-cordova-build-android', err.message));
});
});
};