View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View
@@ -42,22 +42,6 @@ module.exports = function(sails) {
return cb();
}
// Convenience config to bind routes before any of the static app routes
sails.on('router:before', function() {
_.each(self.routes.before, function(middleware, route) {
middleware._middlewareType = self.identity.toUpperCase() + ' HOOK' + (middleware.name ? (': ' + middleware.name) : '');
sails.router.bind(route, middleware);
});
});
// Convenience config to bind routes after the static app routes
sails.on('router:after', function() {
_.each(self.routes.after, function(middleware, route) {
middleware._middlewareType = self.identity.toUpperCase() + ' HOOK' + (middleware.name ? (': ' + middleware.name) : '');
sails.router.bind(route, middleware);
});
});
/**
* Apply hook default configuration to sails.config
*
View
@@ -11,13 +11,6 @@ module.exports = function(sails) {
var buildDictionary = require('sails-build-dictionary');
// TODO:
// Look at improving `includeAll` to work asynchronously
// CommonJS `require` is a blocking operation, and makes apps
// start slower.
/**
* Module loader
*
@@ -70,27 +63,9 @@ module.exports = function(sails) {
// Server-Side Code
//
// For `controllers` hook
controllers: path.resolve(config.appPath, 'api/controllers'),
// For `policies` hook
policies: path.resolve(config.appPath, 'api/policies'),
// For `services` hook
services: path.resolve(config.appPath, 'api/services'),
// For `orm` hook
adapters: path.resolve(config.appPath, 'api/adapters'),
models: path.resolve(config.appPath, 'api/models'),
// For `userhooks` hook
hooks: path.resolve(config.appPath, 'api/hooks'),
// For `blueprints` hook
blueprints: path.resolve(config.appPath, 'api/blueprints'),
// For `responses` hook
responses: path.resolve(config.appPath, 'api/responses'),
// Server-Side HTML
//
// For `views` hook
views: path.resolve(config.appPath, 'views'),
layout: path.resolve(config.appPath, 'views/layout.ejs'),
}
};
},
@@ -125,27 +100,9 @@ module.exports = function(sails) {
// Server-Side Code
//
// For `controllers` hook
controllers: path.resolve(sails.config.appPath, sails.config.paths.controllers),
// For `policies` hook
policies: path.resolve(sails.config.appPath, sails.config.paths.policies),
// For `services` hook
services: path.resolve(sails.config.appPath, sails.config.paths.services),
// For `orm` hook
adapters: path.resolve(sails.config.appPath, sails.config.paths.adapters),
models: path.resolve(sails.config.appPath, sails.config.paths.models),
// For `userhooks` hook
hooks: path.resolve(sails.config.appPath, sails.config.paths.hooks),
// For `blueprints` hook
blueprints: path.resolve(sails.config.appPath, sails.config.paths.blueprints),
// For `responses` hook
responses: path.resolve(sails.config.appPath, sails.config.paths.responses),
// Server-Side HTML
//
// For `views` hook
views: path.resolve(sails.config.appPath, sails.config.paths.views),
layout: path.resolve(sails.config.appPath, sails.config.paths.layout)
models: path.resolve(sails.config.appPath, sails.config.paths.models)
});
},
@@ -213,24 +170,6 @@ module.exports = function(sails) {
/**
* Load app controllers
*
* @param {Object} options
* @param {Function} cb
*/
loadControllers: function (cb) {
buildDictionary.optional({
dirname: sails.config.paths.controllers,
filter: /(.+)Controller\.(js|coffee|litcoffee)$/,
flattenDirectories: true,
keepDirectoryPath: true,
replaceExpr: /Controller/
}, cb);
},
/**
* Load adapters
@@ -281,109 +220,6 @@ module.exports = function(sails) {
/**
* Load app services
*
* @param {Object} options
* @param {Function} cb
*/
loadServices: function (cb) {
buildDictionary.optional({
dirname : sails.config.paths.services,
filter : /(.+)\.(js|coffee|litcoffee)$/,
depth : 1,
caseSensitive : true
}, cb);
},
/**
* Check for the existence of views in the app
*
* @param {Object} options
* @param {Function} cb
*/
statViews: function (cb) {
buildDictionary.optional({
dirname: sails.config.paths.views,
filter: /(.+)\..+$/,
replaceExpr: null,
dontLoad: true
}, cb);
},
/**
* Load app policies
*
* @param {Object} options
* @param {Function} cb
*/
loadPolicies: function (cb) {
buildDictionary.optional({
dirname: sails.config.paths.policies,
filter: /(.+)\.(js|coffee|litcoffee)$/,
replaceExpr: null,
flattenDirectories: true,
keepDirectoryPath: true
}, cb);
},
/**
* Load app hooks
*
* @param {Object} options
* @param {Function} cb
*/
loadUserHooks: function (cb) {
buildDictionary.optional({
dirname: sails.config.paths.hooks,
filter: /^(.+)\.(js|coffee|litcoffee)$/,
// Hooks should be defined as either single files as a function
// OR (better yet) a subfolder with an index.js file
// (like a standard node module)
depth: 2
}, cb);
},
/**
* Load app blueprint middleware.
*
* @param {Object} options
* @param {Function} cb
*/
loadBlueprints: function (cb) {
buildDictionary.optional({
dirname: sails.config.paths.blueprints,
filter: /(.+)\.(js|coffee|litcoffee)$/,
useGlobalIdForKeyName: true
}, cb);
},
/**
* Load custom API responses.
*
* @param {Object} options
* @param {Function} cb
*/
loadResponses: function (cb) {
buildDictionary.optional({
dirname: sails.config.paths.responses,
filter: /(.+)\.(js|coffee|litcoffee)$/,
useGlobalIdForKeyName: true
}, cb);
},
optional: buildDictionary.optional,
required: buildDictionary.required,
aggregate: buildDictionary.aggregate,
View
@@ -4,7 +4,6 @@
var _ = require('lodash');
var async = require('async');
var prompt = require('prompt');
var howto_loadAppModelsAndAdapters = require('./load-user-modules');
var howto_normalizeModelDef = require('./normalize-model');
var howto_buildORM = require('./build-orm');
@@ -96,8 +95,7 @@ module.exports = function(sails) {
// Before continuing any further to actually start up the ORM,
// check the migrate settings for each model to (1) use migrate:safe
// in production and (2) prompt the user to make a decision if no migrate
// configuration is present.
// in production or throw an error.
_doubleCheckMigration: ['normalizedModelDefs', function (next) {
// If there are no models, we're good
@@ -110,77 +108,7 @@ module.exports = function(sails) {
return next();
}
// Otherwise show a prompt
console.log('-----------------------------------------------------------------');
console.log();
prompt.start();
console.log('',
'Excuse my interruption, but it looks like this app'+'\n',
'does not have a project-wide "migrate" setting configured yet.'+'\n',
'(perhaps this is the first time you\'re lifting it with models?)'+'\n',
'\n',
'In short, this setting controls whether/how Sails will attempt to automatically'+'\n',
'rebuild the tables/collections/sets/etc. in your database schema.\n',
'You can read more about the "migrate" setting here:'+'\n',
'http://sailsjs.org/#/documentation/concepts/ORM/model-settings.html?q=migrate\n'
// 'command(⌘)+click to open links in the terminal'
);
console.log('',
'In a production environment (NODE_ENV==="production") Sails always uses'+'\n',
'migrate:"safe" to protect inadvertent deletion of your data.\n',
'However during development, you have a few other options for convenience:'+'\n\n',
'1. safe - never auto-migrate my database(s). I will do it myself (by hand)','\n',
'2. alter - auto-migrate, but attempt to keep my existing data (experimental)\n',
'3. drop - wipe/drop ALL my data and rebuild models every time I lift Sails\n'
);
console.log('What would you like Sails to do?');
console.log();
sails.log.info('To skip this prompt in the future, set `sails.config.models.migrate`.');
sails.log.info('(conventionally, this is done in `config/models.js`)');
console.log();
sails.log.warn('** DO NOT CHOOSE "2" or "3" IF YOU ARE WORKING WITH PRODUCTION DATA **');
console.log();
prompt.get(['?'], function(err, result) {
if (err) return next(err);
result = result['?'];
switch (result) {
case 'alter':
case '2':
sails.config.models.migrate = 'alter';
break;
case 'drop':
case '3':
sails.config.models.migrate = 'drop';
break;
default:
sails.config.models.migrate = 'safe';
break;
}
console.log();
console.log(' Temporarily using `sails.config.models.migrate="%s"...', sails.config.models.migrate);
console.log(' (press CTRL+C to cancel-- continuing lift automatically in 0.5 seconds...)');
console.log();
setTimeout(function (){
return next();
},600);
});
// async.eachSeries(_.keys(sails.models), function (identity, nextModel) {
// // If migrate setting is defined, continue without doing anything else.
// if (typeof sails.models[identity].migrate !== 'undefined') {
// return nextModel();
// }
// // If migrate setting is not specififed on this model,
// // display a prompt and require the user to make a decision about
// // their migration strategy.
// var thisModel = sails.models[identity];
// }, next);
throw new Error("No migration strategy defined, please set migrate: safe in your Sails config");
}],
// Once all user model and adapter definitions are loaded
@@ -210,7 +138,7 @@ module.exports = function(sails) {
}
else {
// If the re-initialization was a success, trigger an event
// in case something needs to respond to the ORM reload (e.g. pubsub hook)
// in case something needs to respond to the ORM reload
sails.emit('hook:orm:reloaded');
}
});
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.