diff --git a/scripts/build-challenge-map-graphql.mjs b/scripts/build-challenge-map-graphql.mjs index 2c7d1ce6a..447ea922a 100644 --- a/scripts/build-challenge-map-graphql.mjs +++ b/scripts/build-challenge-map-graphql.mjs @@ -1,5 +1,6 @@ import { writeFile, mkdir } from 'fs/promises'; import { dirname } from 'path'; +import { fileURLToPath } from 'url'; /** * Build challenge map from freeCodeCamp GraphQL Curriculum Database @@ -7,11 +8,26 @@ import { dirname } from 'path'; * This script fetches the complete curriculum structure from the GraphQL API * and generates a flat lookup map for challenge resolution. * - * Output format: { challengeId: { certification, block, name } } + * Output format: + * { + * "challengeId": { + * "superblocks": ["superblock-dashed-name", ...], + * "blocks": ["block-dashed-name", ...], + * "name": "Challenge Title" + * } + * } + * + * Notes: + * - Challenges may appear in multiple superblocks/blocks; the script records + * all occurrences as arrays. Consumers that need a single canonical + * superblock/block (e.g., dashboard grouping) should use the first array + * element as the canonical value. */ const GRAPHQL_ENDPOINT = 'https://curriculum-db.freecodecamp.org/graphql'; -const OUTPUT_PATH = new URL('../data/challengeMap.json', import.meta.url); +const OUTPUT_PATH = fileURLToPath( + new URL('../data/challengeMap.json', import.meta.url) +); const CHALLENGE_MAP_QUERY = ` query GetChallengeMap { @@ -158,14 +174,14 @@ async function buildChallengeMapFromGraphQL() { const challengeMap = buildChallengeMap(data); // Ensure output directory exists - await mkdir(dirname(OUTPUT_PATH.pathname), { recursive: true }); + await mkdir(dirname(OUTPUT_PATH), { recursive: true }); // Write to file - console.log(`\nšŸ’¾ Writing challenge map to ${OUTPUT_PATH.pathname}...`); + console.log(`\nšŸ’¾ Writing challenge map to ${OUTPUT_PATH}...`); await writeFile(OUTPUT_PATH, JSON.stringify(challengeMap, null, 2)); console.log('āœ… Challenge map successfully generated!\n'); - console.log(` File: ${OUTPUT_PATH.pathname}`); + console.log(` File: ${OUTPUT_PATH}`); console.log(` Size: ${Object.keys(challengeMap).length} challenges`); } catch (err) { console.error('āŒ Error building challenge map:', err);