-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathpublish_website.js
42 lines (36 loc) · 1.06 KB
/
publish_website.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
/*!
wow.export (https://github.com/Kruithne/wow.export)
Authors: Kruithne <[email protected]>
License: MIT
*/
const fs = require('fs');
const fsp = fs.promises;
const SFTPClient = require('ssh2-sftp-client');
(async () => {
let sftp;
try {
const sftp_config = {
host: process.env.SFTP_HOST,
port: process.env.SFTP_PORT ?? 22,
username: process.env.SFTP_USER,
password: process.env.SFTP_PASS,
privateKey: process.env.SFTP_PRIVATE_KEY
};
// Load private key from disk if defined.
if (typeof sftp_config.privateKey === 'string') {
console.log('Loading private key...');
sftp_config.privateKey = await fsp.readFile(sftp_config.privateKey);
}
console.log('Establishing SFTP connection...');
sftp = new SFTPClient();
await sftp.connect(sftp_config);
await sftp.mkdir(process.env.SFTP_REMOTE_WEBSITE_DIR, true);
await sftp.uploadDir('./website', process.env.SFTP_REMOTE_WEBSITE_DIR);
} catch (e) {
console.error('Publish failed due to error: %s', e.message);
console.error(e.stack);
} finally {
if (sftp)
await sftp.end();
}
})();