发布添加copyImage步骤

This commit is contained in:
2022-04-03 20:05:32 +08:00
parent b48ba9dd97
commit 3f43208997
3 changed files with 33 additions and 30 deletions
+24 -17
View File
@@ -1,22 +1,25 @@
const fs = require('fs')
const path = require('path')
module.exports = {
class Deploy {
/**
* 发布静态化的站点
* @param {String} source 源位置
* @param {String} target 目标位置
* @param {Boolean} copyRoot 是否拷贝根目录
* @param {Boolean} isRemove 是否先进行删除
*/
async exec(source, target, copyRoot) {
await new Promise((resolve, reject) => {
console.log(`删除${target}目录中的文件`)
this._deleteFolderRecursive(target, true)
resolve()
})
async exec(source, target, isRemove = false) {
if(isRemove) {
await new Promise((resolve, reject) => {
console.log(`删除${target}目录中的文件`)
this._deleteFolderRecursive(target, true)
resolve()
})
}
console.log(`拷贝${source}所有文件 -> ${target}`)
this._copyFolderRecursive(source, target, copyRoot)
},
this._checkDirectory(target)
this._copyFolderRecursive(source, target)
}
/**
* 递归删除目录以及子目录中的所有文件
@@ -35,7 +38,7 @@ module.exports = {
if(!retainRoot) { // 根目录保留
fs.rmdirSync(curPath)
}
},
}
/**
* 递归拷贝目录
* @param {String} source 源位置
@@ -53,24 +56,28 @@ module.exports = {
let writable = fs.createWriteStream(_target) //创建写入流
readable.pipe(writable);
} else if (stats.isDirectory()) { //是目录则 递归
this._checkDirectory(_src, _target, this._copyFolderRecursive)
this._checkDirectory(_target, this._copyFolderRecursive, _src, _target)
}
})
})
},
}
/**
* 校验目标目录是否存在
* @param {String} src 源目录
* @param {String} target 目标目录
* @param {Function} callback 回调函数
* @param {Array} args 回调函数入参
*/
_checkDirectory (src,target,callback) {
_checkDirectory (target, callback, ...args) {
fs.access(target, fs.constants.F_OK, err => {
if (err) {
fs.mkdirSync(target)
}
callback.call(this, src, target)
if (typeof callback === 'function') {
callback.apply(this, args)
}
})
}
}
}
module.exports = new Deploy()