index.js 958 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const config = require('./config.js')
  2. const shell = require('shelljs')
  3. const path = require('path');
  4. let Client = require('ssh2-sftp-client');
  5. function connectSSh() {
  6. let sftp = new Client();
  7. sftp.connect({
  8. host: config.ip,
  9. port: config.port,
  10. username: config.username,
  11. password: config.password
  12. }).then(() => {
  13. console.log("-----先执行删除服务器文件-----")
  14. return sftp.rmdir(config.rmpath, true);
  15. }).then(() => {
  16. // 上传文件
  17. console.log("-----开始上传-----")
  18. return sftp.uploadDir(path.resolve(__dirname, '../dist/specimenView'), config.path);
  19. }).then((data) => {
  20. console.log("-----上传完成-----");
  21. sftp.end();
  22. }).catch((err) => {
  23. console.log(err, '-----失败-----');
  24. sftp.end();
  25. });
  26. }
  27. function runTask() {
  28. //打包完成
  29. if (shell.exec(`npm run build`).code == 0) {
  30. console.log("-----打包成功-----");
  31. //提交上传
  32. connectSSh();
  33. }
  34. }
  35. runTask()