refactor: migrate (some) curriculum files to TypeScript (#62228)

Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
This commit is contained in:
Oliver Eyton-Williams
2025-10-23 07:24:57 +02:00
committed by GitHub
parent 0d44fff1ff
commit 4a635c1b32
62 changed files with 909 additions and 582 deletions
+40
View File
@@ -0,0 +1,40 @@
// TypeScript declaration file for challenge-parser/parser
// This module exports functions to parse challenge markdown files
type ChallengeFile = {
name: string;
contents: string;
ext: string;
editableRegionBoundaries: number[];
head?: string;
tail?: string;
};
export interface ParsedChallenge {
id: string;
title: string;
challengeType: number;
description?: string;
instructions?: string;
questions?: string[];
challengeFiles?: ChallengeFile[];
solutions?: {
contents: string;
ext: string;
name: string;
}[][];
[key: string]: unknown; // Allow for additional properties that may be added by plugins
}
/**
* Parses a markdown challenge file asynchronously
* @param filename - Path to the markdown file to parse
* @returns Promise that resolves to the parsed challenge data
*/
export function parseMD(filename: string): Promise<ParsedChallenge>;
/**
* Parses a markdown challenge file synchronously
* @param filename - Path to the markdown file to parse
* @returns The parsed challenge data
*/
export function parseMDSync(filename: string): ParsedChallenge;
+40
View File
@@ -0,0 +1,40 @@
export interface ChallengeFile {
contents: string;
ext: string;
name: string;
}
export interface Challenge {
id: string;
title: string;
challengeFiles?: ChallengeFile[];
[key: string]: unknown;
}
export interface CommentDictionary {
[comment: string]: {
[lang: string]: string;
};
}
export function translateComments(
text: string,
lang: string,
dict: CommentDictionary,
codeLang: string
): { text: string };
export function translateCommentsInChallenge(
challenge: Challenge,
lang: string,
dict: CommentDictionary
): Challenge;
export function translateGeneric(
input: { text: string },
config: {
knownComments: string[];
dict: CommentDictionary;
lang: string;
}
): { text: string };
@@ -20,7 +20,9 @@ exports.translateCommentsInChallenge = (challenge, lang, dict) => {
if (challClone?.challengeFiles) {
challClone.challengeFiles.forEach(challengeFile => {
if (challengeFile.contents) {
let { text } = this.translateComments(
// It cannot be this.translateComments because 'this' does not exist
// when imported into an ES module.
let { text } = exports.translateComments(
challengeFile.contents,
lang,
dict,