[build] added gulp builder

This commit is contained in:
2017-12-17 22:29:16 +03:00
parent 823799e8fb
commit 69c2b735a0
24 changed files with 1273 additions and 4 deletions

72
tasks/android.js Normal file
View 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;