mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(tools): make the editing steps tool keep the challenge type (#54308)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import fs from 'fs';
|
||||
import { SuperBlocks } from '../../shared/config/superblocks';
|
||||
import { challengeTypes } from '../../shared/config/challenge-types';
|
||||
import { getProjectPath } from './helpers/get-project-info';
|
||||
import { getMetaData, updateMetaData } from './helpers/project-metadata';
|
||||
import { getChallengeOrderFromFileTree } from './helpers/get-challenge-order';
|
||||
@@ -39,6 +41,12 @@ function insertStep(stepNum: number): void {
|
||||
throw `Step not inserted. New step number must be less than ${
|
||||
challengeOrder.length + 2
|
||||
}.`;
|
||||
const challengeType = [
|
||||
SuperBlocks.SciCompPy,
|
||||
SuperBlocks.UpcomingPython
|
||||
].includes(getMetaData().superBlock)
|
||||
? challengeTypes.python
|
||||
: challengeTypes.html;
|
||||
|
||||
const challengeSeeds =
|
||||
stepNum > 1
|
||||
@@ -49,6 +57,7 @@ function insertStep(stepNum: number): void {
|
||||
|
||||
const stepId = createStepFile({
|
||||
stepNum,
|
||||
challengeType,
|
||||
challengeSeeds
|
||||
});
|
||||
|
||||
@@ -63,9 +72,15 @@ function createEmptySteps(num: number): void {
|
||||
}
|
||||
|
||||
const nextStepNum = getMetaData().challengeOrder.length + 1;
|
||||
const challengeType = [
|
||||
SuperBlocks.SciCompPy,
|
||||
SuperBlocks.UpcomingPython
|
||||
].includes(getMetaData().superBlock)
|
||||
? challengeTypes.python
|
||||
: challengeTypes.html;
|
||||
|
||||
for (let stepNum = nextStepNum; stepNum < nextStepNum + num; stepNum++) {
|
||||
const stepId = createStepFile({ stepNum });
|
||||
const stepId = createStepFile({ stepNum, challengeType });
|
||||
insertStepIntoMeta({ stepNum, stepId });
|
||||
}
|
||||
console.log(`Successfully added ${num} steps`);
|
||||
|
||||
@@ -164,6 +164,7 @@ async function createFirstChallenge(
|
||||
return createStepFile({
|
||||
projectPath: newChallengeDir + '/',
|
||||
stepNum: 1,
|
||||
challengeType: 0,
|
||||
challengeSeeds
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ Test 1
|
||||
tail: ''
|
||||
}
|
||||
},
|
||||
stepNum: 5
|
||||
stepNum: 5,
|
||||
challengeType: 0
|
||||
};
|
||||
|
||||
expect(getStepTemplate(props)).toEqual(baseOutput);
|
||||
|
||||
@@ -24,6 +24,7 @@ type StepOptions = {
|
||||
challengeId: ObjectID;
|
||||
challengeSeeds: Record<string, ChallengeSeed>;
|
||||
stepNum: number;
|
||||
challengeType: number;
|
||||
};
|
||||
|
||||
export interface ChallengeSeed {
|
||||
@@ -38,7 +39,8 @@ export interface ChallengeSeed {
|
||||
function getStepTemplate({
|
||||
challengeId,
|
||||
challengeSeeds,
|
||||
stepNum
|
||||
stepNum,
|
||||
challengeType
|
||||
}: StepOptions): string {
|
||||
const seedTexts = Object.values(challengeSeeds)
|
||||
.map(({ contents, ext, editableRegionBoundaries }: ChallengeSeed) => {
|
||||
@@ -69,7 +71,7 @@ function getStepTemplate({
|
||||
`---
|
||||
id: ${challengeId.toString()}
|
||||
title: Step ${stepNum}
|
||||
challengeType: 0
|
||||
challengeType: ${challengeType}
|
||||
dashedName: step-${stepNum}
|
||||
---
|
||||
|
||||
|
||||
@@ -55,7 +55,8 @@ describe('Challenge utils helper scripts', () => {
|
||||
);
|
||||
process.env.CALLING_DIR = projectPath;
|
||||
const step = createStepFile({
|
||||
stepNum: 3
|
||||
stepNum: 3,
|
||||
challengeType: 0
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
|
||||
@@ -13,12 +13,14 @@ import {
|
||||
|
||||
interface Options {
|
||||
stepNum: number;
|
||||
challengeType: number;
|
||||
projectPath?: string;
|
||||
challengeSeeds?: Record<string, ChallengeSeed>;
|
||||
}
|
||||
|
||||
const createStepFile = ({
|
||||
stepNum,
|
||||
challengeType,
|
||||
projectPath = getProjectPath(),
|
||||
challengeSeeds = {}
|
||||
}: Options): ObjectID => {
|
||||
@@ -27,7 +29,8 @@ const createStepFile = ({
|
||||
const template = getStepTemplate({
|
||||
challengeId,
|
||||
challengeSeeds,
|
||||
stepNum
|
||||
stepNum,
|
||||
challengeType
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
|
||||
Reference in New Issue
Block a user