b81d004641
使用此开关后,游戏包将在启动进入游戏后才请求更新信息, 直到重启后再打开游戏才应用更新. 优化热更流程,可以在构建完成后,再领奖注入热更,上传更新.
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
class FileUtil {
|
|
/*
|
|
* 获取window上的文件目录以及文件列表信息
|
|
* @param { String } localDir 本地路径
|
|
* @return { files, dirs }
|
|
* */
|
|
listDirsAndFiles(localDir) {
|
|
const dirs = []
|
|
const files = []
|
|
const dir = fs.readdirSync(localDir)
|
|
for (let i = 0; i < dir.length; i++) {
|
|
const p = path.join(localDir, dir[i])
|
|
const stat = fs.statSync(p)
|
|
if (stat.isDirectory()) {
|
|
dirs.push(p)
|
|
const children = this.listDirsAndFiles(p)
|
|
dirs.push(...children.dirs)
|
|
files.push(...children.files)
|
|
} else {
|
|
files.push(p)
|
|
}
|
|
}
|
|
return {
|
|
files,
|
|
dirs
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 拷贝文件或目录。
|
|
* @param src
|
|
* @param dst
|
|
*/
|
|
copy(src, dst) {
|
|
const st = fs.statSync(src);
|
|
if (st.isFile()) {
|
|
const data = fs.readFileSync(src);
|
|
fs.writeFileSync(dst, data);
|
|
return;
|
|
}
|
|
|
|
if (!fs.existsSync(dst)) {
|
|
fs.mkdirSync(dst, {recursive: true});
|
|
}
|
|
|
|
//读取目录
|
|
const files = fs.readdirSync(src);
|
|
for (let p of files) {
|
|
this.copy(src + path.sep + p, dst + path.sep + p);
|
|
}
|
|
};
|
|
|
|
write(filePath, content) {
|
|
const pathInfo = path.parse(filePath);
|
|
if (!fs.existsSync(pathInfo.dir)) {
|
|
fs.mkdirSync(pathInfo.dir, {recursive: true});
|
|
}
|
|
fs.writeFileSync(filePath, content, 'utf-8');
|
|
}
|
|
}
|
|
|
|
module.exports = new FileUtil(); |