-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
67 lines (55 loc) · 1.59 KB
/
Copy pathgatsby-node.js
File metadata and controls
67 lines (55 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
let differ = require( "./lib/differ.js" );
let _ = require("lodash");
let colors = require('colors');
///////////////////////////////////////////////////////////
// Get the commits
///////////////////////////////////////////////////////////
exports.sourceNodes = (
{ actions, createNodeId, createContentDigest },
configOptions
) =>
{
const { createNode } = actions
// Gatsby adds a configOption that's not needed for this plugin, delete it
delete configOptions.plugins;
// Helper function that processes a commit to match Gatsby's node structure
const processCommit = commit =>
{
// Get the id of the node
const nodeId = createNodeId( `gitdiff-commit-${commit.commit}` );
// Stringify the commit content
const nodeContent = JSON.stringify( commit );
// Create node object from commit data
const nodeData = Object.assign( {}, commit,
{
id: nodeId,
parent: null,
children: [],
message: commit.message,
date: commit.date,
files: commit.files,
internal:
{
type: `GitDiffCommit`,
content: nodeContent,
contentDigest: createContentDigest(commit),
},
});
return nodeData;
};
// Combine options from config + default options
let options = ( configOptions ) ? _.merge( differ.defaultOptions, configOptions ) : differ.defaultOptions;
try
{
// Process commits
let commits = differ.diff( options );
// For each commit, process and make a node
_.each( commits, c => createNode( processCommit( c ) ) );
}
catch( e )
{
console.log( '\nerror'.red, "\tGitDiff Error: ", e.message );
}
// Debug
// console.log("GitDiffCommit", commits );
}