Merge pull request #4279 from FreeCodeCamp/feature/challenge-dev-mode
Feature in dev mode always pull from disk
This commit is contained in:
@ -54,6 +54,10 @@
|
|||||||
"default": [],
|
"default": [],
|
||||||
"description": "prepended to user code"
|
"description": "prepended to user code"
|
||||||
},
|
},
|
||||||
|
"fileName": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "filename challenge comes from. Used in dev mode"
|
||||||
|
},
|
||||||
"challengeSeed": {
|
"challengeSeed": {
|
||||||
"type": "array"
|
"type": "array"
|
||||||
},
|
},
|
||||||
|
10
gulpfile.js
10
gulpfile.js
@ -93,8 +93,7 @@ var paths = {
|
|||||||
],
|
],
|
||||||
|
|
||||||
challenges: [
|
challenges: [
|
||||||
'seed/challenges/*.json',
|
'seed/challenges/*.json'
|
||||||
'seed/under-construction/*.json'
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -399,10 +398,15 @@ var watchDependents = [
|
|||||||
'pack-watch-manifest'
|
'pack-watch-manifest'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
gulp.task('reload', function() {
|
||||||
|
notify({ message: 'test changed' });
|
||||||
|
reload();
|
||||||
|
});
|
||||||
|
|
||||||
gulp.task('watch', watchDependents, function() {
|
gulp.task('watch', watchDependents, function() {
|
||||||
gulp.watch(paths.lessFiles, ['less']);
|
gulp.watch(paths.lessFiles, ['less']);
|
||||||
gulp.watch(paths.js, ['js']);
|
gulp.watch(paths.js, ['js']);
|
||||||
gulp.watch(paths.challenges, ['test-challenges']);
|
gulp.watch(paths.challenges, ['test-challenges', 'reload']);
|
||||||
gulp.watch(paths.js, ['js', 'dependents']);
|
gulp.watch(paths.js, ['js', 'dependents']);
|
||||||
gulp.watch(paths.dependents, ['dependents']);
|
gulp.watch(paths.dependents, ['dependents']);
|
||||||
gulp.watch(paths.manifest + '/*.json', ['build-manifest-watch']);
|
gulp.watch(paths.manifest + '/*.json', ['build-manifest-watch']);
|
||||||
|
@ -10,7 +10,10 @@ module.exports = function getChallenges() {
|
|||||||
try {
|
try {
|
||||||
return getFilesFor('challenges')
|
return getFilesFor('challenges')
|
||||||
.map(function(file) {
|
.map(function(file) {
|
||||||
return require('./challenges/' + file);
|
var challengeSpec = require('./challenges/' + file);
|
||||||
|
challengeSpec.fileName = file;
|
||||||
|
|
||||||
|
return challengeSpec;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('error', e);
|
console.log('error', e);
|
||||||
|
@ -18,6 +18,7 @@ destroy()
|
|||||||
var order = challengeSpec.order;
|
var order = challengeSpec.order;
|
||||||
var block = challengeSpec.name;
|
var block = challengeSpec.name;
|
||||||
var isBeta = !!challengeSpec.isBeta;
|
var isBeta = !!challengeSpec.isBeta;
|
||||||
|
var fileName = challengeSpec.fileName;
|
||||||
console.log('parsed %s successfully', block);
|
console.log('parsed %s successfully', block);
|
||||||
|
|
||||||
// challenge file has no challenges...
|
// challenge file has no challenges...
|
||||||
@ -37,6 +38,8 @@ destroy()
|
|||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/\:/g, '')
|
.replace(/\:/g, '')
|
||||||
.replace(/\s/g, '-');
|
.replace(/\s/g, '-');
|
||||||
|
|
||||||
|
challenge.fileName = fileName;
|
||||||
challenge.order = order;
|
challenge.order = order;
|
||||||
challenge.suborder = index + 1;
|
challenge.suborder = index + 1;
|
||||||
challenge.block = block;
|
challenge.block = block;
|
||||||
|
@ -4,7 +4,15 @@ import moment from 'moment';
|
|||||||
import { Observable, Scheduler } from 'rx';
|
import { Observable, Scheduler } from 'rx';
|
||||||
import assign from 'object.assign';
|
import assign from 'object.assign';
|
||||||
import debugFactory from 'debug';
|
import debugFactory from 'debug';
|
||||||
import utils from '../utils';
|
|
||||||
|
import {
|
||||||
|
dasherize,
|
||||||
|
unDasherize,
|
||||||
|
getMDNLinks,
|
||||||
|
randomVerb,
|
||||||
|
randomPhrase,
|
||||||
|
randomCompliment
|
||||||
|
} from '../utils';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
saveUser,
|
saveUser,
|
||||||
@ -16,6 +24,8 @@ import {
|
|||||||
ifNoUserSend
|
ifNoUserSend
|
||||||
} from '../utils/middleware';
|
} from '../utils/middleware';
|
||||||
|
|
||||||
|
import getFromDisk$ from '../utils/getFromDisk$';
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV !== 'production';
|
const isDev = process.env.NODE_ENV !== 'production';
|
||||||
const isBeta = !!process.env.BETA;
|
const isBeta = !!process.env.BETA;
|
||||||
const debug = debugFactory('freecc:challenges');
|
const debug = debugFactory('freecc:challenges');
|
||||||
@ -31,10 +41,6 @@ const challengeView = {
|
|||||||
7: 'coursewares/showStep'
|
7: 'coursewares/showStep'
|
||||||
};
|
};
|
||||||
|
|
||||||
const dasherize = utils.dasherize;
|
|
||||||
const unDasherize = utils.unDasherize;
|
|
||||||
const getMDNLinks = utils.getMDNLinks;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function makeChallengesUnique(challengeArr) {
|
function makeChallengesUnique(challengeArr) {
|
||||||
// clone and reverse challenges
|
// clone and reverse challenges
|
||||||
@ -262,6 +268,12 @@ module.exports = function(app) {
|
|||||||
return testChallengeName.test(challenge.name);
|
return testChallengeName.test(challenge.name);
|
||||||
})
|
})
|
||||||
.last({ defaultValue: null })
|
.last({ defaultValue: null })
|
||||||
|
.flatMap(challenge => {
|
||||||
|
if (challenge && isDev) {
|
||||||
|
return getFromDisk$(challenge);
|
||||||
|
}
|
||||||
|
return Observable.just(challenge);
|
||||||
|
})
|
||||||
.flatMap(challenge => {
|
.flatMap(challenge => {
|
||||||
|
|
||||||
// Handle not found
|
// Handle not found
|
||||||
@ -311,11 +323,9 @@ module.exports = function(app) {
|
|||||||
MDNlinks: getMDNLinks(challenge.MDNlinks),
|
MDNlinks: getMDNLinks(challenge.MDNlinks),
|
||||||
|
|
||||||
// htmls specific
|
// htmls specific
|
||||||
environment: utils.whichEnvironment(),
|
verb: randomVerb(),
|
||||||
|
phrase: randomPhrase(),
|
||||||
verb: utils.randomVerb(),
|
compliment: randomCompliment()
|
||||||
phrase: utils.randomPhrase(),
|
|
||||||
compliment: utils.randomCompliment()
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
|
37
server/utils/getFromDisk$.js
Normal file
37
server/utils/getFromDisk$.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import path from 'path';
|
||||||
|
import { Observable } from 'rx';
|
||||||
|
|
||||||
|
const basePath = process.cwd() + '/seed/challenges/';
|
||||||
|
|
||||||
|
export default function getFromDisk$(challenge) {
|
||||||
|
if (challenge && !challenge.fileName) {
|
||||||
|
throw new Error(
|
||||||
|
`Challenge ${challenge.name} has no fileName.
|
||||||
|
Did you remember run node seed?`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
delete require.cache[require.resolve(
|
||||||
|
path.join(basePath, challenge.fileName)
|
||||||
|
)];
|
||||||
|
|
||||||
|
return Observable.just(require(path.join(basePath, challenge.fileName)))
|
||||||
|
.map(challengeSpec => challengeSpec.challenges[challenge.suborder - 1])
|
||||||
|
.map(challenge => {
|
||||||
|
challenge.head = challenge.head || [];
|
||||||
|
challenge.tail = challenge.tail || [];
|
||||||
|
challenge.challengeType = '' + challenge.challengeType;
|
||||||
|
|
||||||
|
challenge.name =
|
||||||
|
_.capitalize(challenge.type) +
|
||||||
|
': ' +
|
||||||
|
challenge.title.replace(/[^a-zA-Z0-9\s]/g, '');
|
||||||
|
|
||||||
|
challenge.dashedName = challenge.name
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/\:/g, '')
|
||||||
|
.replace(/\s/g, '-');
|
||||||
|
|
||||||
|
return challenge;
|
||||||
|
});
|
||||||
|
}
|
@ -100,7 +100,6 @@ block content
|
|||||||
common.challengeType = !{JSON.stringify(challengeType)};
|
common.challengeType = !{JSON.stringify(challengeType)};
|
||||||
common.dashedName = !{JSON.stringify(dashedName)};
|
common.dashedName = !{JSON.stringify(dashedName)};
|
||||||
|
|
||||||
common.prodOrDev = !{JSON.stringify(environment)};
|
|
||||||
common.started = Math.floor(Date.now());
|
common.started = Math.floor(Date.now());
|
||||||
|
|
||||||
include ../partials/challenge-footer
|
include ../partials/challenge-footer
|
||||||
|
Reference in New Issue
Block a user