Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 74bfc39

Browse files
authored
Merge pull request #59 from LubomirGeorgiev/master
Switch to Gatsby's official terminal reporter and Fix #7 #52
2 parents dbedb0b + 38bca74 commit 74bfc39

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/fetch.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import axios from 'axios'
22
import { isObject, startsWith, forEach } from 'lodash'
33
import pluralize from 'pluralize'
44

5-
module.exports = async ({ apiURL, contentType, jwtToken, queryLimit }) => {
6-
console.time('Fetch Strapi data')
7-
console.log(`Starting to fetch data from Strapi (${pluralize(contentType)})`)
8-
5+
module.exports = async ({ apiURL, contentType, jwtToken, queryLimit, reporter }) => {
96
// Define API endpoint.
10-
const apiEndpoint = `${apiURL}/${pluralize(contentType)}?_limit=${queryLimit}`
7+
const apiBase = `${apiURL}/${pluralize(contentType)}`
8+
const apiEndpoint = `${apiBase}?_limit=${queryLimit}`
9+
10+
reporter.info(`Starting to fetch data from Strapi - ${apiBase}`)
1111

1212
// Set authorization token
1313
let fetchRequestConfig = {}
@@ -20,9 +20,6 @@ module.exports = async ({ apiURL, contentType, jwtToken, queryLimit }) => {
2020
// Make API request.
2121
const documents = await axios(apiEndpoint, fetchRequestConfig)
2222

23-
// Query all documents from client.
24-
console.timeEnd('Fetch Strapi data')
25-
2623
// Map and clean data.
2724
return documents.data.map(item => clean(item))
2825
}

src/gatsby-node.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { capitalize } from 'lodash'
55
import normalize from './normalize'
66

77
exports.sourceNodes = async (
8-
{ store, boundActionCreators, cache },
8+
{ store, boundActionCreators, cache, reporter },
99
{
1010
apiURL = 'http://localhost:1337',
1111
contentTypes = [],
@@ -23,8 +23,8 @@ exports.sourceNodes = async (
2323
loginData.hasOwnProperty('password') &&
2424
loginData.password.length !== 0
2525
) {
26-
console.time('Authenticate Strapi user')
27-
console.log('Authenticate Strapi user')
26+
const authenticationActivity = reporter.activityTimer(`Authenticate Strapi User`)
27+
authenticationActivity.start()
2828

2929
// Define API endpoint.
3030
const loginEndpoint = `${apiURL}/auth/local`
@@ -37,19 +37,23 @@ exports.sourceNodes = async (
3737
jwtToken = loginResponse.data.jwt
3838
}
3939
} catch (e) {
40-
console.error('Strapi authentication error: ' + e)
40+
reporter.panic('Strapi authentication error: ' + e)
4141
}
4242

43-
console.timeEnd('Authenticate Strapi user')
43+
authenticationActivity.end()
4444
}
4545

46+
const fetchActivity = reporter.activityTimer(`Fetched Strapi Data`)
47+
fetchActivity.start()
48+
4649
// Generate a list of promises based on the `contentTypes` option.
4750
const promises = contentTypes.map(contentType =>
4851
fetchData({
4952
apiURL,
5053
contentType,
5154
jwtToken,
5255
queryLimit,
56+
reporter
5357
})
5458
)
5559

@@ -73,4 +77,6 @@ exports.sourceNodes = async (
7377
createNode(node)
7478
})
7579
})
80+
81+
fetchActivity.end()
7682
}

0 commit comments

Comments
 (0)