Skip to content
This repository was archived by the owner on Nov 26, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ const clients = {}
* @param {String} accessToken access token
* @param {String} spaceId space id
* @param {String} host host
* @param {String} environment environment
*
* @return {Object} contentful client
*/
function getContentfulClient (accessToken, spaceId, host) {
function getContentfulClient (accessToken, spaceId, host, environment = 'master') {
if (!clients[spaceId]) {
clients[spaceId] = contentful.createClient({
space: spaceId,
accessToken,
host
host,
environment,
})
}

Expand All @@ -40,7 +42,7 @@ function getCommonContentForSpace (entries, options) {
return entries
}

const client = getContentfulClient(options.access_token, options.space_id, options.host)
const client = getContentfulClient(options.access_token, options.space_id, options.host, options.environment)

const commonQueries = []
const commonIds = []
Expand Down Expand Up @@ -127,7 +129,8 @@ function processEntriesForFile (file, entries, options) {
data: entry,
id: entry.sys.id,
contentType: contentfulOptions.content_type,
layout: contentfulOptions.entry_template,
view: contentfulOptions.entry_template,
locale: contentfulOptions.locale,

_fileName: entry._fileName,
_parentFileName: file._fileName
Expand Down Expand Up @@ -158,17 +161,14 @@ function processFile (file, options) {

const spaceId = file.contentful.space_id || options.space_id
const accessToken = file.contentful.access_token || options.access_token
const environment = file.contentful.environment || options.environment
const host = file.contentful.host || options.host
const query = util.getEntriesQuery(file.contentful, options.filterTransforms)

const client = getContentfulClient(accessToken, spaceId, host)

if (file._fileName) {
debug('Query for', file._fileName, '->', query)
}
const client = getContentfulClient(accessToken, spaceId, host, environment)

return client.getEntries(query)
.catch(error => decorateAPIError(error, file))
.catch(error => (decorateAPIError(error, file)))
.then(entries => mapEntriesForFile(entries.items, file, options))
.then(entries => processEntriesForFile(file, entries, options))
.then(entries => getCommonContentForSpace(entries, options))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"node": ">=4"
},
"dependencies": {
"contentful": "^3.5.0",
"contentful": "^6.1.1",
"debug": "^2.6.3",
"lodash.pick": "^4.4.0",
"lodash.template": "^4.4.0",
Expand Down