-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodeDeploy.js
56 lines (51 loc) · 1.36 KB
/
nodeDeploy.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const SftpClient = require("ssh2-sftp-client");
const dotenv = require("dotenv");
const fs = require('fs');
dotenv.config();
const inFilePath = `${process.env.FTP_LOCA_PATH}${process.env.FILE_JS_UMD}`;
const renamedFilePath = `${process.env.FTP_LOCA_PATH}${process.env.FILE_JS}`;
function rename(){
fs.copyFile(inFilePath, renamedFilePath, (err) => {
if (err) {
console.error('Error copying file:', err);
} else {
console.log('File copied and renamed successfully.');
deploy(process.env.FTP_HOST1)
deploy(process.env.FTP_HOST2)
}
});
}
async function deploy(hostFTP) {
const sftp = new SftpClient();
sftp.client.setMaxListeners(10);
const config = {
host: hostFTP,
port: 22,
username: process.env.FTP_USER,
password: process.env.FTP_PASSWORD,
};
try {
await sftp.connect(config);
await sftp.fastPut(
renamedFilePath,
`${process.env.FTP_REMOTE_PATH}${process.env.FILE_JS}`,
{
overwrite: true,
}
);
await sftp.fastPut(
`${process.env.FTP_LOCA_PATH}${process.env.FILE_CSS}`,
`${process.env.FTP_REMOTE_PATH}${process.env.FILE_CSS}`,
{
overwrite: true,
}
);
console.log("Deploy OK");
} catch (err) {
console.error(`Deploy Error: ${err.message}`);
} finally {
console.info("End process deploy");
sftp.end();
}
}
rename();