2022-03-01 15:59:15 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
exports.buildMobileCurriculum = function buildMobileCurriculum(json) {
|
|
|
|
const mobileStaticPath = path.resolve(__dirname, '../../../client/static');
|
2022-03-22 20:11:44 +01:00
|
|
|
const blockIntroPath = path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../../../client/i18n/locales/english/intro.json'
|
|
|
|
);
|
2022-03-01 15:59:15 +01:00
|
|
|
|
|
|
|
fs.mkdirSync(`${mobileStaticPath}/mobile`, { recursive: true });
|
|
|
|
writeAndParseCurriculumJson(json);
|
|
|
|
|
|
|
|
function writeAndParseCurriculumJson(curriculum) {
|
|
|
|
const superBlockKeys = Object.keys(curriculum).filter(
|
2022-03-10 21:41:33 +01:00
|
|
|
key => key !== 'certifications'
|
2022-03-01 15:59:15 +01:00
|
|
|
);
|
|
|
|
|
2022-03-22 20:11:44 +01:00
|
|
|
writeToFile('availableSuperblocks', {
|
|
|
|
// removing "/" as it will create an extra sub-path when accessed via an endpoint
|
|
|
|
|
|
|
|
superblocks: [
|
|
|
|
superBlockKeys.map(key => key.replace(/\//, '-')),
|
|
|
|
getSuperBlockNames(superBlockKeys)
|
|
|
|
]
|
|
|
|
});
|
2022-03-01 15:59:15 +01:00
|
|
|
|
|
|
|
for (let i = 0; i < superBlockKeys.length; i++) {
|
|
|
|
const superBlock = {};
|
|
|
|
const blockNames = Object.keys(curriculum[superBlockKeys[i]].blocks);
|
|
|
|
|
|
|
|
if (blockNames.length === 0) continue;
|
|
|
|
|
|
|
|
superBlock[superBlockKeys[i]] = {};
|
|
|
|
superBlock[superBlockKeys[i]]['blocks'] = {};
|
|
|
|
|
|
|
|
for (let j = 0; j < blockNames.length; j++) {
|
|
|
|
superBlock[superBlockKeys[i]]['blocks'][blockNames[j]] = {};
|
2022-03-22 20:11:44 +01:00
|
|
|
|
|
|
|
superBlock[superBlockKeys[i]]['blocks'][blockNames[j]]['desc'] =
|
|
|
|
getBlockDescription(superBlockKeys[i], blockNames[j]);
|
|
|
|
|
2022-03-01 15:59:15 +01:00
|
|
|
superBlock[superBlockKeys[i]]['blocks'][blockNames[j]]['challenges'] =
|
|
|
|
curriculum[superBlockKeys[i]]['blocks'][blockNames[j]]['meta'];
|
|
|
|
}
|
|
|
|
|
2022-03-22 20:11:44 +01:00
|
|
|
writeToFile(superBlockKeys[i].replace(/\//, '-'), superBlock);
|
2022-03-01 15:59:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 20:11:44 +01:00
|
|
|
function getBlockDescription(superBlockKey, blockKey) {
|
|
|
|
const intros = JSON.parse(fs.readFileSync(blockIntroPath));
|
|
|
|
|
|
|
|
return intros[superBlockKey]['blocks'][blockKey]['intro'];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSuperBlockNames(superBlockKeys) {
|
|
|
|
const superBlocks = JSON.parse(fs.readFileSync(blockIntroPath));
|
|
|
|
|
|
|
|
return superBlockKeys.map(key => superBlocks[key].title);
|
|
|
|
}
|
|
|
|
|
|
|
|
function writeToFile(fileName, json) {
|
|
|
|
const fullPath = `${mobileStaticPath}/mobile/${fileName}.json`;
|
2022-03-10 21:41:33 +01:00
|
|
|
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
|
|
fs.writeFileSync(fullPath, JSON.stringify(json, null, 2));
|
2022-03-01 15:59:15 +01:00
|
|
|
}
|
|
|
|
};
|