Skip to content
Browse files

Merge branch 'flatiron'

  • Loading branch information...
2 parents 3e2d5f9 + 30a3f25 commit 43a404a9c97760f3c22cf736aa3ef5cc5ca1a906 @AvianFlu AvianFlu committed Feb 27, 2012
View
3 .gitignore
@@ -1,2 +1,3 @@
node_modules/
-npm-debug.log
+npm-debug.log
+test/fixtures/test-jitsuconf
View
2 .travis.yml
@@ -1,7 +1,7 @@
language: node_js
node_js:
- - 0.4
- 0.6
+ - 0.7
notifications:
email:
View
10 bin/jitsu
@@ -1,14 +1,10 @@
#!/usr/bin/env node
-var eyes = require('eyes'),
- colors = require('colors'),
- winston = require('winston').cli(),
- argv = require('optimist').argv,
- jitsu = require('../lib/jitsu');
+var jitsu = require('../lib/jitsu');
-jitsu.start(argv, function (err) {
+jitsu.start(function (err) {
if (!err) {
- winston.info('Nodejitsu'.grey + ' ok'.green.bold);
+ jitsu.log.info('Nodejitsu'.grey + ' ok'.green.bold);
}
process.stdout.on('drain', function () {
View
346 lib/jitsu.js
@@ -5,102 +5,112 @@
*
*/
-var jitsu = exports;
+var path = require('path'),
+ colors = require('colors'),
+ flatiron = require('flatiron');
-var path = require('path');
+var jitsu = module.exports = flatiron.app;
-// Failure HTTP Response codes based
-// off of `/lib/broodmother/slave/service.js`
-var failCodes = jitsu.failCodes = {
- 400: 'Bad Request',
- 401: 'Unauthorized',
- 403: 'Not Authorized',
- 404: 'Item not found',
- 409: 'Conflict',
- 500: 'Internal Server Error'
-};
+//
+// Setup `jitsu` to use `pkginfo` to expose version
+//
+require('pkginfo')(module, 'name', 'version');
-// Success HTTP Response codes based
-// off of `/lib/broodmother/slave/service.js`
-var successCodes = jitsu.successCodes = {
- 200: 'OK',
- 201: 'Created'
-};
+//
+// Configure jitsu to use `flatiron.plugins.cli`
+//
+jitsu.use(flatiron.plugins.cli, {
+ version: true,
+ usage: require('./jitsu/usage'),
+ source: path.join(__dirname, 'jitsu', 'commands'),
+ argv: {
+ version: {
+ alias: 'v',
+ description: 'print jitsu version and exit',
+ string: true
+ },
+ localconf: {
+ description: 'search for .jitsuconf file in ./ and then parent directories',
+ string: true
+ },
+ jitsuconf: {
+ alias: 'j',
+ description: 'specify file to load configuration from',
+ string: true
+ },
+ noanalyze: {
+ description: 'skip require-analyzer: do not attempt to dynamicially detect dependencies',
+ boolean: true
+ },
+ colors: {
+ description: '--no-colors will disable output coloring',
+ default: true,
+ boolean: true
+ }
+ }
+});
+
+//
+// Setup config, users, command aliases and prompt settings
+//
+jitsu.prompt.properties = flatiron.common.mixin(
+ jitsu.prompt.properties,
+ require('./jitsu/properties')
+);
+jitsu.prompt.override = jitsu.argv;
+require('./jitsu/config');
+require('./jitsu/alias');
+require('./jitsu/commands');
+
+//
+// Setup other jitsu settings.
+//
+jitsu.started = false;
+jitsu.common = require('./jitsu/common');
+jitsu.package = require('./jitsu/package');
+jitsu.logFile = new (require('./jitsu/common/logfile').LogFile)(path.join(process.env.HOME, '.jitsulog'));
-jitsu.skipAuth = false;
-jitsu.started = false;
-jitsu.utils = require('./jitsu/utils');
-jitsu.package = require('./jitsu/package');
-jitsu.log = require('cliff');
-jitsu.logFile = new (require('./jitsu/utils/logfile').LogFile)(path.join(process.env.HOME, '.jitsulog'));
+//
+// Hoist `jitsu.api` from `nodejitsu-api` module.
+//
jitsu.api = {};
jitsu.api.Client = require('nodejitsu-api').Client;
jitsu.api.Apps = require('nodejitsu-api').Apps;
jitsu.api.Databases = require('nodejitsu-api').Databases;
jitsu.api.Logs = require('nodejitsu-api').Logs;
jitsu.api.Snapshots = require('nodejitsu-api').Snapshots;
jitsu.api.Users = require('nodejitsu-api').Users;
-jitsu.prompt = require('prompt');
-jitsu.prompt.properties = require('./jitsu/properties').properties;
-jitsu.prompt.override = require('optimist').argv;
-jitsu.config = require('./jitsu/config');
-jitsu.commands = require('./jitsu/commands');
//
-// Alias the appropriate commands for simplier CLI usage
-//
-jitsu.commands.alias('create', { resource: 'apps', command: 'create' });
-jitsu.commands.alias('deploy', { resource: 'apps', command: 'deploy' });
-jitsu.commands.alias('list', { resource: 'apps', command: 'list' });
-jitsu.commands.alias('conf', { resource: 'config', command: 'list' });
-jitsu.commands.alias('login', { resource: 'users', command: 'login' });
-jitsu.commands.alias('logout', { resource: 'users', command: 'logout' });
-jitsu.commands.alias('signup', { resource: 'users', command: 'create' });
-jitsu.commands.alias('whoami', { resource: 'users', command: 'whoami' });
-
-var eyes = require('eyes'),
- winston = require('winston'),
- colors = require('colors');
-
-//
-// Setup `jitsu` to use `pkginfo` to expose version
+// ### function welcome ()
+// Print welcome message.
//
-require('pkginfo')(module, 'version');
+jitsu.welcome = function () {
+ jitsu.log.info('Welcome to ' + 'Nodejitsu'.grey);
+ jitsu.log.info('It worked if it ends with ' + 'Nodejitsu'.grey + ' ok'.green.bold);
+};
//
// ### function start (command, callback)
// #### @command {string} Command to execute once started
// #### @callback {function} Continuation to pass control to when complete.
// Starts the jitsu CLI and runs the specified command.
//
-jitsu.start = function (argv, callback) {
- var command = argv._;
-
- //
- // Special -v command for showing current version without winston formatting
- //
- if (argv.version || argv.v) {
- console.log('v' + jitsu.version);
- process.exit(0);
- }
-
+jitsu.start = function (callback) {
//
// Check for --no-colors/--colors option, without hitting the config file
// yet
//
- (typeof argv.colors == "undefined" || argv.colors) || (colors.mode = "none");
+ var useColors = (typeof jitsu.argv.colors == 'undefined' || jitsu.argv.colors);
- // Setup the initial prompt but don't leave it open
- jitsu.prompt.start().pause();
-
- //
- // Default to the `help` command.
- //
- command[0] || (command[0] = 'help');
+ useColors || (colors.mode = "none");
- jitsu.utils.checkVersion(function (err) {
- if (err) return callback();
- jitsu.config.load(function (err) {
+ jitsu.common.checkVersion(function (err) {
+ if (err) {
+ return callback();
+ }
+
+ jitsu.init(function (err) {
if (err) {
jitsu.welcome();
callback(err);
@@ -112,39 +122,34 @@ jitsu.start = function (argv, callback) {
// colors: false in ~/.jitsuconf (see
// https://github.com/nodejitsu/jitsu/issues/101 )
//
- jitsu.config.get('colors') || (colors.mode = "none");
+ if ( !jitsu.config.get('colors') || !useColors ) {
+ colors.mode = "none";
+ jitsu.log.get('default').stripColors = true;
+ jitsu.log.get('default').transports.console.colorize = false;
+ }
jitsu.welcome();
var username = jitsu.config.get('username');
- if (!username && jitsu.commands.requiresAuth(command[0])) {
- return jitsu.setupUser(function (err) {
+ if (!username && jitsu.config.get('requiresAuth').indexOf(jitsu.argv._[0]) !== -1) {
+ return jitsu.commands.users.login(function (err) {
if (err) {
callback(err);
return jitsu.showError.apply(jitsu, [command[0]].concat(arguments));
}
var username = jitsu.config.get('username');
- winston.info('Successfully configured user ' + username.magenta);
- return command.length > 0 ? jitsu.exec(command, callback) : callback();
+ jitsu.log.info('Successfully configured user ' + username.magenta);
+ return jitsu.exec(jitsu.argv._, callback);
});
}
- return jitsu.exec(command, callback)
+ return jitsu.exec(jitsu.argv._, callback);
});
});
};
//
-// ### function welcome ()
-// Print welcome message.
-//
-jitsu.welcome = function () {
- winston.info('Welcome to ' + 'Nodejitsu'.grey);
- winston.info('It worked if it ends with ' + 'Nodejitsu'.grey + ' ok'.green.bold);
-};
-
-//
// ### function exec (command, callback)
// #### @command {string} Command to execute
// #### @callback {function} Continuation to pass control to when complete.
@@ -160,12 +165,12 @@ jitsu.exec = function (command, callback) {
// Remark: This is a temporary fix for aliasing init=>install,
// was having a few issues with the alias command on the install resource
//
- if (command[0] === 'init'){
+ if (command[0] === 'init') {
command[0] = 'install';
}
// Alias db to databases
- if (command[0] === 'db'){
+ if (command[0] === 'db') {
command[0] = 'databases';
}
@@ -174,8 +179,8 @@ jitsu.exec = function (command, callback) {
command[1] = 'app';
}
- winston.info('Executing command ' + command.join(' ').magenta);
- jitsu.commands.run(command, function (err, shallow) {
+ jitsu.log.info('Executing command ' + command.join(' ').magenta);
+ jitsu.router.dispatch('on', command.join(' '), jitsu.log, function (err, shallow) {
if (err) {
callback(err);
return jitsu.showError(command.join(' '), err, shallow);
@@ -213,102 +218,6 @@ jitsu.setup = function (callback) {
};
//
-// ### function auth (callback)
-// #### @callback {function} Continuation to pass control to when complete.
-// Attempts to authenicate the user identified in `jitsu.config.get('username'|'password')`
-//
-jitsu.auth = function (callback) {
- if (jitsu.skipAuth) {
- return callback();
- }
-
- var username = jitsu.config.get('username');
- winston.silly('Attempting to authenticate as ' + username.magenta);
- jitsu.users.auth(function (err, success) {
- if (err || !success) {
- winston.error('Unable to Authenticate as ' + username.magenta);
- winston.error(err.message);
- return callback(err);
- }
-
- jitsu.skipAuth = true;
- winston.info('Authenticated as ' + username.magenta);
- return callback();
- })
-}
-
-//
-// ### function setupUser (callback)
-// #### @callback {function} Continuation to pass control to when complete.
-// Prompts the user for their username / password combo, then sets up the jitsu CLI,
-// and saves the resulting configuration to disk.
-//
-jitsu.setupUser = function (callback) {
- winston.warn('You will need to login to continue');
- winston.info('To login, you will need an activated nodejitsu account');
- winston.help('You can create an account using the ' + 'jitsu signup'.magenta + ' command');
- jitsu.setupUserNoWarn(callback);
-};
-
-//
-// ### function setupUserNoWarn (callback)
-// #### @callback {function} Continuation to pass control to when complete.
-// Prompts the user for their username / password combo, then sets up the jitsu CLI,
-// and saves the resulting configuration to disk without a warning
-//
-jitsu.setupUserNoWarn = function(callback) {
- //
- // Attempt to get the password three times.
- //
- var tries = 0;
-
- function offerReset (username) {
- jitsu.prompt.get(['reset'], function (err, res) {
- if (err) {
- return callback(err);
- }
- if (/^y[es]+/i.test(res['request password reset'])) {
- return jitsu.commands.run(['users', 'forgot', username], callback);
- }
-
- callback(new Error('Invalid username / password.'));
- });
- }
-
- (function setupAuth () {
- jitsu.prompt.get(['username', 'password'], function (err, result) {
- if (err) {
- return callback(err);
- }
-
- jitsu.config.set('username', result.username);
- jitsu.config.set('password', result.password);
- jitsu.setup(function () {
- jitsu.auth(function (err) {
- //
- // Increment the auth attempts
- //
- tries += 1;
-
- if (err) {
- if (tries >= 3) {
- winston.error('Three failed login attempts');
- winston.info('Would you like to reset your password?');
- return offerReset(result.username);
- }
- return setupAuth();
- }
-
- jitsu.config.save(function (err) {
- return err ? callback(err) : callback();
- });
- });
- });
- });
- })();
-};
-
-//
// ### function showError (command, err, shallow, skip)
// #### @command {string} Command which has errored.
// #### @err {Error} Error received for the command.
@@ -317,79 +226,92 @@ jitsu.setupUserNoWarn = function(callback) {
// Displays the `err` to the user for the `command` supplied.
//
jitsu.showError = function (command, err, shallow, skip) {
- var stack;
+ var username,
+ stack;
- if (err.statusCode !== '403' && !skip) {
- winston.error('Error running command ' + command.magenta);
+ if (err.statusCode === '403') {
+ username = jitsu.config.get('username');
+ if (username) {
+ jitsu.log.error('Unable to authenticate as: ' + username.magenta);
+ }
+
+ jitsu.log.error('403 ' + err.result.error);
+ }
+ else if (!skip) {
+ jitsu.log.error('Error running command ' + command.magenta);
if (!jitsu.config.get('nolog')) {
jitsu.logFile.log(err);
}
if (err.message) {
- winston.error(err.message);
+ jitsu.log.error(err.message);
}
if (err.result) {
if (err.result.error) {
- winston.error(err.result.error);
+ jitsu.log.error(err.result.error);
}
if (err.result.result && err.result.result.error) {
if (err.result.result.error.stderr || err.result.result.error.stdout) {
- winston.error('');
- winston.error('There was an error while attempting to start your application.');
- winston.error(err.result.result.error.message);
+ jitsu.log.error('');
+ jitsu.log.error('There was an error while attempting to start your application.');
+ jitsu.log.error(err.result.result.error.message);
if (err.result.result.error.blame) {
- winston.error(err.result.result.error.blame.message);
- winston.error('');
- winston.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
+ jitsu.log.error(err.result.result.error.blame.message);
+ jitsu.log.error('');
+ jitsu.log.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
}
- winston.error('Error output from your application:');
- winston.error('');
+
+ jitsu.log.error('Error output from your application:');
+ jitsu.log.error('');
if (err.result.result.error.stdout) {
err.result.result.error.stdout.split('\n').forEach(function (line) {
- winston.error(line);
+ jitsu.log.error(line);
});
}
+
if (err.result.result.error.stderr) {
err.result.result.error.stderr.split('\n').forEach(function (line) {
- winston.error(line);
+ jitsu.log.error(line);
});
}
}
else if (err.result.result.error.stack && jitsu.config.get('debug')) {
- winston.error('There was an error while attempting to deploy your application.');
- winston.error('');
- winston.error(err.result.result.error.message);
+ jitsu.log.error('There was an error while attempting to deploy your application.');
+ jitsu.log.error('');
+ jitsu.log.error(err.result.result.error.message);
+
if (err.result.result.error.blame) {
- winston.error(err.result.result.error.blame.message);
- winston.error('');
- winston.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
+ jitsu.log.error(err.result.result.error.blame.message);
+ jitsu.log.error('');
+ jitsu.log.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
}
- winston.error('Error output from Haibu:');
- winston.error('');
+
+ jitsu.log.error('Error output from Haibu:');
+ jitsu.log.error('');
stack = err.result.result.error.result || err.result.result.error.stack;
stack.split('\n').forEach(function (line) {
- winston.error(line);
+ jitsu.log.error(line);
});
}
}
else if (err.result.stack) {
- winston.warn('Error returned from Nodejitsu');
+ jitsu.log.warn('Error returned from Nodejitsu');
err.result.stack.split('\n').forEach(function (line) {
- winston.error(line);
+ jitsu.log.error(line);
});
}
}
else {
if (err.stack && !shallow) {
err.stack.split('\n').forEach(function (trace) {
- winston.error(trace);
+ jitsu.log.error(trace);
});
}
}
}
- winston.info('Nodejitsu '.grey + 'not ok'.red.bold);
+ jitsu.log.info('Nodejitsu '.grey + 'not ok'.red.bold);
};
View
15 lib/jitsu/alias.js
@@ -0,0 +1,15 @@
+/*
+ * alias.js: Aliases commands for jitsu.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var jitsu = require('../jitsu');
+
+//
+// Alias the appropriate commands for simplier CLI usage
+//
+jitsu.alias('create', { resource: 'apps', command: 'create' });
+jitsu.alias('deploy', { resource: 'apps', command: 'deploy' });
+jitsu.alias('list', { resource: 'apps', command: 'list' });
View
169 lib/jitsu/commands.js
@@ -1,149 +1,26 @@
-
-
-var fs = require('fs'),
- path = require('path'),
- winston = require('winston'),
- jitsu = require('../jitsu');
-
-var commands = exports;
-
-//
-// Setup the commands organized by resource to be lazy loaded
-// when needed. This speeds up load time.
-//
-commands.commands = {};
-fs.readdirSync(path.join(__dirname, 'commands')).forEach(function (cmd) {
- cmd = cmd.replace('.js', '');
- commands.commands.__defineGetter__(cmd, function () {
- return require('./commands/' + cmd);
- });
-});
-
-var requireAuth = ['apps', 'databases', 'env', 'logs', 'snapshots'];
-
-commands.requiresAuth = function (resource) {
- return requireAuth.indexOf(resource) !== -1;
-};
-
-//
-// ### function run (command, callback)
-// #### @command {Array} Command to run
-// #### @callback {function} Continuation to pass control to when complete.
-// Runs the specified command.
-//
-commands.run = function (command, callback) {
- var parts = command.slice(0),
- name = parts.shift(),
- action = parts.shift(),
- command, expected, resource;
-
- //
- // If we have been asked for `help` or `usage`
- // about a particular resource, print the help
- // for that resource.
- //
- if (action === 'help') {
- commands.commands.help.show(name);
- return callback();
- }
- else if (name === 'help' && (!action || action === 'show')) {
- commands.commands.help.show('help');
- return callback();
- }
-
- if (!commands.commands[name]) {
- return callback(new Error('Cannot run command on unknown resource: ' + name), true);
- }
-
- if (typeof commands.commands[name] !== 'function') {
- if (!action) {
- winston.error('Action is required to run a command on resource: ' + name.magenta);
- commands.commands.help.show(name);
- return callback(true);
- }
-
- resource = commands.commands[name];
- if (!resource[action]) {
- winston.error('Unknown action ' + action + ' on resource ' + name.magenta);
- commands.commands.help.show(name);
- return callback(true);
- }
-
- command = resource[action];
- }
- else {
- if (action) {
- parts.unshift(action);
+/*
+ * commands.js: Configuration for commands provided by flatiron plugins.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var jitsu = require('../jitsu');
+
+jitsu.use(require('flatiron-cli-users'), {
+ before: {
+ login: function (details) {
+ if (!details || !details.username) {
+ jitsu.log.warn('You will need to login to continue');
+ jitsu.log.info('To login, you will need an activated nodejitsu account');
+ jitsu.log.help('You can create an account using the ' + 'jitsu signup'.magenta + ' command');
+ }
}
-
- command = commands.commands[name];
- }
-
- //
- // When the command completes, check for an error, and if
- // we are surpressing the err callstack (i.e. it is an **expected** error)
- // then print the usage of the specified command.
- //
- parts.push(function (err, shallow, skip) {
- if (err && shallow && !skip) {
- winston.help('');
- winston.help('Usage:'.cyan.bold.underline);
- command.usage.forEach(function (line) {
- winston.help(line);
- });
- winston.help('');
+ },
+ after: {
+ create: function (details) {
+ jitsu.log.help('Your account has been created, but it is not yet active');
+ jitsu.log.help('Please check the email we sent to ' + details.email.grey + ' for further instructions');
}
-
- callback(err, shallow);
- });
-
- //
- // Check the arguments length then execute the command.
- //
- expected = command.length;
- if (parts.length > expected) {
- return callback(new Error('Wrong number of arguments: ' + parts.length + ' for ' + expected), true);
- }
-
- function runCommand() {
- if(command.destructive) {
- jitsu.prompt.get(['destroy'], function (err, result) {
- if (result.destroy !== 'yes' && result.destroy !== 'y') {
- return callback(new Error(action + ' operation cancelled'));
- } else {
- command.apply(resource, parts);
- }
- });
- } else {
- command.apply(resource, parts);
- }
- }
-
- //
- // If this resource can only be accessed
- // after authenticating with Nodejitsu, do so
- // then run the specified command on the resource
- //
- if (requireAuth.indexOf(name) !== -1) {
- return jitsu.auth(function (err) {
- if (err) {
- return callback(err);
- }
-
- runCommand();
- });
- }
-
- runCommand();
-};
-
-commands.alias = function (target, source) {
- commands.commands.__defineGetter__(target, function () {
- var resource = commands.commands[source.resource];
- return resource[source.command]
- });
-
- if (requireAuth.indexOf(source.resource) !== -1) {
- requireAuth.push(target);
}
-};
+});
View
114 lib/jitsu/commands/apps.js
@@ -5,9 +5,7 @@
*
*/
-var eyes = require('eyes'),
- winston = require('winston'),
- analyzer = require('require-analyzer'),
+var analyzer = require('require-analyzer'),
jitsu = require('../../jitsu');
var apps = exports;
@@ -46,8 +44,8 @@ apps.deploy = function (callback) {
function startApp (err, existing) {
if (err) {
- winston.error('Error creating snapshot for app ' + pkg.name.magenta);
- winston.error(err.message);
+ jitsu.log.error('Error creating snapshot for app ' + pkg.name.magenta);
+ jitsu.log.error(err.message);
return callback(new Error(), true);
}
@@ -66,15 +64,15 @@ apps.deploy = function (callback) {
}
function activateSnapshot (existing, snapshot) {
- winston.info('Activating snapshot ' + snapshot.grey + ' for ' + existing.name.magenta);
+ jitsu.log.info('Activating snapshot ' + snapshot.grey + ' for ' + existing.name.magenta);
jitsu.snapshots.activate(existing.name, snapshot, function (err) {
- winston.silly('Done activating snapshot ' + snapshot.grey);
+ jitsu.log.silly('Done activating snapshot ' + snapshot.grey);
startApp(err, existing);
});
}
function updateApp (existing, snapshot) {
- winston.info('Updating application ' + existing.name.magenta);
+ jitsu.log.info('Updating application ' + existing.name.magenta);
jitsu.apps.update(existing.name, pkg, function (err) {
if (err) {
return callback(err);
@@ -100,15 +98,15 @@ apps.deploy = function (callback) {
function checkApp (err, local) {
if (err) {
- winston.error(err);
+ jitsu.log.error(err);
return callback(new Error(), true);
}
pkg = local;
- winston.silly('Checking if application ' + local.name.magenta + ' exists.');
+ jitsu.log.silly('Checking if application ' + local.name.magenta + ' exists.');
jitsu.apps.view(local.name, function (err, app) {
if (err) {
- winston.warn('No application exists for ' + local.name.magenta);
+ jitsu.log.warn('No application exists for ' + local.name.magenta);
//
// If there is a before filter we should run before creating the app do so,
// then create the application.
@@ -118,7 +116,7 @@ apps.deploy = function (callback) {
});
}
- app = !app ? {} : jitsu.utils.formatApp(app, ['snapshots', 'active', 'user', 'state']);
+ app = !app ? {} : jitsu.common.formatApp(app, ['snapshots', 'active', 'user', 'state']);
var pkg = analyzer.merge({}, local, app);
jitsu.package.validate(pkg, dir, updateSnapshot);
});
@@ -151,18 +149,12 @@ apps.deploy.usage = [
// using `name` if supplied and falling back to `package.name`.
//
apps.create = function (target, callback) {
-
- var name;
- var dir = process.cwd();
-
- if (!callback) {
- callback = target;
- target = null;
- }
+ var dir = process.cwd(),
+ name;
function executeCreate (err, pkg) {
if (err) {
- winston.error(err);
+ jitsu.log.error(err);
return callback(new Error(), true);
}
@@ -189,18 +181,18 @@ apps.create = function (target, callback) {
if (err) {
return callback(err);
}
- winston.info('Creating app ' + pkg.name.magenta);
+ jitsu.log.info('Creating app ' + pkg.name.magenta);
jitsu.apps.create(pkg, function (err, res, result) {
- winston.silly('Done creating app ' + pkg.name.magenta);
+ jitsu.log.silly('Done creating app ' + pkg.name.magenta);
return err ? callback(err) : callback(null, pkg);
});
}
- winston.info('Checking app availability ' + pkg.name.magenta);
+ jitsu.log.info('Checking app availability ' + pkg.name.magenta);
jitsu.package.available(pkg, dir, createApp, function createPackage (err, result) {
if (err) {
- winston.error('Error creating ' + pkg.name.magenta);
- winston.error(result.message);
+ jitsu.log.error('Error creating ' + pkg.name.magenta);
+ jitsu.log.error(result.message);
return callback(new Error());
}
@@ -237,22 +229,18 @@ apps.create.usage = [
// Lists the applications for the authenticated user.
//
apps.list = function (username, callback) {
- winston.info('Listing apps');
-
- if (!callback) {
- callback = username;
- username = jitsu.config.get('username');
- }
-
+ jitsu.log.info('Listing apps');
+ username = username || jitsu.config.get('username');
+
jitsu.apps.list(username, function (err, apps) {
if (err) {
console.log(err);
return callback(err);
}
if (!apps || apps.length === 0) {
- winston.warn('No applications exist.');
- winston.help('Try creating one with ' + 'jitsu apps create'.magenta);
+ jitsu.log.warn('No applications exist.');
+ jitsu.log.help('Try creating one with ' + 'jitsu apps create'.magenta);
return callback();
}
@@ -269,7 +257,7 @@ apps.list = function (username, callback) {
]);
});
- jitsu.log.putRows('data', rows, colors);
+ jitsu.inspect.putRows('data', rows, colors);
callback();
});
};
@@ -299,14 +287,13 @@ apps.view = function (name, callback) {
return callback(err);
}
- app = jitsu.utils.formatApp(app);
- jitsu.log.putObject(app);
+ app = jitsu.common.formatApp(app);
+ jitsu.inspect.putObject(app);
callback(null, app);
});
}
- if (!callback) {
- callback = name;
+ if (!name) {
return jitsu.package.tryRead(process.cwd(), callback, function (pkg) {
name = pkg.name;
executeView();
@@ -335,12 +322,7 @@ apps.view.usage = [
// Lists the applications for the authenticated user.
//
apps.update = function (name, callback) {
- if(typeof name === 'function') {
- callback = name;
- name = "";
- }
-
- winston.silly('Reading package.json in ' + process.cwd());
+ jitsu.log.silly('Reading package.json in ' + process.cwd());
jitsu.package.tryRead(process.cwd(), callback, function (pkg) {
name = name || pkg.name;
@@ -349,14 +331,14 @@ apps.update = function (name, callback) {
return callback(err);
}
- var diff = jitsu.utils.objectDiff(app, pkg);
+ var diff = jitsu.common.objectDiff(app, pkg);
if (!diff) {
- winston.warn('No changes found to your package.json for ' + name.magenta);
+ jitsu.log.warn('No changes found to your package.json for ' + name.magenta);
return callback();
}
- winston.info('Updating application ' + name.magenta + ' with:');
- jitsu.log.putObject(diff);
+ jitsu.log.info('Updating application ' + name.magenta + ' with:');
+ jitsu.inspect.putObject(diff);
jitsu.apps.update(name, diff, callback);
});
@@ -385,15 +367,14 @@ apps.update.usage = [
apps.destroy = function (name, callback) {
function executeDestroy() {
- winston.info('Destroying app ' + name.magenta);
+ jitsu.log.info('Destroying app ' + name.magenta);
jitsu.apps.destroy(name, function (err) {
- winston.silly('Done destroying app ' + name.magenta);
+ jitsu.log.silly('Done destroying app ' + name.magenta);
return err ? callback(err) : callback();
});
}
- if (!callback) {
- callback = name;
+ if (!name) {
return jitsu.package.tryRead(process.cwd(), callback, function (pkg) {
name = pkg.name;
executeDestroy();
@@ -406,14 +387,14 @@ apps.destroy = function (name, callback) {
//
// Usage for `jitsu apps destroy [<name>]`
//
+apps.destroy.destructive = true
apps.destroy.usage = [
'Destroys the application in the current directory. If',
'<name> is supplied then that application is destroyed instead',
'',
'jitsu apps destroy',
'jitsu apps destroy <name>'
];
-apps.destroy.destructive = true
//
// ### function start (callback)
@@ -425,7 +406,7 @@ apps.destroy.destructive = true
apps.start = function (name, callback) {
function executeStart() {
- winston.info('Starting app ' + name.magenta);
+ jitsu.log.info('Starting app ' + name.magenta);
jitsu.apps.start(name, function (err) {
if (err) {
return callback(err, true);
@@ -436,15 +417,14 @@ apps.start = function (name, callback) {
return callback(err);
}
- winston.info('App ' + name.magenta + ' is now started')
- winston.info(('http://' + app.subdomain + '.nodejitsu.com').magenta + ' on Port ' + '80'.magenta);
+ jitsu.log.info('App ' + name.magenta + ' is now started')
+ jitsu.log.info(('http://' + app.subdomain + '.nodejitsu.com').magenta + ' on Port ' + '80'.magenta);
callback();
});
});
}
- if (!callback) {
- callback = name;
+ if (!name) {
return jitsu.package.tryRead(process.cwd(), callback, function (pkg) {
name = pkg.name;
executeStart();
@@ -475,19 +455,18 @@ apps.start.usage = [
apps.restart = function (name, callback) {
function executeRestart() {
- winston.info('Restarting app ' + name.magenta);
+ jitsu.log.info('Restarting app ' + name.magenta);
jitsu.apps.restart(name, function (err) {
if (err) {
return callback(err);
}
- winston.info('App ' + name.magenta + ' has been restarted');
+ jitsu.log.info('App ' + name.magenta + ' has been restarted');
callback();
});
}
- if (!callback) {
- callback = name;
+ if (!name) {
return jitsu.package.tryRead(process.cwd(), callback, function (pkg) {
name = pkg.name;
executeRestart();
@@ -518,19 +497,18 @@ apps.restart.usage = [
apps.stop = function (name, callback) {
function executeStop() {
- winston.info('Stopping app ' + name.magenta);
+ jitsu.log.info('Stopping app ' + name.magenta);
jitsu.apps.stop(name, function (err) {
if (err) {
return callback(err);
}
- winston.info('App ' + name.magenta + ' is now stopped');
+ jitsu.log.info('App ' + name.magenta + ' is now stopped');
callback();
});
}
- if (!callback) {
- callback = name;
+ if (!name) {
return jitsu.package.tryRead(process.cwd(), callback, function (pkg) {
name = pkg.name;
executeStop();
View
173 lib/jitsu/commands/config.js
@@ -1,173 +0,0 @@
-/*
- * config.js: Command related to jitsu configuration
- *
- * (C) 2010, Nodejitsu Inc.
- *
- */
-
-var winston = require('winston'),
- jitsu = require('../../jitsu');
-
-var config = exports,
- noDelete = ['root', 'remoteUri', 'userconfig', 'auth', 'tmproot', 'tar', 'gzipbin'];
-
-config.usage = [
- '`jitsu config *` commands allow you to edit your',
- 'local jitsu configuration file. Valid commands are:',
- '',
- 'jitsu config list',
- 'jitsu config set <key> <value>',
- 'jitsu config get <key>',
- 'jitsu config delete <key>'
-];
-
-//
-// ### function set (key, value, callback)
-// #### @key {string} Key to set in jitsu config.
-// #### @value {string} Value to set the key to.
-// #### @callback {function} Continuation to pass control to when complete
-// Sets the specified `key` in jitsu config to `value`.
-//
-config.set = function (key, value, callback) {
- var args = Array.prototype.slice.call(arguments);
- callback = args.pop();
-
- if (args.length !== 2) {
- winston.error('You must pass both <key> and <value>');
- return callback(true, true);
- }
-
- jitsu.config.setFromString(key, value)
- jitsu.config.save(callback);
-};
-
-//
-// Usage for `jitsu config set <key> <value>`
-//
-config.set.usage = [
- 'Sets the specified <key> <value> pair in the jitsu configuration',
- '',
- 'jitsu config set <key> <value>'
-];
-
-//
-// ### function get (key, callback)
-// #### @key {string} Key to get in jitsu config.
-// #### @callback {function} Continuation to pass control to when complete
-// Gets the specified `key` in jitsu config.
-//
-config.get = function (key, callback) {
- if (!callback) {
- callback = key;
- winston.error('No configuration for ' + 'undefined'.yellow);
- return callback(new Error(), true, true);
- }
-
- var value = jitsu.config.get(key);
- if (!value) {
- winston.error('No configuration value for ' + key.yellow);
- return callback(new Error(), true, true);
- }
- else if (typeof value === 'object') {
- winston.data(key.yellow);
- jitsu.log.putObject(value);
- return callback();
- }
-
- winston.data([key.yellow, value.magenta].join(' '));
- callback();
-};
-
-//
-// Usage for `jitsu config get <key>`
-//
-config.get.usage = [
- 'Gets the value for the specified <key>',
- 'in the jitsu configuration',
- '',
- 'jitsu config get <key>'
-];
-
-//
-// ### function delete (key, callback)
-// #### @key {string} Key to delete, in jitsu config.
-// #### @callback {function} Continuation to pass control to when complete
-// Deletes the specified `key` in jitsu config.
-//
-config.delete = function (key, callback) {
- if (!callback) {
- callback = key;
- winston.warn('No configuration for ' + 'undefined'.magenta);
- return callback();
- }
-
- var value = jitsu.config.get(key);
- if (!value) {
- winston.warn('No configuration value for ' + key.yellow);
- return callback();
- }
- else if (noDelete.indexOf(key) !== -1) {
- winston.warn('Cannot delete reserved setting ' + key.yellow);
- winston.help('Use jitsu config set <key> <value>');
- return callback();
- }
-
- jitsu.config.clear(key);
- jitsu.config.save(callback);
-};
-
-//
-// Usage for `jitsu config delete <key>`
-//
-config.delete.usage = [
- 'Deletes the specified <key> in the jitsu configuration',
- '',
- 'jitsu config delete <key>'
-];
-
-//
-// ### function list (callback)
-// #### @callback {function} Continuation to pass control to when complete
-// Lists all the key-value pairs in jitsu config.
-//
-config.list = function (callback) {
- var username = jitsu.config.get('username'),
- configFile = jitsu.config.store.file;
-
- var display = [
- ' here is your ' + configFile.grey + ' file:',
- 'If you\'d like to change a property try:',
- 'jitsu config set <key> <value>',
- ];
-
- if (!username) {
- winston.warn('No user has been setup on this machine');
- display[0] = 'Hello' + display[0];
- }
- else {
- display[0] = 'Hello ' + username.green + display[0];
- }
-
- display.forEach(function (line) {
- winston.help(line);
- });
-
- jitsu.log.putObject(jitsu.config.store.store, {
- password: function (line) {
- var password = line.match(/password.*\:\s(.*)$/)[1];
- return line.replace(password, "'********'");
- }
- }, 2);
-
- callback();
-};
-
-//
-// Usage for `jitsu config list`
-//
-config.list.usage = [
- 'Lists all configuration values currently',
- 'set in the .jitsuconf file',
- '',
- 'jitsu config list'
-];
View
148 lib/jitsu/commands/databases.js
@@ -5,8 +5,7 @@
*
*/
-var winston = require('winston'),
- jitsu = require('../../jitsu');
+var jitsu = require('../../jitsu');
var databases = exports;
@@ -20,193 +19,184 @@ databases.usage = [
];
databases.create = function (databaseType, databaseName, callback) {
-
-
- // This gets called after the arguments are sorted out.
- var create = function (databaseType, databaseName, callback) {
+ //
+ // Helper function to execute the database creation.
+ //
+ function executeCreate(databaseType, databaseName, callback) {
// Make sure that the user is passing a valid database type
if (['couch', 'redis', 'mongo'].indexOf(databaseType) === -1) {
- winston.error('Invalid database type ' + databaseType.red);
- winston.info('Expected: ' + 'couch'.magenta + ', ' + 'redis'.magenta + ' or ' + 'mongo'.magenta);
+ jitsu.log.error('Invalid database type ' + databaseType.red);
+ jitsu.log.info('Expected: ' + 'couch'.magenta + ', ' + 'redis'.magenta + ' or ' + 'mongo'.magenta);
return callback();
}
jitsu.databases.create(databaseType, databaseName, function (err, a, res) {
if (err || res.statusCode >= 400) {
if (err && err.statusCode === '409') {
- winston.error('You already created a database with that name.');
+ jitsu.log.error('You already created a database with that name.');
}
else {
- winston.error('Database could not be created.');
- winston.error(err || ('Unknown error code: ' + res.statusCode));
- winston.error('Try again and if it fails again, contact nodejitsu.');
+ jitsu.log.error('Database could not be created.');
+ jitsu.log.error(err || ('Unknown error code: ' + res.statusCode));
+ jitsu.log.error('Try again and if it fails again, contact nodejitsu.');
return callback(err);
}
}
else {
- winston.info('Database ' + databaseName + ' was created.');
+ jitsu.log.info('Database ' + databaseName + ' was created.');
}
databases.get(databaseName, callback);
});
}
- // If not all arguments are there, prompt the user for name and type.
- if (!callback) {
- var promptFor = ['database name'];
-
- winston.error('You need to pass a database name and type');
- winston.error('jitsu databases create <database type> <database name>');
+ var getProperties = [];
+
+ if (!databaseName || !databaseType) {
+ jitsu.log.warn('You need to pass a database name and type');
+ jitsu.log.warn('jitsu databases create <database type> <database name>');
if (!databaseName) {
- callback = databaseType;
- promptFor = ['database type'].concat(promptFor);
- winston.error('Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta + ' or ' + 'mongo'.magenta);
- }
- else {
- callback = databaseName;
-
+ getProperties.push('database name');
}
- jitsu.prompt.get(promptFor, function (err, result) {
- databaseType = result['database type'] || databaseType;
- databaseName = result['database name'] || databaseName;
- create(databaseType, databaseName, callback);
- });
-
- //return callback();
- } else {
- create(databaseType, databaseName, callback);
+ if (!databaseType) {
+ jitsu.log.warn('Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta + ' or ' + 'mongo'.magenta);
+ getProperties.push('database type');
+ }
+ }
+
+ if (!getProperties.length) {
+ return executeCreate(databaseType, databaseName, callback);
}
-
+
+ jitsu.prompt.get(promptFor, function (err, result) {
+ databaseType = result['database type'] || databaseType;
+ databaseName = result['database name'] || databaseName;
+ executeCreate(databaseType, databaseName, callback);
+ });
};
databases.create.usage = [
'Spins up a database for the user',
'',
- 'Example usage:',
'jitsu databases create couch <database name>',
'jitsu databases create mongo <database name>',
'jitsu databases create redis <database name>'
-]
+];
databases.get = function (databaseName, callback) {
- if (!callback) {
- winston.error('You need to pass a database name');
- winston.error('jitsu databases get <database name>');
- winston.error('If you want to get a list of all the databases run:');
- winston.error('jitsu databases list');
- callback = databaseName;
+ if (!databaseName) {
+ jitsu.log.warn('You need to pass a database name');
+ jitsu.log.warn('jitsu databases get <database name>');
+ jitsu.log.warn('If you want to get a list of all the databases run:');
+ jitsu.log.warn('jitsu databases list');
return callback();
}
jitsu.databases.get(databaseName, function (err, results) {
if (err) {
if (err.statusCode === '404') {
- winston.error('Database does not exist');
+ jitsu.log.error('Database does not exist');
}
else {
- winston.error('Unexpected Error: ' + err);
+ jitsu.log.error('Unexpected Error: ' + err);
}
}
else {
printDatabase(results);
}
callback();
});
-}
+};
databases.get.usage = [
'Gets the metadata of a database',
'',
- 'Example usage:',
'jitsu databases get <database name>'
-]
+];
databases.list = function (callback) {
jitsu.databases.list(function (err, results) {
if (err) {
- winston.error('Unexpected Error: ' + err);
+ jitsu.log.error('Unexpected Error: ' + err);
}
else {
results.forEach(function (database) {
- winston.info('');
+ jitsu.log.info('');
printDatabase(database);
});
if (results.length === 0) {
- winston.info('You have no databases.');
+ jitsu.log.info('You have no databases.');
}
}
callback();
});
-}
+};
databases.list.usage = [
'Lists the dabases you currently have running',
'',
- 'Example usage:',
'jitsu databases list'
-]
+];
databases.destroy = function (databaseName, callback) {
- if (!callback) {
- winston.error('You need to pass a database name');
- winston.error('jitsu databases destroy <database name>');
- callback = databaseName;
+ if (!databaseName) {
+ jitsu.log.error('You need to pass a database name');
+ jitsu.log.error('jitsu databases destroy <database name>');
return callback();
}
jitsu.databases.destroy(databaseName, function (err) {
if (err) {
- winston.error('Database could not be destroyed.');
- winston.error(err.result.error);
+ jitsu.log.error('Database could not be destroyed.');
+ jitsu.log.error(err.result.error);
}
else {
- winston.info('Database was deleted.');
+ jitsu.log.info('Database was deleted.');
}
callback();
});
-}
+};
+databases.destroy.destructive = true;
databases.destroy.usage = [
'Deprovisions a database',
'WARNING: this action is not reversible',
'',
- 'Example usage:',
'jitsu databases destroy <database name>'
-]
-databases.destroy.destructive = true
+];
var printDatabase = function (database) {
switch (database.type) {
case 'couch':
var subdomain = database.metadata.id.split('/')[1];
- winston.info('Database name: ' + database.name);
- winston.info('Database type: ' + database.type);
- winston.info('Connection url: ' + ('http://' + subdomain + '.iriscouch.com:5984').grey);
- winston.info('SSL connection url: ' + ('https://' + subdomain + '.iriscouch.com:6984').grey);
+ jitsu.log.info('Database name: ' + database.name);
+ jitsu.log.info('Database type: ' + database.type);
+ jitsu.log.info('Connection url: ' + ('http://' + subdomain + '.iriscouch.com:5984').grey);
+ jitsu.log.info('SSL connection url: ' + ('https://' + subdomain + '.iriscouch.com:6984').grey);
break;
case 'mongo':
- winston.info('Database name: ' + database.name);
- winston.info('Database type: ' + database.type);
- winston.info('Connection url: ' + (database.metadata.config.MONGOHQ_URL).grey);
+ jitsu.log.info('Database name: ' + database.name);
+ jitsu.log.info('Database type: ' + database.type);
+ jitsu.log.info('Connection url: ' + (database.metadata.config.MONGOHQ_URL).grey);
break;
case 'redis':
var port = database.metadata.port,
password = database.metadata.password,
server = database.metadata.label.split('-')[0];
- winston.info('Database name: ' + database.name);
- winston.info('Database type: ' + database.type);
- winston.info('Connection url: ' + ('redis://nodejitsu:' + password+ '@' + server + '.redistogo.com:' + port + '/').grey);
+ jitsu.log.info('Database name: ' + database.name);
+ jitsu.log.info('Database type: ' + database.type);
+ jitsu.log.info('Connection url: ' + ('redis://nodejitsu:' + password+ '@' + server + '.redistogo.com:' + port + '/').grey);
break;
default:
- winston.info('Database name: ' + database.name);
- winston.error('Unknown database type: ' + database.type);
+ jitsu.log.info('Database name: ' + database.name);
+ jitsu.log.error('Unknown database type: ' + database.type);
break;
}
-}
+};
View
104 lib/jitsu/commands/env.js
@@ -5,8 +5,7 @@
*
*/
-var winston = require('winston'),
- jitsu = require('../../jitsu');
+var jitsu = require('../../jitsu');
var env = exports;
@@ -30,21 +29,20 @@ env.usage = [
// Sets the specified `key` in the environment variables to `value` for
// the application in the current directory.
//
-env.set = function (key, value, callback) {
- var args = Array.prototype.slice.call(arguments);
- callback = args.pop();
-
- if (args.length !== 2) {
- winston.error('You must pass both <key> and <value>');
- return callback(true, true);
+env.set = function (appName, key, value, callback) {
+ if (value === null) {
+ value = key;
+ key = appName;
+ return viewApp(callback, update);
}
+
+ viewAppByName(appName, callback, update);
- viewApp(callback, function (err, app) {
+ function update(err, app) {
app.env = app.env || {};
app.env[key] = value;
-
jitsu.apps.update(app.name, { env: app.env }, callback);
- });
+ }
};
//
@@ -64,22 +62,23 @@ env.set.usage = [
// Gets the specified `key` in the environment variables for the
// application in the current directory.
//
-env.get = function (key, callback) {
- if (!callback) {
- callback = key;
- winston.error('No environment variables for ' + 'undefined'.yellow);
- return callback(new Error(), true, true);
+env.get = function (appName, key, callback) {
+ if (key === null) {
+ key = appName;
+ return viewApp(callback, gotEnv);
}
- viewApp(callback, function (err, app) {
+ viewAppByName(appName, callback, gotEnv);
+
+ function gotEnv(err, app) {
if (!app.env[key]) {
- winston.warn('No environment variables for ' + key.yellow);
+ jitsu.log.warn('No environment variables for ' + key.yellow);
return callback();
}
- winston.data([key.yellow, app.env[key].toString().magenta].join(' '));
+ jitsu.log.data([key.yellow, app.env[key].toString().magenta].join(' '));
callback();
- });
+ }
};
//
@@ -99,22 +98,23 @@ env.get.usage = [
// Deletes the specified `key` in the environment variables for the
// application in the current directory.
//
-env.delete = function (key, callback) {
- if (!callback) {
- callback = key;
- winston.warn('No configuration for ' + 'undefined'.magenta);
- return callback();
+env.delete = function (appName, key, callback) {
+ if (key === null) {
+ key = appName;
+ return viewApp(callback, deleteKey);
}
+
+ viewAppByName(appName, callback, deleteKey);
- viewApp(callback, function (err, app) {
+ function deleteKey(err, app) {
if (!app.env[key]) {
- winston.warn('No environment variables for ' + key.yellow);
+ jitsu.log.warn('No environment variables for ' + key.yellow);
return callback();
}
delete app.env[key];
jitsu.apps.update(app.name, { env: app.env }, callback);
- });
+ }
};
//
@@ -134,26 +134,23 @@ env.delete.usage = [
// current directory.
//
env.list = function (appName, callback) {
-
- if (typeof appName === 'function') {
- callback = appName;
- appName = null;
- viewApp(callback, success);
- }
- else {
- viewAppByName(appName, callback, success);
- }
-
- function success(err, app) {
+ function executeList(err, app) {
if (!app.env || Object.keys(app.env).length === 0) {
- winston.warn('No environment variables for ' + app.name.magenta);
+ jitsu.log.warn('No environment variables for ' + app.name.magenta);
return callback();
}
- winston.info('Listing all environment variables for: ' + app.name.magenta);
- jitsu.log.putObject(app.env);
+ jitsu.log.info('Listing all environment variables for: ' + app.name.magenta);
+ jitsu.inspect.putObject(app.env);
callback();
}
+
+ if (!appName) {
+ viewApp(callback, executeList);
+ }
+ else {
+ viewAppByName(appName, callback, executeList);
+ }
};
//
@@ -166,20 +163,26 @@ env.list.usage = [
'jitsu env list'
];
-env.clear = function (callback) {
- viewApp(callback, function (err, app) {
+env.clear = function (appName, callback) {
+ if (appName === null) {
+ return viewApp(callback, clearEnv);
+ }
+
+ viewAppByName(appName, callback, clearEnv);
+
+ function clearEnv(err, app) {
if (!app.env || Object.keys(app.env).length === 0) {
- winston.warn('No environment variables for ' + app.name.magenta);
+ jitsu.log.warn('No environment variables for ' + app.name.magenta);
return callback();
}
- winston.warn('All environment variables for ' + app.name.magenta + ' will be deleted.');
+ jitsu.log.warn('All environment variables for ' + app.name.magenta + ' will be deleted.');
jitsu.prompt.get(['yesno'], function (err, result) {
return err
? callback(err)
: jitsu.apps.update(app.name, { env: {} }, callback);
});
- });
+ }
};
//
@@ -189,9 +192,8 @@ env.clear = function (callback) {
// Attempts to read the package.json for the current directory
// and retrieve it from Nodejitsu.
//
-function viewApp (callback, success) {
+function viewApp(callback, success) {
jitsu.package.tryRead(process.cwd(), callback, function (pkg) {
-
jitsu.apps.view(pkg.name, function (err, app) {
return err ? callback(err) : success(null, app);
});
@@ -204,7 +206,7 @@ function viewApp (callback, success) {
// #### @success {function} Continuation to respond to on success.
// Attempts to retrieve the application from Nodejitsu with the given name.
//
-function viewAppByName (appName, callback, success) {
+function viewAppByName(appName, callback, success) {
jitsu.apps.view(appName, function (err, app) {
return err ? callback(err) : success(null, app);
});
View
126 lib/jitsu/commands/help.js
@@ -1,126 +0,0 @@
-/*
- * help.js: Command related to jitsu help and usage
- *
- * (C) 2010, Nodejitsu Inc.
- *
- */
-
-var colors = require('colors'),
- winston = require('winston'),
- jitsu = require('../../jitsu');
-
-var help = exports;
-
-help.usage = [
- ' ___ __'.cyan,
- ' / / / /_ / /'.cyan,
- ' __/ / / __/ /__/'.cyan,
- '',
-
- 'Flawless deployment of Node.js apps to the cloud',
- 'open-source and fully customizable.',
- 'https://github.com/nodejitsu/jitsu',
- '',
-
- 'Usage:'.cyan.bold.underline,
- '',
- ' jitsu <resource> <action> <param1> <param2> ...',
- '',
-
- 'Common Commands:'.cyan.bold.underline,
- '',
-
- 'To install a pre-built application'.cyan,
- ' jitsu install',
- '',
-
- 'To sign up for Nodejitsu'.cyan,
- ' jitsu signup',
- '',
-
- 'To log into Nodejitsu'.cyan,
- ' jitsu login',
- '',
-
- 'Deploys current path to Nodejitsu'.cyan,
- ' jitsu deploy',
- '',
-
- 'Creates a new application on Nodejitsu'.cyan,
- ' jitsu create',
- '',
-
- 'Lists all applications for the current user'.cyan,
- ' jitsu list',
- '',
-
- 'Additional Commands'.cyan.bold.underline,
- ' jitsu apps',
- ' jitsu logs',
- ' jitsu env',
- ' jitsu conf',
- ' jitsu users',
- ' jitsu databases',
- ' jitsu snapshots',
- ' jitsu logout',
- '',
- 'jitsu options'.cyan.bold.underline,
- '',
- 'jitsu [commands] [options]'.cyan,
- '',
- '--version print jitsu version and exit',
- '--localconf search for .jitsuconf file in ./ and then parent directories',
- '--jitsuconf [file] specify file to load configuration from',
- '--noanalyze skip require-analyzer: do not attempt to dynamicially detect dependencies'
-];
-
-//
-// ### function show (name, action)
-// #### @name {string} Name of the resource to show help for
-// #### @action {string} Name of the action on the resource
-// Shows the help for the resource with the specified `name`.
-// If `action` is supplied, help for `jitsu <name> <action>`
-// is shown.
-//
-help.show = function (name, action) {
- var usage, resource = jitsu.commands.commands[name];
-
- if (typeof resource !== 'function') {
- if (action && !resource[action]) {
- winston.error('No help for command ' + [name, action].join(' ').magenta);
- return;
- }
-
- usage = action ? resource[action].usage : resource.usage;
-
- if (!usage) {
- winston.error('No help for command ' + [name, action].join(' ').magenta);
- return;
- }
- }
- else {
- usage = resource.usage;
- }
-
- winston.help('');
- usage.forEach(function (line) {
- winston.help(line);
- });
- winston.help('');
-};
-
-//
-// Setup exports for all relevant resources:
-// `apps`, `snapshots`, `config`, etc.
-//
-Object.keys(jitsu.commands.commands).forEach(function (resource) {
- help[resource] = function (action, callback) {
- if (!callback) {
- callback = action;
- action = null;
- }
-
- help.show(resource, action);
- callback();
- };
-});
View
161 lib/jitsu/commands/install.js
@@ -1,153 +1,147 @@
-
-var jitsu = require('../../jitsu'),
- winston = require('winston'),
- ncp = require('ncp'),
- rimraf = require('rimraf'),
- path = require('path'),
- fs = require('fs'),
+/*
+ * install.js: Commands for installing and deploying starter apps.
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var fs = require('fs'),
+ path = require('path'),
+ common = require('../common'),
+ cpr = common.cpr,
+ rimraf = common.rimraf,
npmModule = require('npm'),
- thisPath = process.cwd();
+ jitsu = require('../../jitsu');
+var thisPath = process.cwd();
//
// "nodeapps" is a hash of aliases and npm packages,
// this mapping allows us to give short names to all node apps
//
var nodeapps = {
- "helloworld" : {
- "package" : "nodeapps-helloworld",
- "description" : "demo `hello world` http server"
+ "helloworld": {
+ "package": "nodeapps-helloworld",
+ "description": "demo `hello world` http server"
},
- "http-server" : {
- "package" : "http-server",
- "description" : "a robust and customizable http server"
+ "http-server": {
+ "package": "http-server",
+ "description": "a robust and customizable http server"
},
- "express" : {
- "package" : "nodeapps-express",
- "description" : "express.js boilerplate"
+ "express": {
+ "package": "nodeapps-express",
+ "description": "express.js boilerplate"
},
- "socket.io" : {
- "package" : "nodeapps-socket.io",
- "description" : "socket.io boilerplate"
+ "socket.io": {
+ "package": "nodeapps-socket.io",
+ "description": "socket.io boilerplate"
},
- "dnode" : {
- "package" : "nodeapps-dnode",
- "description" : "dnode boilerplate"
+ "dnode": {
+ "package": "nodeapps-dnode",
+ "description": "dnode boilerplate"
},
- "web-http-client" : {
- "package" : "web-http-client",
- "description" : "web based http-client ( with server-side proxy )"
+ "web-http-client": {
+ "package": "web-http-client",
+ "description": "web based http-client ( with server-side proxy )"
},
- "custom-vimeo-site" : {
- "package" : "custom-vimeo-site",
- "description" : "custom homepage for your vimeo videos"
+ "custom-vimeo-site": {
+ "package": "custom-vimeo-site",
+ "description": "custom homepage for your vimeo videos"
},
- "my-nodeapps" : {
- "package" : "nodeapps-my-nodeapps",
- "description" : "simple site to display your node apps"
+ "my-nodeapps": {
+ "package": "nodeapps-my-nodeapps",
+ "description": "simple site to display your node apps"
}
};
-var install = module.exports = function (starterName, callback) {
-
- npmModule.load({exit:false}, function (err) {
+module.exports = function (starterName, callback) {
+ npmModule.load({ exit: false }, function (err) {
if (err) {
return callback(err);
}
- if(typeof callback === 'undefined') {
- callback = starterName;
- starterName = null;
- }
+
if (fs.readdirSync(thisPath).length !== 0) {
return warnOverwrite(starterName, callback);
}
+
if (typeof starterName === 'string') {
return createApp({starter: starterName}, callback);
}
+
promptforAppName(callback);
});
function installApp(starterName, cb) {
- winston.info('Installing ' + starterName.magenta + ' locally.');
- winston.warn('Downloading packages from npm, this may take a moment...');
- npmModule.commands.install(thisPath, [nodeapps[starterName].package], function(err, result){
+ jitsu.log.info('Installing ' + starterName.magenta + ' locally.');
+ jitsu.log.warn('Downloading packages from npm, this may take a moment...');
+ npmModule.commands.install(thisPath, [nodeapps[starterName].package], function (err, result) {
if (err) {
return cb(err);
}
- ncp.ncp(path.join(thisPath, 'node_modules', nodeapps[starterName].package), thisPath, function (err) {
- if (err) {
- return cb(err);
- }
- cb(err, result);
+
+ cpr(path.join(thisPath, 'node_modules', nodeapps[starterName].package), thisPath, function (err) {
+ return err ? cb(err) : cb(err, result);
});
});
}
function warnOverwrite(starterName, cb) {
- winston.warn(process.cwd().grey + ' is not empty.');
- winston.warn('Creating a node app in this directory may overwrite existing files.');
+ jitsu.log.warn(process.cwd().grey + ' is not empty.');
+ jitsu.log.warn('Creating a node app in this directory may overwrite existing files.');
jitsu.prompt.get(['proceed'], function (err, results) {
if (err) {
return cb(err);
}
if (results['proceed'] !== 'yes') {
- winston.info('Try switching to an empty directory to continue.');
+ jitsu.log.info('Try switching to an empty directory to continue.');
return cb(null);
}
- return starterName ? createApp({ starter: starterName }, cb) : promptforAppName(cb);
+
+ return starterName
+ ? createApp({ starter: starterName }, cb)
+ : promptforAppName(cb);
});
}
function promptforAppName(cb) {
- winston.info('Please choose a node app so we can get you started.');
- winston.info('Available node apps:');
+ jitsu.log.info('Please choose a node app so we can get you started.');
+ jitsu.log.info('Available node apps:');
Object.keys(nodeapps).forEach(function (starter) {
- winston.info(starter.magenta + ' ' + nodeapps[starter].description);
+ jitsu.log.info(starter.magenta + ' ' + nodeapps[starter].description);
});
jitsu.prompt.get(['starter'], function (err, results) {
- if (err) {
- return cb(err);
- }
- createApp({ starter: results['starter'] }, callback);
+ return err ? cb(err) : createApp({ starter: results['starter'] }, callback);
});
}
function createApp(results, cb) {
if (Object.keys(nodeapps).indexOf(results['starter']) === -1) {
-