-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathapk-path.js
40 lines (32 loc) · 1.09 KB
/
apk-path.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
const path = require('path');
const RSVP = require('rsvp');
const fs = require('fs');
const logger = require('../../../utils/logger');
const Promise = RSVP.Promise;
module.exports = function(root, opts = {}) {
let buildType = opts.debug ? 'debug' : 'release';
//directory differs if build was with gradle vs studio
/* eslint-disable max-len */
let basePath = path.join(root, 'platforms', 'android');
let gradlePath = path.join(basePath, 'build', 'outputs', 'apk', buildType);
let studioPath = path.join(basePath, 'app', 'build', 'outputs', 'apk', buildType);
/* eslint-enable max-len */
let apkPaths = [gradlePath, studioPath].reduce((arr, dir) => {
if (!fs.existsSync(dir)) {
return arr;
}
fs.readdirSync(dir).forEach((name) => {
if (name.match(/\.apk$/i)) {
arr.push(path.join(dir, name))
}
});
return arr;
}, []);
if (apkPaths.length === 0) {
return Promise.reject('No apk found')
}
if (apkPaths.length > 1) {
logger.warn(`More than one apk found; using ${apkPaths[0]}`)
}
return Promise.resolve(apkPaths[0]);
};