forked from balderdashy/sails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsails-lift.js
73 lines (51 loc) · 1.65 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
#!/usr/bin/env node
/**
* Module dependencies
*/
var nodepath = require('path');
var _ = require('lodash');
var captains = require('captains-log');
var package = require('../package.json');
var rconf = require('../lib/app/configuration/rc');
var Sails = require('../lib/app');
/**
* `sails lift`
*
* Expose method which lifts the appropriate instance of Sails.
* (Fire up the Sails app in our working directory.)
*/
module.exports = function() {
// console.time('cli_lift');
// console.time('cli_prelift');
// console.time('cli_rc');
var log = captains(rconf.log);
// console.timeEnd('cli_rc');
console.log();
require('colors');
log.info('Starting app...'.grey);
console.log();
// Build initial scope, mixing-in rc config
var scope = _.merge({
rootPath: process.cwd(),
sailsPackageJSON: package
}, rconf);
var appPath = process.cwd();
// Use the app's local Sails in `node_modules` if it's extant and valid
var localSailsPath = nodepath.resolve(appPath, 'node_modules/sails');
if (Sails.isLocalSailsValid(localSailsPath, appPath)) {
var localSails = require(localSailsPath);
// console.timeEnd('cli_prelift');
localSails.lift(scope, afterwards);
return;
}
// Otherwise, if no workable local Sails exists, run the app
// using the currently running version of Sails. This is
// probably always the global install.
var globalSails = Sails();
// console.timeEnd('cli_prelift');
globalSails.lift(scope, afterwards);
function afterwards (err, sails) {
if (err) { sails ? sails.log.error(err) : log.error(err); process.exit(1); }
// try {console.timeEnd('cli_lift');}catch(e){}
}
};