This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
37 lines (35 loc) · 1.42 KB
/
deploy.js
File metadata and controls
37 lines (35 loc) · 1.42 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
const Client = require("ssh2-sftp-client");
const fs = require("fs");
const sftpconfig = require("./sftp.json");
const sftp = new Client();
const options = {
host: sftpconfig.host,
port: sftpconfig.port,
username: sftpconfig.username,
passphrase: sftpconfig.passphrase,
privateKey: fs.readFileSync(sftpconfig.privateKey),
};
async function exec(){
console.log(`Forming SFTP connection to: ${sftpconfig.username}@${sftpconfig.host}:${sftpconfig.port}`);
try {
await sftp.connect(options);
console.log("Connected!\n");
const promises = [];
promises.push(sftp.uploadDir(`./frontend/react_build`,`./react_build`))
promises.push(sftp.put(`./frontend/servePage.js`,`./servePage.js`))
fs.readdir("./backend/backend_build",(e,files)=> { //Handle uploading the backend files
files.filter(x => x.endsWith(".js")).forEach(async filename => {
promises.push(sftp.put(`${__dirname}/backend/backend_build/${filename}`,`./backend_build/${filename}`));
});
files.filter(x => !x.split("").includes(".")).forEach(async foldername => {
promises.push(sftp.uploadDir(`${__dirname}/backend/backend_build/${foldername}`,`./backend_build/${foldername}`));
});
Promise.all(promises).then(()=>{
sftp.end();
});
});
} catch(e){
console.error(e);
}
}
exec();