Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions getChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs');
const path = require('path');
const omit = require('lodash/omit');

const hiddenFile = /(^(\.|\/\.))|(.md$)/g;
const hiddenFile = /(^(\.|\/\.))|(.md$)|(~$)/g;

function getFilesFor(dir) {
let targetDir = path.join(__dirname, dir);
Expand Down Expand Up @@ -47,7 +47,12 @@ module.exports = function getChallenges(challengesDir) {
challengesDir = 'challenges';
}
return getFilesFor(challengesDir).map(function(data) {
const challengeSpec = require('./' + challengesDir + '/' + data.file);
// During development, challenge files are often read multiple times.
// As a result, rather than clear the require cache we read them directly.
const rawChallenge = fs.readFileSync(
path.join(__dirname, challengesDir, data.file)
);
const challengeSpec = JSON.parse(rawChallenge);
let superInfo = superblockInfo(data.superBlock);
challengeSpec.fileName = data.file;
challengeSpec.superBlock = superInfo.name;
Expand Down
59 changes: 44 additions & 15 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,56 @@ const util = require('gulp-util');
const jsonMinify = require('gulp-json-minify');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
const path = require('path');
const fs = require('fs');

gulp.task('json:minify', function() {
return gulp.src('./challenges/**/*.json')
.pipe(jsonMinify())
.pipe(gulp.dest('dist/challenges/'))
.on('error', util.log);
gulp.task('json:minify', () =>
gulp
.src('./challenges/**/*.json')
.pipe(jsonMinify())
.pipe(gulp.dest('dist/challenges/'))
.on('error', util.log)
);

gulp.task('json:copy', () =>
gulp
.src('./challenges/**/*.json')
.pipe(gulp.dest('dist/challenges/'))
.on('error', util.log)
);

gulp.task('json:watch', ['json:copy'], () => {
gulp.watch('./challenges/**/*.json', event => {
// Copying via streams can result in dist files being updated incrementally
// this means that, if it is watching, Gatsby might try to read an
// unfinished file.
util.log('Updating', event.path);
const src = event.path;
const tail = src.split(path.sep).slice(-2);
const dest = path.join(__dirname, 'dist', 'challenges', ...tail);
fs.copyFileSync(src, dest);
});
});

gulp.task('babel-getChallenges', () =>
gulp.src('./getChallenges.js')
.pipe(babel({
presets: ['env']
}))
gulp
.src('./getChallenges.js')
.pipe(
babel({
presets: ['env']
})
)
.pipe(gulp.dest('dist'))
);

gulp.task('babel', ['babel-getChallenges'], () =>
gulp.src('./package-entry.js')
.pipe(rename('./index.js'))
.pipe(babel({
presets: ['env']
}))
.pipe(gulp.dest('dist/'))
gulp
.src('./package-entry.js')
.pipe(rename('./index.js'))
.pipe(
babel({
presets: ['env']
})
)
.pipe(gulp.dest('dist/'))
);
Loading