Files
freecodecamp--freecodecamp/tools/challenge-helper-scripts/rename-challenge-files.ts
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

78 lines
1.7 KiB
TypeScript

import { exec } from 'child_process';
import { readFile, readdir } from 'fs/promises';
import { join } from 'path';
import { promisify } from 'util';
import gray from 'gray-matter';
import { select } from '@inquirer/prompts';
const asyncExec = promisify(exec);
void (async () => {
const superblocks = await readdir(
join(process.cwd(), 'curriculum', 'challenges', 'english')
);
const superblock = await select<string>({
message: 'Select target superblock:',
choices: superblocks.map(value => ({ name: value, value }))
});
const blocks = await readdir(
join(process.cwd(), 'curriculum', 'challenges', 'english', superblock)
);
const block = await select<string>({
message: 'Select target block:',
choices: blocks.map(value => ({ name: value, value }))
});
const files = await readdir(
join(
process.cwd(),
'curriculum',
'challenges',
'english',
superblock,
block
)
);
console.log(`Processing ${files.length} files.`);
for (const file of files) {
const fileData = await readFile(
join(
process.cwd(),
'curriculum',
'challenges',
'english',
superblock,
block,
file
)
);
const challengeId = (await gray(fileData).data.id) as string;
if (`${challengeId}.md` === file) {
console.warn(`${file} already has the correct name. Skipping.`);
continue;
}
await asyncExec(
`git mv ${join(
'curriculum',
'challenges',
'english',
superblock,
block,
file
)} ${join(
'curriculum',
'challenges',
'english',
superblock,
block,
`${challengeId}.md`
)}`
);
}
})();