-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathconfig.js
More file actions
134 lines (113 loc) · 4.08 KB
/
Copy pathconfig.js
File metadata and controls
134 lines (113 loc) · 4.08 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var cjson = require('cjson');
var path = require('path');
var fs = require('fs');
var helpers = require('./helpers');
var format = require('util').format;
require('colors');
exports.read = function(configFileName) {
var mupJsonPath = path.resolve(configFileName);
// path of the mup.json file is the basedir and everything
// will be based on that path
var basedir = path.dirname(mupJsonPath);
if(fs.existsSync(mupJsonPath)) {
var mupJson = cjson.load(mupJsonPath);
//initialize options
mupJson.env = mupJson.env || {};
mupJson.env['PORT'] = mupJson.env['PORT'] || 80;
if(typeof mupJson.setupNode === "undefined") {
mupJson.setupNode = true;
}
if(typeof mupJson.setupPhantom === "undefined") {
mupJson.setupPhantom = true;
}
if(typeof mupJson.appName === "undefined") {
mupJson.appName = "meteor";
}
if(typeof mupJson.dockerImage === "undefined") {
mupJson.dockerImage = "meteorhacks/meteord:base";
}
if(typeof mupJson.enableUploadProgressBar === "undefined") {
mupJson.enableUploadProgressBar = true;
}
//validating servers
if(!mupJson.servers || mupJson.servers.length == 0) {
mupErrorLog('Server information does not exist');
} else {
mupJson.servers.forEach(function(server) {
var sshAgentExists = false;
var sshAgent = process.env.SSH_AUTH_SOCK;
if(sshAgent) {
sshAgentExists = fs.existsSync(sshAgent);
server.sshOptions = server.sshOptions || {};
server.sshOptions.agent = sshAgent;
}
if(!server.host) {
mupErrorLog('Server host does not exist');
} else if(!server.username) {
mupErrorLog('Server username does not exist');
} else if(!server.password && !server.pem && !sshAgentExists) {
mupErrorLog('Server password, pem or a ssh agent does not exist');
} else if(!mupJson.app) {
mupErrorLog('Path to app does not exist');
}
server.os = server.os || "linux";
if(server.pem) {
server.pem =
rewritePath(server.pem, "SSH private key file is invalid");
}
server.env = server.env || {};
var defaultEndpointUrl =
format("http://%s:%s", server.host, mupJson.env['PORT']);
server.env['CLUSTER_ENDPOINT_URL'] =
server.env['CLUSTER_ENDPOINT_URL'] || defaultEndpointUrl;
});
}
//rewrite ~ with $HOME
mupJson.app = rewritePath(
mupJson.app, "There is no meteor app in the current app path.");
if(mupJson.ssl) {
mupJson.ssl.port = mupJson.ssl.port || 443;
mupJson.ssl.certificate = rewritePath(
mupJson.ssl.certificate, "SSL certificate file does not exists.");
mupJson.ssl.key = rewritePath(
mupJson.ssl.key, "SSL key file does not exists.");
}
// additional build options
mupJson.buildOptions = mupJson.buildOptions || {};
return mupJson;
} else {
var message =
'configuration file ' + configFileName + ' does not exist!'.red.bold;
console.error(message);
helpers.printHelp();
process.exit(1);
}
function rewritePath(location, errorMessage) {
if(!location) {
return mupErrorLog(errorMessage);
}
var homeLocation = process.env.HOME;
if(/^win/.test(process.platform)) {
homeLocation = process.env.USERPROFILE;
}
var location = location.replace('~', homeLocation).trim();
if(location.indexOf(0) !== "/" || location.indexOf(0) !== "\\") {
// if path does not start with / or \ (on windows)
// we need to make sure, they are from the basedir
// but not from the current dir
location = path.resolve(basedir, location);
} else {
// anyway, we need to resolve path for windows compatibility
location = path.resolve(location);
}
if(!fs.existsSync(location)) {
mupErrorLog(errorMessage);
}
return location;
}
function mupErrorLog(message) {
var errorMessage = 'Invalid configuration file ' + configFileName + ': ' + message;
console.error(errorMessage.red.bold);
process.exit(1);
}
};