From 2f4f325a867740303d6056e7064b69516fbe6c7e Mon Sep 17 00:00:00 2001 From: PhilKunz Date: Wed, 20 Jan 2016 04:01:21 +0100 Subject: [PATCH] added callback support --- index.d.ts | 1 + index.js | 9 ++++++++- test.js | 5 ++++- ts/index.ts | 11 +++++++++-- ts/test.ts | 6 +++++- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index c5647eb..096c78a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -23,5 +23,6 @@ declare var remotezip: { get: (options: { from: string; toPath: string; + cb?: any; }) => void; }; diff --git a/index.js b/index.js index 520ca75..5d034a1 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ var remotezip = { return; } ; - plugins.gulp.task('default', function () { + plugins.gulp.task("remotezip", function () { plugins.beautylog.log('Now trying to download and extract...'); var stream = plugins.g.remoteSrc(["master.zip"], { base: "https://github.com/UmbrellaZone/legaldocs/archive/" @@ -35,6 +35,13 @@ var remotezip = { .pipe(plugins.gulp.dest(options.toPath)); return stream; }); + plugins.gulp.task("default", ["remotezip"], function () { + plugins.beautylog.success("Download complete and archive extracted"); + if (typeof options.cb == "function") { + options.cb(); + } + ; + }); plugins.gulp.start.apply(plugins.gulp, ['default']); } }; diff --git a/test.js b/test.js index 4971390..b72567b 100644 --- a/test.js +++ b/test.js @@ -3,5 +3,8 @@ var remotezip = require("./index.js"); var path = require("path"); remotezip.get({ from: "https://github.com/UmbrellaZone/legaldocs/archive/master.zip", - toPath: path.resolve("./test/") + toPath: path.resolve("./test/"), + cb: function () { + console.log("This is a callback"); + } }); diff --git a/ts/index.ts b/ts/index.ts index 56f0c35..97f27bc 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -4,7 +4,7 @@ var plugins = RemotezipPlugins.init(); var remotezip = { - get: function(options:{from:string,toPath:string}){ + get: function(options:{from:string,toPath:string, cb?}){ if (!plugins.path.isAbsolute(options.toPath)) { //check wether supplied path is absolute plugins.beautylog.error("Please supply remotezip with an absolute path"); @@ -12,7 +12,7 @@ var remotezip = { } ; - plugins.gulp.task('default', function () { + plugins.gulp.task("remotezip", function () { plugins.beautylog.log('Now trying to download and extract...'); var stream = plugins.g.remoteSrc(["master.zip"], { base: "https://github.com/UmbrellaZone/legaldocs/archive/" @@ -22,6 +22,13 @@ var remotezip = { return stream; }); + plugins.gulp.task("default",["remotezip"], function(){ + plugins.beautylog.success("Download complete and archive extracted"); + if(typeof options.cb == "function"){ + options.cb(); + }; + }); + plugins.gulp.start.apply(plugins.gulp, ['default']); } }; diff --git a/ts/test.ts b/ts/test.ts index cce40b9..33d2a80 100644 --- a/ts/test.ts +++ b/ts/test.ts @@ -1,7 +1,11 @@ /// var remotezip = require("./index.js"); var path = require("path"); + remotezip.get({ from:"https://github.com/UmbrellaZone/legaldocs/archive/master.zip", - toPath:path.resolve("./test/") + toPath:path.resolve("./test/"), + cb: function(){ + console.log("This is a callback") + } }); \ No newline at end of file