publish.js 863 B

123456789101112131415161718192021222324252627282930313233
  1. const Client = require("node-ssh");
  2. const ssh = new Client();
  3. ssh.connect({
  4. host: process.env.npm_package_remote_host,
  5. port: "22",
  6. username: process.env.npm_package_remote_user,
  7. password: process.env.npm_package_remote_password
  8. }).then(() => {
  9. const failedList = [];
  10. ssh.putDirectory(
  11. process.env.npm_package_remote_local,
  12. process.env.npm_package_remote_path,
  13. {
  14. recursive: true,
  15. concurrency: 1,
  16. tick: function(localPath, remotePath, error) {
  17. if (error) {
  18. failedList.push(localPath);
  19. }
  20. }
  21. }
  22. ).then(status => {
  23. if (failedList.length > 0) {
  24. console.log("发布失败");
  25. console.log("failed transfers", failedList.join(", "));
  26. } else {
  27. console.log(status ? "发布成功" : "发布失败");
  28. }
  29. ssh.dispose();
  30. });
  31. });