This commit is contained in:
2017-12-22 17:10:46 +03:00
parent 6345ddcd19
commit 0dd878224b
14 changed files with 88 additions and 136 deletions

View File

@@ -1,4 +1,3 @@
"use strict";
const fs = require('fs');
const tmp = require('tmp-file');
const gutil = require('gulp-util');

View File

@@ -1,72 +0,0 @@
"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;

View File

@@ -1,4 +1,3 @@
"use strict";
const fs = require('fs');
const os = require('os');
const path = require('path');

View File

@@ -1,4 +1,3 @@
"use strict";
const os = require('os');
const gulp = require('gulp');
const gutil = require('gulp-util');

View File

@@ -1,26 +0,0 @@
'use strict';
const through = require('through2');
const gutil = require('gulp-util');
const col = gutil.colors;
const Tail = require('tail').Tail;
module.exports = (handler) => {
let stream = null;
let tail = null;
const bufferContents = (file, enc, callback) => {
tail = new Tail(file.path);
tail.on("line", handler);
callback();
};
const endStream = (callback) => {
if (tail) {
tail.unwatch();
tail = null;
}
callback();
};
return stream = through.obj(bufferContents, endStream);
};