remove unused challenge utils
This commit is contained in:
@ -1,12 +1,5 @@
|
|||||||
var path = require('path'),
|
var cheerio = require('cheerio'),
|
||||||
// debug = require('debug')('freecc:cntr:resources'),
|
|
||||||
cheerio = require('cheerio'),
|
|
||||||
request = require('request'),
|
request = require('request'),
|
||||||
R = require('ramda'),
|
|
||||||
_ = require('lodash'),
|
|
||||||
fs = require('fs'),
|
|
||||||
|
|
||||||
|
|
||||||
MDNlinks = require('../../seed/bonfireMDNlinks'),
|
MDNlinks = require('../../seed/bonfireMDNlinks'),
|
||||||
resources = require('./resources.json'),
|
resources = require('./resources.json'),
|
||||||
nonprofits = require('../../seed/nonprofits.json');
|
nonprofits = require('../../seed/nonprofits.json');
|
||||||
@ -14,33 +7,7 @@ var path = require('path'),
|
|||||||
/**
|
/**
|
||||||
* Cached values
|
* Cached values
|
||||||
*/
|
*/
|
||||||
var allNonprofitNames,
|
var allNonprofitNames;
|
||||||
challengeMap, challengeMapForDisplay, challengeMapWithIds,
|
|
||||||
challengeMapWithNames, allChallengeIds,
|
|
||||||
challengeMapWithDashedNames;
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
if (!challengeMap) {
|
|
||||||
var localChallengeMap = {};
|
|
||||||
var files = fs.readdirSync(
|
|
||||||
path.join(__dirname, '../../seed/challenges')
|
|
||||||
);
|
|
||||||
var keyCounter = 0;
|
|
||||||
files = files.map(function(file) {
|
|
||||||
return require(
|
|
||||||
path.join(__dirname, '../../seed/challenges/' + file)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
files = files.sort(function(a, b) {
|
|
||||||
return a.order - b.order;
|
|
||||||
});
|
|
||||||
files.forEach(function(file) {
|
|
||||||
localChallengeMap[keyCounter++] = file;
|
|
||||||
});
|
|
||||||
challengeMap = _.cloneDeep(localChallengeMap);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
dasherize: function dasherize(name) {
|
dasherize: function dasherize(name) {
|
||||||
@ -59,75 +26,6 @@ module.exports = {
|
|||||||
.trim();
|
.trim();
|
||||||
},
|
},
|
||||||
|
|
||||||
getChallengeMapForDisplay: function() {
|
|
||||||
if (!challengeMapForDisplay) {
|
|
||||||
challengeMapForDisplay = {};
|
|
||||||
Object.keys(challengeMap).forEach(function(key) {
|
|
||||||
challengeMapForDisplay[key] = {
|
|
||||||
name: challengeMap[key].title,
|
|
||||||
dashedName: challengeMap[key].title.replace(/\s/g, '-'),
|
|
||||||
challenges: challengeMap[key].challenges,
|
|
||||||
completedCount: challengeMap[key].challenges
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return challengeMapForDisplay;
|
|
||||||
},
|
|
||||||
|
|
||||||
getChallengeMapWithIds: function() {
|
|
||||||
if (!challengeMapWithIds) {
|
|
||||||
challengeMapWithIds = {};
|
|
||||||
Object.keys(challengeMap).forEach(function(key) {
|
|
||||||
var onlyIds = challengeMap[key].challenges.map(function(elem) {
|
|
||||||
return elem.id;
|
|
||||||
});
|
|
||||||
challengeMapWithIds[key] = onlyIds;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return challengeMapWithIds;
|
|
||||||
},
|
|
||||||
|
|
||||||
allChallengeIds: function() {
|
|
||||||
|
|
||||||
if (!allChallengeIds) {
|
|
||||||
allChallengeIds = [];
|
|
||||||
Object.keys(this.getChallengeMapWithIds()).forEach(function(key) {
|
|
||||||
allChallengeIds.push(challengeMapWithIds[key]);
|
|
||||||
});
|
|
||||||
allChallengeIds = R.flatten(allChallengeIds);
|
|
||||||
}
|
|
||||||
return allChallengeIds;
|
|
||||||
},
|
|
||||||
|
|
||||||
getChallengeMapWithNames: function() {
|
|
||||||
if (!challengeMapWithNames) {
|
|
||||||
challengeMapWithNames = {};
|
|
||||||
Object.keys(challengeMap).
|
|
||||||
forEach(function(key) {
|
|
||||||
var onlyNames = challengeMap[key].challenges.map(function(elem) {
|
|
||||||
return elem.name;
|
|
||||||
});
|
|
||||||
challengeMapWithNames[key] = onlyNames;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return challengeMapWithNames;
|
|
||||||
},
|
|
||||||
|
|
||||||
getChallengeMapWithDashedNames: function() {
|
|
||||||
if (!challengeMapWithDashedNames) {
|
|
||||||
challengeMapWithDashedNames = {};
|
|
||||||
Object.keys(challengeMap).
|
|
||||||
forEach(function(key) {
|
|
||||||
var onlyNames = challengeMap[key].challenges.map(function(elem) {
|
|
||||||
return elem.dashedName;
|
|
||||||
});
|
|
||||||
challengeMapWithDashedNames[key] = onlyNames;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return challengeMapWithDashedNames;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
randomPhrase: function() {
|
randomPhrase: function() {
|
||||||
return resources.phrases[
|
return resources.phrases[
|
||||||
Math.floor(Math.random() * resources.phrases.length)
|
Math.floor(Math.random() * resources.phrases.length)
|
||||||
|
Reference in New Issue
Block a user