MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / addMetaToChallenge

Function addMetaToChallenge

curriculum/src/build-superblock.ts:147–214  ·  view source on GitHub ↗
(
  challengeIn: Partial<Challenge>,
  meta: Meta
)

Source from the content-addressed store, hash-verified

145 * @returns {object} The challenge object with added meta information
146 */
147export function addMetaToChallenge(
148 challengeIn: Partial<Challenge>,
149 meta: Meta
150): Challenge {
151 const challenge = cloneDeep(challengeIn);
152
153 const challengeOrderIndex = meta.challengeOrder.findIndex(
154 ({ id }) => id === challenge.id
155 );
156
157 const isLastChallengeInBlock =
158 meta.challengeOrder.length - 1 === challengeOrderIndex;
159
160 // Add basic meta properties
161 challenge.block = meta.dashedName;
162 challenge.blockLabel = meta.blockLabel;
163 challenge.blockLayout = meta.blockLayout;
164 challenge.hasEditableBoundaries = !!meta.hasEditableBoundaries;
165 challenge.order = meta.order;
166
167 // Ensure required properties exist
168 if (!challenge.description) challenge.description = '';
169 if (!challenge.instructions) challenge.instructions = '';
170 if (!challenge.questions) challenge.questions = [];
171
172 // Set superblock-related properties
173 challenge.superBlock = meta.superBlock;
174 challenge.superOrder = meta.superOrder;
175 challenge.challengeOrder = challengeOrderIndex;
176 challenge.isLastChallengeInBlock = isLastChallengeInBlock;
177 challenge.required = (meta.required || []).concat(challenge.required || []);
178 challenge.template = meta.template;
179 challenge.helpCategory = challenge.helpCategory || meta.helpCategory;
180 challenge.usesMultifileEditor = !!meta.usesMultifileEditor;
181 challenge.disableLoopProtectTests = !!meta.disableLoopProtectTests;
182 challenge.disableLoopProtectPreview = !!meta.disableLoopProtectPreview;
183
184 // Add chapter and module if present in meta
185 if (meta.chapter) challenge.chapter = meta.chapter;
186 if (meta.module) challenge.module = meta.module;
187
188 // Handle certification field for legacy support
189 const dupeCertifications = [
190 {
191 certification: 'responsive-web-design',
192 dupe: '2022/responsive-web-design'
193 }
194 ];
195 const hasDupe = dupeCertifications.find(
196 cert => cert.dupe === meta.superBlock
197 );
198
199 const maybeCert = (
200 hasDupe ? hasDupe.certification : meta.superBlock
201 ) as Certification;
202
203 challenge.certification = maybeCert;
204 // TODO: reimplement after updating the client to expect Certification | null

Callers 2

finalizeChallengeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected