-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from JollyGrin/fix/card-types
Fix/card types
- Loading branch information
Showing
11 changed files
with
39,822 additions
and
24,207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//@ts-nocheck | ||
// THIS PATCHES THE CARD DATA TO ADD SLUG | ||
|
||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
// Define your types | ||
type Card = { | ||
name: string; | ||
slug: string; | ||
guardian: { | ||
type: string; | ||
}; | ||
}; | ||
|
||
type ProcessedCard = { | ||
name: string; | ||
slug: string; | ||
type: string; | ||
}; | ||
|
||
// Function to process the cards array | ||
function processCards(cards: any[]): any[] { | ||
return cards.map((card) => { | ||
const _slug = card.sets?.[0]?.variants?.[0].slug; | ||
const slug = _slug.split("_").slice(1).join("_"); | ||
return { | ||
...card, | ||
slug: slug, | ||
type: card.guardian.type.toLowerCase(), | ||
}; | ||
}); | ||
} | ||
|
||
console.log("xxxxxxx", __dirname); | ||
// Paths for reading and writing files | ||
const inputFilePath = path.join(__dirname, "/public/card-data/_cards.json"); | ||
const outputFilePath = path.join(__dirname, "/public/card-data/cards.json"); | ||
|
||
// Read the original JSON file | ||
fs.readFile(inputFilePath, "utf-8", (err, data) => { | ||
if (err) { | ||
console.error("Error reading the input file:", err); | ||
return; | ||
} | ||
|
||
try { | ||
// Parse the JSON data | ||
const cards: Card[] = JSON.parse(data); | ||
|
||
// Process the cards | ||
const processedCards = processCards(cards).sort((a, b) => { | ||
if (a.name < b.name) return -1; | ||
if (a.name > b.name) return 1; | ||
return 0; | ||
}); | ||
|
||
// Write the processed data to a new file | ||
fs.writeFile( | ||
outputFilePath, | ||
JSON.stringify(processedCards, null, 2), | ||
"utf-8", | ||
(err) => { | ||
if (err) { | ||
console.error("Error writing the output file:", err); | ||
} else { | ||
console.log("Processed cards written to:", outputFilePath); | ||
} | ||
}, | ||
); | ||
} catch (parseError) { | ||
console.error("Error parsing JSON:", parseError); | ||
} | ||
}); |
Oops, something went wrong.