-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
83 lines (70 loc) · 1.92 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
77
78
79
80
81
82
83
'use strict';
const shelljs = require('shelljs');
const fs = require('fs');
const os = require('os');
const path = require('path');
const platform = os.platform();
const aapt = path.join(__dirname, 'bin', platform , 'aapt');
if (platform === 'linux') {
fs.chmodSync(aapt, '777')
}
function promistify(cmd, callback) {
callback = callback || function () {};
return new Promise((resolve, reject) => {
shelljs.exec(cmd, (code, stdout, stderr) => {
if (code !== 0) {
reject(stderr);
callback(stderr, null);
} else {
resolve(stdout);
callback(null, stdout);
}
})
});
}
function list(apkfilePath, callback) {
return promistify(`${aapt} l ${apkfilePath}`, callback);
}
function dump(what, apkfilePath, callback) {
return promistify(`${aapt} d ${what} ${apkfilePath}`, callback);
}
function packageCmd(command, callback) {
return promistify(`${aapt} p ${command}`, callback);
}
function remove(apkfilePath, files, callback) {
if (!Array.isArray(files)) {
files = [files]
}
const removeFiles = files.join(' ')
return promistify(`${aapt} r ${apkfilePath} ${removeFiles}`, callback);
}
function add(apkfilePath, files, callback) {
if (!Array.isArray(files)) {
files = [files]
}
const addFiles = files.join(' ')
return promistify(`${aapt} a ${apkfilePath} ${addFiles}`, callback);
}
function crunch(resource, outputFolder, callback) {
if (!Array.isArray(resource)) {
resource = [resource]
}
const resourceSources = resource.join(' ')
return promistify(`${aapt} c -S ${resourceSources} -C ${outputFolder}`, callback);
}
function singleCrunch(inputFile, outputfile, callback) {
return promistify(`${aapt} s -i ${inputFile} -o ${outputfile}`, callback);
}
function version(callback) {
return promistify(`${aapt} v`, callback);
}
module.exports = {
list: list,
dump: dump,
packageCmd: packageCmd,
remove: remove,
add: add,
crunch: crunch,
singleCrunch: singleCrunch,
version: version
}