feat: get footer from cdn (#47174)

Co-authored-by: ahmad abdolsaheb <ahmad.abdolsaheb@gmail.com>
Co-authored-by: scissorsneedfoodtoo <scissorsneedfoodtoo@gmail.com>
This commit is contained in:
Tom
2022-12-01 08:23:17 -06:00
committed by GitHub
parent 2325cc5ee9
commit 60d15e4631
19 changed files with 1926 additions and 6916 deletions

View File

@@ -0,0 +1,47 @@
import { writeFileSync } from 'fs';
import fetch from 'node-fetch';
import yaml from 'js-yaml';
import { trendingSchemaValidator } from '../../../client/i18n/schema/trendingSchema';
import envData from '../../../config/env.json';
const { clientLocale } = envData;
const createCdnUrl = (lang: string) =>
`https://cdn.freecodecamp.org/universal/trending/${lang}.yaml`;
const download = async () => {
const url = createCdnUrl(clientLocale);
const res = await fetch(url);
if (!res.ok) {
throw new Error(
`
----------------------------------------------------
Error: The CDN is missing the trending YAML file.
----------------------------------------------------
Unable to fetch the ${clientLocale} footer: ${res.statusText}
`
);
}
const data = await res.text();
const trendingJSON = JSON.stringify(yaml.load(data));
const trendingLocation = `./client/i18n/locales/${clientLocale}/trending.json`;
writeFileSync(trendingLocation, trendingJSON);
const trendingObject = JSON.parse(trendingJSON) as Record<string, string>;
const validationError =
(trendingSchemaValidator(trendingObject).error as Error) || null;
if (validationError) {
throw new Error(
`
----------------------------------------------------
Error: The trending JSON is invalid.
----------------------------------------------------
Unable to validate the ${clientLocale} trending JSON schema: ${validationError.message}
`
);
}
};
void download();

View File

@@ -19,8 +19,10 @@
"author": "freeCodeCamp <team@freecodecamp.org>",
"main": "none",
"devDependencies": {
"@types/js-yaml": "4.0.5",
"debug": "4.3.2",
"dotenv": "16.0.3",
"js-yaml": "4.1.0",
"readdirp": "3.6.0"
}
}