feat(seed): "unpack" and "repack" scripts
add "npm run seed" as alias to "node seed" unpack tests and solution into HTML file; add titles and help text; style unpacked file enable running unpacked assert tests in browser Using browserify, compile "tape", "lodash", jQuery into "unpacked-bundle.js" for use during in-browser unpacked tests feat(seed): diff after repacking feat(seed): unpacked tests use Browser TAP chrome dev tool if available
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
c754880476
commit
590f646263
@@ -4,64 +4,54 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const hiddenFile = /(^(\.|\/\.))|(.md$)/g;
|
||||
|
||||
function getFilesFor(dir) {
|
||||
return fs.readdirSync(path.join(__dirname, '/' + dir))
|
||||
let targetDir = path.join(__dirname, dir);
|
||||
return fs.readdirSync(targetDir)
|
||||
.filter(file => !hiddenFile.test(file))
|
||||
.map(function(file) {
|
||||
let superBlock;
|
||||
if (fs.statSync(path.join(__dirname, dir + '/' + file)).isFile()) {
|
||||
return { file: file };
|
||||
if (fs.statSync(path.join(targetDir, file)).isFile()) {
|
||||
return {file: file};
|
||||
}
|
||||
superBlock = file;
|
||||
return getFilesFor(dir + '/' + superBlock)
|
||||
return getFilesFor(path.join(dir, superBlock))
|
||||
.map(function(data) {
|
||||
return {
|
||||
file: superBlock + '/' + data.file,
|
||||
file: path.join(superBlock, data.file),
|
||||
superBlock: superBlock
|
||||
};
|
||||
});
|
||||
})
|
||||
.reduce(function(files, file) {
|
||||
if (!Array.isArray(file)) {
|
||||
files.push(file);
|
||||
return files;
|
||||
}
|
||||
return files.concat(file);
|
||||
.reduce(function(files, entry) {
|
||||
return files.concat(entry);
|
||||
}, []);
|
||||
}
|
||||
|
||||
function getSupOrder(filePath) {
|
||||
const order = parseInt((filePath || '').split('-')[0], 10);
|
||||
// check for NaN
|
||||
if (order !== order) {
|
||||
return 0;
|
||||
function superblockInfo(filePath) {
|
||||
let parts = (filePath || '').split('-');
|
||||
let order = parseInt(parts[0], 10);
|
||||
if (isNaN(order)) {
|
||||
return {order: 0, name: filePath};
|
||||
} else {
|
||||
return {
|
||||
order: order,
|
||||
name: parts.splice(1).join('-')
|
||||
};
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
function getSupName(filePath) {
|
||||
const order = parseInt((filePath || '').split('-')[0], 10);
|
||||
// check for NaN
|
||||
if (order !== order) {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
return (filePath || '').split('-').splice(1).join('-');
|
||||
}
|
||||
|
||||
module.exports = function getChallenges() {
|
||||
try {
|
||||
return getFilesFor('challenges')
|
||||
.map(function(data) {
|
||||
const challengeSpec = require('./challenges/' + data.file);
|
||||
challengeSpec.fileName = data.file;
|
||||
challengeSpec.superBlock = getSupName(data.superBlock);
|
||||
challengeSpec.superOrder = getSupOrder(data.superBlock);
|
||||
|
||||
return challengeSpec;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('error: ', e);
|
||||
return [];
|
||||
module.exports = function getChallenges(challengesDir) {
|
||||
if (!challengesDir) {
|
||||
challengesDir = 'challenges';
|
||||
}
|
||||
return getFilesFor(challengesDir)
|
||||
.map(function(data) {
|
||||
const challengeSpec = require('./' + challengesDir + '/' + data.file);
|
||||
let superInfo = superblockInfo(data.superBlock);
|
||||
challengeSpec.fileName = data.file;
|
||||
challengeSpec.superBlock = superInfo.name;
|
||||
challengeSpec.superOrder = superInfo.order;
|
||||
return challengeSpec;
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user