-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy.js
executable file
·51 lines (48 loc) · 1.2 KB
/
deploy.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
// usage: https://www.npmjs.com/package/node-ssh
let path; let node_ssh; let ssh; let fs; let opn; let
host;
fs = require('fs');
path = require('path');
node_ssh = require('node-ssh');
opn = new require('opn');
ssh = new node_ssh();
host = 'localhost';
const localDir = './dist';
const remoteDir = '/opt/frontend/new';
const removeCommand = 'rm -rf ./*';
const pwdCommand = 'pwd';
ssh
.connect({
host,
username: 'root',
port: 22,
// password,
privateKey: './.ssh/id_rsa',
})
/*
Or
ssh.connect({
host: 'localhost',
username: 'steel',
privateKey: fs.readFileSync('/home/steel/.ssh/id_rsa')
})
if you want to use the raw string as private key
*/
.then(() => {
ssh.execCommand(removeCommand, { cwd: remoteDir }).then((result) => {
console.log(`STDOUT: ${result.stdout}`);
console.log(`STDERR: ${result.stderr}`);
ssh.putDirectory(localDir, remoteDir).then(
() => {
console.log('The File thing is done');
ssh.dispose();
opn(`http://${host}`, { app: ['chrome'] });
},
(error) => {
console.log("Something's wrong");
console.log(error);
ssh.dispose();
},
);
});
});