refactor: acceptedLanguage -> supported

This commit is contained in:
Oliver Eyton-Williams
2020-08-28 12:21:44 +02:00
parent 1f530602ba
commit 34f2c4ae32

View File

@ -15,6 +15,7 @@ const { isAuditedCert } = require('../utils/is-audited');
const { dasherize, nameify } = require('../utils/slugs'); const { dasherize, nameify } = require('../utils/slugs');
const { createPoly } = require('../utils/polyvinyl'); const { createPoly } = require('../utils/polyvinyl');
const { blockNameify } = require('../utils/block-nameify'); const { blockNameify } = require('../utils/block-nameify');
const { supportedLangs } = require('./utils');
const challengesDir = path.resolve(__dirname, './challenges'); const challengesDir = path.resolve(__dirname, './challenges');
const metaDir = path.resolve(challengesDir, '_meta'); const metaDir = path.resolve(challengesDir, '_meta');
@ -137,7 +138,7 @@ async function createChallenge(fullPath, maybeMeta) {
} }
const { name: superBlock } = superBlockInfoFromFullPath(fullPath); const { name: superBlock } = superBlockInfoFromFullPath(fullPath);
const lang = getChallengeLang(fullPath); const lang = getChallengeLang(fullPath);
if (!isAcceptedLanguage(lang)) if (!supportedLangs.includes(lang))
throw Error(`${lang} is not a accepted language. throw Error(`${lang} is not a accepted language.
Trying to parse ${fullPath}`); Trying to parse ${fullPath}`);
// assumes superblock names are unique // assumes superblock names are unique
@ -236,8 +237,8 @@ function getEnglishPath(fullPath) {
.join(path.posix.sep); .join(path.posix.sep);
const match = posix.match(/(.*curriculum\/challenges\/)([^/]*)(.*)(\2)(.*)/); const match = posix.match(/(.*curriculum\/challenges\/)([^/]*)(.*)(\2)(.*)/);
const lang = getChallengeLang(fullPath); const lang = getChallengeLang(fullPath);
if (!isAcceptedLanguage(lang)) if (!supportedLangs.includes(lang))
throw Error(`${getChallengeLang(fullPath)} is not a accepted language. throw Error(`${lang} is not a accepted language.
Trying to parse ${fullPath}`); Trying to parse ${fullPath}`);
if (match) { if (match) {
return path.join(match[1], 'english', match[3] + 'english' + match[5]); return path.join(match[1], 'english', match[3] + 'english' + match[5]);
@ -258,11 +259,6 @@ function isEnglishChallenge(fullPath) {
return getChallengeLang(fullPath) === 'english'; return getChallengeLang(fullPath) === 'english';
} }
function isAcceptedLanguage(lang) {
const acceptedLanguages = ['english', 'chinese'];
return acceptedLanguages.includes(lang);
}
exports.getChallengeLang = getChallengeLang; exports.getChallengeLang = getChallengeLang;
exports.getEnglishPath = getEnglishPath; exports.getEnglishPath = getEnglishPath;
exports.isEnglishChallenge = isEnglishChallenge; exports.isEnglishChallenge = isEnglishChallenge;