-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
52 lines (39 loc) · 1.56 KB
/
index.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
/**
* Module dependences
*/
var path = require('path');
var _ = require('lodash');
module.exports = function sailsDeploy(inputs, cb) {
// `inputs.config` is provided with the raw config that Sails core gathered by running `rc`.
//
try {
// If `deploy` or `deploy.module` are missing or invalid, bail out w/ an error
// (we just throw an error w/ a helpful message, since the catch() below will take care of it)
if (!_.isObject(inputs.config) || !_.isObject(inputs.config.deploy) || !_.isString(inputs.config.deploy.module) ) {
throw new Error('Incomplete `config` provided to sails-deploy! Expected `config.deploy.module` to exist and be a string.');
}
// TODO: determine configured deployment strategy
var configuredStrategy = inputs.config.deploy.module;
// TODO: normalize and deterine the appropriate require path for the strategy
// (if it's expressed as a relative path, resolve it from the appPath; ie inputs.config.appPath)
var appPath = inputs.config.appPath||process.cwd();
var pathToStrategy = path.resolve(appPath, 'node_modules', inputs.config.deploy.module);
// TODO: require the strategy code
var strategy = require(pathToStrategy);
// Run the strategy
strategy({
config: inputs.config
}, function (err) {
if (err) {
console.error('Deployment failed! Details:\n',err);
return cb(err);
}
console.error('Deployment successful.');
return cb();
});
}
catch (e) {
console.error('Deployment failed! Details:\n',e.stack);
return cb(e);
}
};