-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
gatsby-node.js
69 lines (60 loc) · 1.59 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
62
63
64
65
66
67
68
69
const runNumber = parseInt(process.env.ARTIFACTS_RUN_SETUP, 10) || 1
const isFirstRun = runNumber === 1
exports.sourceNodes = ({ actions, getNode }) => {
reporter.info(`Using test setup #${runNumber}`)
function createNodeHelper(type, nodePartial) {
const node = {
template: `default`,
...nodePartial,
internal: {
type,
contentDigest: createContentDigest(nodePartial),
},
}
actions.createNode(node)
}
for (let prevRun = 1; prevRun < runNumber; prevRun++) {
const node = getNode(`node-created-in-run-${prevRun}`)
if (node) {
actions.touchNode(node)
}
}
createNodeHelper(`NodeCounterTest`, {
id: `node-created-in-run-${runNumber}`,
label: `Node created in run ${runNumber}`,
})
}
exports.createPages = ({ actions }) => {
function createPageHelper(dummyId) {
actions.createPage({
path: `/stale-pages/${dummyId}`,
component: require.resolve(`./src/templates/dummy`),
context: {
dummyId,
},
})
}
// stable page that always gets created
createPageHelper(`stable`)
if (isFirstRun) {
// page exists in first run, but not in second
createPageHelper(`only-in-first`)
} else {
// page exists only in second run
createPageHelper(`only-in-second`)
}
}
let counter = 1
exports.onPostBuild = ({ getNodes }) => {
console.log(`[test] onPostBuild`)
fs.writeJSONSync(
path.join(
process.cwd(),
`.cache`,
`build-manifest-for-test-${counter++}.json`
),
{
allNodeCounters: getNodes().map(node => [node.id, node.internal.counter]),
}
)
}