var path = require('path');
var fs = require('fs');
var sftp = require('./uploadSftp');

var rimraf = require('rimraf');

//把html文件放到指定的目录
var timestamp = Date.parse(new Date());

var projName = 'museum';

console.log('projName--->', projName);

var nativePath = `dist/temp`;

// var cdnpath = "";//fs.readFileSync('lib/cdnpath.txt', 'utf8')
// if (!cdnpath) {
//   console.error('upload cdn error no cdnpath.txt')
// }
//创建临时目录
fs.mkdirSync(nativePath);

//拷贝html到 nativePath
var indexHtml = fs.readFileSync('dist/index.html');
fs.writeFileSync(nativePath + path.sep + 'index.html', indexHtml);

let pageName = 'index.html';

var isRelease = true;
var serverPath = `/var/www/html/projects/museum/`;

//拷贝html文件到nativePath
// fs.mkdirSync(nativePath)
// var indexHtml = fs.readFileSync('dist/' + pageName)
// fs.writeFileSync(nativePath + path.sep + pageName, indexHtml)

var ftpUtils = new sftp({
  remotePath: serverPath,
  path: nativePath,
  username: 'root',
  password: 'MmxInfish@2020',
  host: '124.71.139.24',
  verbose: true,
});
ftpUtils.apply(function () {
  //删除maps文件夹
  rimraf.sync(nativePath);

  console.log(`ftp upload success!`);
});
