@hoowu/cocos-plugin-o2-web-assets
Version:
适用于 O2 平台 的 Web + Assets 项目的发布构建处理流程
46 lines (45 loc) • 1.98 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeFile = exports.renameFiles = exports.renameDir = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const const_1 = require("./const");
const renameDir = (oldPath, newDirName) => {
const stat = fs_1.default.statSync(oldPath);
if (stat.isDirectory()) {
const newPath = path_1.default.join(path_1.default.dirname(oldPath), newDirName);
fs_1.default.renameSync(oldPath, newPath);
console.info(`[${const_1.PACKAGE_NAME}] 目录重命名: ${oldPath} => ${newPath}`);
}
};
exports.renameDir = renameDir;
const renameFiles = (dir, oldExt, newExt) => {
let currentPath;
const files = fs_1.default.readdirSync(dir);
for (const k in files) {
currentPath = path_1.default.join(dir, files[k]);
const stat = fs_1.default.statSync(currentPath);
if (stat.isDirectory()) {
(0, exports.renameFiles)(currentPath, oldExt, newExt);
}
else if (stat.isFile()) {
if (path_1.default.extname(currentPath) === oldExt) {
const newPath = path_1.default.join(path_1.default.dirname(currentPath), `${path_1.default.basename(currentPath, oldExt)}${newExt}`);
fs_1.default.renameSync(currentPath, newPath);
console.info(`[${const_1.PACKAGE_NAME}] 文件重命名: ${currentPath} => ${newPath}`);
}
}
}
};
exports.renameFiles = renameFiles;
const removeFile = (dir, fileName) => {
const filePath = path_1.default.join(dir, fileName);
if (fs_1.default.existsSync(filePath)) {
fs_1.default.unlinkSync(filePath);
console.info(`[${const_1.PACKAGE_NAME}] 文件删除: ${filePath}`);
}
};
exports.removeFile = removeFile;