#1979 #2176 display error when module installation failed + better spinner

This commit is contained in:
Unitech 2016-05-23 10:12:57 +00:00
parent b2292038d6
commit 618862fb4e
2 changed files with 21 additions and 23 deletions

View File

@ -268,7 +268,18 @@ UX.dispKeys = function(kv, target_module) {
});
}
var defaultSpinnerString = '|/-\\';
var defaultSpinnerString = [
"⠋",
"⠙",
"⠹",
"⠸",
"⠼",
"⠴",
"⠦",
"⠧",
"⠇",
"⠏"
].join('');
var Spinner = function(textToShow){
this.text = textToShow || '';
@ -305,22 +316,10 @@ Spinner.prototype.stop = function() {
clearInterval(this.id);
};
UX.dotSpinner = {
start : function() {
this.interval = setInterval(function() {
console.log('asddsa');
process.stdout.write('.');
}, 100);
},
stop : function() {
clearInterval(this.interval);
}
};
UX.processing = {
current_spinner : null,
start : function() {
this.current_spinner = new Spinner('Connecting...');
start : function(text) {
this.current_spinner = new Spinner(text || 'Connecting...');
this.current_spinner.start();
},
stop : function() {

View File

@ -106,17 +106,16 @@ function installModule(module_name, cb) {
* Production mode
*/
Common.printOut(cst.PREFIX_MSG_MOD + 'Processing...');
var inter = setInterval(function() {
process.stdout.write('.');
}, 500);
UX.processing.start('Downloading module');
shelljs.exec('npm install ' + module_name + ' --prefix ' + cst.PM2_ROOT_PATH, {silent : true}, function(code) {
clearInterval(inter);
var command = 'npm install ' + module_name + ' --prefix ' + cst.PM2_ROOT_PATH;
shelljs.exec(command, {async : true}, function(code, out, err) {
UX.processing.stop();
if (code != 0) {
Common.printError(cst.PREFIX_MSG_MOD_ERR + 'Unknown module');
return cb({msg:'Unknown module'});
Common.printError(cst.PREFIX_MSG_MOD_ERR + 'Installation failed');
return cb(new Error(err));
}
Common.printOut(cst.PREFIX_MSG_MOD + 'Module downloaded');