[sdk] update progress bar

This commit is contained in:
2019-08-26 23:02:16 +03:00
parent 2b703fb66a
commit bd4fc36ff1
4 changed files with 50 additions and 13 deletions

View File

@@ -55,10 +55,11 @@ class Android extends Sdk {
// ToDo: support windows
const url = `https://dl.google.com/android/repository/android-ndk-${this.ndk_version}-linux-x86_64.zip`;
this.log.d('download: *%s*', url);
return Sdk.Downloader.download(url, this.ndk_home);
return Sdk.Downloader.download(url, this.ndk_home, 1, true);
}
sdkmanager(packages) {
this.log.i('sdkmanager: *%s*', packages.join(', '));
const androidBin = path.join(this.path, 'tools/bin/sdkmanager');
if (fs.existsSync(androidBin)) {
fs.chmodSync(androidBin, 0o755);

View File

@@ -116,9 +116,12 @@ FlashPlayer.VERSION_24 = '24';
FlashPlayer.VERSION_25 = '25';
FlashPlayer.VERSION_26 = '26';
FlashPlayer.VERSION_27 = '27';
FlashPlayer.VERSION_28 = '28';
FlashPlayer.VERSION_29 = '29';
FlashPlayer.VERSION_30 = '30';
FlashPlayer.VERSION_31 = '31';
FlashPlayer.VERSION_32 = '32';
FlashPlayer.VERSION = FlashPlayer.VERSION_30;
FlashPlayer.VERSION = FlashPlayer.VERSION_32;
module.exports = FlashPlayer;

View File

@@ -5,7 +5,7 @@ const ps = require('promise-streams');
const got = require('got');
const unzip = require('unzip-stream');
const tar = require('tar');
const ProgressBar = require('progress');
const progress = require('cli-progress');
const fse = require('fs-extra');
const Log = require('./log');
@@ -37,19 +37,52 @@ class System {
class Downloader {
static download(url, dest, strip = 1) {
static createProgressBar() {
if (Downloader.bar == null) {
Downloader.bar = new progress.MultiBar({
clearOnComplete: true,
}, progress.Presets.shades_grey);
}
return Downloader.bar.create();
}
static releaseProgressBar(bar) {
bar.stop();
if (Downloader.bar != null) {
Downloader.bar.remove(bar);
if (Downloader.bar.bars.length === 0) {
Downloader.bar.stop();
Downloader.bar = null;
}
}
}
static download(url, dest, strip = 1, executable = false) {
fse.ensureDirSync(dest);
const bar = new ProgressBar(`download [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
const bar = Downloader.createProgressBar();
let stream = got.stream(url);
stream = stream.on('downloadProgress', (p) => bar.update(p.percent));
stream = stream
.on('request', r => {
bar.start(1, 0);
})
.on('downloadProgress', p => {
bar.setTotal(p.total);
bar.update(p.transferred);
if (p.total === p.transferred) {
Downloader.releaseProgressBar(bar);
}
});
if (url.endsWith('.zip')) {
stream = stream.pipe(unzip.Parse()).on('entry', (entry) => {
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))));
entry.pipe(fs.createWriteStream(path.join(dest, path.normalize(filePath)), {
// ToDo: zip entry file mode?
mode: executable ? 0o755 : undefined,
}));
}
} else {
entry.autodrain();

View File

@@ -1,14 +1,15 @@
{
"name": "gulp-haxetool",
"version": "0.0.22",
"version": "0.0.23",
"description": "HaXe Tool for Gulp",
"main": "index.js",
"dependencies": {
"ansi-colors": "^1.1.0",
"async": "^2.6.0",
"cli-progress": "^3.0.0",
"fancy-log": "^1.3.2",
"fs-extra": "^5.0.0",
"got": "^8.3.0",
"got": "^9.6.0",
"gulp": "^4.0.0",
"gulp-debian": "^0.1.9",
"gulp-gzip": "^1.4.2",
@@ -19,7 +20,6 @@
"lodash.defaults": "^4.2.0",
"lodash.template": "^4.4.0",
"plugin-error": "^1.0.1",
"progress": "^2.0.0",
"promise-streams": "^2.1.1",
"tail": "^1.2.3",
"tar": "^4.4.1",