Skip to content

Commit

Permalink
feat(gatsby): Add activity for writing out page-data.json files to th…
Browse files Browse the repository at this point in the history
…e public directory (#31987)

Co-authored-by: Ward Peeters <ward@coding-tech.com>
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
3 people authored Jun 29, 2021
1 parent 74a1a9b commit 0be1025
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/gatsby/src/utils/__tests__/get-page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ jest.mock(`fs-extra`, () => {
}
})

jest.mock(`gatsby-cli/lib/reporter`, () => {
return {
createProgress: (): any => {
return {
start: jest.fn(),
tick: jest.fn(),
end: jest.fn(),
}
},
}
})

describe(`get-page-data-util`, () => {
const queryResultContent = {
data: {
Expand Down
13 changes: 11 additions & 2 deletions packages/gatsby/src/utils/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ export async function flush(): Promise<void> {

const { pagePaths } = pendingPageDataWrites

const pagesToWrite = pagePaths.values()
const writePageDataActivity = reporter.createProgress(
`Writing page-data.json files to public directory`,
pagePaths.size,
0
)
writePageDataActivity.start()

const flushQueue = fastq(async (pagePath, cb) => {
const page = pages.get(pagePath)
Expand Down Expand Up @@ -181,6 +186,8 @@ export async function flush(): Promise<void> {
}
)

writePageDataActivity.tick()

if (program?._?.[0] === `develop`) {
websocketManager.emitPageData({
id: pagePath,
Expand All @@ -199,7 +206,7 @@ export async function flush(): Promise<void> {
return cb(null, true)
}, 25)

for (const pagePath of pagesToWrite) {
for (const pagePath of pagePaths) {
flushQueue.push(pagePath, () => {})
}

Expand All @@ -209,7 +216,9 @@ export async function flush(): Promise<void> {
})
}

writePageDataActivity.end()
isFlushing = false

return
}

Expand Down

0 comments on commit 0be1025

Please sign in to comment.