[build] added gulp builder
This commit is contained in:
72
tasks/android.js
Normal file
72
tasks/android.js
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
const exec = require('./exec');
|
||||
const fs = require('fs');
|
||||
const through = require('through2');
|
||||
|
||||
|
||||
const Android = {
|
||||
adb: (args) => {
|
||||
const adbBin = `${process.env.ANDROID_HOME}/platform-tools/adb.exe`;
|
||||
return exec('.', [adbBin].concat(args).join(' ')).then((data) => {
|
||||
for (let line of data.stderr.split('\n')) {
|
||||
if (line.indexOf('Error') > -1) {
|
||||
throw line;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
aapt: (args) => {
|
||||
let buildToolsVersion = null;
|
||||
fs.readdirSync(`${process.env.ANDROID_HOME}/build-tools`).forEach(file => {
|
||||
buildToolsVersion = file;
|
||||
});
|
||||
const aaptBin = `${process.env.ANDROID_HOME}/build-tools/${buildToolsVersion}/aapt.exe`;
|
||||
return exec('.', [aaptBin].concat(args).join(' '));
|
||||
},
|
||||
|
||||
apk: () => {
|
||||
return through.obj(function(file, enc, callback) {
|
||||
Android.aapt(['l', '-a', file.path]).then((data) => {
|
||||
let activity = false;
|
||||
for (let line of data.stdout.split('\n')) {
|
||||
if (line.indexOf('package') > -1) {
|
||||
const value = /"(.*?)"/.exec(line);
|
||||
if (value) file.package = value[1]
|
||||
}
|
||||
if (line.indexOf('activity') > -1) {
|
||||
activity = true;
|
||||
}
|
||||
if (activity && line.indexOf('name') > -1) {
|
||||
const value = /"(.*?)"/.exec(line);
|
||||
if (value) {
|
||||
file.activity = value[1];
|
||||
activity = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
install: () => {
|
||||
return through.obj(function(file, enc, callback) {
|
||||
Android.adb(['install', '-r', file.path]).then(() => {
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
start: () => {
|
||||
return through.obj((file, enc, callback) => {
|
||||
const name = `${file.package}/${file.activity}`;
|
||||
Android.adb(['shell', 'am', 'start', '-n', name]).then(() => callback());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = Android;
|
||||
Reference in New Issue
Block a user