bettergi-scripts-list/repo/js/LinneaMining/tools/reindex-positions.js
躁动的氨气 ffe9d777c6
feat: 莉奈娅挖矿一条龙 (#3174)
* feat: 莉奈娅挖矿一条龙

* feat: 更新版本号

* fix: 修复一些问题

* feat: 清理路线

* feat: 添加选择
2026-05-01 21:30:13 +08:00

41 lines
1.3 KiB
JavaScript

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const targetDir = path.join(__dirname, '..', 'paths');
function reindexPositions(dir) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
reindexPositions(fullPath);
} else if (entry.name.endsWith('.json')) {
let raw = fs.readFileSync(fullPath, 'utf-8');
if (raw.charCodeAt(0) === 0xFEFF) {
raw = raw.slice(1);
fs.writeFileSync(fullPath, raw, 'utf-8');
console.log(`Removed BOM: ${path.relative(targetDir, fullPath)}`);
}
const data = JSON.parse(raw);
if (!data.positions || !Array.isArray(data.positions)) continue;
let changed = false;
data.positions.forEach((pos, i) => {
if (pos.id !== i + 1) {
pos.id = i + 1;
changed = true;
}
});
if (changed) {
fs.writeFileSync(fullPath, JSON.stringify(data, null, 2) + '\n');
console.log(`Reindexed: ${path.relative(targetDir, fullPath)} (${data.positions.length} positions)`);
}
}
}
}
reindexPositions(targetDir);
console.log('Done.');