Skip to content

Commit 3c7b3b4

Browse files
committed
Refactoring, formatting, comments
1 parent 61e56d1 commit 3c7b3b4

38 files changed

+1183
-1118
lines changed

bin/_commander.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
/**
22
* Module dependencies
33
*/
4-
var _ = require('lodash')
5-
, program = require('commander');
4+
5+
var _ = require('lodash');
6+
var program = require('commander');
67

78

89
//
910
//
1011
// Monkey-patch commander
11-
//
12-
//
12+
//
13+
//
1314

1415
// Allow us to display help(), but omit the wildcard (*) command.
1516
program.Command.prototype.usageMinusWildcard =
16-
program.usageMinusWildcard =function () {
17-
program.commands = _.reject(program.commands, {_name: '*'});
18-
program.help();
17+
program.usageMinusWildcard = function() {
18+
program.commands = _.reject(program.commands, {
19+
_name: '*'
20+
});
21+
program.help();
1922
};
2023

2124
// Force commander to display version information.
2225
program.Command.prototype.versionInformation =
23-
program.versionInformation =
24-
function () {
25-
program.emit('version');
26+
program.versionInformation =
27+
function() {
28+
program.emit('version');
2629
};
2730

2831
module.exports = program;

bin/_generate-api.js

+51-42
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
11
/**
22
* Module dependencies
33
*/
4-
var async = require('async')
5-
, sailsgen = require('sails-generate')
6-
, STRINGFILE = require('sails-stringfile')
7-
, _ = require('lodash');
8-
9-
10-
//
11-
// Run both the controller and model generators and add in a couple
12-
// of extra log messages.
13-
// (todo: pull this out into a simple generator)
14-
module.exports = function generateAPI (scope, cb) {
15-
16-
console.log();
17-
18-
// Create the controller and model
19-
async.parallel(_.map(['controller', 'model'], subGen), function(err) {
20-
21-
// As long as there were no errors, add some logs about how to call the new API
22-
if (!err) {
23-
console.log();
24-
cb.log.info('REST API generated @ ' + ('http://localhost:1337/' + scope.args[0]).underline);
25-
cb.log.info('and will be available the next time you run `sails lift`.');
26-
}
27-
});
28-
29-
// Create a function suitable for use with async.parallel to run a generator.
30-
// Uses "cb.log" b/c it has that nice log format.
31-
function subGen(generatorType) {
32-
var _scope = _.extend({}, _.cloneDeep(scope), {generatorType: generatorType});
33-
return function(_cb) {
34-
sailsgen (_scope, {
35-
success: function() {
36-
cb.log('Generated a new '+_scope.generatorType+' `'+_scope.id+'` at '+_scope.destDir+_scope.globalID+'.js!');
37-
return _cb();
38-
},
39-
error: function(err) {
40-
cb.error(err);
41-
return _cb(err);
42-
},
4+
5+
var _ = require('lodash');
6+
var async = require('async');
7+
var sailsgen = require('sails-generate');
8+
9+
10+
/**
11+
*
12+
* Run both the controller and model generators and add in a couple
13+
* of extra log messages.
14+
*
15+
* TODO: Pull this out into a simple generator
16+
* @param {[type]} scope [description]
17+
* @param {Function} cb [description]
18+
* @return {[type]} [description]
19+
*/
20+
21+
module.exports = function generateAPI(scope, cb) {
22+
23+
console.log();
24+
25+
// Create the controller and model
26+
async.parallel(_.map(['controller', 'model'], subGen), function(err) {
27+
28+
// As long as there were no errors, add some logs about how to call the new API
29+
if (!err) {
30+
console.log();
31+
cb.log.info('REST API generated @ ' + ('http://localhost:1337/' + scope.args[0]).underline);
32+
cb.log.info('and will be available the next time you run `sails lift`.');
33+
}
34+
});
35+
36+
// Create a function suitable for use with async.parallel to run a generator.
37+
// Uses "cb.log" b/c it has that nice log format.
38+
function subGen(generatorType) {
39+
var _scope = _.extend({}, _.cloneDeep(scope), {
40+
generatorType: generatorType
41+
});
42+
return function(_cb) {
43+
sailsgen(_scope, {
44+
success: function() {
45+
cb.log('Generated a new ' + _scope.generatorType + ' `' + _scope.id + '` at ' + _scope.destDir + _scope.globalID + '.js!');
46+
return _cb();
47+
},
48+
error: function(err) {
49+
cb.error(err);
50+
return _cb(err);
51+
},
4352
invalid: 'error'
44-
});
45-
};
46-
}
53+
});
54+
};
55+
}
4756
};

bin/sails-configure.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
* Module dependencies
66
*/
77

8-
var captains = require('captains-log');
8+
var CaptainsLog = require('captains-log');
99

1010

1111

12-
module.exports = function ( ) {
12+
module.exports = function() {
1313

14-
var config = {};
15-
var log = captains();
14+
var config = {};
15+
var log = CaptainsLog();
1616

17-
log.info('To configure the Sails command-line interface, create a `.sailsrc` file.');
18-
log.warn('`.sailrc` is currently experimental, and the API may change.');
19-
log.warn('Please share your feedback on Github! (http://github.com/balderdashy/sails)');
20-
return;
17+
log.info('To configure the Sails command-line interface, create a `.sailsrc` file.');
18+
log.warn('`.sailrc` is currently experimental, and the API may change.');
19+
log.warn('Please share your feedback on Github! (http://github.com/balderdashy/sails)');
20+
return;
2121
};

bin/sails-console.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
* Module dependencies
66
*/
77

8-
var Sails = require('../lib/app');
9-
var path = require('path');
10-
var _ = require('lodash');
11-
var rconf = require('../lib/configuration/rc');
12-
var captains = require('captains-log');
8+
var nodepath = require('path');
139
var REPL = require('repl');
1410
var fs = require('fs');
11+
var _ = require('lodash');
1512
require('colors');
13+
var CaptainsLog = require('captains-log');
14+
var Sails = require('../lib/app');
15+
var rconf = require('../lib/app/configuration/rc');
1616

1717

1818

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

2626
module.exports = function() {
2727

28-
var log = captains(rconf.log);
28+
var log = CaptainsLog(rconf.log);
2929

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

5555
var repl = REPL.start('sails> ');
5656
try {
57-
history(repl, path.join(sails.config.paths.tmp, '.node_history'));
57+
history(repl, nodepath.join(sails.config.paths.tmp, '.node_history'));
58+
} catch (e) {
59+
log.verbose('Error finding console history:', e);
5860
}
59-
catch(e) { log.verbose('Error finding console history:',e); }
6061
repl.on('exit', function(err) {
6162
if (err) {
6263
log.error(err);
@@ -70,7 +71,6 @@ module.exports = function() {
7071

7172

7273

73-
7474
/**
7575
* REPL History
7676
* Pulled directly from https://github.com/tmpvar/repl.history

bin/sails-debug.js

+26-24
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* Module dependencies
66
*/
77

8-
var Sails = require('../lib/app')
9-
, path = require('path')
10-
, Womb = require('child_process')
11-
, captains = require('captains-log');
8+
var Sails = require('../lib/app');
9+
var path = require('path');
10+
var Womb = require('child_process');
11+
var CaptainsLog = require('captains-log');
1212

1313

1414
/*
@@ -18,29 +18,31 @@ node --debug `which sails` $@
1818
*/
1919

2020

21-
module.exports = function () {
22-
var log = captains();
21+
module.exports = function() {
22+
var log = CaptainsLog();
2323

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

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

4040

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

44-
// Spin up child process for Sails
45-
Womb.spawn('node', ['--debug', pathToSails, 'lift'], { stdio: 'inherit' });
44+
// Spin up child process for Sails
45+
Womb.spawn('node', ['--debug', pathToSails, 'lift'], {
46+
stdio: 'inherit'
47+
});
4648
};

0 commit comments

Comments
 (0)