chore: remove challenge seeding
This commit is contained in:
@ -53,7 +53,7 @@
|
|||||||
"postinstall": "npm run bootstrap",
|
"postinstall": "npm run bootstrap",
|
||||||
"seed": "npm-run-all -p seed:*",
|
"seed": "npm-run-all -p seed:*",
|
||||||
"seed:auth-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser",
|
"seed:auth-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser",
|
||||||
"seed:challenges": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedChallenges",
|
"seed:path-migration": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/create-path-migration",
|
||||||
"serve:client": "cd ./client && npm run serve",
|
"serve:client": "cd ./client && npm run serve",
|
||||||
"start": "npm-run-all ensure-env -p develop:server serve:client",
|
"start": "npm-run-all ensure-env -p develop:server serve:client",
|
||||||
"test": "npm-run-all -p test:*",
|
"test": "npm-run-all -p test:*",
|
||||||
|
27
tools/scripts/seed/create-path-migration.js
Normal file
27
tools/scripts/seed/create-path-migration.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
|
||||||
|
const debug = require('debug');
|
||||||
|
|
||||||
|
const { getChallengesForLang } = require('../../../curriculum/getChallenges');
|
||||||
|
const { createPathMigrationMap } = require('./createPathMigrationMap');
|
||||||
|
|
||||||
|
const log = debug('fcc:tools:seedChallenges');
|
||||||
|
const { LOCALE: lang = 'english' } = process.env;
|
||||||
|
|
||||||
|
getChallengesForLang(lang).then(curriculum => {
|
||||||
|
log('generating path migration map');
|
||||||
|
const pathMap = createPathMigrationMap(curriculum);
|
||||||
|
const outputDir = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
'../../../api-server/server/resources/pathMigration.json'
|
||||||
|
);
|
||||||
|
fs.writeFile(outputDir, JSON.stringify(pathMap), err => {
|
||||||
|
if (err) {
|
||||||
|
console.error('failed to save pathMigration');
|
||||||
|
console.error(err);
|
||||||
|
} else {
|
||||||
|
log('path migration map generated');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
@ -1,86 +0,0 @@
|
|||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
|
|
||||||
const { MongoClient, ObjectID } = require('mongodb');
|
|
||||||
const { flatten } = require('lodash');
|
|
||||||
const debug = require('debug');
|
|
||||||
|
|
||||||
const { getChallengesForLang } = require('../../../curriculum/getChallenges');
|
|
||||||
const { createPathMigrationMap } = require('./createPathMigrationMap');
|
|
||||||
|
|
||||||
const log = debug('fcc:tools:seedChallenges');
|
|
||||||
const { MONGOHQ_URL, LOCALE: lang = 'english' } = process.env;
|
|
||||||
|
|
||||||
function handleError(err, client) {
|
|
||||||
if (err) {
|
|
||||||
console.error('Oh noes!!');
|
|
||||||
console.error(err);
|
|
||||||
try {
|
|
||||||
client.close();
|
|
||||||
} catch (e) {
|
|
||||||
// no-op
|
|
||||||
} finally {
|
|
||||||
/* eslint-disable-next-line no-process-exit */
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MongoClient.connect(MONGOHQ_URL, { useNewUrlParser: true }, function(
|
|
||||||
err,
|
|
||||||
client
|
|
||||||
) {
|
|
||||||
handleError(err, client);
|
|
||||||
|
|
||||||
log('Connected successfully to mongo at %s', MONGOHQ_URL);
|
|
||||||
|
|
||||||
const db = client.db('freecodecamp');
|
|
||||||
const challengeCollection = db.collection('challenge');
|
|
||||||
|
|
||||||
challengeCollection.deleteMany({}, async err => {
|
|
||||||
handleError(err, client);
|
|
||||||
|
|
||||||
log('deleted all the challenges');
|
|
||||||
|
|
||||||
const curriculum = await getChallengesForLang(lang);
|
|
||||||
|
|
||||||
const allChallenges = Object.keys(curriculum)
|
|
||||||
.map(key => curriculum[key].blocks)
|
|
||||||
.reduce((challengeArray, superBlock) => {
|
|
||||||
const challengesForBlock = Object.keys(superBlock).map(
|
|
||||||
key => superBlock[key].challenges
|
|
||||||
);
|
|
||||||
return [...challengeArray, ...flatten(challengesForBlock)];
|
|
||||||
}, [])
|
|
||||||
.map(challenge => {
|
|
||||||
const currentId = challenge.id.slice(0);
|
|
||||||
challenge._id = ObjectID(currentId);
|
|
||||||
delete challenge.id;
|
|
||||||
return challenge;
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
challengeCollection.insertMany(allChallenges, { ordered: false }, err => {
|
|
||||||
handleError(err, client);
|
|
||||||
log('challenge seed complete');
|
|
||||||
client.close();
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
handleError(e, client);
|
|
||||||
} finally {
|
|
||||||
log('generating path migration map');
|
|
||||||
const pathMap = createPathMigrationMap(curriculum);
|
|
||||||
const outputDir = path.resolve(
|
|
||||||
__dirname,
|
|
||||||
'../../../api-server/server/resources/pathMigration.json'
|
|
||||||
);
|
|
||||||
fs.writeFile(outputDir, JSON.stringify(pathMap), err => {
|
|
||||||
if (err) {
|
|
||||||
console.error('Oh noes!!');
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
log('path migration map generated');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
Reference in New Issue
Block a user