Skip to content

Commit

Permalink
Merge pull request #51 from JollyGrin/fix/card-types
Browse files Browse the repository at this point in the history
Fix/card types
  • Loading branch information
JollyGrin authored Oct 20, 2024
2 parents 36a3f69 + cbbce51 commit 171e022
Show file tree
Hide file tree
Showing 11 changed files with 39,822 additions and 24,207 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"start": "npx serve@latest out",
"lint": "next lint",
"note": "node daily.js",
"process-cards": "ts-node minimizeCardData.ts"
"process-cards": "ts-node minimizeCardData.ts",
"patch-cards": "ts-node patchCardData.ts"
},
"dependencies": {
"@dnd-kit/core": "^6.1.0",
Expand Down
74 changes: 74 additions & 0 deletions patchCardData.ts
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);
}
});
Loading

0 comments on commit 171e022

Please sign in to comment.