contentful-import 8.2.24 → 8.2.25
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 +8 -8
|
@@ -1,163 +1,135 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.publishEntities = publishEntities;
|
|
7
|
+
exports.archiveEntities = archiveEntities;
|
|
8
|
+
|
|
9
|
+
var _getEntityName = require("contentful-batch-libs/dist/get-entity-name");
|
|
10
|
+
|
|
11
|
+
var _getEntityName2 = _interopRequireDefault(_getEntityName);
|
|
12
|
+
|
|
13
|
+
var _logging = require("contentful-batch-libs/dist/logging");
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
16
|
|
|
8
17
|
/**
|
|
9
18
|
* Publish a list of entities.
|
|
10
19
|
* Does not return a rejected promise in the case of an error, pushing it
|
|
11
20
|
* to an error buffer instead.
|
|
12
21
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (entitiesToPublish.length === 0) {
|
|
24
|
-
_logging.logEmitter.emit('info', 'Skipping publishing since zero valid entities passed');
|
|
25
|
-
return [];
|
|
22
|
+
async function publishEntities({
|
|
23
|
+
entities,
|
|
24
|
+
requestQueue
|
|
25
|
+
}) {
|
|
26
|
+
const entitiesToPublish = entities.filter(entity => {
|
|
27
|
+
if (!entity || !entity.publish) {
|
|
28
|
+
_logging.logEmitter.emit('warning', `Unable to publish ${(0, _getEntityName2.default)(entity)}`);
|
|
29
|
+
|
|
30
|
+
return false;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
const type = entity.sys.type || 'unknown type';
|
|
30
|
-
_logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`);
|
|
31
|
-
|
|
32
|
-
const result = yield runQueue(entitiesToPublish, [], requestQueue);
|
|
33
|
-
_logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`);
|
|
34
|
-
return result;
|
|
33
|
+
return true;
|
|
35
34
|
});
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
|
|
42
|
-
let archiveEntities = exports.archiveEntities = (() => {
|
|
43
|
-
var _ref2 = _asyncToGenerator(function* ({ entities, requestQueue }) {
|
|
44
|
-
const entitiesToArchive = entities.filter(function (entity) {
|
|
45
|
-
if (!entity || !entity.archive) {
|
|
46
|
-
_logging.logEmitter.emit('warning', `Unable to archive ${(0, _getEntityName2.default)(entity)}`);
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
return true;
|
|
50
|
-
});
|
|
36
|
+
if (entitiesToPublish.length === 0) {
|
|
37
|
+
_logging.logEmitter.emit('info', 'Skipping publishing since zero valid entities passed');
|
|
51
38
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
56
41
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
_logging.logEmitter.emit('info', `Archiving ${entities.length} ${type}s`);
|
|
60
|
-
|
|
61
|
-
const pendingArchivedEntities = entitiesToArchive.map(function (entity) {
|
|
62
|
-
return requestQueue.add(_asyncToGenerator(function* () {
|
|
63
|
-
try {
|
|
64
|
-
const archivedEntity = yield entity.archive();
|
|
65
|
-
return archivedEntity;
|
|
66
|
-
} catch (err) {
|
|
67
|
-
err.entity = entity;
|
|
68
|
-
_logging.logEmitter.emit('error', err);
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
});
|
|
42
|
+
const entity = entities[0].original || entities[0];
|
|
43
|
+
const type = entity.sys.type || 'unknown type';
|
|
73
44
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
45
|
+
_logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`);
|
|
46
|
+
|
|
47
|
+
const result = await runQueue(entitiesToPublish, [], requestQueue);
|
|
78
48
|
|
|
79
|
-
|
|
49
|
+
_logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`);
|
|
80
50
|
|
|
81
|
-
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function archiveEntities({
|
|
55
|
+
entities,
|
|
56
|
+
requestQueue
|
|
57
|
+
}) {
|
|
58
|
+
const entitiesToArchive = entities.filter(entity => {
|
|
59
|
+
if (!entity || !entity.archive) {
|
|
60
|
+
_logging.logEmitter.emit('warning', `Unable to archive ${(0, _getEntityName2.default)(entity)}`);
|
|
61
|
+
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return true;
|
|
82
66
|
});
|
|
83
67
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
})();
|
|
68
|
+
if (entitiesToArchive.length === 0) {
|
|
69
|
+
_logging.logEmitter.emit('info', 'Skipping archiving since zero valid entities passed');
|
|
88
70
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const publishedEntities = [];
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
92
73
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var _iteratorError = undefined;
|
|
74
|
+
const entity = entities[0].original || entities[0];
|
|
75
|
+
const type = entity.sys.type || 'unknown type';
|
|
96
76
|
|
|
97
|
-
|
|
98
|
-
for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
99
|
-
const entity = _step.value;
|
|
100
|
-
|
|
101
|
-
_logging.logEmitter.emit('info', `Publishing ${entity.sys.type} ${(0, _getEntityName2.default)(entity)}`);
|
|
102
|
-
try {
|
|
103
|
-
const publishedEntity = yield requestQueue.add(function () {
|
|
104
|
-
return entity.publish();
|
|
105
|
-
});
|
|
106
|
-
publishedEntities.push(publishedEntity);
|
|
107
|
-
} catch (err) {
|
|
108
|
-
err.entity = entity;
|
|
109
|
-
_logging.logEmitter.emit('error', err);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
} catch (err) {
|
|
113
|
-
_didIteratorError = true;
|
|
114
|
-
_iteratorError = err;
|
|
115
|
-
} finally {
|
|
116
|
-
try {
|
|
117
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
118
|
-
_iterator.return();
|
|
119
|
-
}
|
|
120
|
-
} finally {
|
|
121
|
-
if (_didIteratorError) {
|
|
122
|
-
throw _iteratorError;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
77
|
+
_logging.logEmitter.emit('info', `Archiving ${entities.length} ${type}s`);
|
|
126
78
|
|
|
127
|
-
|
|
79
|
+
const pendingArchivedEntities = entitiesToArchive.map(entity => {
|
|
80
|
+
return requestQueue.add(async () => {
|
|
81
|
+
try {
|
|
82
|
+
const archivedEntity = await entity.archive();
|
|
83
|
+
return archivedEntity;
|
|
84
|
+
} catch (err) {
|
|
85
|
+
err.entity = entity;
|
|
128
86
|
|
|
129
|
-
|
|
130
|
-
return entity.sys.id;
|
|
131
|
-
}));
|
|
132
|
-
const unpublishedEntities = queue.filter(function (entity) {
|
|
133
|
-
return !publishedEntityIds.has(entity.sys.id);
|
|
134
|
-
});
|
|
87
|
+
_logging.logEmitter.emit('error', err);
|
|
135
88
|
|
|
136
|
-
|
|
137
|
-
if (queue.length === unpublishedEntities.length) {
|
|
138
|
-
// Fail when queue could not publish at least one item
|
|
139
|
-
const unpublishedEntityNames = unpublishedEntities.map(_getEntityName2.default).join(', ');
|
|
140
|
-
_logging.logEmitter.emit('error', `Could not publish the following entities: ${unpublishedEntityNames}`);
|
|
141
|
-
} else {
|
|
142
|
-
// Rerun queue with unpublished entities
|
|
143
|
-
return runQueue(unpublishedEntities, result, requestQueue);
|
|
89
|
+
return null;
|
|
144
90
|
}
|
|
145
|
-
}
|
|
146
|
-
// Return only published entities + last result
|
|
147
|
-
return result;
|
|
91
|
+
});
|
|
148
92
|
});
|
|
93
|
+
const allPossiblyArchivedEntities = await Promise.all(pendingArchivedEntities);
|
|
94
|
+
const allArchivedEntities = allPossiblyArchivedEntities.filter(entity => entity);
|
|
149
95
|
|
|
150
|
-
|
|
151
|
-
return _ref4.apply(this, arguments);
|
|
152
|
-
};
|
|
153
|
-
})();
|
|
96
|
+
_logging.logEmitter.emit('info', `Successfully archived ${allArchivedEntities.length} ${type}s`);
|
|
154
97
|
|
|
155
|
-
|
|
98
|
+
return allArchivedEntities;
|
|
99
|
+
}
|
|
156
100
|
|
|
157
|
-
|
|
101
|
+
async function runQueue(queue, result = [], requestQueue) {
|
|
102
|
+
const publishedEntities = [];
|
|
158
103
|
|
|
159
|
-
|
|
104
|
+
for (const entity of queue) {
|
|
105
|
+
_logging.logEmitter.emit('info', `Publishing ${entity.sys.type} ${(0, _getEntityName2.default)(entity)}`);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const publishedEntity = await requestQueue.add(() => entity.publish());
|
|
109
|
+
publishedEntities.push(publishedEntity);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
err.entity = entity;
|
|
112
|
+
|
|
113
|
+
_logging.logEmitter.emit('error', err);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
result = [...result, ...publishedEntities];
|
|
118
|
+
const publishedEntityIds = new Set(publishedEntities.map(entity => entity.sys.id));
|
|
119
|
+
const unpublishedEntities = queue.filter(entity => !publishedEntityIds.has(entity.sys.id));
|
|
120
|
+
|
|
121
|
+
if (unpublishedEntities.length > 0) {
|
|
122
|
+
if (queue.length === unpublishedEntities.length) {
|
|
123
|
+
// Fail when queue could not publish at least one item
|
|
124
|
+
const unpublishedEntityNames = unpublishedEntities.map(_getEntityName2.default).join(', ');
|
|
125
|
+
|
|
126
|
+
_logging.logEmitter.emit('error', `Could not publish the following entities: ${unpublishedEntityNames}`);
|
|
127
|
+
} else {
|
|
128
|
+
// Rerun queue with unpublished entities
|
|
129
|
+
return runQueue(unpublishedEntities, result, requestQueue);
|
|
130
|
+
}
|
|
131
|
+
} // Return only published entities + last result
|
|
160
132
|
|
|
161
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
162
133
|
|
|
163
|
-
|
|
134
|
+
return result;
|
|
135
|
+
}
|