Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard committed Dec 1, 2012
2 parents e2d4c2e + db86f14 commit d117f96
Show file tree
Hide file tree
Showing 29 changed files with 264 additions and 60 deletions.
Empty file modified .gitignore 100644 → 100755
Empty file.
Empty file modified LICENSE-MIT 100644 → 100755
Empty file.
Empty file modified README.md 100644 → 100755
Empty file.
Empty file modified bin/modulus 100644 → 100755
Empty file.
Empty file modified lib/commands/env.js 100644 → 100755
Empty file.
Empty file modified lib/commands/help.js 100644 → 100755
Empty file.
Empty file modified lib/commands/misc.js 100644 → 100755
Empty file.
70 changes: 66 additions & 4 deletions lib/commands/project.js 100644 → 100755
Expand Up @@ -12,6 +12,72 @@ var modulus = require('../modulus'),

var project = {};

project.stop = function(cb) {
project.stopStartRestart('stop', cb);
};

project.start = function(cb) {
project.stopStartRestart('start', cb);
};

project.restart = function(cb) {
project.stopStartRestart('restart', cb);
};

project.stopStartRestart = function(action, cb) {
projectController.find({
userId : userConfig.data.userId
},
function(err, projects) {
if(err) {
err = error.handleApiError(err, 'GET_PROJECTS', cb);
if(err.length > 0) {
return cb(err);
}
}
if(projects.length === 0) {
modulus.io.error('You currently have no projects. Please create one on the website');
return cb();
}
project.chooseProjectPrompt(projects, function(err, result) {
if(err) {
err = error.handleApiError(err, 'RESTART_PROJECT', cb);
if(err.length > 0) {
return cb(err);
}
}
if(!result) {
return cb('You must select a project to restart.');
}

var func = null;
var message = null;

switch(action) {
case 'restart' :
func = projectController.restart;
message = result.name + ' restarted at ' + result.domain;
break;
case 'stop' :
func = projectController.stop;
message = result.name + ' stopped';
break;
case 'start' :
func = projectController.start;
message = result.name + ' started at ' + result.domain;
break;
}

func(result.id, function(err, result) {
if(!err) {
modulus.io.success(message);
}
cb(err);
});
});
});
};

