publish.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. const Client = require("node-ssh");
  21. const ssh = new Client();
  22. ssh.connect({
  23. host: process.env.npm_package_remote_host,
  24. port: "22",
  25. username: process.env.npm_package_remote_user,
  26. password: process.env.npm_package_remote_password
  27. }).then(() => {
  28. const failedList = [];
  29. ssh.putDirectory(
  30. process.env.npm_package_remote_local,
  31. process.env.npm_package_remote_path,
  32. {
  33. recursive: true,
  34. concurrency: 1,
  35. tick: function(localPath, remotePath, error) {
  36. if (error) {
  37. failedList.push(localPath);
  38. }
  39. }
  40. }
  41. ).then(status => {
  42. if (failedList.length > 0) {
  43. console.log("发布失败");
  44. console.log("failed transfers", failedList.join(", "));
  45. } else {
  46. console.log(status ? "发布成功" : "发布失败");
  47. }
  48. ssh.dispose();
  49. });
  50. });