mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor(challenge-helper-scripts): update challengeLang type to ChallengeLang (#66243)
This commit is contained in:
@@ -7,7 +7,8 @@ import { ObjectId } from 'bson';
|
||||
import {
|
||||
SuperBlocks,
|
||||
languageSuperBlocks,
|
||||
chapterBasedSuperBlocks
|
||||
chapterBasedSuperBlocks,
|
||||
type ChallengeLang
|
||||
} from '@freecodecamp/shared/config/curriculum';
|
||||
|
||||
import { BlockLayouts, BlockLabel } from '@freecodecamp/shared/config/blocks';
|
||||
@@ -95,7 +96,7 @@ async function createLanguageBlock(
|
||||
moduleTitle
|
||||
});
|
||||
|
||||
const challengeLang = getLangFromSuperBlock(superBlock);
|
||||
const challengeLang: ChallengeLang = getLangFromSuperBlock(superBlock);
|
||||
const challengeId: ObjectId = new ObjectId();
|
||||
|
||||
await createMetaJson(
|
||||
@@ -241,7 +242,7 @@ async function createMetaJson(
|
||||
async function createDialogueChallenge(
|
||||
challengeId: ObjectId,
|
||||
block: string,
|
||||
challengeLang: string
|
||||
challengeLang: ChallengeLang
|
||||
): Promise<ObjectId> {
|
||||
const { blockContentDir } = getContentConfig('english') as {
|
||||
blockContentDir: string;
|
||||
@@ -262,7 +263,7 @@ async function createQuizChallenge(
|
||||
block: string,
|
||||
title: string,
|
||||
questionCount: number,
|
||||
challengeLang: string
|
||||
challengeLang: ChallengeLang
|
||||
): Promise<ObjectId> {
|
||||
return createQuizFile({
|
||||
challengeId,
|
||||
|
||||
@@ -17,7 +17,10 @@ const createNextTask = async () => {
|
||||
|
||||
const prevChallengeId =
|
||||
meta.challengeOrder[meta.challengeOrder.length - 1]?.id;
|
||||
const challengeLang = prevChallengeId && getChallenge(prevChallengeId)?.lang;
|
||||
|
||||
const challengeLang = prevChallengeId
|
||||
? getChallenge(prevChallengeId)?.lang
|
||||
: undefined;
|
||||
|
||||
const inputType = await getInputType(challengeType, challengeLang);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ObjectId } from 'bson';
|
||||
import type { ChallengeLang } from '@freecodecamp/shared/config/curriculum';
|
||||
|
||||
const sanitizeTitle = (title: string) => {
|
||||
return title.includes(':') || title.includes("'") ? `"${title}"` : title;
|
||||
@@ -10,7 +11,7 @@ interface ChallengeOptions {
|
||||
dashedName: string;
|
||||
challengeType: string;
|
||||
questionCount?: number;
|
||||
challengeLang?: string;
|
||||
challengeLang?: ChallengeLang;
|
||||
inputType?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { challengeTypes } from '@freecodecamp/shared/config/challenge-types';
|
||||
|
||||
export const getInputType = async (
|
||||
challengeType: string,
|
||||
challengeLang?: string
|
||||
challengeLang?: ChallengeLang
|
||||
): Promise<string | undefined> => {
|
||||
const isRequired =
|
||||
parseInt(challengeType) === challengeTypes.fillInTheBlank &&
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ObjectId } from 'bson';
|
||||
import { getStepTemplate } from './get-step-template.js';
|
||||
import { ChallengeLang } from '@freecodecamp/shared/config/curriculum';
|
||||
|
||||
const props = {
|
||||
challengeId: new ObjectId('60d4ebe4801158d1abe1b18f'),
|
||||
@@ -65,8 +66,11 @@ dashedName: step-5
|
||||
lang: es
|
||||
---`;
|
||||
|
||||
expect(getStepTemplate({ ...props, challengeLang: 'es' })).match(
|
||||
new RegExp(`^${frontMatter}`)
|
||||
);
|
||||
expect(
|
||||
getStepTemplate({
|
||||
...props,
|
||||
challengeLang: ChallengeLang.Spanish
|
||||
})
|
||||
).match(new RegExp(`^${frontMatter}`));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ObjectId } from 'bson';
|
||||
import type { ChallengeLang } from '@freecodecamp/shared/config/curriculum';
|
||||
import { insertErms } from './insert-erms.js';
|
||||
|
||||
// Builds a block
|
||||
@@ -25,7 +26,7 @@ type StepOptions = {
|
||||
stepNum: number;
|
||||
challengeType?: number;
|
||||
isFirstChallenge?: boolean;
|
||||
challengeLang?: string;
|
||||
challengeLang?: ChallengeLang;
|
||||
};
|
||||
|
||||
export interface ChallengeSeed {
|
||||
|
||||
@@ -5,6 +5,7 @@ import matter from 'gray-matter';
|
||||
import { uniq } from 'lodash';
|
||||
|
||||
import { challengeTypes } from '@freecodecamp/shared/config/challenge-types';
|
||||
import type { ChallengeLang } from '@freecodecamp/shared/config/curriculum';
|
||||
import { parseCurriculumStructure } from '@freecodecamp/curriculum/build-curriculum';
|
||||
import { parseMDSync } from '../challenge-parser/parser/index.js';
|
||||
import { getMetaData, updateMetaData } from './helpers/project-metadata.js';
|
||||
@@ -23,7 +24,7 @@ interface Options {
|
||||
projectPath?: string;
|
||||
challengeSeeds?: ChallengeSeed[];
|
||||
isFirstChallenge?: boolean;
|
||||
challengeLang?: string;
|
||||
challengeLang?: ChallengeLang;
|
||||
}
|
||||
|
||||
interface QuizOptions {
|
||||
@@ -32,7 +33,7 @@ interface QuizOptions {
|
||||
title: string;
|
||||
dashedName: string;
|
||||
questionCount: number;
|
||||
challengeLang?: string;
|
||||
challengeLang?: ChallengeLang;
|
||||
}
|
||||
|
||||
export async function getAllBlocks() {
|
||||
@@ -108,7 +109,7 @@ const createDialogueFile = ({
|
||||
}: {
|
||||
challengeId: ObjectId;
|
||||
projectPath: string;
|
||||
challengeLang: string;
|
||||
challengeLang: ChallengeLang;
|
||||
}): ObjectId => {
|
||||
const challengeType = challengeTypes.dialogue.toString();
|
||||
const template = getTemplate(challengeType);
|
||||
@@ -274,7 +275,7 @@ const updateTaskMarkdownFiles = (): void => {
|
||||
type Challenge = {
|
||||
challengeType: number;
|
||||
challengeFiles: ChallengeSeed[];
|
||||
lang?: string;
|
||||
lang?: ChallengeLang;
|
||||
};
|
||||
|
||||
const getChallenge = (challengeId: string): Challenge => {
|
||||
|
||||
Reference in New Issue
Block a user