Skip to content

Commit

Permalink
Refactoring, formatting, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Apr 27, 2014
1 parent 61e56d1 commit 3c7b3b4
Show file tree
Hide file tree
Showing 38 changed files with 1,183 additions and 1,118 deletions.
23 changes: 13 additions & 10 deletions bin/_commander.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
/**
* Module dependencies
*/
var _ = require('lodash')
, program = require('commander');

var _ = require('lodash');
var program = require('commander');


//
//
// Monkey-patch commander
//
//
//
//

// Allow us to display help(), but omit the wildcard (*) command.
program.Command.prototype.usageMinusWildcard =
program.usageMinusWildcard =function () {
program.commands = _.reject(program.commands, {_name: '*'});
program.help();
program.usageMinusWildcard = function() {
program.commands = _.reject(program.commands, {
_name: '*'
});
program.help();
};

// Force commander to display version information.
program.Command.prototype.versionInformation =
program.versionInformation =
function () {
program.emit('version');
program.versionInformation =
function() {
program.emit('version');
};

module.exports = program;
93 changes: 51 additions & 42 deletions bin/_generate-api.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
/**
* Module dependencies
*/
var async = require('async')
, sailsgen = require('sails-generate')
, STRINGFILE = require('sails-stringfile')
, _ = require('lodash');


//
// Run both the controller and model generators and add in a couple
// of extra log messages.
// (todo: pull this out into a simple generator)
module.exports = function generateAPI (scope, cb) {

console.log();

// Create the controller and model
async.parallel(_.map(['controller', 'model'], subGen), function(err) {

// As long as there were no errors, add some logs about how to call the new API
if (!err) {
console.log();
cb.log.info('REST API generated @ ' + ('http://localhost:1337/' + scope.args[0]).underline);
cb.log.info('and will be available the next time you run `sails lift`.');
}
});

// Create a function suitable for use with async.parallel to run a generator.
// Uses "cb.log" b/c it has that nice log format.
function subGen(generatorType) {
var _scope = _.extend({}, _.cloneDeep(scope), {generatorType: generatorType});
return function(_cb) {
sailsgen (_scope, {
success: function() {
cb.log('Generated a new '+_scope.generatorType+' `'+_scope.id+'` at '+_scope.destDir+_scope.globalID+'.js!');
return _cb();
},
error: function(err) {
cb.error(err);
return _cb(err);
},

var _ = require('lodash');
var async = require('async');
var sailsgen = require('sails-generate');


/**
*
* Run both the controller and model generators and add in a couple
* of extra log messages.
*
* TODO: Pull this out into a simple generator
* @param {[type]} scope [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/

module.exports = function generateAPI(scope, cb) {

console.log();

// Create the controller and model
async.parallel(_.map(['controller', 'model'], subGen), function(err) {

// As long as there were no errors, add some logs about how to call the new API
if (!err) {
console.log();
cb.log.info('REST API generated @ ' + ('http://localhost:1337/' + scope.args[0]).underline);
cb.log.info('and will be available the next time you run `sails lift`.');
}
});

// Create a function suitable for use with async.parallel to run a generator.
// Uses "cb.log" b/c it has that nice log format.
function subGen(generatorType) {
var _scope = _.extend({}, _.cloneDeep(scope), {
generatorType: generatorType
});
return function(_cb) {
sailsgen(_scope, {
success: function() {
cb.log('Generated a new ' + _scope.generatorType + ' `' + _scope.id + '` at ' + _scope.destDir + _scope.globalID + '.js!');
return _cb();
},
error: function(err) {
cb.error(err);
return _cb(err);
},
invalid: 'error'
});
};
}
});
};
}
};
16 changes: 8 additions & 8 deletions bin/sails-configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
* Module dependencies
*/

var captains = require('captains-log');
var CaptainsLog = require('captains-log');



module.exports = function ( ) {
module.exports = function() {

var config = {};
var log = captains();
var config = {};
var log = CaptainsLog();

log.info('To configure the Sails command-line interface, create a `.sailsrc` file.');
log.warn('`.sailrc` is currently experimental, and the API may change.');
log.warn('Please share your feedback on Github! (http://github.com/balderdashy/sails)');
return;
log.info('To configure the Sails command-line interface, create a `.sailsrc` file.');
log.warn('`.sailrc` is currently experimental, and the API may change.');
log.warn('Please share your feedback on Github! (http://github.com/balderdashy/sails)');
return;
};
18 changes: 9 additions & 9 deletions bin/sails-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* Module dependencies
*/

var Sails = require('../lib/app');
var path = require('path');
var _ = require('lodash');
var rconf = require('../lib/configuration/rc');
var captains = require('captains-log');
var nodepath = require('path');
var REPL = require('repl');
var fs = require('fs');
var _ = require('lodash');
require('colors');
var CaptainsLog = require('captains-log');
var Sails = require('../lib/app');
var rconf = require('../lib/app/configuration/rc');



Expand All @@ -25,7 +25,7 @@ require('colors');

module.exports = function() {

var log = captains(rconf.log);
var log = CaptainsLog(rconf.log);

console.log();
log.info('Starting app in interactive mode...'.debug);
Expand Down Expand Up @@ -54,9 +54,10 @@ module.exports = function() {

var repl = REPL.start('sails> ');
try {
history(repl, path.join(sails.config.paths.tmp, '.node_history'));
history(repl, nodepath.join(sails.config.paths.tmp, '.node_history'));
} catch (e) {
log.verbose('Error finding console history:', e);
}
catch(e) { log.verbose('Error finding console history:',e); }
repl.on('exit', function(err) {
if (err) {
log.error(err);
Expand All @@ -70,7 +71,6 @@ module.exports = function() {




/**
* REPL History
* Pulled directly from https://github.com/tmpvar/repl.history
Expand Down
50 changes: 26 additions & 24 deletions bin/sails-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* Module dependencies
*/

var Sails = require('../lib/app')
, path = require('path')
, Womb = require('child_process')
, captains = require('captains-log');
var Sails = require('../lib/app');
var path = require('path');
var Womb = require('child_process');
var CaptainsLog = require('captains-log');


/*
Expand All @@ -18,29 +18,31 @@ node --debug `which sails` $@
*/


module.exports = function () {
var log = captains();
module.exports = function() {
var log = CaptainsLog();

// Use the app's local Sails in `node_modules` if one exists
// But first make sure it'll work...
var appPath = process.cwd();
var pathToSails = path.resolve(appPath, '/node_modules/sails');
if ( !Sails.isLocalSailsValid(pathToSails, appPath) ) {
// otherwise, use the currently-running instance of Sails
pathToSails = path.resolve(__dirname, './sails.js');
}
// Use the app's local Sails in `node_modules` if one exists
// But first make sure it'll work...
var appPath = process.cwd();
var pathToSails = path.resolve(appPath, '/node_modules/sails');
if (!Sails.isLocalSailsValid(pathToSails, appPath)) {
// otherwise, use the currently-running instance of Sails
pathToSails = path.resolve(__dirname, './sails.js');
}

console.log();
log.info('Running node-inspector on this app...');
log.info('If you don\'t know what to do next, type `help`');
log.info('Or check out the docs:');
log.info('http://nodejs.org/api/debugger.html');
console.log();
console.log();
log.info('Running node-inspector on this app...');
log.info('If you don\'t know what to do next, type `help`');
log.info('Or check out the docs:');
log.info('http://nodejs.org/api/debugger.html');
console.log();


log.info(('( to exit, type '+'<CTRL>+<C>'+' )').grey);
console.log();
log.info(('( to exit, type ' + '<CTRL>+<C>' + ' )').grey);
console.log();

// Spin up child process for Sails
Womb.spawn('node', ['--debug', pathToSails, 'lift'], { stdio: 'inherit' });
// Spin up child process for Sails
Womb.spawn('node', ['--debug', pathToSails, 'lift'], {
stdio: 'inherit'
});
};
Loading

0 comments on commit 3c7b3b4

Please sign in to comment.