[build] remove deprecated gulp-utils

This commit is contained in:
2017-12-30 17:53:25 +03:00
parent 0dd878224b
commit ecb0629494
12 changed files with 93 additions and 135 deletions

View File

@@ -1,13 +1,12 @@
const os = require('os');
const gulp = require('gulp');
const gutil = require('gulp-util');
const col = gutil.colors;
const download = require('./download');
const unzip = require('gulp-unzip');
const gunzip = require('gulp-gunzip');
const untar = require('gulp-untar');
const Promise = require('bluebird');
const fs = require('fs');
const ps = require('promise-streams');
const got = require('got');
const unzip = require('unzip-stream');
const ProgressBar = require('progress');
const colors = require('ansi-colors');
const log = require('fancy-log');
class Sdk {
static set dir(value) {
@@ -24,7 +23,7 @@ class Sdk {
constructor(name, version) {
this.name = name;
this.tag = col.green(`[${name}]`);
this.tag = colors.green(`[${name}]`);
this.version = version;
this.path = Sdk.path(name, version);
}
@@ -49,27 +48,25 @@ class Sdk {
}
prepare() {
gutil.log(this.tag, `version: ${col.magenta(this.version)}`);
return new Promise((success, fail) => {
if (this.prepared) {
success();
log(this.tag, `version: ${colors.magenta(this.version)}`);
if (this.prepared) {
return Promise.resolve();
} else {
const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
let stream = got.stream(this.link);
stream = stream.on('downloadProgress', (p) => bar.update(p.percent));
//stream = stream.pipe(fs.createWriteStream(this.path + '.zip'));
if (this.link.endsWith('.zip')) {
stream = stream.pipe(unzip.Extract({path: this.path}));
} else if (this.link.endsWith('tar.gz')) {
// ToDo: unpack tar.gz
//stream = stream.pipe(gunzip()).pipe(untar())
} else {
const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
let stream = download(this.link)
.on('error', fail)
.on('progress', (p) => bar.update(p.percent))
.on('end', () => bar.update(1));
if (this.link.endsWith('.zip')) {
stream = stream.pipe(unzip());
} else if (this.link.endsWith('tar.gz')) {
stream = stream.pipe(gunzip()).pipe(untar())
}
return stream
.pipe(gulp.dest(this.path))
.on('end', success)
.on('error', fail);
stream = stream.pipe(fs.createWriteStream(this.path));
}
});
return ps.wait(stream);
}
}
}