-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.js
39 lines (32 loc) · 933 Bytes
/
config.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
const async = require('async');
const fs = require('fs');
const path = require('path');
const possibleExecutables = exports.executables = [
path.resolve('nginx'),
'/usr/sbin/nginx',
'/usr/local/bin/nginx'
];
exports.command = function(basePath, callback) {
const existingFiles = possibleExecutables.filter(fs.existsSync);
async.map(
existingFiles,
(executable, cb) => fs.stat(executable, cb),
findFirstFile
);
function findFirstFile(err, results) {
if (err) {
return callback(err);
}
// find the first result that is a file
results = results
.map((stats, idx) => ({
stats: stats,
executable: existingFiles[idx]
}))
.filter(data => data.stats.isFile());
if (results.length === 0) {
return callback(new Error('No nginx executable found'));
}
callback(null, `${results[0].executable} -p ${basePath}/ -c conf/nginx.conf`);
}
};