-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployer.js
executable file
·42 lines (31 loc) · 955 Bytes
/
deployer.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
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const connect = require('connect');
const http = require('http');
const https = require('https');
const argv = require('minimist')(process.argv.slice(2));
const shell = require('shelljs');
const hooks = require(argv.hooks);
const app = connect();
app.use((req, res) => {
const request = req._parsedUrl.pathname.replace(/^\/+/, '');
if (hooks.hasOwnProperty(request)) {
const hook = hooks[request];
res.writeHead(200, {'Content-Type': 'text/plain'});
const child = shell.exec(hook.exec, {
cwd: hook.cwd || '.',
async: true,
});
} else {
res.writeHead(404, {'Content-Type': 'text/plain'});
}
res.end();
});
http.createServer(app).listen(argv.port || 3000);
if (argv.ssl_key && argv.ssl_cert) {
https.createServer({
key: fs.readFileSync(argv.ssl_key),
cert: fs.readFileSync(argv.ssl_cert),
}, app).listen(argv.https_port || 3443);
}