[build] remove deprecated gulp-utils
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,6 +7,7 @@ out/
|
|||||||
*.ids
|
*.ids
|
||||||
*.stackdump
|
*.stackdump
|
||||||
.idea/
|
.idea/
|
||||||
|
.ideaDataSources/
|
||||||
config.json
|
config.json
|
||||||
package-lock.json
|
package-lock.json
|
||||||
/node_modules
|
/node_modules
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ const packages = [
|
|||||||
{name:'lime', version:'5.3.0'},
|
{name:'lime', version:'5.3.0'},
|
||||||
'promhx',
|
'promhx',
|
||||||
'protohx',
|
'protohx',
|
||||||
'haxework',
|
//'haxework',
|
||||||
|
{name:'haxework', git:'git@bitbucket.org:shmyga/haxework.git'},
|
||||||
|
|
||||||
|
'orm',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ const os = require('os');
|
|||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const clean = require('gulp-clean');
|
const clean = require('gulp-clean');
|
||||||
const Sdk = require('./tasks/sdk');
|
const Sdk = require('./tasks/sdk');
|
||||||
|
const FlashPlayer = require('./tasks/flashplayer');
|
||||||
const Config = require('./config.json');
|
const Config = require('./config.json');
|
||||||
const prepare = require('./build/prepare');
|
const prepare = require('./build/prepare');
|
||||||
|
|
||||||
|
//FlashPlayer.VERSION = '25.0.0.171';
|
||||||
|
|
||||||
if (Config.SdkDir) {
|
if (Config.SdkDir) {
|
||||||
Sdk.dir = Config.SdkDir;
|
Sdk.dir = Config.SdkDir;
|
||||||
}
|
}
|
||||||
|
|||||||
32
package.json
32
package.json
@@ -3,29 +3,19 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.1.2",
|
"ansi-colors": "^1.0.1",
|
||||||
"dateformat": "^2.0.0",
|
"async": "^2.6.0",
|
||||||
"fs-extra": "^3.0.1",
|
"download": "^6.2.5",
|
||||||
|
"fancy-log": "^1.3.2",
|
||||||
|
"fs-extra": "^5.0.0",
|
||||||
|
"got": "^8.0.1",
|
||||||
"gulp": "github:gulpjs/gulp#4.0",
|
"gulp": "github:gulpjs/gulp#4.0",
|
||||||
"gulp-add-src": "^0.2.0",
|
|
||||||
"gulp-cat": "^0.3.3",
|
|
||||||
"gulp-clean": "^0.3.2",
|
"gulp-clean": "^0.3.2",
|
||||||
"gulp-exec": "^2.1.3",
|
"plugin-error": "^0.1.2",
|
||||||
"gulp-gunzip": "^1.0.0",
|
|
||||||
"gulp-mark": "0.0.2",
|
|
||||||
"gulp-replace-task": "^0.11.0",
|
|
||||||
"gulp-sequence": "^0.4.6",
|
|
||||||
"gulp-ssh": "^0.6.0",
|
|
||||||
"gulp-untar": "0.0.6",
|
|
||||||
"gulp-unzip": "^0.2.0",
|
|
||||||
"merge-stream": "^1.0.1",
|
|
||||||
"progress": "^2.0.0",
|
"progress": "^2.0.0",
|
||||||
"request": "^2.81.0",
|
"promise-streams": "^2.1.1",
|
||||||
"request-progress": "^3.0.0",
|
|
||||||
"tail": "^1.2.2",
|
|
||||||
"tmp-file": "^2.0.1",
|
"tmp-file": "^2.0.1",
|
||||||
"vinyl-source-stream": "^1.1.0",
|
"unzip-stream": "^0.2.1",
|
||||||
"yargs": "^8.0.2"
|
"yargs": "^10.0.3"
|
||||||
},
|
}
|
||||||
"dependencies": {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const tmp = require('tmp-file');
|
const tmp = require('tmp-file');
|
||||||
const gutil = require('gulp-util');
|
|
||||||
const exec = require('./exec');
|
const exec = require('./exec');
|
||||||
const download = require('./download');
|
|
||||||
const unzip = require('gulp-unzip');
|
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const through = require('through2');
|
const through = require('through2');
|
||||||
const mark = require('gulp-mark');
|
//const mark = require('gulp-mark');
|
||||||
const replace = require('gulp-replace-task');
|
//const replace = require('gulp-replace-task');
|
||||||
const col = gutil.colors;
|
|
||||||
const Sdk = require('./sdk');
|
const Sdk = require('./sdk');
|
||||||
|
|
||||||
|
|
||||||
|
// ToDo: remove gutil
|
||||||
class AdobeAir extends Sdk {
|
class AdobeAir extends Sdk {
|
||||||
|
|
||||||
get adtBin() {
|
get adtBin() {
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
const gulp = require('gulp');
|
|
||||||
const gutil = require('gulp-util');
|
|
||||||
const col = gutil.colors;
|
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const through = require('through2');
|
const through = require('through2');
|
||||||
|
const colors = require('ansi-colors');
|
||||||
|
const log = require('fancy-log');
|
||||||
|
|
||||||
const color = (level) => {
|
const color = (level) => {
|
||||||
return {
|
return {
|
||||||
'[DEBUG]': col.white,
|
'[DEBUG]': colors.white,
|
||||||
'[INFO]': col.cyan,
|
'[INFO]': colors.cyan,
|
||||||
'[ERROR]': col.red,
|
'[ERROR]': colors.red,
|
||||||
'[WARNING]': col.yellow,
|
'[WARNING]': colors.yellow,
|
||||||
}[level] || col.reset;
|
}[level] || colors.reset;
|
||||||
};
|
};
|
||||||
|
|
||||||
const log = (line) => {
|
const _log = (line) => {
|
||||||
const result = line.split(' ');
|
const result = line.split(' ');
|
||||||
console.log(col.gray(result[0]) + ' ' + color(result[1])(result.slice(1).join(' ')));
|
console.log(colors.gray(result[0]) + ' ' + color(result[1])(result.slice(1).join(' ')));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
@@ -30,7 +29,7 @@ module.exports = () => {
|
|||||||
socket.on("data", (data) => {
|
socket.on("data", (data) => {
|
||||||
const lines = data.toString().split('\n');
|
const lines = data.toString().split('\n');
|
||||||
for (let line of lines) if (line.length > 2) {
|
for (let line of lines) if (line.length > 2) {
|
||||||
log(line);
|
_log(line);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
socket.on("close", () => {
|
socket.on("close", () => {
|
||||||
@@ -40,7 +39,7 @@ module.exports = () => {
|
|||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
gutil.log(col.green('[debug]'), col.cyan('listen on'), col.magenta(`${debug.host}:${debug.port}`));
|
log(colors.green('[debug]'), colors.cyan('listen on'), colors.magenta(`${debug.host}:${debug.port}`));
|
||||||
server.listen(debug.port, debug.host);
|
server.listen(debug.port, debug.host);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
const path = require('path');
|
|
||||||
const request = require('request');
|
|
||||||
const progress = require('request-progress');
|
|
||||||
const source = require('vinyl-source-stream');
|
|
||||||
const gutil = require('gulp-util');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = (url) => {
|
|
||||||
const name = path.basename(url);
|
|
||||||
let stream = null;
|
|
||||||
return stream = progress(request({url: url, encoding: null}, function(error, response, body) {
|
|
||||||
try {
|
|
||||||
if (error) throw error;
|
|
||||||
if (response.statusCode !== 200) throw `${response.statusCode} ${response.statusMessage}`;
|
|
||||||
} catch (e) {
|
|
||||||
this.emit('error', new gutil.PluginError({plugin: 'download', message: e}));
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.on('error', (e) => stream.emit('error', e))
|
|
||||||
.on('progress', (p) => stream.emit('progress', p))
|
|
||||||
.pipe(source(name));
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
const gutil = require('gulp-util');
|
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const col = gutil.colors;
|
const colors = require('ansi-colors');
|
||||||
const Promise = require("bluebird");
|
const log = require('fancy-log');
|
||||||
|
|
||||||
|
const TAG = colors.green('[exec]');
|
||||||
const TAG = col.green('[exec]');
|
|
||||||
|
|
||||||
const queue = async.queue((task, done) => {
|
const queue = async.queue((task, done) => {
|
||||||
//gutil.log(TAG, col.magenta(task.command));
|
//log(TAG, colors.magenta(task.command));
|
||||||
//process.chdir(task.dir);
|
//process.chdir(task.dir);
|
||||||
child_process.exec(task.command, {cwd: task.dir, maxBuffer: 1024 * 5000}, (err, stdout, stderr) => {
|
child_process.exec(task.command, {cwd: task.dir, maxBuffer: 1024 * 5000}, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const fse = require('fs-extra');
|
const fse = require('fs-extra');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const gunzip = require('gulp-gunzip');
|
|
||||||
const untar = require('gulp-untar');
|
|
||||||
const through = require('through2');
|
const through = require('through2');
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const gutil = require('gulp-util');
|
|
||||||
const Sdk = require('./sdk');
|
const Sdk = require('./sdk');
|
||||||
const exec = require('./exec');
|
const exec = require('./exec');
|
||||||
const col = gutil.colors;
|
const PluginError = require('plugin-error');
|
||||||
|
const colors = require('ansi-colors');
|
||||||
|
const log = require('fancy-log');
|
||||||
|
|
||||||
|
|
||||||
class FlashPlayer extends Sdk {
|
class FlashPlayer extends Sdk {
|
||||||
@@ -35,6 +34,7 @@ class FlashPlayer extends Sdk {
|
|||||||
const extract = (debug) => {
|
const extract = (debug) => {
|
||||||
const v = this.version.split('.');
|
const v = this.version.split('.');
|
||||||
const playerPath = this.playerPath(debug);
|
const playerPath = this.playerPath(debug);
|
||||||
|
// ToDo: fix
|
||||||
const archive = `${playerPath}/flashplayer${v[0]}_${v[1]}r${v[2]}_${v[3]}_linux_sa${debug ? '_debug' : ''}.${arch}.tar.gz`;
|
const archive = `${playerPath}/flashplayer${v[0]}_${v[1]}r${v[2]}_${v[3]}_linux_sa${debug ? '_debug' : ''}.${arch}.tar.gz`;
|
||||||
return gulp.src(archive)
|
return gulp.src(archive)
|
||||||
.pipe(gunzip()).pipe(untar())
|
.pipe(gunzip()).pipe(untar())
|
||||||
@@ -120,20 +120,20 @@ class FlashPlayer extends Sdk {
|
|||||||
run(debug) {
|
run(debug) {
|
||||||
let stream = null;
|
let stream = null;
|
||||||
const bufferContents = (file, enc, callback) => {
|
const bufferContents = (file, enc, callback) => {
|
||||||
gutil.log(this.tag, col.cyan("run"), col.magenta(file.path));
|
log(this.tag, colors.cyan("run"), colors.magenta(file.path));
|
||||||
FlashPlayer.trust(file.path);
|
FlashPlayer.trust(file.path);
|
||||||
FlashPlayer.enableLog();
|
FlashPlayer.enableLog();
|
||||||
exec('.', [this.flashPlayerBin(debug), file.path].join(' ')).then(() => {
|
exec('.', [this.flashPlayerBin(debug), file.path].join(' ')).then(() => {
|
||||||
stream.emit('end');
|
stream.emit('end');
|
||||||
callback();
|
callback();
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
stream.emit('error', new gutil.PluginError({plugin: this.tag, message: error}));
|
stream.emit('error', new PluginError({plugin: this.tag, message: error}));
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
//stream.push(file);
|
//stream.push(file);
|
||||||
// ToDo: watch when file is exists
|
// ToDo: watch when file is exists
|
||||||
// or create log file in FlashPlayer.enableLog()?
|
// or create log file in FlashPlayer.enableLog()?
|
||||||
/*stream.push(new gutil.File({
|
/*stream.push(new Vinyl({
|
||||||
path: FlashPlayer.log
|
path: FlashPlayer.log
|
||||||
}));*/
|
}));*/
|
||||||
stream.push(file);
|
stream.push(file);
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ const fs = require('fs');
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const tmp = require('tmp-file');
|
const tmp = require('tmp-file');
|
||||||
const gutil = require('gulp-util');
|
|
||||||
const exec = require('./exec');
|
const exec = require('./exec');
|
||||||
const download = require('./download');
|
|
||||||
const gulp = require('gulp');
|
|
||||||
const through = require('through2');
|
const through = require('through2');
|
||||||
const col = gutil.colors;
|
|
||||||
const Sdk = require('./sdk');
|
const Sdk = require('./sdk');
|
||||||
const dateformat = require('dateformat');
|
const dateformat = require('dateformat');
|
||||||
|
const Vinyl = require('vinyl');
|
||||||
|
const PluginError = require('plugin-error');
|
||||||
|
const colors = require('ansi-colors');
|
||||||
|
const log = require('fancy-log');
|
||||||
|
|
||||||
|
|
||||||
class Haxe extends Sdk {
|
class Haxe extends Sdk {
|
||||||
@@ -26,16 +26,8 @@ class Haxe extends Sdk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get binPath() {
|
get binPath() {
|
||||||
if (os.type() === 'Windows_NT') {
|
|
||||||
if (this.intVersion >= 342) {
|
|
||||||
return `${this.path}`;
|
|
||||||
} else {
|
|
||||||
return `${this.path}/haxe-${this.version}`;
|
return `${this.path}/haxe-${this.version}`;
|
||||||
}
|
}
|
||||||
} else if (os.type() === 'Linux') {
|
|
||||||
return `${this.path}/haxe-${this.version}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get haxeBin() {
|
get haxeBin() {
|
||||||
return this.getBin('haxe');
|
return this.getBin('haxe');
|
||||||
@@ -80,7 +72,7 @@ class Haxe extends Sdk {
|
|||||||
install(packages) {
|
install(packages) {
|
||||||
let promise = this.haxelib(['setup', `${this.path}/lib`]);
|
let promise = this.haxelib(['setup', `${this.path}/lib`]);
|
||||||
const next = (args) => () => {
|
const next = (args) => () => {
|
||||||
gutil.log(this.tag, col.cyan('haxelib', 'install'), col.magenta(args[1]));
|
log(this.tag, colors.cyan('haxelib', 'install'), colors.magenta(args[1]));
|
||||||
return this.haxelib(args);
|
return this.haxelib(args);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -146,7 +138,7 @@ class Haxe extends Sdk {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const endStream = (callback) => {
|
const endStream = (callback) => {
|
||||||
gutil.log(this.tag, col.cyan("openfl", params.command, params.platform), '=>', col.magenta(params.outputFile));
|
log(this.tag, colors.cyan("openfl", params.command, params.platform), '=>', colors.magenta(params.outputFile));
|
||||||
const args = ['-cwd', files[0].path, 'run', 'openfl', params.command, params.platform];
|
const args = ['-cwd', files[0].path, 'run', 'openfl', params.command, params.platform];
|
||||||
if (params.values) for (let key of Object.keys(params.values)) {
|
if (params.values) for (let key of Object.keys(params.values)) {
|
||||||
const value = params.values[key];
|
const value = params.values[key];
|
||||||
@@ -163,28 +155,29 @@ class Haxe extends Sdk {
|
|||||||
args.push(`--app-file=${name}`);
|
args.push(`--app-file=${name}`);
|
||||||
if (params.version) args.push(`--meta-version=${params.version}`);
|
if (params.version) args.push(`--meta-version=${params.version}`);
|
||||||
//if (params.build) args.push(`--haxedef=BUILD="${params.build}"`);
|
//if (params.build) args.push(`--haxedef=BUILD="${params.build}"`);
|
||||||
args.push(`--haxeflag="--macro=CompilationOption.set('build','${params.build}')"`);
|
args.push(`--haxeflag="--macro CompilationOption.set('build','${params.build}')"`);
|
||||||
let debug = null;
|
let debug = null;
|
||||||
if (params.debug) {
|
if (params.debug) {
|
||||||
debug = {
|
debug = {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 6000 + Math.floor(Math.random() * 1000),
|
port: 6000 + Math.floor(Math.random() * 1000),
|
||||||
};
|
};
|
||||||
args.push(`--haxeflag="--macro=CompilationOption.set('debug.address','${debug.host}')"`);
|
args.push(`--haxeflag="--macro CompilationOption.set('debug.address','${debug.host}')"`);
|
||||||
args.push(`--haxeflag="--macro=CompilationOption.set('debug.port','${debug.port}')"`);
|
args.push(`--haxeflag="--macro CompilationOption.set('debug.port','${debug.port}')"`);
|
||||||
args.push('-debug');
|
args.push('-debug');
|
||||||
}
|
}
|
||||||
//console.log('haxelib', args.join(' '));
|
//console.log('haxelib', args.join(' '));
|
||||||
this.haxelib(args).then(() => {
|
this.haxelib(args).then(() => {
|
||||||
const out = new gutil.File({
|
const out = new Vinyl({
|
||||||
path: params.outputFile,
|
path: params.outputFile,
|
||||||
contents: fs.createReadStream(`${dir}/flash/bin/${name}.swf`)
|
//contents: fs.createReadStream(`${dir}/flash/bin/${name}.swf`),
|
||||||
|
contents: fs.readFileSync(`${dir}/flash/bin/${name}.swf`),
|
||||||
});
|
});
|
||||||
out.debug = debug;
|
out.debug = debug;
|
||||||
stream.push(out);
|
stream.push(out);
|
||||||
callback();
|
callback();
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
|
stream.emit('error', new PluginError({plugin: this.name, message: error}));
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -225,7 +218,7 @@ class Haxe extends Sdk {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const endStream = (callback) => {
|
const endStream = (callback) => {
|
||||||
gutil.log(this.tag, col.cyan("haxe", params.platform), '=>', col.magenta(params.outputFile));
|
log(this.tag, colors.cyan("haxe", params.platform), '=>', colors.magenta(params.outputFile));
|
||||||
const args = [];
|
const args = [];
|
||||||
args.push('-main', params.main);
|
args.push('-main', params.main);
|
||||||
for (const lib of params.lib) {
|
for (const lib of params.lib) {
|
||||||
@@ -262,15 +255,16 @@ class Haxe extends Sdk {
|
|||||||
}
|
}
|
||||||
//console.log('haxe', args.join(' '));
|
//console.log('haxe', args.join(' '));
|
||||||
this.haxe(args).then(() => {
|
this.haxe(args).then(() => {
|
||||||
const out = new gutil.File({
|
const out = new Vinyl({
|
||||||
path: params.outputFile,
|
path: params.outputFile,
|
||||||
contents: fs.createReadStream(tmpFile.path)
|
//contents: fs.createReadStream(tmpFile.path),
|
||||||
|
contents: fs.readFileSync(tmpFile.path),
|
||||||
});
|
});
|
||||||
out.debug = debug;
|
out.debug = debug;
|
||||||
stream.push(out);
|
stream.push(out);
|
||||||
callback();
|
callback();
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
|
stream.emit('error', new PluginError({plugin: this.name, message: error}));
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const exec = require('./exec');
|
const exec = require('./exec');
|
||||||
const gutil = require('gulp-util');
|
|
||||||
const through = require('through2');
|
const through = require('through2');
|
||||||
const col = gutil.colors;
|
const PluginError = require('plugin-error');
|
||||||
|
const colors = require('ansi-colors');
|
||||||
|
const log = require('fancy-log');
|
||||||
|
|
||||||
class Neko {
|
class Neko {
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class Neko {
|
|||||||
run() {
|
run() {
|
||||||
let stream = null;
|
let stream = null;
|
||||||
const bufferContents = (file, enc, callback) => {
|
const bufferContents = (file, enc, callback) => {
|
||||||
gutil.log(this.tag, col.cyan("run"), col.magenta(file.path));
|
log(this.tag, colors.cyan("run"), colors.magenta(file.path));
|
||||||
|
|
||||||
exec('.', ['neko', file.path].join(' '))
|
exec('.', ['neko', file.path].join(' '))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -21,7 +21,7 @@ class Neko {
|
|||||||
callback();
|
callback();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
stream.emit('error', new gutil.PluginError({plugin: this.tag, message: error}));
|
stream.emit('error', new PluginError({plugin: this.tag, message: error}));
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
43
tasks/sdk.js
43
tasks/sdk.js
@@ -1,13 +1,12 @@
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const gulp = require('gulp');
|
const fs = require('fs');
|
||||||
const gutil = require('gulp-util');
|
const ps = require('promise-streams');
|
||||||
const col = gutil.colors;
|
const got = require('got');
|
||||||
const download = require('./download');
|
const unzip = require('unzip-stream');
|
||||||
const unzip = require('gulp-unzip');
|
|
||||||
const gunzip = require('gulp-gunzip');
|
|
||||||
const untar = require('gulp-untar');
|
|
||||||
const Promise = require('bluebird');
|
|
||||||
const ProgressBar = require('progress');
|
const ProgressBar = require('progress');
|
||||||
|
const colors = require('ansi-colors');
|
||||||
|
const log = require('fancy-log');
|
||||||
|
|
||||||
|
|
||||||
class Sdk {
|
class Sdk {
|
||||||
static set dir(value) {
|
static set dir(value) {
|
||||||
@@ -24,7 +23,7 @@ class Sdk {
|
|||||||
|
|
||||||
constructor(name, version) {
|
constructor(name, version) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.tag = col.green(`[${name}]`);
|
this.tag = colors.green(`[${name}]`);
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.path = Sdk.path(name, version);
|
this.path = Sdk.path(name, version);
|
||||||
}
|
}
|
||||||
@@ -49,27 +48,25 @@ class Sdk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
gutil.log(this.tag, `version: ${col.magenta(this.version)}`);
|
log(this.tag, `version: ${colors.magenta(this.version)}`);
|
||||||
return new Promise((success, fail) => {
|
|
||||||
if (this.prepared) {
|
if (this.prepared) {
|
||||||
success();
|
return Promise.resolve();
|
||||||
} else {
|
} else {
|
||||||
const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
|
const bar = new ProgressBar(`${this.tag} [:bar] :percent :etas`, {width: 40, total: 1000, clear: true});
|
||||||
let stream = download(this.link)
|
let stream = got.stream(this.link);
|
||||||
.on('error', fail)
|
stream = stream.on('downloadProgress', (p) => bar.update(p.percent));
|
||||||
.on('progress', (p) => bar.update(p.percent))
|
//stream = stream.pipe(fs.createWriteStream(this.path + '.zip'));
|
||||||
.on('end', () => bar.update(1));
|
|
||||||
if (this.link.endsWith('.zip')) {
|
if (this.link.endsWith('.zip')) {
|
||||||
stream = stream.pipe(unzip());
|
stream = stream.pipe(unzip.Extract({path: this.path}));
|
||||||
} else if (this.link.endsWith('tar.gz')) {
|
} else if (this.link.endsWith('tar.gz')) {
|
||||||
stream = stream.pipe(gunzip()).pipe(untar())
|
// ToDo: unpack tar.gz
|
||||||
|
//stream = stream.pipe(gunzip()).pipe(untar())
|
||||||
|
} else {
|
||||||
|
stream = stream.pipe(fs.createWriteStream(this.path));
|
||||||
}
|
}
|
||||||
return stream
|
return ps.wait(stream);
|
||||||
.pipe(gulp.dest(this.path))
|
|
||||||
.on('end', success)
|
|
||||||
.on('error', fail);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user