feat: convert rename tool into proper utility (#52626)
parent
70c488a561
commit
80033f44ae
|
@ -69,6 +69,7 @@
|
|||
"preseed": "npm-run-all create:shared",
|
||||
"playwright:install-build-tools": "cd ./e2e && npm i && npx playwright install && npx playwright install-deps",
|
||||
"playwright:install-build-tools-linux": "sh ./playwright-install.sh",
|
||||
"rename-challenges": "ts-node tools/challenge-helper-scripts/rename-challenge-files.ts",
|
||||
"seed": "pnpm seed:surveys && pnpm seed:exams && cross-env DEBUG=fcc:* node ./tools/scripts/seed/seed-demo-user",
|
||||
"seed:certified-user": "pnpm seed:surveys && pnpm seed:exams && cross-env DEBUG=fcc:* node ./tools/scripts/seed/seed-demo-user certified-user",
|
||||
"seed:exams": "cross-env DEBUG=fcc:* node tools/scripts/seed-exams/create-exams",
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
const { readdir, readFile } = require('fs').promises;
|
||||
const { join } = require('path');
|
||||
const { exec } = require('child_process');
|
||||
const { promisify } = require('util');
|
||||
const gray = require('gray-matter');
|
||||
|
||||
/**
|
||||
* From the root directory, run the following CLI command to rename all RWD-22 challenge files:
|
||||
* node tools/challenge-helper-scripts/rename-challenge-files.js
|
||||
*/
|
||||
(async () => {
|
||||
const asyncExec = promisify(exec);
|
||||
const blocks = await readdir(
|
||||
join(
|
||||
process.cwd(),
|
||||
'curriculum/challenges/english/14-responsive-web-design-22'
|
||||
)
|
||||
);
|
||||
for (const block of blocks) {
|
||||
const files = await readdir(
|
||||
join(
|
||||
process.cwd(),
|
||||
`curriculum/challenges/english/14-responsive-web-design-22/${block}`
|
||||
)
|
||||
);
|
||||
for (const file of files) {
|
||||
const fileData = await readFile(
|
||||
join(
|
||||
process.cwd(),
|
||||
`curriculum/challenges/english/14-responsive-web-design-22/${block}/${file}`
|
||||
)
|
||||
);
|
||||
const challengeId = await gray(fileData).data.id;
|
||||
await asyncExec(
|
||||
`git mv curriculum/challenges/english/14-responsive-web-design-22/${block}/${file} curriculum/challenges/english/14-responsive-web-design-22/${block}/${challengeId}.md`
|
||||
);
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -0,0 +1,81 @@
|
|||
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 { prompt } from 'inquirer';
|
||||
|
||||
const asyncExec = promisify(exec);
|
||||
|
||||
void (async () => {
|
||||
const superblocks = await readdir(
|
||||
join(process.cwd(), 'curriculum', 'challenges', 'english')
|
||||
);
|
||||
|
||||
const { superblock } = (await prompt({
|
||||
name: 'superblock',
|
||||
message: 'Select target superblock:',
|
||||
type: 'list',
|
||||
choices: superblocks.map(e => ({ name: e, value: e }))
|
||||
})) as { superblock: string };
|
||||
|
||||
const blocks = await readdir(
|
||||
join(process.cwd(), 'curriculum', 'challenges', 'english', superblock)
|
||||
);
|
||||
|
||||
const { block } = (await prompt({
|
||||
name: 'block',
|
||||
message: 'Select target block:',
|
||||
type: 'list',
|
||||
choices: blocks.map(e => ({ name: e, value: e }))
|
||||
})) as { block: string };
|
||||
|
||||
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`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
})();
|
Loading…
Reference in New Issue