fix:高版本node报错

This commit is contained in:
bietiaop 2024-07-10 16:38:50 +08:00
parent b92c557b19
commit 6765ecfc85
4 changed files with 26 additions and 2 deletions

View file

@ -1,6 +1,22 @@
import fs from 'fs';
import { mapResourcesPath } from '../lib/path.js';
export function checkFolderExistAndCreate(folderPath) {
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true });
}
}
/**
*
* @param {string} fileName 名称不包含后缀
* @returns {object | null}
*/
export function getMapData(fileName) {
const mapDataPath = `${mapResourcesPath}/${fileName}.json`;
try {
const mapData = fs.readFileSync(mapDataPath, 'utf-8');
return JSON.parse(mapData);
} catch (error) {
return null;
}
}