publish.js 876 B

12345678910111213141516171819202122232425262728
  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(process.env.npm_package_remote_local, process.env.npm_package_remote_path, {
  11. recursive: true,
  12. concurrency: 1,
  13. tick: function(localPath, remotePath, error) {
  14. if (error) {
  15. failedList.push(localPath)
  16. }
  17. },
  18. }).then((status) => {
  19. if (failedList.length > 0) {
  20. console.log('发布失败')
  21. console.log('failed transfers', failedList.join(', '))
  22. } else {
  23. console.log(status ? '发布成功' : '发布失败')
  24. }
  25. ssh.dispose()
  26. })
  27. })