12345678910111213141516171819202122232425262728293031323334353637 |
- const config = require('./config.js')
- const shell = require('shelljs')
- const path = require('path');
- let Client = require('ssh2-sftp-client');
- function connectSSh() {
- let sftp = new Client();
- sftp.connect({
- host: config.ip,
- port: config.port,
- username: config.username,
- password: config.password
- }).then(() => {
- console.log("-----先执行删除服务器文件-----")
- return sftp.rmdir(config.rmpath, true);
- }).then(() => {
- // 上传文件
- console.log("-----开始上传-----")
- return sftp.uploadDir(path.resolve(__dirname, '../dist/specimenView'), config.path);
- }).then((data) => {
- console.log("-----上传完成-----");
- sftp.end();
- }).catch((err) => {
- console.log(err, '-----失败-----');
- sftp.end();
- });
- }
- function runTask() {
- //打包完成
- if (shell.exec(`npm run build`).code == 0) {
- console.log("-----打包成功-----");
- //提交上传
- connectSSh();
- }
- }
- runTask()
|