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.
- package/dist/index.js +49 -75
- package/dist/parseOptions.js +27 -20
- package/dist/tasks/get-destination-data.js +116 -122
- package/dist/tasks/init-client.js +12 -6
- package/dist/tasks/push-to-space/assets.js +55 -65
- package/dist/tasks/push-to-space/creation.js +154 -157
- package/dist/tasks/push-to-space/publishing.js +100 -128
- package/dist/tasks/push-to-space/push-to-space.js +242 -399
- package/dist/transform/transform-space.js +9 -10
- package/dist/transform/transformers.js +12 -7
- package/dist/usageParams.js +6 -4
- package/dist/utils/headers.js +9 -9
- package/dist/utils/schema.js +26 -21
- package/dist/utils/sort-entries.js +13 -14
- package/dist/utils/sort-locales.js +2 -4
- package/dist/utils/validations.js +11 -8
- package/package.json +9 -9
|
@@ -1,44 +1,45 @@
|
|
|
1
|
-
|
|
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(
|
|
8
|
+
var _listr = require("listr");
|
|
14
9
|
|
|
15
10
|
var _listr2 = _interopRequireDefault(_listr);
|
|
16
11
|
|
|
17
|
-
var _listrVerboseRenderer = require(
|
|
12
|
+
var _listrVerboseRenderer = require("listr-verbose-renderer");
|
|
18
13
|
|
|
19
14
|
var _listrVerboseRenderer2 = _interopRequireDefault(_listrVerboseRenderer);
|
|
20
15
|
|
|
21
|
-
var _logging = require(
|
|
16
|
+
var _logging = require("contentful-batch-libs/dist/logging");
|
|
22
17
|
|
|
23
|
-
var _listr3 = require(
|
|
18
|
+
var _listr3 = require("contentful-batch-libs/dist/listr");
|
|
24
19
|
|
|
25
|
-
var _assets = require(
|
|
20
|
+
var _assets = require("./assets");
|
|
26
21
|
|
|
27
22
|
var assets = _interopRequireWildcard(_assets);
|
|
28
23
|
|
|
29
|
-
var _creation = require(
|
|
24
|
+
var _creation = require("./creation");
|
|
30
25
|
|
|
31
26
|
var creation = _interopRequireWildcard(_creation);
|
|
32
27
|
|
|
33
|
-
var _publishing = require(
|
|
28
|
+
var _publishing = require("./publishing");
|
|
34
29
|
|
|
35
30
|
var publishing = _interopRequireWildcard(_publishing);
|
|
36
31
|
|
|
37
|
-
function
|
|
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
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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 =
|
|
92
|
-
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
|
-
|
|
101
|
-
|
|
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
|
-
|
|
111
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
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
|
-
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
271
|
-
|
|
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
|
-
|
|
281
|
-
return _ref9.apply(this, arguments);
|
|
282
|
-
};
|
|
283
|
-
})());
|
|
190
|
+
_logging.logEmitter.emit('info', `Fetched editor interface for ${contentType.name}`);
|
|
284
191
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
-
|
|
294
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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
|
-
|
|
408
|
-
|
|
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
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
-
|
|
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
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
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
|
-
|
|
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
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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
|
-
|
|
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
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
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({
|
|
520
|
-
|
|
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
|
-
|
|
354
|
+
return publishing.archiveEntities({
|
|
355
|
+
entities: entitiesToArchive,
|
|
356
|
+
requestQueue
|
|
357
|
+
});
|
|
525
358
|
}
|
|
526
359
|
|
|
527
|
-
function publishEntities({
|
|
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(({
|
|
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
|
-
|
|
373
|
+
return publishing.publishEntities({
|
|
374
|
+
entities: entitiesToPublish,
|
|
375
|
+
requestQueue
|
|
376
|
+
});
|
|
535
377
|
}
|
|
378
|
+
|
|
536
379
|
module.exports = exports.default;
|