26 lines
		
	
	
		
			668 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			668 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import fs from "fs"
 | 
						|
 | 
						|
const data = JSON.parse(fs.readFileSync("data.json", "utf8"))
 | 
						|
 | 
						|
const dataPerRegion = {}
 | 
						|
 | 
						|
for (const item of data) {
 | 
						|
	if (!dataPerRegion[item.regionName]) {
 | 
						|
		dataPerRegion[item.regionName] = []
 | 
						|
	}
 | 
						|
	const connectedSystems = item.connectedSystems.split(",")
 | 
						|
	item.connectedSystems = connectedSystems
 | 
						|
	item.x = parseInt(item.x)
 | 
						|
	item.y = parseInt(item.y)
 | 
						|
	dataPerRegion[item.regionName].push(item)
 | 
						|
	delete item.regionName
 | 
						|
}
 | 
						|
 | 
						|
for (const region in dataPerRegion) {
 | 
						|
	const regionFile = `../public/${region}.json`
 | 
						|
	console.log("Writing to", regionFile)
 | 
						|
	fs.writeFileSync(regionFile, JSON.stringify(dataPerRegion[region], null, 2))
 | 
						|
}
 | 
						|
 | 
						|
console.log("Done")
 |