forked from balderdashy/sails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsails-lift.js
95 lines (75 loc) · 3.07 KB
/
sails-lift.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Module dependencies
*/
var nodepath = require('path');
var _ = require('@sailshq/lodash');
var chalk = require('chalk');
var captains = require('captains-log');
var rconf = require('../lib/app/configuration/rc')();
var Sails = require('../lib/app');
var SharedErrorHelpers = require('../errors');
/**
* `sails lift`
*
* Fire up the Sails app in our working directory, using the
* appropriate version of Sails.
*
* > This uses the locally-installed Sails, if available.
* > Otherwise, it uses the currently-running Sails (which,
* > 99.9% of the time, is the globally-installed version.)
*
* @stability 3
* @see http://sailsjs.com/documentation/reference/command-line-interface/sails-lift
*/
module.exports = function() {
// Get a temporary logger just for use in `sails lift`.
// > This is so that logging levels are configurable, even when a
// > Sails app hasn't been loaded yet.
var cliLogger = captains(rconf.log);
console.log();
cliLogger.info(chalk.grey('Starting app...'));
console.log();
// Now grab our dictionary of configuration overrides to pass in
// momentarily when we lift (or load) our Sails app. This is the
// dictionary of configuration settings built from `.sailsrc` file(s),
// command-line options, and environment variables.
// (No need to clone, since it's not being used anywhere else)
var configOverrides = rconf;
// Determine whether to use the local or global Sails install.
var sailsApp = (function _determineAppropriateSailsAppInstance(){
// Use the app's locally-installed Sails dependency (in `node_modules/sails`),
// assuming it's extant and valid.
// > Note that we always assume the current working directory to be the
// > root directory of the app.
var appPath = process.cwd();
var localSailsPath = nodepath.resolve(appPath, 'node_modules/sails');
if (Sails.isLocalSailsValid(localSailsPath, appPath)) {
cliLogger.verbose('Using locally-installed Sails.');
cliLogger.silly('(which is located at `'+localSailsPath+'`)');
return require(localSailsPath);
}// --•
// Otherwise, since no workable locally-installed Sails exists,
// run the app using the currently running version of Sails.
// > This is probably always the global install.
cliLogger.info('No local Sails install detected; using globally-installed Sails.');
return Sails();
})();
// Lift (or load) Sails
(function _loadOrLift(proceed){
// If `--dontLift` was set, then use `.load()` instead.
if (!_.isUndefined(configOverrides.dontLift)) {
sailsApp.load(configOverrides, proceed);
}
// Otherwise, go with the default behavior (`.lift()`)
else {
sailsApp.lift(configOverrides, proceed);
}
})(function afterwards(err){// ~∞%°
if (err) {
return SharedErrorHelpers.fatal.failedToLoadSails(err);
}// --•
// If we made it here, the app is all lifted and ready to go.
// The server will lower when the process is terminated-- either by a signal,
// or via an uncaught fatal error.
});//</after lifting or loading Sails app>
};