[android] build, run and logcat
This commit is contained in:
@@ -35,6 +35,36 @@ class System {
|
||||
}
|
||||
|
||||
|
||||
class Downloader {
|
||||
|
||||
static download(url, dest, strip = 1) {
|
||||
fse.ensureDirSync(dest);
|
||||
const bar = new ProgressBar(`download [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
|
||||
let stream = got.stream(url);
|
||||
stream = stream.on('downloadProgress', (p) => bar.update(p.percent));
|
||||
if (url.endsWith('.zip')) {
|
||||
stream = stream.pipe(unzip.Parse()).on('entry', (entry) => {
|
||||
const filePath = entry.path.split('/').slice(strip).join(path.sep);
|
||||
if (filePath.length > 0) {
|
||||
if (entry.type === 'Directory') {
|
||||
fse.ensureDirSync(path.join(dest, path.normalize(filePath)));
|
||||
} else if (entry.type === 'File') {
|
||||
entry.pipe(fs.createWriteStream(path.join(dest, path.normalize(filePath))));
|
||||
}
|
||||
} else {
|
||||
entry.autodrain();
|
||||
}
|
||||
});
|
||||
} else if (url.endsWith('tar.gz')) {
|
||||
stream = stream.pipe(tar.x({C: dest, strip: strip}));
|
||||
} else {
|
||||
stream = stream.pipe(fs.createWriteStream(path.join(dest, url.split('/').pop())));
|
||||
}
|
||||
return ps.wait(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Sdk {
|
||||
static set dir(value) {
|
||||
Sdk._dir = value
|
||||
@@ -79,34 +109,13 @@ class Sdk {
|
||||
if (this.prepared) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
fse.ensureDirSync(this.path);
|
||||
const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
|
||||
this.log.d('download: *%s*', this.link);
|
||||
let stream = got.stream(this.link);
|
||||
stream = stream.on('downloadProgress', (p) => bar.update(p.percent));
|
||||
if (this.link.endsWith('.zip')) {
|
||||
stream = stream.pipe(unzip.Parse()).on('entry', (entry) => {
|
||||
const filePath = entry.path.split('/').slice(strip).join(path.sep);
|
||||
if (filePath.length > 0) {
|
||||
if (entry.type === 'Directory') {
|
||||
fse.ensureDirSync(path.join(this.path, path.normalize(filePath)));
|
||||
} else if (entry.type === 'File') {
|
||||
entry.pipe(fs.createWriteStream(path.join(this.path, path.normalize(filePath))));
|
||||
}
|
||||
} else {
|
||||
entry.autodrain();
|
||||
}
|
||||
});
|
||||
} else if (this.link.endsWith('tar.gz')) {
|
||||
stream = stream.pipe(tar.x({C: this.path, strip: strip}));
|
||||
} else {
|
||||
stream = stream.pipe(fs.createWriteStream(path.join(this.path, this.link.split('/').pop())));
|
||||
}
|
||||
return ps.wait(stream);
|
||||
return Downloader.download(this.link, this.path, strip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sdk.Downloader = Downloader;
|
||||
Sdk.System = System;
|
||||
|
||||
module.exports = Sdk;
|
||||
|
||||
Reference in New Issue
Block a user