feat(client): ts-migrate client/utils/** (#42823)

* rename js files

* update imports and references

* migrate build-challenges

* migrate challenge-types

* migrate utils/index

* migrate state-management

* install @types/psl for tags

* migrate tags

* migrate tags.test

* migrate challenge-page-creator

* migrate utils/gatsby/index

* migrate layout-selector

* migrate layout-selector.test

* revert challenge-types

Curriculum can't handle TS or modules

* convert arrow functions

* revert build-challenges

* revert utils/gatsby/index

* revert challenge-page-creator

* revert challenge-types reference

* Delete state-management

Deleted in #42960

* Disable render-result-naming-convention (for now)

* update layout-selector.test comment

* reorder imports in build-challenges

* change ts-ignore to ts-expect-error
This commit is contained in:
awu43
2021-08-09 01:30:31 -07:00
committed by GitHub
parent fcadd534e7
commit dd5d2919be
23 changed files with 116 additions and 83 deletions

View File

@ -0,0 +1,53 @@
const path = require('path');
const _ = require('lodash');
const envData = require('../../config/env.json');
const {
getChallengesForLang,
createChallenge,
challengesDir,
getChallengesDirForLang
} = require('../../curriculum/getChallenges');
const { curriculumLocale } = envData;
exports.localeChallengesRootDir = getChallengesDirForLang(curriculumLocale);
exports.replaceChallengeNode = () => {
return async function replaceChallengeNode(filePath) {
// get the meta so that challengeOrder is accurate
const blockNameRe = /\d\d-[-\w]+\/([^/]+)\//;
const posix = path.normalize(filePath).split(path.sep).join(path.posix.sep);
const blockName = posix.match(blockNameRe)[1];
const metaPath = path.resolve(
__dirname,
`../../curriculum/challenges/_meta/${blockName}/meta.json`
);
delete require.cache[require.resolve(metaPath)];
const meta = require(metaPath);
return await createChallenge(
challengesDir,
filePath,
curriculumLocale,
meta
);
};
};
exports.buildChallenges = async function buildChallenges() {
const curriculum = await getChallengesForLang(curriculumLocale);
const superBlocks = Object.keys(curriculum);
const blocks = superBlocks
.map(superBlock => curriculum[superBlock].blocks)
.reduce((blocks, superBlock) => {
const currentBlocks = Object.keys(superBlock).map(key => superBlock[key]);
return blocks.concat(_.flatten(currentBlocks));
}, []);
const builtChallenges = blocks
.filter(block => !block.isPrivate)
.map(({ challenges }) => challenges)
.reduce((accu, current) => accu.concat(current), []);
return builtChallenges;
};