Skip to content

Commit

Permalink
Add missing extension APIs onPreBootstrap, onPostBootstrap, and onPre…
Browse files Browse the repository at this point in the history
…Build (#2241)

* Add missing extension APIs onPreBootstrap, onPostBootstrap, and onPreBuild

* remove console.log
  • Loading branch information
KyleAMathews committed Sep 26, 2017
1 parent 2c96699 commit 06e4fcc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
3 changes: 1 addition & 2 deletions packages/gatsby-plugin-typography/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const os = require(`os`)

// Write out a typography module to .cache.

// TODO add a new API hook e.g onPreBootstrap
exports.sourceNodes = ({ store }, pluginOptions) => {
exports.onPreBootstrap = ({ store }, pluginOptions) => {
const program = store.getState().program

let module
Expand Down
29 changes: 15 additions & 14 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ module.exports = async (program: any) => {
)
fs.writeFileSync(`${siteDir}/api-runner-ssr.js`, sSRAPIRunner, `utf-8`)

activity.end()
/**
* Start the main bootstrap processes.
*/

// onPreBootstrap
activity = report.activityTimer(`onPreBootstrap`)
activity.start()
await apiRunnerNode(`onPreBootstrap`)
activity.end()

// Source nodes
Expand Down Expand Up @@ -333,20 +342,6 @@ module.exports = async (program: any) => {
await require(`../schema`)()
activity.end()

// Load the page hot reloader. It listens for node changes
// and re-runs `createPages` and removes pages which weren't
// recreated.
//
// Algorithm is make clone of pages, run createPages, remove from
// both pages create by plugins only implementing `createPagesStatefully`.
// Check for pages not updated (need update timestamp) and remove
// those. yeah, just figure out in reducer if the plugin implements
// createPagesStatefully and mark the page as stateful to simplify
// things.
//
// TODO fix deleting nodes so we can both add markdown pages
// and remove pages as well just by adding/removing markdown files.

const checkJobsDone = _.debounce(resolve => {
const state = store.getState()
if (state.jobs.active.length === 0) {
Expand All @@ -358,6 +353,12 @@ module.exports = async (program: any) => {
}, 100)

if (store.getState().jobs.active.length === 0) {
// onPostBootstrap
activity = report.activityTimer(`onPostBootstrap`)
activity.start()
await apiRunnerNode(`onPostBootstrap`)
activity.end()

report.log(``)
report.info(`bootstrap finished - ${process.uptime()} s`)
report.log(``)
Expand Down
15 changes: 15 additions & 0 deletions packages/gatsby/src/utils/api-node-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ exports.modifyBabelrc = true
*/
exports.modifyWebpackConfig = true

/**
* Called at the start of the bootstrap process before any other extension APIs are called.
*/
exports.onPreBootstrap = true

/**
* Called at the end of the bootstrap process after all other extension APIs have been called.
*/
exports.onPostBootstrap = true

/**
* The first extension point called during the build process. Called after the bootstrap has completed but before the build steps start.
*/
exports.onPreBuild = true

/**
* The last extension point called after all other parts of the build process
* are complete.
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby/src/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function reportFailure(msg, err: Error) {

async function html(program: any) {
const { graphqlRunner } = await bootstrap(program)

await apiRunnerNode(`onPreBuild`, { graphql: graphqlRunner })

// Copy files from the static directory to
// an equivalent static directory within public.
copyStaticDirectory()
Expand Down

0 comments on commit 06e4fcc

Please sign in to comment.