-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
61 lines (48 loc) · 1.37 KB
/
gatsby-node.js
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
const crypto = require("crypto")
const { exec } = require("child_process")
exports.sourceNodes = ({ actions, createNodeId}, configOptions) => {
const { createNode } = actions
delete configOptions.plugins
const processNode = (node) => {
const nodeId = node.id
const typeName = node.typeName
delete node.id
delete node.typeName
const nodeContent = JSON.stringify(node)
const nodeContentDigest = crypto
.createHash("md5")
.update(nodeContent)
.digest("hex")
const nodeData = Object.assign({}, node, {
id: nodeId,
parent: null,
children: [],
internal: {
type: typeName,
content: nodeContent,
contentDigest: nodeContentDigest
}
})
return createNode(nodeData)
}
return new Promise( async (resolve, reject) => {
exec('git log -1 --format="%H%n%at%n%s"', (err, stdout, stderr) => {
if( err ) {
reject("Error in child process")
}
const buildId = process.env.TRAVIS_BUILD_ID ? process.env.TRAVIS_BUILD_ID : "--"
const buildNum = process.env.TRAVIS_BUILD_NUMBER ? process.env.TRAVIS_BUILD_NUMBER : "--"
const gitArr = stdout.split('\n')
processNode({
id: createNodeId(`git-commit-0`),
typeName: "GitCommit",
commitHash: gitArr[0],
commitDate: gitArr[1],
commitSubject: gitArr[2],
travisId: buildId,
travisNum: buildNum
})
})
resolve()
})
}