Skip to content

Commit

Permalink
feat(task-listing): implements listr for getFullSourceSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Rötsch authored and axe312ger committed Apr 25, 2017
1 parent f3cb9be commit d3133c6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 29 deletions.
128 changes: 99 additions & 29 deletions lib/get/get-full-source-space.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Promise from 'bluebird'
import log from 'npmlog'
import Listr from 'listr'
import verboseRenderer from 'listr-verbose-renderer'

const MAX_ALLOWED_LIMIT = 1000
let pageLimit = MAX_ALLOWED_LIMIT
Expand All @@ -16,43 +17,112 @@ export default function getFullSourceSpace ({
skipWebhooks,
skipRoles,
includeDrafts,
maxAllowedLimit
maxAllowedLimit,
listrOptions
}) {
pageLimit = maxAllowedLimit || MAX_ALLOWED_LIMIT
log.info('Getting content from source space')
listrOptions = listrOptions || {
renderer: verboseRenderer
}

return managementClient.getSpace(spaceId)
.then((space) => {
return Promise.props({
contentTypes: skipContentModel ? [] : pagedGet(space, 'getContentTypes').then(extractItems),
entries: skipContent ? [] : pagedGet(space, 'getEntries').then(extractItems).then((items) => filterDrafts(items, includeDrafts)),
assets: skipContent ? [] : pagedGet(space, 'getAssets').then(extractItems),
locales: skipContentModel ? [] : pagedGet(space, 'getLocales').then(extractItems),
webhooks: skipWebhooks ? [] : pagedGet(space, 'getWebhooks').then(extractItems),
roles: skipRoles ? [] : pagedGet(space, 'getRoles').then(extractItems)
}).then((response) => {
if (response.contentTypes.length !== 0) {
response.editorInterfaces = getEditorInterfaces(response.contentTypes)
return Promise.props(response)
}
response.editorInterfaces = []
return response
}).then((response) => {
response.editorInterfaces = response.editorInterfaces.filter((editorInterface) => {
return editorInterface !== null
})
return response
})
}, (err) => {
log.error(`
return new Listr([
{
title: 'Connecting to space',
task: (ctx) => {
return managementClient.getSpace(spaceId)
.then((space) => {
ctx.space = space
})
.catch((err) => {
console.error(`
The destination space was not found. This can happen for multiple reasons:
- If you haven't yet, you should create your space manually.
- If your destination space is in another organization, and your user from the source space does not have access to it, you'll need to specify separate sourceManagementToken and destinationManagementToken
Full error details below.
`)
throw err
})
throw err
})
}
},
{
title: 'Fetching content types data',
task: (ctx) => {
return pagedGet(ctx.space, 'getContentTypes')
.then(extractItems)
.then((items) => {
ctx.data.contentTypes = items
})
},
skip: () => skipContentModel
},
{
title: 'Fetching editor interfaces data',
task: (ctx) => {
return getEditorInterfaces(ctx.data.contentTypes)
.then((editorInterfaces) => {
ctx.data.editorInterfaces = editorInterfaces
})
},
skip: (ctx) => skipContentModel || (ctx.data.contentTypes.length === 0 && 'Skipped since no content types downloaded')
},
{
title: 'Fetching content entries data',
task: (ctx) => {
return pagedGet(ctx.space, 'getEntries')
.then(extractItems)
.then(filterDrafts)
.then((items) => {
ctx.data.entries = items
})
},
skip: () => skipContent
},
{
title: 'Fetching assets data',
task: (ctx) => {
return pagedGet(ctx.space, 'getAssets')
.then(extractItems)
.then((items) => {
ctx.data.assets = items
})
},
skip: () => skipContent
},
{
title: 'Fetching locales data',
task: (ctx) => {
return pagedGet(ctx.space, 'getLocales')
.then(extractItems)
.then((items) => {
ctx.data.locales = items
})
},
skip: () => skipContentModel
},
{
title: 'Fetching webhooks data',
task: (ctx) => {
return pagedGet(ctx.space, 'getWebhooks')
.then(extractItems)
.then((items) => {
ctx.data.webhooks = items
})
},
skip: () => skipWebhooks
},
{
title: 'Fetching roles data',
task: (ctx) => {
return pagedGet(ctx.space, 'getRoles')
.then(extractItems)
.then((items) => {
ctx.data.roles = items
})
},
skip: () => skipRoles
}
], listrOptions)
}
function getEditorInterfaces (contentTypes) {
const editorInterfacePromises = contentTypes.map((contentType) => {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"bluebird": "^3.3.3",
"contentful": "^3.3.12",
"contentful-management": "^3.3.0",
"listr": "^0.11.0",
"listr-verbose-renderer": "^0.4.0",
"lodash": "^4.0.1",
"npmlog": "^4.0.2"
},
Expand Down

0 comments on commit d3133c6

Please sign in to comment.