-
Notifications
You must be signed in to change notification settings - Fork 37
/
gen-schema.js
69 lines (55 loc) · 1.63 KB
/
gen-schema.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
/* eslint-disable @typescript-eslint/no-var-requires */
'use strict'
/**
* @file Run Gatsby bootstrap step to generate schema files to lint
*/
const fsExtra = require('fs-extra')
const reporter = require('gatsby-cli/lib/reporter')
const redux = require('gatsby-cli/lib/reporter/redux')
const { updateSiteMetadata } = require('gatsby-core-utils')
const path = require('path')
const {
initialize,
customizeSchema,
buildSchema,
sourceNodes,
postBootstrap,
} = require('gatsby/dist/services')
async function build (program) {
await updateSiteMetadata({
name: program.sitePackageJson.name,
sitePath: program.directory,
lastRun: Date.now(),
pid: process.pid,
})
const bootstrapContext = {
program,
parentSpan: 'Span {}',
shouldRunCreatePagesStatefully: true,
}
const context = {
...bootstrapContext,
...(await initialize(bootstrapContext)),
}
await customizeSchema(context)
await sourceNodes(context)
await buildSchema(context)
await postBootstrap(context)
// explicitly exit as gatsby still monitors somewhere
// workaround: wait 1000ms to ensure introspection is written
await new Promise(resolve => setTimeout(resolve, 1000))
process.exit(0)
}
process.env.gatsby_log_level = 'verbose'
process.env.gatsby_executing_command = 'build'
const directory = path.resolve('.')
const useYarn = fsExtra.existsSync(path.join(directory, 'yarn.lock'))
const program = {
directory: directory,
browserslist: ['>0.25%', 'not dead'],
sitePackageJson: require(path.join(directory, 'package.json')),
report: reporter.default,
useYarn: useYarn,
setStore: redux.setStore,
}
build(program)