Merge pull request #439 from netlify/empty-test-repo
allow test repo to be used without window.testRepo
This commit is contained in:
commit
0885f84db9
@ -1,3 +1,4 @@
|
||||
import { attempt, isError } from 'lodash';
|
||||
import TestRepoBackend from "./test-repo/implementation";
|
||||
import GitHubBackend from "./github/implementation";
|
||||
import NetlifyAuthBackend from "./netlify-auth/implementation";
|
||||
@ -91,7 +92,7 @@ class Backend {
|
||||
collection.get("name"),
|
||||
selectEntrySlug(collection, loadedEntry.file.path),
|
||||
loadedEntry.file.path,
|
||||
{ raw: loadedEntry.data, label: loadedEntry.file.label }
|
||||
{ raw: loadedEntry.data || '', label: loadedEntry.file.label }
|
||||
))
|
||||
))
|
||||
.then(entries => (
|
||||
@ -121,8 +122,9 @@ class Backend {
|
||||
entryWithFormat(collectionOrEntity) {
|
||||
return (entry) => {
|
||||
const format = resolveFormat(collectionOrEntity, entry);
|
||||
if (entry && entry.raw) {
|
||||
return Object.assign(entry, { data: format && format.fromFile(entry.raw) });
|
||||
if (entry && entry.raw !== undefined) {
|
||||
const data = (format && attempt(format.fromFile.bind(null, entry.raw))) || {};
|
||||
return Object.assign(entry, { data: isError(data) ? {} : data });
|
||||
}
|
||||
return format.fromFile(entry);
|
||||
};
|
||||
|
@ -1,13 +1,15 @@
|
||||
import AuthenticationPage from './AuthenticationPage';
|
||||
import { fileExtension } from '../../lib/pathHelper'
|
||||
|
||||
window.repoFiles = window.repoFiles || {};
|
||||
|
||||
function getFile(path) {
|
||||
const segments = path.split('/');
|
||||
let obj = window.repoFiles;
|
||||
while (obj && segments.length) {
|
||||
obj = obj[segments.shift()];
|
||||
}
|
||||
return obj;
|
||||
return obj || {};
|
||||
}
|
||||
|
||||
function nameFromEmail(email) {
|
||||
@ -22,9 +24,6 @@ function nameFromEmail(email) {
|
||||
export default class TestRepo {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
if (window.repoFiles == null) {
|
||||
throw 'The TestRepo backend needs a "window.repoFiles" object.';
|
||||
}
|
||||
}
|
||||
|
||||
setUser() {}
|
||||
@ -84,6 +83,8 @@ export default class TestRepo {
|
||||
const newEntry = options.newEntry || false;
|
||||
const folder = entry.path.substring(0, entry.path.lastIndexOf('/'));
|
||||
const fileName = entry.path.substring(entry.path.lastIndexOf('/') + 1);
|
||||
window.repoFiles[folder] = window.repoFiles[folder] || {};
|
||||
window.repoFiles[folder][fileName] = window.repoFiles[folder][fileName] || {};
|
||||
if (newEntry) {
|
||||
window.repoFiles[folder][fileName] = { content: entry.raw };
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user