Add head/tail to file

This commit is contained in:
Berkeley Martinez
2016-05-14 16:46:20 -07:00
parent 9a7d9cc953
commit 2573dc0b22
3 changed files with 8 additions and 5 deletions

View File

@ -3,7 +3,7 @@ import { createPoly } from '../../../../utils/polyvinyl';
import types from './types';
import { BONFIRE, HTML, JS } from '../../../utils/challengeTypes';
import { buildSeed, createTests, getPath } from '../utils';
import { arrayToString, buildSeed, createTests, getPath } from '../utils';
const initialState = {
challenge: '',
@ -82,7 +82,9 @@ const filesReducer = handleActions(
...state,
[path]: createPoly({
path,
contents: buildSeed(challenge)
contents: buildSeed(challenge),
head: arrayToString(challenge.head),
tail: arrayToString(challenge.tail)
})
};
}

View File

@ -27,7 +27,7 @@ export function decodeFccfaaAttr(value) {
);
}
export function arrayToNewLineString(seedData = []) {
export function arrayToString(seedData = ['']) {
seedData = Array.isArray(seedData) ? seedData : [seedData];
return seedData.reduce((seed, line) => '' + seed + line + '\n', '\n');
}
@ -35,7 +35,7 @@ export function arrayToNewLineString(seedData = []) {
export function buildSeed({ challengeSeed = [] } = {}) {
return compose(
decodeSafeTags,
arrayToNewLineString
arrayToString
)(challengeSeed);
}

View File

@ -15,7 +15,7 @@ import invariant from 'invariant';
// contents: String,
// history?: [...String],
// }) => PolyVinyl, throws
export function createPoly({ path, contents, history } = {}) {
export function createPoly({ path, contents, history, ...rest } = {}) {
invariant(
typeof path === 'string',
'path must be a string but got %s',
@ -29,6 +29,7 @@ export function createPoly({ path, contents, history } = {}) {
);
return {
...rest,
history: Array.isArray(history) ? history : [ path ],
path: path,
contents: contents,