deployHtmlToServer.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 = 'screenshow';
  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. var frame3dHtml = fs.readFileSync('dist/frame3d.html');
  19. fs.writeFileSync(nativePath + path.sep + 'index.html', indexHtml);
  20. fs.writeFileSync(nativePath + path.sep + 'frame3d.html', frame3dHtml);
  21. let pageName = 'index.html';
  22. var isRelease = true;
  23. var serverPath = `/var/www/html/projects/screenshow/`;
  24. //拷贝html文件到nativePath
  25. // fs.mkdirSync(nativePath)
  26. // var indexHtml = fs.readFileSync('dist/' + pageName)
  27. // fs.writeFileSync(nativePath + path.sep + pageName, indexHtml)
  28. var ftpUtils = new sftp({
  29. remotePath: serverPath,
  30. path: nativePath,
  31. username: 'root',
  32. password: 'MmxInfish@2020',
  33. host: '124.71.139.24',
  34. verbose: true,
  35. });
  36. ftpUtils.apply(function () {
  37. //删除maps文件夹
  38. rimraf.sync(nativePath);
  39. console.log(`ftp upload success!`);
  40. });