mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor(curriculum): remove block name metadata and source titles from intro (#66415)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -161,21 +161,17 @@ describe('external curriculum data build', () => {
|
||||
superBlock
|
||||
] as GeneratedBlockBasedCurriculumProps;
|
||||
|
||||
// Temporary skip these checks to keep CI stable.
|
||||
// TODO: uncomment these once https://github.com/freeCodeCamp/freeCodeCamp/issues/60660 is completed.
|
||||
|
||||
// Randomly pick a block to check its data.
|
||||
// const blocks = superBlockData.blocks;
|
||||
// const randomBlockIndex = Math.floor(Math.random() * blocks.length);
|
||||
// const randomBlock = blocks[randomBlockIndex];
|
||||
|
||||
expect(superBlockData.intro).toEqual(intros[superBlock].intro);
|
||||
// expect(superBlockData.blocks[randomBlockIndex].intro).toEqual(
|
||||
// intros[superBlock].blocks[randomBlock.meta.dashedName as string].intro
|
||||
// );
|
||||
// expect(superBlockData.blocks[randomBlockIndex].meta.name).toEqual(
|
||||
// intros[superBlock].blocks[randomBlock.meta.dashedName as string].title
|
||||
// );
|
||||
const blocks = superBlockData.blocks;
|
||||
|
||||
for (const block of blocks) {
|
||||
expect(block.intro).toEqual(
|
||||
intros[superBlock].blocks[block.meta.dashedName as string].intro
|
||||
);
|
||||
expect(block.meta.name).toEqual(
|
||||
intros[superBlock].blocks[block.meta.dashedName as string].title
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -244,22 +240,22 @@ describe('external curriculum data build', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// Temporary skip these checks to keep CI stable.
|
||||
// TODO: uncomment these once https://github.com/freeCodeCamp/freeCodeCamp/issues/60660 is completed.
|
||||
for (const chapter of superBlockData.chapters) {
|
||||
if (chapter.comingSoon) continue;
|
||||
|
||||
// Check block data
|
||||
// expect(
|
||||
// superBlockData.chapters[randomChapterIndex].modules[randomModuleIndex]
|
||||
// .blocks[randomBlockIndex].intro
|
||||
// ).toEqual(
|
||||
// superBlockIntros.blocks[randomBlock.meta.dashedName as string].intro
|
||||
// );
|
||||
// expect(
|
||||
// superBlockData.chapters[randomChapterIndex].modules[randomModuleIndex]
|
||||
// .blocks[randomBlockIndex].meta.name
|
||||
// ).toEqual(
|
||||
// superBlockIntros.blocks[randomBlock.meta.dashedName as string].title
|
||||
// );
|
||||
for (const module of chapter.modules) {
|
||||
if (module.comingSoon) continue;
|
||||
|
||||
for (const block of module.blocks) {
|
||||
expect(block.intro).toEqual(
|
||||
superBlockIntros.blocks[block.meta.dashedName as string].intro
|
||||
);
|
||||
expect(block.meta.name).toEqual(
|
||||
superBlockIntros.blocks[block.meta.dashedName as string].title
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -376,9 +376,15 @@ export function buildExtCurriculumDataV2(
|
||||
.filter(block => blocksWithData[block])
|
||||
.map(block => {
|
||||
const blockData = blocksWithData[block];
|
||||
const blockIntro = superBlockIntros.blocks[block];
|
||||
return {
|
||||
intro: superBlockIntros.blocks[block].intro,
|
||||
meta: omit(blockData.meta, ['chapter', 'module'])
|
||||
intro: blockIntro.intro,
|
||||
// Keep `meta.name` for backward compatibility with
|
||||
// consumers that have not migrated to intro-based titles.
|
||||
meta: {
|
||||
...omit(blockData.meta, ['chapter', 'module']),
|
||||
name: blockIntro.title
|
||||
}
|
||||
};
|
||||
})
|
||||
}))
|
||||
@@ -398,10 +404,13 @@ export function buildExtCurriculumDataV2(
|
||||
const blockNames = Object.keys(curriculum[superBlockKey].blocks);
|
||||
const blocks = blockNames.map(blockName => {
|
||||
const blockData = curriculum[superBlockKey].blocks[blockName];
|
||||
const blockIntro = intros[superBlockKey].blocks[blockName];
|
||||
|
||||
return {
|
||||
intro: intros[superBlockKey].blocks[blockName].intro,
|
||||
meta: blockData.meta
|
||||
intro: blockIntro.intro,
|
||||
// Keep `meta.name` for backward compatibility with
|
||||
// consumers that have not migrated to intro-based titles.
|
||||
meta: { ...blockData.meta, name: blockIntro.title }
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const CURRICULUM_PATH = '../../../curriculum/generated/curriculum.json';
|
||||
// const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
// Curriculum is read using fs, because it is too large for VSCode's LSP to handle type inference which causes annoying behavior.
|
||||
const curriculum = JSON.parse(
|
||||
readFileSync(join(__dirname, CURRICULUM_PATH), 'utf-8')
|
||||
);
|
||||
|
||||
import { getCurriculum } from '../get-curriculum';
|
||||
import {
|
||||
buildExtCurriculumDataV2,
|
||||
Curriculum as CurriculumV2,
|
||||
@@ -24,5 +15,5 @@ if (isSelectiveBuild) {
|
||||
'Skipping external curriculum build (selective build mode active)'
|
||||
);
|
||||
} else {
|
||||
buildExtCurriculumDataV2(curriculum as CurriculumV2<CurriculumPropsV2>);
|
||||
buildExtCurriculumDataV2(getCurriculum() as CurriculumV2<CurriculumPropsV2>);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const CURRICULUM_PATH = '../../curriculum/generated/curriculum.json';
|
||||
|
||||
// Curriculum is read using fs, because it is too large for VSCode's LSP to handle type inference which causes annoying behavior.
|
||||
export const getCurriculum = () =>
|
||||
JSON.parse(readFileSync(join(__dirname, CURRICULUM_PATH), 'utf-8'));
|
||||
Reference in New Issue
Block a user