Files
freeCodeCamp/tools/challenge-helper-scripts/update-challenge-order.ts
Jeevankumar S e72a5dc1bb refactor(tools) : migrate inquirer prompts (#66139)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Sem Bauke <sem@freecodecamp.org>
2026-03-05 13:04:01 +01:00

51 lines
1.5 KiB
TypeScript

import { select, confirm } from '@inquirer/prompts';
import { getMetaData, updateMetaData } from './helpers/project-metadata.js';
const updateChallengeOrder = async () => {
const oldChallengeOrder = getMetaData().challengeOrder;
console.log('Current challenge order is: ');
console.table(oldChallengeOrder.map(({ title }) => ({ title })));
const newChallengeOrder: { id: string; title: string }[] = [];
while (oldChallengeOrder.length) {
const nextChallengeId = await select<string>({
message: newChallengeOrder.length
? `What challenge comes after ${
newChallengeOrder[newChallengeOrder.length - 1].title
}?`
: 'What is the first challenge?',
choices: oldChallengeOrder.map(({ id, title }) => ({
name: title,
value: id
}))
});
const nextChallengeIndex = oldChallengeOrder.findIndex(
({ id }) => id === nextChallengeId
);
const targetChallenge = oldChallengeOrder[nextChallengeIndex];
oldChallengeOrder.splice(nextChallengeIndex, 1);
newChallengeOrder.push(targetChallenge);
}
console.log('New challenge order is: ');
console.table(newChallengeOrder.map(({ title }) => ({ title })));
const isCorrect = await confirm({
message: 'Is this correct?',
default: false
});
if (!isCorrect) {
console.error('Aborting.');
return;
}
const meta = getMetaData();
meta.challengeOrder = newChallengeOrder;
await updateMetaData(meta);
};
void (async () => await updateChallengeOrder())();