fix: refactoring build of pipeline
This commit is contained in:
@ -1,5 +1,3 @@
|
|||||||
import { flow } from 'lodash';
|
|
||||||
|
|
||||||
import { throwers } from '../rechallenge/throwers';
|
import { throwers } from '../rechallenge/throwers';
|
||||||
import {
|
import {
|
||||||
challengeFilesSelector,
|
challengeFilesSelector,
|
||||||
@ -9,7 +7,6 @@ import {
|
|||||||
} from '../redux';
|
} from '../redux';
|
||||||
import { transformers, testJS$JSX } from '../rechallenge/transformers';
|
import { transformers, testJS$JSX } from '../rechallenge/transformers';
|
||||||
import { cssToHtml, jsToHtml, concatHtml } from '../rechallenge/builders.js';
|
import { cssToHtml, jsToHtml, concatHtml } from '../rechallenge/builders.js';
|
||||||
import { isPromise } from './polyvinyl';
|
|
||||||
|
|
||||||
const frameRunner = [
|
const frameRunner = [
|
||||||
{
|
{
|
||||||
@ -30,41 +27,25 @@ function filterJSIfDisabled(state) {
|
|||||||
return file => !(testJS$JSX(file) && !isJSEnabled);
|
return file => !(testJS$JSX(file) && !isJSEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
const applyFunction = fn => file => {
|
const applyFunction = fn =>
|
||||||
if (file.error) {
|
async function(file) {
|
||||||
return file;
|
try {
|
||||||
}
|
if (file.error) {
|
||||||
try {
|
return file;
|
||||||
let newFile = fn(file);
|
|
||||||
if (typeof newFile !== 'undefined') {
|
|
||||||
if (isPromise(newFile)) {
|
|
||||||
newFile = newFile.catch(() => {
|
|
||||||
// file.error = e.message;
|
|
||||||
return file;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return newFile;
|
const newFile = await fn.call(this, file);
|
||||||
|
if (typeof newFile !== 'undefined') {
|
||||||
|
return newFile;
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
} catch {
|
||||||
|
// file.error = e.message;
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
return file;
|
}.bind(this);
|
||||||
} catch {
|
|
||||||
// file.error = e.message;
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const applyFunctions = fns => file =>
|
const composeFunctions = (...fns) =>
|
||||||
fns.reduce((file, fn) => {
|
fns.map(applyFunction.bind(this)).reduce((f, g) => x => f(x).then(g));
|
||||||
if (isPromise(file)) {
|
|
||||||
return file.then(applyFunction(fn));
|
|
||||||
}
|
|
||||||
return applyFunction(fn)(file);
|
|
||||||
}, file);
|
|
||||||
const toHtml = [jsToHtml, cssToHtml];
|
|
||||||
const pipeLine = flow(
|
|
||||||
applyFunctions(throwers),
|
|
||||||
applyFunctions(transformers),
|
|
||||||
applyFunctions(toHtml)
|
|
||||||
);
|
|
||||||
|
|
||||||
function buildSourceMap(files) {
|
function buildSourceMap(files) {
|
||||||
return files.reduce((sources, file) => {
|
return files.reduce((sources, file) => {
|
||||||
@ -77,6 +58,8 @@ export function buildDOMChallenge(state) {
|
|||||||
const files = challengeFilesSelector(state);
|
const files = challengeFilesSelector(state);
|
||||||
const { required = [], template } = challengeMetaSelector(state);
|
const { required = [], template } = challengeMetaSelector(state);
|
||||||
const finalRequires = [...globalRequires, ...required, ...frameRunner];
|
const finalRequires = [...globalRequires, ...required, ...frameRunner];
|
||||||
|
const toHtml = [jsToHtml, cssToHtml];
|
||||||
|
const pipeLine = composeFunctions(...throwers, ...transformers, ...toHtml);
|
||||||
const finalFiles = Object.keys(files)
|
const finalFiles = Object.keys(files)
|
||||||
.map(key => files[key])
|
.map(key => files[key])
|
||||||
.filter(filterJSIfDisabled(state))
|
.filter(filterJSIfDisabled(state))
|
||||||
@ -90,10 +73,7 @@ export function buildDOMChallenge(state) {
|
|||||||
|
|
||||||
export function buildJSChallenge(state) {
|
export function buildJSChallenge(state) {
|
||||||
const files = challengeFilesSelector(state);
|
const files = challengeFilesSelector(state);
|
||||||
const pipeLine = flow(
|
const pipeLine = composeFunctions(...throwers, ...transformers);
|
||||||
applyFunctions(throwers),
|
|
||||||
applyFunctions(transformers)
|
|
||||||
);
|
|
||||||
const finalFiles = Object.keys(files)
|
const finalFiles = Object.keys(files)
|
||||||
.map(key => files[key])
|
.map(key => files[key])
|
||||||
.map(pipeLine);
|
.map(pipeLine);
|
||||||
|
Reference in New Issue
Block a user