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
| const scpClient = require('scp2'); const ora = require('ora'); const chalk = require('chalk');
const spinner = ora('正在发布到 ' + process.env.NODE_ENV + ' 服务器...\n'); spinner.start(); const SERVER_LIST = { 'development': { hostname: '0.0.0.0', port: 22, username: 'root', password: 'xxx', path: '/opt/www' }, 'production': { hostname: '0.0.0.0', port: 22, username: 'root', password: 'xxx', path: '/opt/www' }, };
const path = 'C:\\Users\\Administrator\\.ssh\\id_rsa' const privateKey = require('fs').readFileSync(path).toString()
const server = SERVER_LIST[process.env.NODE_ENV]; scpClient.scp( 'dist/', { host: server.hostname, port: server.port, username: server.username, password: server.password, privateKey, path: server.path }, function (err) { spinner.stop(); if (err) { console.log(chalk.red('发布失败.\n')); throw err; } else { console.log(chalk.green('Success! 成功发布到' + process.env.NODE_ENV + '服务器! \n')); } } );
|