publish.js 1011 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * @Author: zhangyu
  3. * @Date: 2019-12-18 16:18:30
  4. * @Info: 自动化部署
  5. * @LastEditTime : 2020-02-11 17:47:56
  6. */
  7. const Client = require("node-ssh");
  8. const ssh = new Client();
  9. ssh.connect({
  10. host: process.env.npm_package_remote_host,
  11. port: "22",
  12. // privateKey: `${process.env.HOME}\\.ssh\\id_rsa_2048`,
  13. username: process.env.npm_package_remote_user,
  14. password: process.env.npm_package_remote_password
  15. }).then(() => {
  16. const failedList = [];
  17. ssh.putDirectory(
  18. process.env.npm_package_remote_local,
  19. process.env.npm_package_remote_path,
  20. {
  21. recursive: true,
  22. concurrency: 1,
  23. tick: function(localPath, remotePath, error) {
  24. if (error) {
  25. failedList.push(localPath);
  26. }
  27. }
  28. }
  29. ).then(status => {
  30. if (failedList.length > 0) {
  31. console.log("发布失败");
  32. console.log("failed transfers", failedList.join(", "));
  33. } else {
  34. console.log(status ? "发布成功" : "发布失败");
  35. }
  36. ssh.dispose();
  37. });
  38. });