feature(package) jaguar v3.0.0

This commit is contained in:
coderaiser 2016-11-08 16:33:11 +02:00
parent 9e11f02a45
commit ea8743fa99
3 changed files with 51 additions and 59 deletions

View file

@ -67,12 +67,12 @@
if (!config.auth) {
ok();
} else {
spawn.emit('auth', config.username, config.password);
spawn.on('accept', ok);
spawn.on('reject', function() {
Dialog.alert(TITLE, 'Wrong credentials!');
});
spawn.emit('auth', config.username, config.password);
}
});
}
@ -123,12 +123,12 @@
packer.on('connect', function() {
authCheck(packer, function() {
packFn = function(data, callback) {
setListeners(packer, callback);
setListeners(packer, {noContinue: true}, callback);
packer.pack(data.from, data.to, data.names);
};
extractFn = function(data, callback) {
setListeners(packer, callback);
setListeners(packer, {noContinue: true}, callback);
packer.extract(data.from, data.to);
};
});
@ -145,52 +145,49 @@
Util.exec(callback);
}
function setListeners(emitter, callback) {
var wasError,
done,
listeners = {
progress: function(value) {
done = value === 100;
Images.setProgress(value);
},
end: function() {
if (!wasError)
callback();
Images
.hide()
.clearProgress();
events.forEach(function(name) {
emitter.removeListener(name, listeners[name]);
});
},
error: function(error) {
var msg,
messageBox;
wasError = true;
if (done) {
msg = error;
messageBox = Dialog.alert;
} else {
msg = error + '\n Continue?';
messageBox = Dialog.confirm;
}
messageBox(TITLE, msg).then(function() {
emitter.continue();
}, function() {
emitter.abort();
});
}
},
function setListeners(emitter, options, callback) {
if (!callback) {
callback = options;
options = {};
}
events = Object.keys(listeners);
var done;
var listeners = {
progress: function(value) {
done = value === 100;
Images.setProgress(value);
},
end: function(error) {
Images
.hide()
.clearProgress();
events.forEach(function(name) {
emitter.removeListener(name, listeners[name]);
});
if (error || done)
callback(error);
},
error: function(error) {
if (options.noContinue) {
listeners.end(error);
Dialog.alert(TITLE, error)
}
else
Dialog.confirm(TITLE, error + '\n Continue?')
.then(function() {
emitter.continue();
}, function() {
emitter.abort();
});
}
};
var events = Object.keys(listeners);
events.forEach(function(name) {
emitter.on(name, listeners[name]);

View file

@ -262,7 +262,6 @@ function extract(from, to, fn) {
}
function operation(op, from, to, names, fn) {
var wasError;
var packer;
if (!fn) {
@ -275,7 +274,6 @@ function operation(op, from, to, names, fn) {
packer = jaguar[op](from, to, names);
packer.on('error', function(error) {
wasError = true;
fn(error);
});
@ -288,15 +286,12 @@ function operation(op, from, to, names, fn) {
});
packer.on('end', function() {
var name, msg;
process.stdout.write('\n');
if (!wasError) {
name = path.basename(from);
msg = formatMsg(op, name);
fn(null, msg);
}
var name = path.basename(from);
var msg = formatMsg(op, name);
fn(null, msg);
});
}

View file

@ -100,7 +100,7 @@
"format-io": "^0.9.6",
"http-auth": "^2.3.1",
"ishtar": "^1.5.0",
"jaguar": "^2.1.0",
"jaguar": "^3.0.0",
"join-io": "^1.4.0",
"jonny": "^1.0.0",
"markdown-it": "^8.0.0",