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.
@@ -1,34 +1,47 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
- exports.default = pushToSpace;
7
- var _listr = _interopRequireDefault(require("listr"));
8
- var _listrVerboseRenderer = _interopRequireDefault(require("listr-verbose-renderer"));
9
- var _logging = require("contentful-batch-libs/dist/logging");
10
- var _listr2 = require("contentful-batch-libs/dist/listr");
11
- var assets = _interopRequireWildcard(require("./assets"));
12
- var creation = _interopRequireWildcard(require("./creation"));
13
- var publishing = _interopRequireWildcard(require("./publishing"));
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
21
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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
- entries: [],
24
- assets: [],
25
- contentTypes: [],
26
- tags: [],
27
- locales: [],
28
- webhooks: [],
29
- editorInterfaces: []
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
- function pushToSpace({
55
- sourceData,
56
- destinationData = {},
57
- client,
58
- spaceId,
59
- environmentId,
60
- contentModelOnly,
61
- skipContentModel,
62
- skipLocales,
63
- skipContentPublishing,
64
- timeout,
65
- retryLimit,
66
- listrOptions,
67
- uploadAssets,
68
- assetsDirectory,
69
- requestQueue
70
- }) {
71
- sourceData = _objectSpread(_objectSpread({}, DEFAULT_CONTENT_STRUCTURE), sourceData);
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
- destinationDataById[entityType] = entitiesById;
83
- }
84
- return new _listr.default([{
85
- title: 'Connecting to space',
86
- task: (0, _listr2.wrapTask)(async (ctx, task) => {
87
- const space = await client.getSpace(spaceId);
88
- const environment = await space.getEnvironment(environmentId);
89
- ctx.space = space;
90
- ctx.environment = environment;
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
- entities: sourceData.locales,
101
- destinationEntitiesById: destinationDataById.locales,
102
- requestQueue
103
- });
104
- ctx.data.locales = locales;
105
- }),
106
- skip: () => skipContentModel || skipLocales
107
- }, {
108
- title: 'Importing Content Types',
109
- task: (0, _listr2.wrapTask)(async (ctx, task) => {
110
- const contentTypes = await creation.createEntities({
111
- context: {
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
- entities: sourceData.contentTypes,
116
- destinationEntitiesById: destinationDataById.contentTypes,
117
- requestQueue
118
- });
119
- ctx.data.contentTypes = contentTypes;
120
- }),
121
- skip: () => skipContentModel
122
- }, {
123
- title: 'Publishing Content Types',
124
- task: (0, _listr2.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
- 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
- entities: sourceData.tags,
142
- destinationEntitiesById: destinationDataById.tags,
143
- requestQueue
144
- });
145
- ctx.data.tags = tags;
146
- }),
147
- // we remove `tags` from destination data if an error was thrown trying to access them
148
- // this means the user doesn't have access to this feature, skip importing tags
149
- skip: () => !destinationDataById.tags
150
- }, {
151
- title: 'Importing Editor Interfaces',
152
- task: (0, _listr2.wrapTask)(async (ctx, task) => {
153
- const allEditorInterfacesBeingFetched = ctx.data.contentTypes.map(async contentType => {
154
- const editorInterface = sourceData.editorInterfaces.find(editorInterface => {
155
- return editorInterface.sys.contentType.sys.id === contentType.sys.id;
156
- });
157
- if (!editorInterface) {
158
- return;
159
- }
160
- try {
161
- const ctEditorInterface = await requestQueue.add(() => ctx.environment.getEditorInterfaceForContentType(contentType.sys.id));
162
- _logging.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
163
- ctEditorInterface.controls = editorInterface.controls;
164
- ctEditorInterface.groupControls = editorInterface.groupControls;
165
- ctEditorInterface.editorLayout = editorInterface.editorLayout;
166
- const updatedEditorInterface = await requestQueue.add(() => ctEditorInterface.update());
167
- return updatedEditorInterface;
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
- title: 'Uploading Assets',
180
- task: (0, _listr2.wrapTask)(async (ctx, task) => {
181
- const allPendingUploads = [];
182
- for (const asset of sourceData.assets) {
183
- for (const file of Object.values(asset.transformed.fields.file)) {
184
- allPendingUploads.push(requestQueue.add(async () => {
185
- try {
186
- _logging.logEmitter.emit('info', `Uploading Asset file ${file.upload}`);
187
- const assetStream = await assets.getAssetStreamForURL(file.upload, assetsDirectory);
188
- const upload = await ctx.environment.createUpload({
189
- fileName: asset.transformed.sys.id,
190
- file: assetStream
191
- });
192
- delete file.upload;
193
- file.uploadFrom = {
194
- sys: {
195
- type: 'Link',
196
- linkType: 'Upload',
197
- id: upload.sys.id
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
- return upload;
201
- } catch (err) {
202
- _logging.logEmitter.emit('error', err);
203
- }
204
- }));
205
- }
206
- }
207
-
208
- // We call the pending uploads for the side effects
209
- // so we can just await all pending ones that are queued
210
- const uploads = await Promise.all(allPendingUploads);
211
- ctx.data.uploadedAssetFiles = uploads;
212
- }),
213
- skip: ctx => !uploadAssets || !sourceData.assets.length
214
- }, {
215
- title: 'Importing Assets',
216
- task: (0, _listr2.wrapTask)(async (ctx, task) => {
217
- const assetsToProcess = await creation.createEntities({
218
- context: {
219
- target: ctx.environment,
220
- type: 'Asset'
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
- entities: sourceData.assets,
223
- destinationEntitiesById: destinationDataById.assets,
224
- requestQueue
225
- });
226
- const processedAssets = await assets.processAssets({
227
- assets: assetsToProcess,
228
- timeout,
229
- retryLimit,
230
- requestQueue
231
- });
232
- ctx.data.assets = processedAssets;
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
- entities: sourceData.entries,
266
- destinationEntitiesById: destinationDataById.entries,
267
- requestQueue
268
- });
269
- ctx.data.entries = entries;
270
- }),
271
- skip: ctx => contentModelOnly
272
- }, {
273
- title: 'Publishing Content Entries',
274
- task: (0, _listr2.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
- 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
- entities: sourceData.webhooks,
303
- destinationEntitiesById: destinationDataById.webhooks,
304
- requestQueue
305
- });
306
- ctx.data.webhooks = webhooks;
307
- }),
308
- skip: ctx => contentModelOnly || environmentId !== 'master' && 'Webhooks can only be imported in master environment'
309
- }], listrOptions);
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
- function archiveEntities({
312
- entities,
313
- sourceEntities,
314
- requestQueue
315
- }) {
316
- const entityIdsToArchive = sourceEntities.filter(({
317
- original
318
- }) => original.sys.archivedVersion).map(({
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
- entities,
329
- sourceEntities,
330
- requestQueue
331
- }) {
332
- // Find all entities in source content which are published
333
- const entityIdsToPublish = sourceEntities.filter(({
334
- original
335
- }) => original.sys.publishedVersion).map(({
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;