-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdeploy-env.production.js
51 lines (39 loc) · 1.27 KB
/
deploy-env.production.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
/* eslint-disable @typescript-eslint/no-var-requires */
const { NodeSSH } = require('node-ssh');
const fs = require('fs');
const path = require('path');
const os = require('os');
const ssh = new NodeSSH();
let keyFile = process.env.DEPLOY_PRODUCTION_KEY_PATH || undefined;
if (keyFile) keyFile = keyFile.replace(/^~/g, os.homedir());
if (!keyFile) {
const defaultKeyFile = path.join(os.homedir(), '.ssh', 'id_rsa');
if (fs.existsSync(defaultKeyFile)) {
keyFile = defaultKeyFile;
}
}
const config = {
privateKey: keyFile,
host: process.env.DEPLOY_PRODUCTION_HOST,
username: process.env.DEPLOY_PRODUCTION_USER,
path: process.env.DEPLOY_PRODUCTION_PATH,
};
console.log(config);
(async () => {
const session = await ssh.connect({
host: config.host,
username: config.username,
privateKey: config.privateKey,
});
const configFile = path.join(__dirname, 'config.js');
const envFile = path.join(__dirname, '.env');
const targetDir = path.join(config.path, 'current');
if (fs.existsSync(envFile)) {
session.putFile(envFile, path.join(targetDir, '.env'));
} else if (fs.existsSync(configFile)) {
// use js object style config
session.putFile(configFile, path.join(targetDir, 'config.js'));
}
session.dispose();
process.exit(0);
})();