-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
74 lines (59 loc) · 1.59 KB
/
app.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
/*
This snippet allows the app to be runned from
another directory without concerns to Sails.
*/
process.chdir(__dirname);
var sails = require('sails');
var colors = require('colors');
var _ = require('lodash');
var argv = require('optimist').argv;
console.info(argv);
/*
Set a password for login purposes. If none is set, will be public
Usege:
node app --env.PASSWORD 123456
*/
if(argv.env && argv.env.PASSWORD){
var password = argv.env.PASSWORD;
console.log('\n$ Using Password: '.cyan + password);
}
/*
Set a custom adapter for current Node process
Usage:
node app --adapter.module "sails-disk"
node app --adapter.module "sails-mongo" --adapter.url "localhost:12702/test"
*/
if(argv.adapter){
var adapter = argv.adapter;
console.log('\n$ Using Custom Adapter: '.cyan + adapter.module);
// Inject adapter into config files
var adapterConfig = require('./config/adapters.js');
adapterConfig.adapters.default = adapter;
}
/*
Set vars in env object to process.env
*/
if(argv.env){
for(var k in argv.env)
process.env[k] = argv.env[k];
// _.extend(process.env, argv.env);
}
/*
Set process name as the APP_NAME
*/
process.title = 'node | ' + (
process.env.APP_NAME ||
process.env.PORT || '1337');
// Start sails and pass it command line arguments
sails.lift(argv, function (sails) {
/*
Initialize Backuper.
Either start backing up the current contents of the DB or restore them from a JSON file.
*/
if(argv.backup){
Backup.start(argv.backup);
setTimeout(Backup.save, 2000);
} else if (argv.restore) {
Backup.restore(argv.restore);
}
});