publish.js 951 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * @Author: zhangyu
  3. * @Date: 2019-12-18 16:18:30
  4. * @Info: 自动化部署
  5. * @LastEditTime: 2020-05-06 14:48:27
  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. username: process.env.npm_package_remote_user,
  13. password: process.env.npm_package_remote_password
  14. }).then(() => {
  15. const failedList = [];
  16. ssh.putDirectory(
  17. process.env.npm_package_remote_local,
  18. process.env.npm_package_remote_path,
  19. {
  20. recursive: true,
  21. concurrency: 1,
  22. tick: function(localPath, remotePath, error) {
  23. if (error) {
  24. failedList.push(localPath);
  25. }
  26. }
  27. }
  28. ).then(status => {
  29. if (failedList.length > 0) {
  30. console.log("发布失败");
  31. console.log("failed transfers", failedList.join(", "));
  32. } else {
  33. console.log(status ? "发布成功" : "发布失败");
  34. }
  35. ssh.dispose();
  36. });
  37. });