Files
Tools-H5/nodejs/switchGame.js
2025-07-24 11:56:37 +08:00

106 lines
2.6 KiB
JavaScript

var fs = require('fs');
var path = require('path');
var GameID = process.argv[2]
var absPath = path.resolve('../build/web-mobile/') + '\\'
console.log(absPath)
const BundleConfig = {
'6001': 'whot',
'6002': 'whot',
'6003': 'whot',
'6005': 'BRWhot',
'2001': 'roulette',
'2002': 'wajeSpin',
'2003': 'bottleSpin',
'2004': 'blackjack',
'2006': 'betterjack',
'6007': 'whot',
'2008': 'slots',
}
var emptyDir = function (fileUrl) {
var files = fs.readdirSync(fileUrl);//读取该文件夹
files.forEach(function (file) {
var stats = fs.statSync(fileUrl + '/' + file);
if (stats.isDirectory()) {
emptyDir(fileUrl + '/' + file);
} else {
fs.unlinkSync(fileUrl + '/' + file);
// console.log("删除文件" + fileUrl + '/' + file + "成功");
}
});
}
//删除所有的空文件夹
var rmEmptyDir = function (fileUrl) {
var files = fs.readdirSync(fileUrl);
if (files.length > 0) {
var tempFile = 0;
files.forEach(function (fileName) {
tempFile++;
rmEmptyDir(fileUrl + '/' + fileName);
});
if (tempFile == files.length) {//删除母文件夹下的所有字空文件夹后,将母文件夹也删除
fs.rmdirSync(fileUrl);
// console.log('删除空文件夹' + fileUrl + '成功');
}
} else {
fs.rmdirSync(fileUrl);
// console.log('删除空文件夹' + fileUrl + '成功');
}
}
function checkDirectory(dst) {
let arr = dst.substring(0, dst.lastIndexOf('/') + 1).split('/')
let dstPath = ''
while (arr.length) {
dstPath += arr.splice(0, 1)
dstPath += '/'
try {
fs.accessSync(dstPath)
} catch (error) {
fs.mkdirSync(dstPath)
}
}
}
const unlinkArray = [
'cocos2d-js-min.13181.js',
'physics-min.ce5ee.js',
'style-desktop.dfd76.css',
'style-mobile.6e9cd.css'
]
const filesArray = fs.readdirSync(absPath)
filesArray.forEach(function (fname) {
const file = path.join(absPath, fname)
if (unlinkArray.includes(fname)) {
// 删除公用文件
fs.unlinkSync(file)
}
})
const keepArray = [
'main',
'internal',
'resources',
BundleConfig[GameID]
]
const bundleRoot = path.join(absPath, 'assets')
const bundleArray = fs.readdirSync(bundleRoot)
bundleArray.forEach(function (fname) {
const dir = path.join(bundleRoot, fname)
if (!keepArray.includes(fname)) {
// 删除公用文件
// fs.unlinkSync(file)
// console.log(dir)
emptyDir(dir)
rmEmptyDir(dir)
}
})