project.list = function(cb) {
projectController.find({
userId : userConfig.data.userId
Expand Down Expand Up @@ -54,10 +120,6 @@ project.create = function(cb) {
var user = results[0],
projects = results[1];

if (user.status === 'BETA_LOCKED') {
return cb('You can not create projects at this time. You need to have a beta unlocked account.');
}

if (parseInt(user.projectLimit, 10) === projects.length) {
return cb('You can not create any more projects at this time. You have reached your project limit.');
}
Expand Down
28 changes: 0 additions & 28 deletions lib/commands/user.js 100644 → 100755
Expand Up @@ -110,34 +110,6 @@ user.logout = function(cb) {
return cb();
};

user.unlock = function(cb) {
modulus.io.prompt.get([{
name: 'betakey',
description: 'Enter a beta code:',
required: true
}], function(err, result) {
if(err) {
return error.handlePromptError(err, cb);
}
var userId = userConfig.data.userId;
userController.unlock(
userId,
result.betakey,
function(err, res) {
if(err) {
err = error.handleApiError(err, 'UNLOCK', cb);
if(err.length > 0) {
modulus.io.error(err);
return user.unlock(cb);
}
}

modulus.io.success('Your account has been unlocked. You may now create and deploy projects');
return cb();
});
});
};

user.resetPassword = function(cb) {
modulus.io.prompt.get([{
name: 'email',
Expand Down
2 changes: 1 addition & 1 deletion lib/common/api.js 100644 → 100755
@@ -1,4 +1,4 @@
var librarian = require('../librarian/librarian').init('api.onmodulus.net', 443, true),
var librarian = require('../librarian/librarian').init('staging.onmodulus.com', 8888, false),
UserConfig = require('./userConfig');

module.exports = {
Expand Down
Empty file modified lib/common/colors.js 100644 → 100755
Empty file.
Empty file modified lib/common/error.js 100644 → 100755
Empty file.
Empty file modified lib/common/help.js 100644 → 100755
Empty file.
Empty file modified lib/common/io.js 100644 → 100755
Empty file.
Empty file modified lib/common/userConfig.js 100644 → 100755
Empty file.
106 changes: 105 additions & 1 deletion lib/controllers/project.js 100644 → 100755
Expand Up @@ -4,27 +4,129 @@ var modulus = require('../modulus'),
fs = require('fs'),
ProgressBar = require('progress'),
Progress = require('../util/progress'),
Errors = require('../util/errors'),
request = require('request');

//-----------------------------------------------------------------------------
var Project = function() {

};

//-----------------------------------------------------------------------------
Project.prototype.create = function(name, creatorId, callback) {
librarian.project.create({
name: name,
creator: creatorId
}, false, userConfig.data.apiKey, callback);
};

//-----------------------------------------------------------------------------
Project.prototype.restart = function(projectId, callback) {
librarian.project.restart(projectId, userConfig.data.apiKey, function(err, result) {
if(err) {
return callback(Errors.getMessage(err));
}

var dbar = new Progress.indeterminate('Restarting [:bar]');
dbar.start();

var checkStatus = function() {
librarian.project.find({projectId : projectId}, userConfig.data.apiKey, function(err, proj) {

if(err) {
return callback(Errors.getMessage(err));
}

if(proj.status.toLowerCase() === Project.status.running) {
dbar.stop();
modulus.io.print(' ');
return callback(null, proj);
}
else {
setTimeout(checkStatus, 1000);
}
});
};

setTimeout(checkStatus, 1000);
});
};

//-----------------------------------------------------------------------------
Project.prototype.stop = function(projectId, callback) {
librarian.project.stop(projectId, userConfig.data.apiKey, function(err, result) {
if(err) {
return callback(Errors.getMessage(err));
}

var dbar = new Progress.indeterminate('Stopping [:bar]');
dbar.start();

var checkStatus = function() {
librarian.project.find({projectId : projectId}, userConfig.data.apiKey, function(err, proj) {

if(err) {
return callback(Errors.getMessage(err));
}

if(proj.status.toLowerCase() === Project.status.stopped) {
dbar.stop();
modulus.io.print(' ');
return callback(null, proj);
}
else {
setTimeout(checkStatus, 1000);
}
});
};

setTimeout(checkStatus, 1000);
});
};

//-----------------------------------------------------------------------------
Project.prototype.start = function(projectId, callback) {
librarian.project.start(projectId, userConfig.data.apiKey, function(err, result) {
if(err) {
return callback(Errors.getMessage(err));
}

var dbar = new Progress.indeterminate('Starting [:bar]');
dbar.start();

var checkStatus = function() {
librarian.project.find({projectId : projectId}, userConfig.data.apiKey, function(err, proj) {

if(err) {
return callback(Errors.getMessage(err));
}

if(proj.status.toLowerCase() === Project.status.running) {
dbar.stop();
modulus.io.print(' ');
return callback(null, proj);
}
else {
setTimeout(checkStatus, 1000);
}
});
};

setTimeout(checkStatus, 1000);
});
};

//-----------------------------------------------------------------------------
Project.prototype.find = function(opts, callback) {
librarian.project.find(opts, userConfig.data.apiKey, callback);
};

//-----------------------------------------------------------------------------
Project.prototype.saveVars = function(projectId, vars, callback) {
librarian.project.saveVars(projectId, vars, userConfig.data.apiKey, callback);
};

//-----------------------------------------------------------------------------
Project.prototype.deploy = function(projectId, file, callback) {
var host = librarian._http._host;
var port = librarian._http._port;
Expand Down Expand Up @@ -106,10 +208,12 @@ Project.prototype.deploy = function(projectId, file, callback) {
});
};

//-----------------------------------------------------------------------------
Project.status = {
uploading : 'uploading',
deploying : 'deploying',
running : 'running'
running : 'running',
stopped: 'stopped'
};

module.exports = new Project();
4 changes: 0 additions & 4 deletions lib/controllers/user.js 100644 → 100755
Expand Up @@ -23,10 +23,6 @@ User.prototype.authenticate = function(login, password, callback) {
librarian.user.authenticate(login, hashPass, callback);
};

User.prototype.unlock = function(userId, betaKey, callback) {
librarian.user.unlock(userId, betaKey, userConfig.data.apiKey, callback);
};

User.prototype.resetPassword = function(email, callback) {
librarian.user.resetPassword(email, callback);
};
Expand Down
Empty file modified lib/librarian/http.js 100644 → 100755
Empty file.
25 changes: 18 additions & 7 deletions lib/librarian/librarian.js 100644 → 100755
Expand Up @@ -173,13 +173,6 @@ librarian.user.activity = function(userId, authToken, callback) {
}
};

//-----------------------------------------------------------------------------
librarian.user.unlock = function(userId, betaKey, authToken, callback) {
if(checkInit(callback)) {
librarian._http.request(util.format('/user/%s/unlock?authToken=%s', userId, authToken), 'POST', { key: betaKey }, callback);
}
};

//-----------------------------------------------------------------------------
librarian.user.resetPassword = function(email, callback) {
if(checkInit(callback)) {
Expand Down Expand Up @@ -290,8 +283,26 @@ librarian.project.delete = function(projectId, authToken, callback) {
}
};

//-----------------------------------------------------------------------------
librarian.project.stop = function(projectId, authToken, callback) {
if(checkInit(callback)) {
librarian._http.request(util.format('/project/%s/stop?authToken=%s', projectId, authToken), 'GET', callback);
}
};

//-----------------------------------------------------------------------------
librarian.project.restart = function(projectId, authToken, callback) {
if(checkInit(callback)) {
librarian._http.request(util.format('/project/%s/restart?authToken=%s', projectId, authToken), 'GET', callback);
}
};

//-----------------------------------------------------------------------------
librarian.project.start = function(projectId, authToken, callback) {
if(checkInit(callback)) {
librarian._http.request(util.format('/project/%s/start?authToken=%s', projectId, authToken), 'GET', callback);
}
};

//-----------------------------------------------------------------------------
// CONTACT
Expand Down
Empty file modified lib/librarian/util.js 100644 → 100755
Empty file.
Empty file modified lib/routes/env.js 100644 → 100755
Empty file.
Empty file modified lib/routes/misc.js 100644 → 100755
Empty file.
42 changes: 42 additions & 0 deletions lib/routes/project.js 100644 → 100755
Expand Up @@ -37,6 +37,48 @@ module.exports = function(modulus) {
modulus.runCommand(modulus.commands.project.create, true);
});

// restart command
help.add('restart', function() {
this.line('project restart'.verbose);
this.line('Creates a new project.'.input);
});

modulus.program
.command('project restart')
.description('Restarts a running project.')
.on('--help', help.commands.create)
.action(function() {
modulus.runCommand(modulus.commands.project.restart, true);
});

// stop command
help.add('stop', function() {
this.line('project stop'.verbose);
this.line('Stops a running project'.input);
});

modulus.program
.command('project stop')
.description('Stops a running project.')
.on('--help', help.commands.create)
.action(function() {
modulus.runCommand(modulus.commands.project.stop, true);
});

// start command
help.add('start', function() {
this.line('project start'.verbose);
this.line('Starts a running project'.input);
});

modulus.program
.command('project start')
.description('Starts a stopped project.')
.on('--help', help.commands.create)
.action(function() {
modulus.runCommand(modulus.commands.project.start, true);
});

// deploy command
help.add('deploy', function() {
this.line('project deploy (deploy)'.verbose);
Expand Down
14 changes: 0 additions & 14 deletions lib/routes/user.js 100644 → 100755
Expand Up @@ -43,20 +43,6 @@ module.exports = function(modulus) {
modulus.runCommand(modulus.commands.user.logout, true);
});

// unlock command
help.add('unlock', function() {
this.line('unlock'.verbose);
this.line('Unlocks your account, allowing you to create projects.'.input);
});

modulus.program
.command('unlock')
.description('Unlock the current account.')
.on('--help', help.commands.unlock)
.action(function(){
modulus.runCommand(modulus.commands.user.unlock, true);
});

// resetPassword command
help.add('reset', function() {
this.line('resetPassword'.verbose);
Expand Down

0 comments on commit d117f96

Please sign in to comment.