contentful-import 8.2.23 → 8.2.27

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,44 +1,45 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
8
-
9
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
10
-
11
6
  exports.default = pushToSpace;
12
7
 
13
- var _listr = require('listr');
8
+ var _listr = require("listr");
14
9
 
15
10
  var _listr2 = _interopRequireDefault(_listr);
16
11
 
17
- var _listrVerboseRenderer = require('listr-verbose-renderer');
12
+ var _listrVerboseRenderer = require("listr-verbose-renderer");
18
13
 
19
14
  var _listrVerboseRenderer2 = _interopRequireDefault(_listrVerboseRenderer);
20
15
 
21
- var _logging = require('contentful-batch-libs/dist/logging');
16
+ var _logging = require("contentful-batch-libs/dist/logging");
22
17
 
23
- var _listr3 = require('contentful-batch-libs/dist/listr');
18
+ var _listr3 = require("contentful-batch-libs/dist/listr");
24
19
 
25
- var _assets = require('./assets');
20
+ var _assets = require("./assets");
26
21
 
27
22
  var assets = _interopRequireWildcard(_assets);
28
23
 
29
- var _creation = require('./creation');
24
+ var _creation = require("./creation");
30
25
 
31
26
  var creation = _interopRequireWildcard(_creation);
32
27
 
33
- var _publishing = require('./publishing');
28
+ var _publishing = require("./publishing");
34
29
 
35
30
  var publishing = _interopRequireWildcard(_publishing);
36
31
 
37
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
32
+ 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); }
33
+
34
+ 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; }
38
35
 
39
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
37
 
41
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
38
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
39
+
40
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
41
+
42
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
42
43
 
