Skip to content

Commit

Permalink
Version changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomphill committed Sep 15, 2019
1 parent 92efc46 commit 80aea7c
Show file tree
Hide file tree
Showing 4 changed files with 4,008 additions and 81 deletions.
21 changes: 8 additions & 13 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,28 @@ const getDigest = id =>
.digest('hex');

exports.sourceNodes = async (
{ boundActionCreators },
{ actions },
{ types, credential }
) => {

try{
if (firebase.apps || !firebase.apps.length) {
firebase.initializeApp({credential: firebase.credential.cert(credential)});
}
firebase.initializeApp({ credential: firebase.credential.cert(credential) });
} catch (e) {
report.warn('Could not initialize Firebase. Please check `credential` property in gatsby-config.js');
report.warn(e);
return;
}

const db = firebase.firestore();
db.settings({
timestampsInSnapshots: true
});

const { createNode, createNodeField } = boundActionCreators;
const { createNode } = actions;

const promises = types.map(
async ({ collection, type, populate, map = node => node }) => {
const snapshot = await db.collection(collection).get().catch(e => report.warn(e));
async ({ collection, type, map = node => node }) => {
const snapshot = await db.collection(collection).get();
for (let doc of snapshot.docs) {
const contentDigest = getDigest(doc.id);
const node = createNode(
createNode(
Object.assign({}, map(doc.data()), {
id: doc.id,
parent: null,
Expand All @@ -52,7 +47,7 @@ exports.sourceNodes = async (
}
);

await Promise.all(promises).catch(e => report.warn(e));
await Promise.all(promises);

return;
};
};
Loading

0 comments on commit 80aea7c

Please sign in to comment.