fix(dev): filter hidden files from seed

This commit is contained in:
Berkeley Martinez
2017-01-18 15:16:23 -08:00
parent 4181e2a0f9
commit c272257b5e

View File

@ -1,9 +1,12 @@
/* eslint-disable no-self-compare */ /* eslint-disable no-self-compare */
var fs = require('fs'); // no import here as this runs without babel
var path = require('path'); const fs = require('fs');
const path = require('path');
const hiddenFile = /^(\.|\/\.)/g;
function getFilesFor(dir) { function getFilesFor(dir) {
return fs.readdirSync(path.join(__dirname, '/' + dir)) return fs.readdirSync(path.join(__dirname, '/' + dir))
.filter(file => !hiddenFile.test(file))
.map(function(file) { .map(function(file) {
let superBlock; let superBlock;
if (fs.statSync(path.join(__dirname, dir + '/' + file)).isFile()) { if (fs.statSync(path.join(__dirname, dir + '/' + file)).isFile()) {
@ -28,7 +31,7 @@ function getFilesFor(dir) {
} }
function getSupOrder(filePath) { function getSupOrder(filePath) {
var order = parseInt((filePath || '').split('-')[0], 10); const order = parseInt((filePath || '').split('-')[0], 10);
// check for NaN // check for NaN
if (order !== order) { if (order !== order) {
return 0; return 0;
@ -37,7 +40,7 @@ function getSupOrder(filePath) {
} }
function getSupName(filePath) { function getSupName(filePath) {
var order = parseInt((filePath || '').split('-')[0], 10); const order = parseInt((filePath || '').split('-')[0], 10);
// check for NaN // check for NaN
if (order !== order) { if (order !== order) {
return filePath; return filePath;
@ -50,7 +53,7 @@ module.exports = function getChallenges() {
try { try {
return getFilesFor('challenges') return getFilesFor('challenges')
.map(function(data) { .map(function(data) {
var challengeSpec = require('./challenges/' + data.file); const challengeSpec = require('./challenges/' + data.file);
challengeSpec.fileName = data.file; challengeSpec.fileName = data.file;
challengeSpec.superBlock = getSupName(data.superBlock); challengeSpec.superBlock = getSupName(data.superBlock);
challengeSpec.superOrder = getSupOrder(data.superBlock); challengeSpec.superOrder = getSupOrder(data.superBlock);
@ -58,7 +61,7 @@ module.exports = function getChallenges() {
return challengeSpec; return challengeSpec;
}); });
} catch (e) { } catch (e) {
console.log('error', e); console.error('error: ', e);
return []; return [];
} }
}; };