Skip to content

Commit c8224fb

Browse files
committed
Fix sails-generate to use sails-generate dep.
1 parent 240a1da commit c8224fb

File tree

3 files changed

+70
-63
lines changed

3 files changed

+70
-63
lines changed

bin/sails-generate.js

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

8-
var Sails = require('../lib/app')
8+
var package = require('../package.json')
9+
, reportback = require('reportback')()
910
, path = require('path')
1011
, captains = require('captains-log')
1112
, sailsgen = require('sails-generate');
@@ -19,7 +20,7 @@ var Sails = require('../lib/app')
1920
* Generate module(s) for the app in our working directory.
2021
* Internally, uses ejs for rendering the various module templates.
2122
*
22-
* @param {Object} options
23+
* @param {Object} scope
2324
* {String} appPath - path to sails app
2425
* {String} module - e.g. 'controller' or 'model'
2526
* {String} path - path to output directory
@@ -33,38 +34,79 @@ var Sails = require('../lib/app')
3334
* {Function} * - different callbacks than may be triggered
3435
*/
3536

36-
module.exports = function ( ) {
37+
module.exports = function () {
38+
3739

40+
// TODO: get config
3841
var config = {};
3942
var log = captains(config.log);
4043

4144

42-
var entity = options.module;
45+
// Build initial scope
46+
var scope = {
47+
48+
// TODO: get semantic info from CLI args
49+
args: cliArguments,
50+
rootPath: process.cwd(),
51+
sailsPackageJSON: package
52+
};
53+
54+
var cliArguments = Array.prototype.slice.call(arguments);
55+
cliArguments.pop();
4356

44-
if (!entity) { throw new Error(); }
57+
var generatorType = cliArguments.shift();
58+
scope.args = cliArguments;
4559

46-
// TODO: Look up generator entity in config and grab the module name
47-
// for now:
48-
var module = 'sails-generate-' + entity;
60+
var module = 'sails-generate-'+generatorType;
4961

5062
var Generator;
5163
try {
5264
Generator = require(module);
5365
}
54-
catch (e) { throw e; }
55-
56-
sailsgen (Generator, options, {
57-
error: function (err) { log.error(err); },
58-
success: function (output) { log.info('ok!'); },
59-
notSailsApp: function () { log.error('Not a sails app.'); },
60-
alreadyExists: function () {
61-
62-
// Log custom message if override is defined
63-
if (options.logStatusOverrides && options.logStatusOverrides.alreadyExists) {
64-
return options.logStatusOverrides.alreadyExists(options, log);
65-
}
66-
67-
CLIController.error(options.globalID + ' already exists!');
68-
}
69-
});
66+
catch(e) {
67+
// cb.couldNotLoadGenerator
68+
throw e;
69+
}
70+
71+
return sailsgen(Generator, scope, reportback.extend());
7072
};
73+
74+
75+
76+
77+
// function (module) {
78+
// var cmd = module;
79+
// if (arguments.length === 1) {
80+
// module = null;
81+
// }
82+
83+
// console.log('sails generate '+module);
84+
// // program
85+
// // .command('model <resource>')
86+
// // .description('')
87+
// // .action(console.log);
88+
// // program
89+
// // .command('controller <resource>')
90+
// // .description('');
91+
// // program
92+
// // .command('api <resource>')
93+
// // .description('');
94+
// // generate
95+
// // .command('response <method>')
96+
// // .description('');
97+
// // generate
98+
// // .command('policy <name>')
99+
// // .description('');
100+
// // generate
101+
// // .command('service <name>')
102+
// // .description('');
103+
// // generate
104+
// // .command('adapter <name>')
105+
// // .description('');
106+
// // generate
107+
// // .command('generator <name>')
108+
// // .description('');
109+
// // generate
110+
// // .command('hook <name>')
111+
// // .description('');
112+
// });

bin/sails-lift.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ module.exports = function () {
2727

2828
// Use the app's local Sails in `node_modules` if one exists
2929
var appPath = process.cwd();
30-
var localSailsPath = appPath + '/node_modules/sails';
30+
var localSailsPath = path.resolve(appPath, '/node_modules/sails', '/lib');
3131

3232
// But first make sure it'll work...
33-
if (Sails.isLocalSailsValid(localSailsPath, appPath)) {
34-
require(localSailsPath + '/lib').lift(options);
33+
if ( Sails.isLocalSailsValid(localSailsPath, appPath) ) {
34+
require(localSailsPath).lift(options);
3535
return;
3636
}
3737

bin/sails.js

+1-36
Original file line numberDiff line numberDiff line change
@@ -69,42 +69,7 @@ program
6969
program.command('generate')
7070
.description('')
7171
.option('--dry')
72-
.action(function (module) {
73-
var cmd = module;
74-
if (arguments.length === 1) {
75-
module = null;
76-
}
77-
78-
console.log('sails generate '+module);
79-
// program
80-
// .command('model <resource>')
81-
// .description('')
82-
// .action(console.log);
83-
// program
84-
// .command('controller <resource>')
85-
// .description('');
86-
// program
87-
// .command('api <resource>')
88-
// .description('');
89-
// generate
90-
// .command('response <method>')
91-
// .description('');
92-
// generate
93-
// .command('policy <name>')
94-
// .description('');
95-
// generate
96-
// .command('service <name>')
97-
// .description('');
98-
// generate
99-
// .command('adapter <name>')
100-
// .description('');
101-
// generate
102-
// .command('generator <name>')
103-
// .description('');
104-
// generate
105-
// .command('hook <name>')
106-
// .description('');
107-
});
72+
.action(require('./sails-generate'));
10873

10974

11075

0 commit comments

Comments
 (0)