Skip to content

Commit d3133c6

Browse files
Benedikt Rötschaxe312ger
Benedikt Rötsch
authored andcommitted
feat(task-listing): implements listr for getFullSourceSpace
1 parent f3cb9be commit d3133c6

File tree

2 files changed

+101
-29
lines changed

2 files changed

+101
-29
lines changed

lib/get/get-full-source-space.js

+99-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Promise from 'bluebird'
2-
import log from 'npmlog'
2+
import Listr from 'listr'
3+
import verboseRenderer from 'listr-verbose-renderer'
34

45
const MAX_ALLOWED_LIMIT = 1000
56
let pageLimit = MAX_ALLOWED_LIMIT
@@ -16,43 +17,112 @@ export default function getFullSourceSpace ({
1617
skipWebhooks,
1718
skipRoles,
1819
includeDrafts,
19-
maxAllowedLimit
20+
maxAllowedLimit,
21+
listrOptions
2022
}) {
2123
pageLimit = maxAllowedLimit || MAX_ALLOWED_LIMIT
22-
log.info('Getting content from source space')
24+
listrOptions = listrOptions || {
25+
renderer: verboseRenderer
26+
}
2327

24-
return managementClient.getSpace(spaceId)
25-
.then((space) => {
26-
return Promise.props({
27-
contentTypes: skipContentModel ? [] : pagedGet(space, 'getContentTypes').then(extractItems),
28-
entries: skipContent ? [] : pagedGet(space, 'getEntries').then(extractItems).then((items) => filterDrafts(items, includeDrafts)),
29-
assets: skipContent ? [] : pagedGet(space, 'getAssets').then(extractItems),
30-
locales: skipContentModel ? [] : pagedGet(space, 'getLocales').then(extractItems),
31-
webhooks: skipWebhooks ? [] : pagedGet(space, 'getWebhooks').then(extractItems),
32-
roles: skipRoles ? [] : pagedGet(space, 'getRoles').then(extractItems)
33-
}).then((response) => {
34-
if (response.contentTypes.length !== 0) {
35-
response.editorInterfaces = getEditorInterfaces(response.contentTypes)
36-
return Promise.props(response)
37-
}
38-
response.editorInterfaces = []
39-
return response
40-
}).then((response) => {
41-
response.editorInterfaces = response.editorInterfaces.filter((editorInterface) => {
42-
return editorInterface !== null
43-
})
44-
return response
45-
})
46-
}, (err) => {
47-
log.error(`
28+
return new Listr([
29+
{
30+
title: 'Connecting to space',
31+
task: (ctx) => {
32+
return managementClient.getSpace(spaceId)
33+
.then((space) => {
34+
ctx.space = space
35+
})
36+
.catch((err) => {
37+
console.error(`
4838
The destination space was not found. This can happen for multiple reasons:
4939
- If you haven't yet, you should create your space manually.
5040
- 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
5141
5242
Full error details below.
5343
`)
54-
throw err
55-
})
44+
throw err
45+
})
46+
}
47+
},
48+
{
49+
title: 'Fetching content types data',
50+
task: (ctx) => {
51+
return pagedGet(ctx.space, 'getContentTypes')
52+
.then(extractItems)
53+
.then((items) => {
54+
ctx.data.contentTypes = items
55+
})
56+
},
57+
skip: () => skipContentModel
58+
},
59+
{
60+
title: 'Fetching editor interfaces data',
61+
task: (ctx) => {
62+
return getEditorInterfaces(ctx.data.contentTypes)
63+
.then((editorInterfaces) => {
64+
ctx.data.editorInterfaces = editorInterfaces
65+
})
66+
},
67+
skip: (ctx) => skipContentModel || (ctx.data.contentTypes.length === 0 && 'Skipped since no content types downloaded')
68+
},
69+
{
70+
title: 'Fetching content entries data',
71+
task: (ctx) => {
72+
return pagedGet(ctx.space, 'getEntries')
73+
.then(extractItems)
74+
.then(filterDrafts)
75+
.then((items) => {
76+
ctx.data.entries = items
77+
})
78+
},
79+
skip: () => skipContent
80+
},
81+
{
82+
title: 'Fetching assets data',
83+
task: (ctx) => {
84+
return pagedGet(ctx.space, 'getAssets')
85+
.then(extractItems)
86+
.then((items) => {
87+
ctx.data.assets = items
88+
})
89+
},
90+
skip: () => skipContent
91+
},
92+
{
93+
title: 'Fetching locales data',
94+
task: (ctx) => {
95+
return pagedGet(ctx.space, 'getLocales')
96+
.then(extractItems)
97+
.then((items) => {
98+
ctx.data.locales = items
99+
})
100+
},
101+
skip: () => skipContentModel
102+
},
103+
{
104+
title: 'Fetching webhooks data',
105+
task: (ctx) => {
106+
return pagedGet(ctx.space, 'getWebhooks')
107+
.then(extractItems)
108+
.then((items) => {
109+
ctx.data.webhooks = items
110+
})
111+
},
112+
skip: () => skipWebhooks
113+
},
114+
{
115+
title: 'Fetching roles data',
116+
task: (ctx) => {
117+
return pagedGet(ctx.space, 'getRoles')
118+
.then(extractItems)
119+
.then((items) => {
120+
ctx.data.roles = items
121+
})
122+
},
123+
skip: () => skipRoles
124+
}
125+
], listrOptions)
56126
}
57127
function getEditorInterfaces (contentTypes) {
58128
const editorInterfacePromises = contentTypes.map((contentType) => {

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"bluebird": "^3.3.3",
3333
"contentful": "^3.3.12",
3434
"contentful-management": "^3.3.0",
35+
"listr": "^0.11.0",
36+
"listr-verbose-renderer": "^0.4.0",
3537
"lodash": "^4.0.1",
3638
"npmlog": "^4.0.2"
3739
},

0 commit comments

Comments
 (0)