contentful-import 9.0.21 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +155 -160
- package/dist/parseOptions.js +92 -89
- package/dist/tasks/get-destination-data.js +100 -133
- package/dist/tasks/init-client.js +14 -20
- package/dist/tasks/push-to-space/assets.js +66 -74
- package/dist/tasks/push-to-space/creation.js +134 -183
- package/dist/tasks/push-to-space/publishing.js +86 -86
- package/dist/tasks/push-to-space/push-to-space.js +293 -310
- package/dist/transform/transform-space.js +49 -29
- package/dist/transform/transformers.js +50 -55
- package/dist/usageParams.js +113 -74
- package/dist/utils/headers.js +21 -28
- package/dist/utils/schema.js +62 -71
- package/dist/utils/sort-entries.js +83 -60
- package/dist/utils/sort-locales.js +27 -32
- package/dist/utils/validations.js +42 -45
- package/package.json +12 -18
|
@@ -1,34 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
5
17
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const listr_1 = __importDefault(require("listr"));
|
|
30
|
+
const listr_verbose_renderer_1 = __importDefault(require("listr-verbose-renderer"));
|
|
31
|
+
const logging_1 = require("contentful-batch-libs/dist/logging");
|
|
32
|
+
const listr_2 = require("contentful-batch-libs/dist/listr");
|
|
33
|
+
const assets = __importStar(require("./assets"));
|
|
34
|
+
const creation = __importStar(require("./creation"));
|
|
35
|
+
const publishing = __importStar(require("./publishing"));
|
|
22
36
|
const DEFAULT_CONTENT_STRUCTURE = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
entries: [],
|
|
38
|
+
assets: [],
|
|
39
|
+
contentTypes: [],
|
|
40
|
+
tags: [],
|
|
41
|
+
locales: [],
|
|
42
|
+
webhooks: [],
|
|
43
|
+
editorInterfaces: []
|
|
30
44
|
};
|
|
31
|
-
|
|
32
45
|
/**
|
|
33
46
|
* Pushes all changes to a given space. Handles (un)publishing
|
|
34
47
|
* as well as delays after creation and before publishing.
|
|
@@ -50,297 +63,267 @@ const DEFAULT_CONTENT_STRUCTURE = {
|
|
|
50
63
|
* - uploadAssets: upload exported files instead of pointing to an existing URL
|
|
51
64
|
* - assetsDirectory: path to exported asset files to be uploaded instead of pointing to an existing URL
|
|
52
65
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
destinationData = _objectSpread(_objectSpread({}, DEFAULT_CONTENT_STRUCTURE), destinationData);
|
|
73
|
-
listrOptions = listrOptions || {
|
|
74
|
-
renderer: _listrVerboseRenderer.default
|
|
75
|
-
};
|
|
76
|
-
const destinationDataById = {};
|
|
77
|
-
for (const [entityType, entities] of Object.entries(destinationData)) {
|
|
78
|
-
const entitiesById = new Map();
|
|
79
|
-
for (const entity of entities) {
|
|
80
|
-
entitiesById.set(entity.sys.id, entity);
|
|
66
|
+
function pushToSpace({ sourceData, destinationData = {}, client, spaceId, environmentId, contentModelOnly, skipContentModel, skipLocales, skipContentPublishing, timeout, retryLimit, listrOptions, uploadAssets, assetsDirectory, requestQueue }) {
|
|
67
|
+
sourceData = {
|
|
68
|
+
...DEFAULT_CONTENT_STRUCTURE,
|
|
69
|
+
...sourceData
|
|
70
|
+
};
|
|
71
|
+
destinationData = {
|
|
72
|
+
...DEFAULT_CONTENT_STRUCTURE,
|
|
73
|
+
...destinationData
|
|
74
|
+
};
|
|
75
|
+
listrOptions = listrOptions || {
|
|
76
|
+
renderer: listr_verbose_renderer_1.default
|
|
77
|
+
};
|
|
78
|
+
const destinationDataById = {};
|
|
79
|
+
for (const [entityType, entities] of Object.entries(destinationData)) {
|
|
80
|
+
const entitiesById = new Map();
|
|
81
|
+
for (const entity of entities) {
|
|
82
|
+
entitiesById.set(entity.sys.id, entity);
|
|
83
|
+
}
|
|
84
|
+
destinationDataById[entityType] = entitiesById;
|
|
81
85
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
})
|
|
92
|
-
}, {
|
|
93
|
-
title: 'Importing Locales',
|
|
94
|
-
task: (0, _listr2.wrapTask)(async (ctx, task) => {
|
|
95
|
-
const locales = await creation.createLocales({
|
|
96
|
-
context: {
|
|
97
|
-
target: ctx.environment,
|
|
98
|
-
type: 'Locale'
|
|
86
|
+
return new listr_1.default([
|
|
87
|
+
{
|
|
88
|
+
title: 'Connecting to space',
|
|
89
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
90
|
+
const space = await client.getSpace(spaceId);
|
|
91
|
+
const environment = await space.getEnvironment(environmentId);
|
|
92
|
+
ctx.space = space;
|
|
93
|
+
ctx.environment = environment;
|
|
94
|
+
})
|
|
99
95
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
target: ctx.environment,
|
|
113
|
-
type: 'ContentType'
|
|
96
|
+
{
|
|
97
|
+
title: 'Importing Locales',
|
|
98
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
99
|
+
const locales = await creation.createLocales({
|
|
100
|
+
context: { target: ctx.environment, type: 'Locale' },
|
|
101
|
+
entities: sourceData.locales,
|
|
102
|
+
destinationEntitiesById: destinationDataById.locales,
|
|
103
|
+
requestQueue
|
|
104
|
+
});
|
|
105
|
+
ctx.data.locales = locales;
|
|
106
|
+
}),
|
|
107
|
+
skip: () => skipContentModel || skipLocales
|
|
114
108
|
},
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
sourceEntities: sourceData.contentTypes,
|
|
128
|
-
requestQueue
|
|
129
|
-
});
|
|
130
|
-
ctx.data.contentTypes = publishedContentTypes;
|
|
131
|
-
}),
|
|
132
|
-
skip: ctx => skipContentModel
|
|
133
|
-
}, {
|
|
134
|
-
title: 'Importing Tags',
|
|
135
|
-
task: (0, _listr2.wrapTask)(async (ctx, task) => {
|
|
136
|
-
const tags = await creation.createEntities({
|
|
137
|
-
context: {
|
|
138
|
-
target: ctx.environment,
|
|
139
|
-
type: 'Tag'
|
|
109
|
+
{
|
|
110
|
+
title: 'Importing Content Types',
|
|
111
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
112
|
+
const contentTypes = await creation.createEntities({
|
|
113
|
+
context: { target: ctx.environment, type: 'ContentType' },
|
|
114
|
+
entities: sourceData.contentTypes,
|
|
115
|
+
destinationEntitiesById: destinationDataById.contentTypes,
|
|
116
|
+
requestQueue
|
|
117
|
+
});
|
|
118
|
+
ctx.data.contentTypes = contentTypes;
|
|
119
|
+
}),
|
|
120
|
+
skip: () => skipContentModel
|
|
140
121
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
122
|
+
{
|
|
123
|
+
title: 'Publishing Content Types',
|
|
124
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
125
|
+
const publishedContentTypes = await publishEntities({
|
|
126
|
+
entities: ctx.data.contentTypes,
|
|
127
|
+
sourceEntities: sourceData.contentTypes,
|
|
128
|
+
requestQueue
|
|
129
|
+
});
|
|
130
|
+
ctx.data.contentTypes = publishedContentTypes;
|
|
131
|
+
}),
|
|
132
|
+
skip: (ctx) => skipContentModel
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
title: 'Importing Tags',
|
|
136
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
137
|
+
const tags = await creation.createEntities({
|
|
138
|
+
context: { target: ctx.environment, type: 'Tag' },
|
|
139
|
+
entities: sourceData.tags,
|
|
140
|
+
destinationEntitiesById: destinationDataById.tags,
|
|
141
|
+
requestQueue
|
|
142
|
+
});
|
|
143
|
+
ctx.data.tags = tags;
|
|
144
|
+
}),
|
|
145
|
+
// we remove `tags` from destination data if an error was thrown trying to access them
|
|
146
|
+
// this means the user doesn't have access to this feature, skip importing tags
|
|
147
|
+
skip: () => !destinationDataById.tags
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
title: 'Importing Editor Interfaces',
|
|
151
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
152
|
+
const allEditorInterfacesBeingFetched = ctx.data.contentTypes.map(async (contentType) => {
|
|
153
|
+
const editorInterface = sourceData.editorInterfaces.find((editorInterface) => {
|
|
154
|
+
return editorInterface.sys.contentType.sys.id === contentType.sys.id;
|
|
155
|
+
});
|
|
156
|
+
if (!editorInterface) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const ctEditorInterface = await requestQueue.add(() => ctx.environment.getEditorInterfaceForContentType(contentType.sys.id));
|
|
161
|
+
logging_1.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
|
|
162
|
+
ctEditorInterface.controls = editorInterface.controls;
|
|
163
|
+
ctEditorInterface.groupControls = editorInterface.groupControls;
|
|
164
|
+
ctEditorInterface.editorLayout = editorInterface.editorLayout;
|
|
165
|
+
const updatedEditorInterface = await requestQueue.add(() => ctEditorInterface.update());
|
|
166
|
+
return updatedEditorInterface;
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
err.entity = editorInterface;
|
|
170
|
+
throw err;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const allEditorInterfaces = await Promise.all(allEditorInterfacesBeingFetched);
|
|
174
|
+
const editorInterfaces = allEditorInterfaces.filter((editorInterface) => editorInterface);
|
|
175
|
+
ctx.data.editorInterfaces = editorInterfaces;
|
|
176
|
+
}),
|
|
177
|
+
skip: (ctx) => skipContentModel || ctx.data.contentTypes.length === 0
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
title: 'Uploading Assets',
|
|
181
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
182
|
+
const allPendingUploads = [];
|
|
183
|
+
for (const asset of sourceData.assets) {
|
|
184
|
+
for (const file of Object.values(asset.transformed.fields.file)) {
|
|
185
|
+
allPendingUploads.push(requestQueue.add(async () => {
|
|
186
|
+
try {
|
|
187
|
+
logging_1.logEmitter.emit('info', `Uploading Asset file ${file.upload}`);
|
|
188
|
+
const assetStream = await assets.getAssetStreamForURL(file.upload, assetsDirectory);
|
|
189
|
+
const upload = await ctx.environment.createUpload({
|
|
190
|
+
fileName: asset.transformed.sys.id,
|
|
191
|
+
file: assetStream
|
|
192
|
+
});
|
|
193
|
+
delete file.upload;
|
|
194
|
+
file.uploadFrom = {
|
|
195
|
+
sys: {
|
|
196
|
+
type: 'Link',
|
|
197
|
+
linkType: 'Upload',
|
|
198
|
+
id: upload.sys.id
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
return upload;
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
logging_1.logEmitter.emit('error', err);
|
|
205
|
+
}
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
198
208
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
209
|
+
// We call the pending uploads for the side effects
|
|
210
|
+
// so we can just await all pending ones that are queued
|
|
211
|
+
const uploads = await Promise.all(allPendingUploads);
|
|
212
|
+
ctx.data.uploadedAssetFiles = uploads;
|
|
213
|
+
}),
|
|
214
|
+
skip: (ctx) => !uploadAssets || !sourceData.assets.length
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
title: 'Importing Assets',
|
|
218
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
219
|
+
const assetsToProcess = await creation.createEntities({
|
|
220
|
+
context: { target: ctx.environment, type: 'Asset' },
|
|
221
|
+
entities: sourceData.assets,
|
|
222
|
+
destinationEntitiesById: destinationDataById.assets,
|
|
223
|
+
requestQueue
|
|
224
|
+
});
|
|
225
|
+
const processedAssets = await assets.processAssets({
|
|
226
|
+
assets: assetsToProcess,
|
|
227
|
+
timeout,
|
|
228
|
+
retryLimit,
|
|
229
|
+
requestQueue
|
|
230
|
+
});
|
|
231
|
+
ctx.data.assets = processedAssets;
|
|
232
|
+
}),
|
|
233
|
+
skip: (ctx) => contentModelOnly
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
title: 'Publishing Assets',
|
|
237
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
238
|
+
const publishedAssets = await publishEntities({
|
|
239
|
+
entities: ctx.data.assets,
|
|
240
|
+
sourceEntities: sourceData.assets,
|
|
241
|
+
requestQueue
|
|
242
|
+
});
|
|
243
|
+
ctx.data.publishedAssets = publishedAssets;
|
|
244
|
+
}),
|
|
245
|
+
skip: (ctx) => contentModelOnly || skipContentPublishing
|
|
221
246
|
},
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}),
|
|
234
|
-
skip: ctx => contentModelOnly
|
|
235
|
-
}, {
|
|
236
|
-
title: 'Publishing Assets',
|
|
237
|
-
task: (0, _listr2.wrapTask)(async (ctx, task) => {
|
|
238
|
-
const publishedAssets = await publishEntities({
|
|
239
|
-
entities: ctx.data.assets,
|
|
240
|
-
sourceEntities: sourceData.assets,
|
|
241
|
-
requestQueue
|
|
242
|
-
});
|
|
243
|
-
ctx.data.publishedAssets = publishedAssets;
|
|
244
|
-
}),
|
|
245
|
-
skip: ctx => contentModelOnly || skipContentPublishing
|
|
246
|
-
}, {
|
|
247
|
-
title: 'Archiving Assets',
|
|
248
|
-
task: (0, _listr2.wrapTask)(async (ctx, task) => {
|
|
249
|
-
const archivedAssets = await archiveEntities({
|
|
250
|
-
entities: ctx.data.assets,
|
|
251
|
-
sourceEntities: sourceData.assets,
|
|
252
|
-
requestQueue
|
|
253
|
-
});
|
|
254
|
-
ctx.data.archivedAssets = archivedAssets;
|
|
255
|
-
}),
|
|
256
|
-
skip: ctx => contentModelOnly || skipContentPublishing
|
|
257
|
-
}, {
|
|
258
|
-
title: 'Importing Content Entries',
|
|
259
|
-
task: (0, _listr2.wrapTask)(async (ctx, task) => {
|
|
260
|
-
const entries = await creation.createEntries({
|
|
261
|
-
context: {
|
|
262
|
-
target: ctx.environment,
|
|
263
|
-
skipContentModel
|
|
247
|
+
{
|
|
248
|
+
title: 'Archiving Assets',
|
|
249
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
250
|
+
const archivedAssets = await archiveEntities({
|
|
251
|
+
entities: ctx.data.assets,
|
|
252
|
+
sourceEntities: sourceData.assets,
|
|
253
|
+
requestQueue
|
|
254
|
+
});
|
|
255
|
+
ctx.data.archivedAssets = archivedAssets;
|
|
256
|
+
}),
|
|
257
|
+
skip: (ctx) => contentModelOnly || skipContentPublishing
|
|
264
258
|
},
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
sourceEntities: sourceData.entries,
|
|
278
|
-
requestQueue
|
|
279
|
-
});
|
|
280
|
-
ctx.data.publishedEntries = publishedEntries;
|
|
281
|
-
}),
|
|
282
|
-
skip: ctx => contentModelOnly || skipContentPublishing
|
|
283
|
-
}, {
|
|
284
|
-
title: 'Archiving Entries',
|
|
285
|
-
task: (0, _listr2.wrapTask)(async (ctx, task) => {
|
|
286
|
-
const archivedEntries = await archiveEntities({
|
|
287
|
-
entities: ctx.data.entries,
|
|
288
|
-
sourceEntities: sourceData.entries,
|
|
289
|
-
requestQueue
|
|
290
|
-
});
|
|
291
|
-
ctx.data.archivedEntries = archivedEntries;
|
|
292
|
-
}),
|
|
293
|
-
skip: ctx => contentModelOnly || skipContentPublishing
|
|
294
|
-
}, {
|
|
295
|
-
title: 'Creating Web Hooks',
|
|
296
|
-
task: (0, _listr2.wrapTask)(async (ctx, task) => {
|
|
297
|
-
const webhooks = await creation.createEntities({
|
|
298
|
-
context: {
|
|
299
|
-
target: ctx.space,
|
|
300
|
-
type: 'Webhook'
|
|
259
|
+
{
|
|
260
|
+
title: 'Importing Content Entries',
|
|
261
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
262
|
+
const entries = await creation.createEntries({
|
|
263
|
+
context: { target: ctx.environment, skipContentModel },
|
|
264
|
+
entities: sourceData.entries,
|
|
265
|
+
destinationEntitiesById: destinationDataById.entries,
|
|
266
|
+
requestQueue
|
|
267
|
+
});
|
|
268
|
+
ctx.data.entries = entries;
|
|
269
|
+
}),
|
|
270
|
+
skip: (ctx) => contentModelOnly
|
|
301
271
|
},
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
272
|
+
{
|
|
273
|
+
title: 'Publishing Content Entries',
|
|
274
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
275
|
+
const publishedEntries = await publishEntities({
|
|
276
|
+
entities: ctx.data.entries,
|
|
277
|
+
sourceEntities: sourceData.entries,
|
|
278
|
+
requestQueue
|
|
279
|
+
});
|
|
280
|
+
ctx.data.publishedEntries = publishedEntries;
|
|
281
|
+
}),
|
|
282
|
+
skip: (ctx) => contentModelOnly || skipContentPublishing
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
title: 'Archiving Entries',
|
|
286
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
287
|
+
const archivedEntries = await archiveEntities({
|
|
288
|
+
entities: ctx.data.entries,
|
|
289
|
+
sourceEntities: sourceData.entries,
|
|
290
|
+
requestQueue
|
|
291
|
+
});
|
|
292
|
+
ctx.data.archivedEntries = archivedEntries;
|
|
293
|
+
}),
|
|
294
|
+
skip: (ctx) => contentModelOnly || skipContentPublishing
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
title: 'Creating Web Hooks',
|
|
298
|
+
task: (0, listr_2.wrapTask)(async (ctx, task) => {
|
|
299
|
+
const webhooks = await creation.createEntities({
|
|
300
|
+
context: { target: ctx.space, type: 'Webhook' },
|
|
301
|
+
entities: sourceData.webhooks,
|
|
302
|
+
destinationEntitiesById: destinationDataById.webhooks,
|
|
303
|
+
requestQueue
|
|
304
|
+
});
|
|
305
|
+
ctx.data.webhooks = webhooks;
|
|
306
|
+
}),
|
|
307
|
+
skip: (ctx) => contentModelOnly || (environmentId !== 'master' && 'Webhooks can only be imported in master environment')
|
|
308
|
+
}
|
|
309
|
+
], listrOptions);
|
|
310
310
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
original
|
|
320
|
-
}) => original.sys.id);
|
|
321
|
-
const entitiesToArchive = entities.filter(entity => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
|
|
322
|
-
return publishing.archiveEntities({
|
|
323
|
-
entities: entitiesToArchive,
|
|
324
|
-
requestQueue
|
|
325
|
-
});
|
|
311
|
+
exports.default = pushToSpace;
|
|
312
|
+
function archiveEntities({ entities, sourceEntities, requestQueue }) {
|
|
313
|
+
const entityIdsToArchive = sourceEntities
|
|
314
|
+
.filter(({ original }) => original.sys.archivedVersion)
|
|
315
|
+
.map(({ original }) => original.sys.id);
|
|
316
|
+
const entitiesToArchive = entities
|
|
317
|
+
.filter((entity) => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
|
|
318
|
+
return publishing.archiveEntities({ entities: entitiesToArchive, requestQueue });
|
|
326
319
|
}
|
|
327
|
-
function publishEntities({
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
original
|
|
337
|
-
}) => original.sys.id);
|
|
338
|
-
|
|
339
|
-
// Filter imported entities and publish only these who got published in the source
|
|
340
|
-
const entitiesToPublish = entities.filter(entity => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
|
|
341
|
-
return publishing.publishEntities({
|
|
342
|
-
entities: entitiesToPublish,
|
|
343
|
-
requestQueue
|
|
344
|
-
});
|
|
320
|
+
function publishEntities({ entities, sourceEntities, requestQueue }) {
|
|
321
|
+
// Find all entities in source content which are published
|
|
322
|
+
const entityIdsToPublish = sourceEntities
|
|
323
|
+
.filter(({ original }) => original.sys.publishedVersion)
|
|
324
|
+
.map(({ original }) => original.sys.id);
|
|
325
|
+
// Filter imported entities and publish only these who got published in the source
|
|
326
|
+
const entitiesToPublish = entities
|
|
327
|
+
.filter((entity) => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
|
|
328
|
+
return publishing.publishEntities({ entities: entitiesToPublish, requestQueue });
|
|
345
329
|
}
|
|
346
|
-
module.exports = exports.default;
|