43
44
  const DEFAULT_CONTENT_STRUCTURE = {
44
45
  entries: [],
@@ -48,30 +49,30 @@ const DEFAULT_CONTENT_STRUCTURE = {
48
49
  locales: [],
49
50
  webhooks: [],
50
51
  editorInterfaces: []
51
-
52
- /**
53
- * Pushes all changes to a given space. Handles (un)publishing
54
- * as well as delays after creation and before publishing.
55
- *
56
- * Creates everything in the right order so that a content type for a given entry
57
- * is there when entry creation for that content type is attempted.
58
- *
59
- * Allows only content model or only content pushing.
60
- *
61
- * Options:
62
- * - sourceData: see DEFAULT_CONTENT_STRUCTURE
63
- * - destinationData: see DEFAULT_CONTENT_STRUCTURE
64
- * - client: preconfigured management API client
65
- * - spaceId: ID of space content is being copied to
66
- * - contentModelOnly: synchronizes only content types and locales
67
- * - skipLocales: skips locales when synchronizing the content model
68
- * - skipContentModel: synchronizes only entries and assets
69
- * - skipContentPublishing: create content but don't publish it
70
- * - uploadAssets: upload exported files instead of pointing to an existing URL
71
- * - assetsDirectory: path to exported asset files to be uploaded instead of pointing to an existing URL
72
- */
73
-
74
- };function pushToSpace({
52
+ };
53
+ /**
54
+ * Pushes all changes to a given space. Handles (un)publishing
55
+ * as well as delays after creation and before publishing.
56
+ *
57
+ * Creates everything in the right order so that a content type for a given entry
58
+ * is there when entry creation for that content type is attempted.
59
+ *
60
+ * Allows only content model or only content pushing.
61
+ *
62
+ * Options:
63
+ * - sourceData: see DEFAULT_CONTENT_STRUCTURE
64
+ * - destinationData: see DEFAULT_CONTENT_STRUCTURE
65
+ * - client: preconfigured management API client
66
+ * - spaceId: ID of space content is being copied to
67
+ * - contentModelOnly: synchronizes only content types and locales
68
+ * - skipLocales: skips locales when synchronizing the content model
69
+ * - skipContentModel: synchronizes only entries and assets
70
+ * - skipContentPublishing: create content but don't publish it
71
+ * - uploadAssets: upload exported files instead of pointing to an existing URL
72
+ * - assetsDirectory: path to exported asset files to be uploaded instead of pointing to an existing URL
73
+ */
74
+
75
+ function pushToSpace({
75
76
  sourceData,
76
77
  destinationData = {},
77
78
  client,
@@ -88,449 +89,291 @@ const DEFAULT_CONTENT_STRUCTURE = {
88
89
  assetsDirectory,
89
90
  requestQueue
90
91
  }) {
91
- sourceData = _extends({}, DEFAULT_CONTENT_STRUCTURE, sourceData);
92
- destinationData = _extends({}, DEFAULT_CONTENT_STRUCTURE, destinationData);
93
-
92
+ sourceData = _objectSpread(_objectSpread({}, DEFAULT_CONTENT_STRUCTURE), sourceData);
93
+ destinationData = _objectSpread(_objectSpread({}, DEFAULT_CONTENT_STRUCTURE), destinationData);
94
94
  listrOptions = listrOptions || {
95
95
  renderer: _listrVerboseRenderer2.default
96
96
  };
97
-
98
97
  const destinationDataById = {};
99
98
 
100
- var _iteratorNormalCompletion = true;
101
- var _didIteratorError = false;
102
- var _iteratorError = undefined;
103
-
104
- try {
105
- for (var _iterator = Object.entries(destinationData)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
106
- const _ref = _step.value;
107
-
108
- var _ref2 = _slicedToArray(_ref, 2);
99
+ for (const [entityType, entities] of Object.entries(destinationData)) {
100
+ const entitiesById = new Map();
109
101
 
110
- const entityType = _ref2[0];
111
- const entities = _ref2[1];
112
-
113
- const entitiesById = new Map();
114
-
115
- var _iteratorNormalCompletion4 = true;
116
- var _didIteratorError4 = false;
117
- var _iteratorError4 = undefined;
118
-
119
- try {
120
- for (var _iterator4 = entities[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
121
- const entity = _step4.value;
122
-
123
- entitiesById.set(entity.sys.id, entity);
124
- }
125
- } catch (err) {
126
- _didIteratorError4 = true;
127
- _iteratorError4 = err;
128
- } finally {
129
- try {
130
- if (!_iteratorNormalCompletion4 && _iterator4.return) {
131
- _iterator4.return();
132
- }
133
- } finally {
134
- if (_didIteratorError4) {
135
- throw _iteratorError4;
136
- }
137
- }
138
- }
139
-
140
- destinationDataById[entityType] = entitiesById;
141
- }
142
- } catch (err) {
143
- _didIteratorError = true;
144
- _iteratorError = err;
145
- } finally {
146
- try {
147
- if (!_iteratorNormalCompletion && _iterator.return) {
148
- _iterator.return();
149
- }
150
- } finally {
151
- if (_didIteratorError) {
152
- throw _iteratorError;
153
- }
102
+ for (const entity of entities) {
103
+ entitiesById.set(entity.sys.id, entity);
154
104
  }
105
+
106
+ destinationDataById[entityType] = entitiesById;
155
107
  }
156
108
 
157
109
  return new _listr2.default([{
158
110
  title: 'Connecting to space',
159
- task: (0, _listr3.wrapTask)((() => {
160
- var _ref3 = _asyncToGenerator(function* (ctx, task) {
161
- const space = yield client.getSpace(spaceId);
162
- const environment = yield space.getEnvironment(environmentId);
163
-
164
- ctx.space = space;
165
- ctx.environment = environment;
166
- });
167
-
168
- return function (_x, _x2) {
169
- return _ref3.apply(this, arguments);
170
- };
171
- })())
111
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
112
+ const space = await client.getSpace(spaceId);
113
+ const environment = await space.getEnvironment(environmentId);
114
+ ctx.space = space;
115
+ ctx.environment = environment;
116
+ })
172
117
  }, {
173
118
  title: 'Importing Locales',
174
- task: (0, _listr3.wrapTask)((() => {
175
- var _ref4 = _asyncToGenerator(function* (ctx, task) {
176
- const locales = yield creation.createLocales({
177
- context: { target: ctx.environment, type: 'Locale' },
178
- entities: sourceData.locales,
179
- destinationEntitiesById: destinationDataById.locales,
180
- requestQueue
181
- });
182
-
183
- ctx.data.locales = locales;
119
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
120
+ const locales = await creation.createLocales({
121
+ context: {
122
+ target: ctx.environment,
123
+ type: 'Locale'
124
+ },
125
+ entities: sourceData.locales,
126
+ destinationEntitiesById: destinationDataById.locales,
127
+ requestQueue
184
128
  });
185
-
186
- return function (_x3, _x4) {
187
- return _ref4.apply(this, arguments);
188
- };
189
- })()),
129
+ ctx.data.locales = locales;
130
+ }),
190
131
  skip: () => skipContentModel || skipLocales
191
132
  }, {
192
133
  title: 'Importing Content Types',
193
- task: (0, _listr3.wrapTask)((() => {
194
- var _ref5 = _asyncToGenerator(function* (ctx, task) {
195
- const contentTypes = yield creation.createEntities({
196
- context: { target: ctx.environment, type: 'ContentType' },
197
- entities: sourceData.contentTypes,
198
- destinationEntitiesById: destinationDataById.contentTypes,
199
- requestQueue
200
- });
201
-
202
- ctx.data.contentTypes = contentTypes;
134
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
135
+ const contentTypes = await creation.createEntities({
136
+ context: {
137
+ target: ctx.environment,
138
+ type: 'ContentType'
139
+ },
140
+ entities: sourceData.contentTypes,
141
+ destinationEntitiesById: destinationDataById.contentTypes,
142
+ requestQueue
203
143
  });
204
-
205
- return function (_x5, _x6) {
206
- return _ref5.apply(this, arguments);
207
- };
208
- })()),
144
+ ctx.data.contentTypes = contentTypes;
145
+ }),
209
146
  skip: () => skipContentModel
210
147
  }, {
211
148
  title: 'Publishing Content Types',
212
- task: (0, _listr3.wrapTask)((() => {
213
- var _ref6 = _asyncToGenerator(function* (ctx, task) {
214
- const publishedContentTypes = yield publishEntities({
215
- entities: ctx.data.contentTypes,
216
- sourceEntities: sourceData.contentTypes,
217
- requestQueue
218
- });
219
- ctx.data.contentTypes = publishedContentTypes;
149
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
150
+ const publishedContentTypes = await publishEntities({
151
+ entities: ctx.data.contentTypes,
152
+ sourceEntities: sourceData.contentTypes,
153
+ requestQueue
220
154
  });
221
-
222
- return function (_x7, _x8) {
223
- return _ref6.apply(this, arguments);
224
- };
225
- })()),
155
+ ctx.data.contentTypes = publishedContentTypes;
156
+ }),
226
157
  skip: ctx => skipContentModel
227
158
  }, {
228
159
  title: 'Importing Tags',
229
- task: (0, _listr3.wrapTask)((() => {
230
- var _ref7 = _asyncToGenerator(function* (ctx, task) {
231
- const tags = yield creation.createEntities({
232
- context: { target: ctx.environment, type: 'Tag' },
233
- entities: sourceData.tags,
234
- destinationEntitiesById: destinationDataById.tags,
235
- requestQueue
236
- });
237
- ctx.data.tags = tags;
160
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
161
+ const tags = await creation.createEntities({
162
+ context: {
163
+ target: ctx.environment,
164
+ type: 'Tag'
165
+ },
166
+ entities: sourceData.tags,
167
+ destinationEntitiesById: destinationDataById.tags,
168
+ requestQueue
238
169
  });
239
-
240
- return function (_x9, _x10) {
241
- return _ref7.apply(this, arguments);
242
- };
243
- })()),
170
+ ctx.data.tags = tags;
171
+ }),
244
172
  // we remove `tags` from destination data if an error was thrown trying to access them
245
173
  // this means the user doesn't have access to this feature, skip importing tags
246
174
  skip: () => !destinationDataById.tags
247
175
  }, {
248
176
  title: 'Importing Editor Interfaces',
249
- task: (0, _listr3.wrapTask)((() => {
250
- var _ref8 = _asyncToGenerator(function* (ctx, task) {
251
- const allEditorInterfacesBeingFetched = ctx.data.contentTypes.map((() => {
252
- var _ref9 = _asyncToGenerator(function* (contentType) {
253
- const editorInterface = sourceData.editorInterfaces.find(function (editorInterface) {
254
- return editorInterface.sys.contentType.sys.id === contentType.sys.id;
255
- });
256
-
257
- if (!editorInterface) {
258
- return;
259
- }
177
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
178
+ const allEditorInterfacesBeingFetched = ctx.data.contentTypes.map(async contentType => {
179
+ const editorInterface = sourceData.editorInterfaces.find(editorInterface => {
180
+ return editorInterface.sys.contentType.sys.id === contentType.sys.id;
181
+ });
260
182
 
261
- try {
262
- const ctEditorInterface = yield requestQueue.add(function () {
263
- return ctx.environment.getEditorInterfaceForContentType(contentType.sys.id);
264
- });
265
- _logging.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
266
- ctEditorInterface.controls = editorInterface.controls;
267
- ctEditorInterface.groupControls = editorInterface.groupControls;
268
- ctEditorInterface.editorLayout = editorInterface.editorLayout;
183
+ if (!editorInterface) {
184
+ return;
185
+ }
269
186
 
270
- const updatedEditorInterface = yield requestQueue.add(function () {
271
- return ctEditorInterface.update();
272
- });
273
- return updatedEditorInterface;
274
- } catch (err) {
275
- err.entity = editorInterface;
276
- throw err;
277
- }
278
- });
187
+ try {
188
+ const ctEditorInterface = await requestQueue.add(() => ctx.environment.getEditorInterfaceForContentType(contentType.sys.id));
279
189
 
280
- return function (_x13) {
281
- return _ref9.apply(this, arguments);
282
- };
283
- })());
190
+ _logging.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
284
191
 
285
- const allEditorInterfaces = yield Promise.all(allEditorInterfacesBeingFetched);
286
- const editorInterfaces = allEditorInterfaces.filter(function (editorInterface) {
287
- return editorInterface;
288
- });
289
-
290
- ctx.data.editorInterfaces = editorInterfaces;
192
+ ctEditorInterface.controls = editorInterface.controls;
193
+ ctEditorInterface.groupControls = editorInterface.groupControls;
194
+ ctEditorInterface.editorLayout = editorInterface.editorLayout;
195
+ const updatedEditorInterface = await requestQueue.add(() => ctEditorInterface.update());
196
+ return updatedEditorInterface;
197
+ } catch (err) {
198
+ err.entity = editorInterface;
199
+ throw err;
200
+ }
291
201
  });
292
-
293
- return function (_x11, _x12) {
294
- return _ref8.apply(this, arguments);
295
- };
296
- })()),
202
+ const allEditorInterfaces = await Promise.all(allEditorInterfacesBeingFetched);
203
+ const editorInterfaces = allEditorInterfaces.filter(editorInterface => editorInterface);
204
+ ctx.data.editorInterfaces = editorInterfaces;
205
+ }),
297
206
  skip: ctx => skipContentModel || ctx.data.contentTypes.length === 0
298
207
  }, {
299
208
  title: 'Uploading Assets',
300
- task: (0, _listr3.wrapTask)((() => {
301
- var _ref10 = _asyncToGenerator(function* (ctx, task) {
302
- const allPendingUploads = [];
303
-
304
- var _iteratorNormalCompletion2 = true;
305
- var _didIteratorError2 = false;
306
- var _iteratorError2 = undefined;
307
-
308
- try {
309
- for (var _iterator2 = sourceData.assets[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
310
- const asset = _step2.value;
311
- var _iteratorNormalCompletion3 = true;
312
- var _didIteratorError3 = false;
313
- var _iteratorError3 = undefined;
209
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
210
+ const allPendingUploads = [];
314
211
 
212
+ for (const asset of sourceData.assets) {
213
+ for (const file of Object.values(asset.transformed.fields.file)) {
214
+ allPendingUploads.push(requestQueue.add(async () => {
315
215
  try {
316
- for (var _iterator3 = Object.values(asset.transformed.fields.file)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
317
- const file = _step3.value;
318
-
319
- allPendingUploads.push(requestQueue.add(_asyncToGenerator(function* () {
320
- try {
321
- _logging.logEmitter.emit('info', `Uploading Asset file ${file.upload}`);
322
- const assetStream = yield assets.getAssetStreamForURL(file.upload, assetsDirectory);
323
- const upload = yield ctx.environment.createUpload({
324
- fileName: asset.transformed.sys.id,
325
- file: assetStream
326
- });
327
-
328
- delete file.upload;
329
-
330
- file.uploadFrom = {
331
- sys: {
332
- type: 'Link',
333
- linkType: 'Upload',
334
- id: upload.sys.id
335
- }
336
- };
337
-
338
- return upload;
339
- } catch (err) {
340
- _logging.logEmitter.emit('error', err);
341
- }
342
- })));
343
- }
344
- } catch (err) {
345
- _didIteratorError3 = true;
346
- _iteratorError3 = err;
347
- } finally {
348
- try {
349
- if (!_iteratorNormalCompletion3 && _iterator3.return) {
350
- _iterator3.return();
351
- }
352
- } finally {
353
- if (_didIteratorError3) {
354
- throw _iteratorError3;
355
- }
356
- }
357
- }
358
- }
216
+ _logging.logEmitter.emit('info', `Uploading Asset file ${file.upload}`);
359
217
 
360
- // We call the pending uploads for the side effects
361
- // so we can just await all pending ones that are queued
362
- } catch (err) {
363
- _didIteratorError2 = true;
364
- _iteratorError2 = err;
365
- } finally {
366
- try {
367
- if (!_iteratorNormalCompletion2 && _iterator2.return) {
368
- _iterator2.return();
369
- }
370
- } finally {
371
- if (_didIteratorError2) {
372
- throw _iteratorError2;
218
+ const assetStream = await assets.getAssetStreamForURL(file.upload, assetsDirectory);
219
+ const upload = await ctx.environment.createUpload({
220
+ fileName: asset.transformed.sys.id,
221
+ file: assetStream
222
+ });
223
+ delete file.upload;
224
+ file.uploadFrom = {
225
+ sys: {
226
+ type: 'Link',
227
+ linkType: 'Upload',
228
+ id: upload.sys.id
229
+ }
230
+ };
231
+ return upload;
232
+ } catch (err) {
233
+ _logging.logEmitter.emit('error', err);
373
234
  }
374
- }
235
+ }));
375
236
  }
237
+ } // We call the pending uploads for the side effects
238
+ // so we can just await all pending ones that are queued
376
239
 
377
- const uploads = yield Promise.all(allPendingUploads);
378
240
 
379
- ctx.data.uploadedAssetFiles = uploads;
380
- });
381
-
382
- return function (_x14, _x15) {
383
- return _ref10.apply(this, arguments);
384
- };
385
- })()),
241
+ const uploads = await Promise.all(allPendingUploads);
242
+ ctx.data.uploadedAssetFiles = uploads;
243
+ }),
386
244
  skip: ctx => !uploadAssets || !sourceData.assets.length
387
245
  }, {
388
246
  title: 'Importing Assets',
389
- task: (0, _listr3.wrapTask)((() => {
390
- var _ref12 = _asyncToGenerator(function* (ctx, task) {
391
- const assetsToProcess = yield creation.createEntities({
392
- context: { target: ctx.environment, type: 'Asset' },
393
- entities: sourceData.assets,
394
- destinationEntitiesById: destinationDataById.assets,
395
- requestQueue
396
- });
397
-
398
- const processedAssets = yield assets.processAssets({
399
- assets: assetsToProcess,
400
- timeout,
401
- retryLimit,
402
- requestQueue
403
- });
404
- ctx.data.assets = processedAssets;
247
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
248
+ const assetsToProcess = await creation.createEntities({
249
+ context: {
250
+ target: ctx.environment,
251
+ type: 'Asset'
252
+ },
253
+ entities: sourceData.assets,
254
+ destinationEntitiesById: destinationDataById.assets,
255
+ requestQueue
405
256
  });
406
-
407
- return function (_x16, _x17) {
408
- return _ref12.apply(this, arguments);
409
- };
410
- })()),
257
+ const processedAssets = await assets.processAssets({
258
+ assets: assetsToProcess,
259
+ timeout,
260
+ retryLimit,
261
+ requestQueue
262
+ });
263
+ ctx.data.assets = processedAssets;
264
+ }),
411
265
  skip: ctx => contentModelOnly
412
266
  }, {
413
267
  title: 'Publishing Assets',
414
- task: (0, _listr3.wrapTask)((() => {
415
- var _ref13 = _asyncToGenerator(function* (ctx, task) {
416
- const publishedAssets = yield publishEntities({
417
- entities: ctx.data.assets,
418
- sourceEntities: sourceData.assets,
419
- requestQueue
420
- });
421
- ctx.data.publishedAssets = publishedAssets;
268
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
269
+ const publishedAssets = await publishEntities({
270
+ entities: ctx.data.assets,
271
+ sourceEntities: sourceData.assets,
272
+ requestQueue
422
273
  });
423
-
424
- return function (_x18, _x19) {
425
- return _ref13.apply(this, arguments);
426
- };
427
- })()),
274
+ ctx.data.publishedAssets = publishedAssets;
275
+ }),
428
276
  skip: ctx => contentModelOnly || skipContentPublishing
429
277
  }, {
430
278
  title: 'Archiving Assets',
431
- task: (0, _listr3.wrapTask)((() => {
432
- var _ref14 = _asyncToGenerator(function* (ctx, task) {
433
- const archivedAssets = yield archiveEntities({
434
- entities: ctx.data.assets,
435
- sourceEntities: sourceData.assets,
436
- requestQueue
437
- });
438
- ctx.data.archivedAssets = archivedAssets;
279
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
280
+ const archivedAssets = await archiveEntities({
281
+ entities: ctx.data.assets,
282
+ sourceEntities: sourceData.assets,
283
+ requestQueue
439
284
  });
440
-
441
- return function (_x20, _x21) {
442
- return _ref14.apply(this, arguments);
443
- };
444
- })()),
285
+ ctx.data.archivedAssets = archivedAssets;
286
+ }),
445
287
  skip: ctx => contentModelOnly || skipContentPublishing
446
288
  }, {
447
289
  title: 'Importing Content Entries',
448
- task: (0, _listr3.wrapTask)((() => {
449
- var _ref15 = _asyncToGenerator(function* (ctx, task) {
450
- const entries = yield creation.createEntries({
451
- context: { target: ctx.environment, skipContentModel },
452
- entities: sourceData.entries,
453
- destinationEntitiesById: destinationDataById.entries,
454
- requestQueue
455
- });
456
- ctx.data.entries = entries;
290
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
291
+ const entries = await creation.createEntries({
292
+ context: {
293
+ target: ctx.environment,
294
+ skipContentModel
295
+ },
296
+ entities: sourceData.entries,
297
+ destinationEntitiesById: destinationDataById.entries,
298
+ requestQueue
457
299
  });
458
-
459
- return function (_x22, _x23) {
460
- return _ref15.apply(this, arguments);
461
- };
462
- })()),
300
+ ctx.data.entries = entries;
301
+ }),
463
302
  skip: ctx => contentModelOnly
464
303
  }, {
465
304
  title: 'Publishing Content Entries',
466
- task: (0, _listr3.wrapTask)((() => {
467
- var _ref16 = _asyncToGenerator(function* (ctx, task) {
468
- const publishedEntries = yield publishEntities({
469
- entities: ctx.data.entries,
470
- sourceEntities: sourceData.entries,
471
- requestQueue
472
- });
473
- ctx.data.publishedEntries = publishedEntries;
305
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
306
+ const publishedEntries = await publishEntities({
307
+ entities: ctx.data.entries,
308
+ sourceEntities: sourceData.entries,
309
+ requestQueue
474
310
  });
475
-
476
- return function (_x24, _x25) {
477
- return _ref16.apply(this, arguments);
478
- };
479
- })()),
311
+ ctx.data.publishedEntries = publishedEntries;
312
+ }),
480
313
  skip: ctx => contentModelOnly || skipContentPublishing
481
314
  }, {
482
315
  title: 'Archiving Entries',
483
- task: (0, _listr3.wrapTask)((() => {
484
- var _ref17 = _asyncToGenerator(function* (ctx, task) {
485
- const archivedEntries = yield archiveEntities({
486
- entities: ctx.data.entries,
487
- sourceEntities: sourceData.entries,
488
- requestQueue
489
- });
490
- ctx.data.archivedEntries = archivedEntries;
316
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
317
+ const archivedEntries = await archiveEntities({
318
+ entities: ctx.data.entries,
319
+ sourceEntities: sourceData.entries,
320
+ requestQueue
491
321
  });
492
-
493
- return function (_x26, _x27) {
494
- return _ref17.apply(this, arguments);
495
- };
496
- })()),
322
+ ctx.data.archivedEntries = archivedEntries;
323
+ }),
497
324
  skip: ctx => contentModelOnly || skipContentPublishing
498
325
  }, {
499
326
  title: 'Creating Web Hooks',
500
- task: (0, _listr3.wrapTask)((() => {
501
- var _ref18 = _asyncToGenerator(function* (ctx, task) {
502
- const webhooks = yield creation.createEntities({
503
- context: { target: ctx.space, type: 'Webhook' },
504
- entities: sourceData.webhooks,
505
- destinationEntitiesById: destinationDataById.webhooks,
506
- requestQueue
507
- });
508
- ctx.data.webhooks = webhooks;
327
+ task: (0, _listr3.wrapTask)(async (ctx, task) => {
328
+ const webhooks = await creation.createEntities({
329
+ context: {
330
+ target: ctx.space,
331
+ type: 'Webhook'
332
+ },
333
+ entities: sourceData.webhooks,
334
+ destinationEntitiesById: destinationDataById.webhooks,
335
+ requestQueue
509
336
  });
510
-
511
- return function (_x28, _x29) {
512
- return _ref18.apply(this, arguments);
513
- };
514
- })()),
337
+ ctx.data.webhooks = webhooks;
338
+ }),
515
339
  skip: ctx => contentModelOnly || environmentId !== 'master' && 'Webhooks can only be imported in master environment'
516
340
  }], listrOptions);
517
341
  }
518
342
 
519
- function archiveEntities({ entities, sourceEntities, requestQueue }) {
520
- const entityIdsToArchive = sourceEntities.filter(({ original }) => original.sys.archivedVersion).map(({ original }) => original.sys.id);
521
-
343
+ function archiveEntities({
344
+ entities,
345
+ sourceEntities,
346
+ requestQueue
347
+ }) {
348
+ const entityIdsToArchive = sourceEntities.filter(({
349
+ original
350
+ }) => original.sys.archivedVersion).map(({
351
+ original
352
+ }) => original.sys.id);
522
353
  const entitiesToArchive = entities.filter(entity => entityIdsToArchive.indexOf(entity.sys.id) !== -1);
523
-
524
- return publishing.archiveEntities({ entities: entitiesToArchive, requestQueue });
354
+ return publishing.archiveEntities({
355
+ entities: entitiesToArchive,
356
+ requestQueue
357
+ });
525
358
  }
526
359
 
527
- function publishEntities({ entities, sourceEntities, requestQueue }) {
360
+ function publishEntities({
361
+ entities,
362
+ sourceEntities,
363
+ requestQueue
364
+ }) {
528
365
  // Find all entities in source content which are published
529
- const entityIdsToPublish = sourceEntities.filter(({ original }) => original.sys.publishedVersion).map(({ original }) => original.sys.id);
366
+ const entityIdsToPublish = sourceEntities.filter(({
367
+ original
368
+ }) => original.sys.publishedVersion).map(({
369
+ original
370
+ }) => original.sys.id); // Filter imported entities and publish only these who got published in the source
530
371
 
531
- // Filter imported entities and publish only these who got published in the source
532
372
  const entitiesToPublish = entities.filter(entity => entityIdsToPublish.indexOf(entity.sys.id) !== -1);
533
-
534
- return publishing.publishEntities({ entities: entitiesToPublish, requestQueue });
373
+ return publishing.publishEntities({
374
+ entities: entitiesToPublish,
375
+ requestQueue
376
+ });
535
377
  }
378
+
536
379
  module.exports = exports.default;