deployHtmlToServer.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var path = require('path');
  2. var fs = require('fs');
  3. var sftp = require('./uploadSftp');
  4. var rimraf = require('rimraf');
  5. //把html文件放到指定的目录
  6. var timestamp = Date.parse(new Date());
  7. var projName = 'museum';
  8. console.log('projName--->', projName);
  9. var nativePath = `dist/temp`;
  10. // var cdnpath = "";//fs.readFileSync('lib/cdnpath.txt', 'utf8')
  11. // if (!cdnpath) {
  12. // console.error('upload cdn error no cdnpath.txt')
  13. // }
  14. //创建临时目录
  15. fs.mkdirSync(nativePath);
  16. //拷贝html到 nativePath
  17. var indexHtml = fs.readFileSync('dist/index.html');
  18. fs.writeFileSync(nativePath + path.sep + 'index.html', indexHtml);
  19. let pageName = 'index.html';
  20. var isRelease = true;
  21. var serverPath = `/var/www/html/projects/museum/`;
  22. //拷贝html文件到nativePath
  23. // fs.mkdirSync(nativePath)
  24. // var indexHtml = fs.readFileSync('dist/' + pageName)
  25. // fs.writeFileSync(nativePath + path.sep + pageName, indexHtml)
  26. var ftpUtils = new sftp({
  27. remotePath: serverPath,
  28. path: nativePath,
  29. username: 'root',
  30. password: 'MmxInfish@2020',
  31. host: '124.71.139.24',
  32. verbose: true,
  33. });
  34. ftpUtils.apply(function () {
  35. //删除maps文件夹
  36. rimraf.sync(nativePath);
  37. console.log(`ftp upload success!`);
  38. });