chore: create renaming script (#44692)

pull/44707/head
Nicholas Carrigan (he/him) 2022-01-06 23:50:48 -08:00 committed by GitHub
parent ca09b941ea
commit 08ad03e051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
const { readdir, readFile } = require('fs').promises;
const { join } = require('path');
const gray = require('gray-matter');
const { exec } = require('child_process');
const { promisify } = require('util');
/**
* 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`
);
}
}
})();