Add head/tail to file
This commit is contained in:
@ -3,7 +3,7 @@ import { createPoly } from '../../../../utils/polyvinyl';
|
|||||||
|
|
||||||
import types from './types';
|
import types from './types';
|
||||||
import { BONFIRE, HTML, JS } from '../../../utils/challengeTypes';
|
import { BONFIRE, HTML, JS } from '../../../utils/challengeTypes';
|
||||||
import { buildSeed, createTests, getPath } from '../utils';
|
import { arrayToString, buildSeed, createTests, getPath } from '../utils';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
challenge: '',
|
challenge: '',
|
||||||
@ -82,7 +82,9 @@ const filesReducer = handleActions(
|
|||||||
...state,
|
...state,
|
||||||
[path]: createPoly({
|
[path]: createPoly({
|
||||||
path,
|
path,
|
||||||
contents: buildSeed(challenge)
|
contents: buildSeed(challenge),
|
||||||
|
head: arrayToString(challenge.head),
|
||||||
|
tail: arrayToString(challenge.tail)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ export function decodeFccfaaAttr(value) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function arrayToNewLineString(seedData = []) {
|
export function arrayToString(seedData = ['']) {
|
||||||
seedData = Array.isArray(seedData) ? seedData : [seedData];
|
seedData = Array.isArray(seedData) ? seedData : [seedData];
|
||||||
return seedData.reduce((seed, line) => '' + seed + line + '\n', '\n');
|
return seedData.reduce((seed, line) => '' + seed + line + '\n', '\n');
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ export function arrayToNewLineString(seedData = []) {
|
|||||||
export function buildSeed({ challengeSeed = [] } = {}) {
|
export function buildSeed({ challengeSeed = [] } = {}) {
|
||||||
return compose(
|
return compose(
|
||||||
decodeSafeTags,
|
decodeSafeTags,
|
||||||
arrayToNewLineString
|
arrayToString
|
||||||
)(challengeSeed);
|
)(challengeSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import invariant from 'invariant';
|
|||||||
// contents: String,
|
// contents: String,
|
||||||
// history?: [...String],
|
// history?: [...String],
|
||||||
// }) => PolyVinyl, throws
|
// }) => PolyVinyl, throws
|
||||||
export function createPoly({ path, contents, history } = {}) {
|
export function createPoly({ path, contents, history, ...rest } = {}) {
|
||||||
invariant(
|
invariant(
|
||||||
typeof path === 'string',
|
typeof path === 'string',
|
||||||
'path must be a string but got %s',
|
'path must be a string but got %s',
|
||||||
@ -29,6 +29,7 @@ export function createPoly({ path, contents, history } = {}) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
...rest,
|
||||||
history: Array.isArray(history) ? history : [ path ],
|
history: Array.isArray(history) ? history : [ path ],
|
||||||
path: path,
|
path: path,
|
||||||
contents: contents,
|
contents: contents,
|
||||||
|
Reference in New Issue
Block a user