[build] remove deprecated gulp-utils
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
const fs = require('fs');
|
||||
const tmp = require('tmp-file');
|
||||
const gutil = require('gulp-util');
|
||||
const exec = require('./exec');
|
||||
const download = require('./download');
|
||||
const unzip = require('gulp-unzip');
|
||||
const gulp = require('gulp');
|
||||
const through = require('through2');
|
||||
const mark = require('gulp-mark');
|
||||
const replace = require('gulp-replace-task');
|
||||
const col = gutil.colors;
|
||||
//const mark = require('gulp-mark');
|
||||
//const replace = require('gulp-replace-task');
|
||||
const Sdk = require('./sdk');
|
||||
|
||||
|
||||
// ToDo: remove gutil
|
||||
class AdobeAir extends Sdk {
|
||||
|
||||
get adtBin() {
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
const gulp = require('gulp');
|
||||
const gutil = require('gulp-util');
|
||||
const col = gutil.colors;
|
||||
const net = require('net');
|
||||
const through = require('through2');
|
||||
const colors = require('ansi-colors');
|
||||
const log = require('fancy-log');
|
||||
|
||||
const color = (level) => {
|
||||
return {
|
||||
'[DEBUG]': col.white,
|
||||
'[INFO]': col.cyan,
|
||||
'[ERROR]': col.red,
|
||||
'[WARNING]': col.yellow,
|
||||
}[level] || col.reset;
|
||||
'[DEBUG]': colors.white,
|
||||
'[INFO]': colors.cyan,
|
||||
'[ERROR]': colors.red,
|
||||
'[WARNING]': colors.yellow,
|
||||
}[level] || colors.reset;
|
||||
};
|
||||
|
||||
const log = (line) => {
|
||||
const _log = (line) => {
|
||||
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 = () => {
|
||||
@@ -30,7 +29,7 @@ module.exports = () => {
|
||||
socket.on("data", (data) => {
|
||||
const lines = data.toString().split('\n');
|
||||
for (let line of lines) if (line.length > 2) {
|
||||
log(line);
|
||||
_log(line);
|
||||
}
|
||||
});
|
||||
socket.on("close", () => {
|
||||
@@ -40,7 +39,7 @@ module.exports = () => {
|
||||
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);
|
||||
})
|
||||
};
|
||||
|
||||
@@ -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 async = require('async');
|
||||
const col = gutil.colors;
|
||||
const Promise = require("bluebird");
|
||||
const colors = require('ansi-colors');
|
||||
const log = require('fancy-log');
|
||||
|
||||
|
||||
const TAG = col.green('[exec]');
|
||||
const TAG = colors.green('[exec]');
|
||||
|
||||
const queue = async.queue((task, done) => {
|
||||
//gutil.log(TAG, col.magenta(task.command));
|
||||
//log(TAG, colors.magenta(task.command));
|
||||
//process.chdir(task.dir);
|
||||
child_process.exec(task.command, {cwd: task.dir, maxBuffer: 1024 * 5000}, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
|
||||
@@ -2,14 +2,13 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const os = require('os');
|
||||
const gunzip = require('gulp-gunzip');
|
||||
const untar = require('gulp-untar');
|
||||
const through = require('through2');
|
||||
const gulp = require('gulp');
|
||||
const gutil = require('gulp-util');
|
||||
const Sdk = require('./sdk');
|
||||
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 {
|
||||
@@ -35,6 +34,7 @@ class FlashPlayer extends Sdk {
|
||||
const extract = (debug) => {
|
||||
const v = this.version.split('.');
|
||||
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`;
|
||||
return gulp.src(archive)
|
||||
.pipe(gunzip()).pipe(untar())
|
||||
@@ -120,20 +120,20 @@ class FlashPlayer extends Sdk {
|
||||
run(debug) {
|
||||
let stream = null;
|
||||
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.enableLog();
|
||||
exec('.', [this.flashPlayerBin(debug), file.path].join(' ')).then(() => {
|
||||
stream.emit('end');
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.tag, message: error}));
|
||||
stream.emit('error', new PluginError({plugin: this.tag, message: error}));
|
||||
callback();
|
||||
});
|
||||
//stream.push(file);
|
||||
// ToDo: watch when file is exists
|
||||
// or create log file in FlashPlayer.enableLog()?
|
||||
/*stream.push(new gutil.File({
|
||||
/*stream.push(new Vinyl({
|
||||
path: FlashPlayer.log
|
||||
}));*/
|
||||
stream.push(file);
|
||||
|
||||
@@ -2,14 +2,14 @@ const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const tmp = require('tmp-file');
|
||||
const gutil = require('gulp-util');
|
||||
const exec = require('./exec');
|
||||
const download = require('./download');
|
||||
const gulp = require('gulp');
|
||||
const through = require('through2');
|
||||
const col = gutil.colors;
|
||||
const Sdk = require('./sdk');
|
||||
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 {
|
||||
@@ -26,15 +26,7 @@ class Haxe extends Sdk {
|
||||
}
|
||||
|
||||
get binPath() {
|
||||
if (os.type() === 'Windows_NT') {
|
||||
if (this.intVersion >= 342) {
|
||||
return `${this.path}`;
|
||||
} else {
|
||||
return `${this.path}/haxe-${this.version}`;
|
||||
}
|
||||
} else if (os.type() === 'Linux') {
|
||||
return `${this.path}/haxe-${this.version}`;
|
||||
}
|
||||
return `${this.path}/haxe-${this.version}`;
|
||||
}
|
||||
|
||||
get haxeBin() {
|
||||
@@ -80,7 +72,7 @@ class Haxe extends Sdk {
|
||||
install(packages) {
|
||||
let promise = this.haxelib(['setup', `${this.path}/lib`]);
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -146,7 +138,7 @@ class Haxe extends Sdk {
|
||||
};
|
||||
|
||||
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];
|
||||
if (params.values) for (let key of Object.keys(params.values)) {
|
||||
const value = params.values[key];
|
||||
@@ -163,28 +155,29 @@ class Haxe extends Sdk {
|
||||
args.push(`--app-file=${name}`);
|
||||
if (params.version) args.push(`--meta-version=${params.version}`);
|
||||
//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;
|
||||
if (params.debug) {
|
||||
debug = {
|
||||
host: 'localhost',
|
||||
port: 6000 + Math.floor(Math.random() * 1000),
|
||||
};
|
||||
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.address','${debug.host}')"`);
|
||||
args.push(`--haxeflag="--macro CompilationOption.set('debug.port','${debug.port}')"`);
|
||||
args.push('-debug');
|
||||
}
|
||||
//console.log('haxelib', args.join(' '));
|
||||
this.haxelib(args).then(() => {
|
||||
const out = new gutil.File({
|
||||
const out = new Vinyl({
|
||||
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;
|
||||
stream.push(out);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
|
||||
stream.emit('error', new PluginError({plugin: this.name, message: error}));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
@@ -225,7 +218,7 @@ class Haxe extends Sdk {
|
||||
};
|
||||
|
||||
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 = [];
|
||||
args.push('-main', params.main);
|
||||
for (const lib of params.lib) {
|
||||
@@ -262,15 +255,16 @@ class Haxe extends Sdk {
|
||||
}
|
||||
//console.log('haxe', args.join(' '));
|
||||
this.haxe(args).then(() => {
|
||||
const out = new gutil.File({
|
||||
const out = new Vinyl({
|
||||
path: params.outputFile,
|
||||
contents: fs.createReadStream(tmpFile.path)
|
||||
//contents: fs.createReadStream(tmpFile.path),
|
||||
contents: fs.readFileSync(tmpFile.path),
|
||||
});
|
||||
out.debug = debug;
|
||||
stream.push(out);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
|
||||
stream.emit('error', new PluginError({plugin: this.name, message: error}));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const exec = require('./exec');
|
||||
const gutil = require('gulp-util');
|
||||
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 {
|
||||
|
||||
@@ -13,7 +13,7 @@ class Neko {
|
||||
run() {
|
||||
let stream = null;
|
||||
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(' '))
|
||||
.then(() => {
|
||||
@@ -21,7 +21,7 @@ class Neko {
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.tag, message: error}));
|
||||
stream.emit('error', new PluginError({plugin: this.tag, message: error}));
|
||||
callback();
|
||||
});
|
||||
|
||||
|
||||
53
tasks/sdk.js
53
tasks/sdk.js
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user