contentful-batch-libs
Advanced tools
Comparing version 6.0.2 to 6.0.3
@@ -20,2 +20,4 @@ 'use strict'; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
/** | ||
@@ -27,13 +29,5 @@ * Publish a list of entities. | ||
function publishEntities(entities) { | ||
if (entities.length === 0) { | ||
_logging.logEmitter.emit('info', 'Skipping publishing since zero entities passed'); | ||
return entities; | ||
} | ||
var entity = entities[0].original || entities[0]; | ||
var type = entity.sys.type || 'unknown type'; | ||
_logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`); | ||
var entitiesToPublish = entities.filter(function (entity) { | ||
if (!entity || !entity.publish) { | ||
_logging.logEmitter.emit('warning', `Unable to publish entity ${(0, _getEntityName2.default)(entity)}`); | ||
_logging.logEmitter.emit('warning', `Unable to publish ${(0, _getEntityName2.default)(entity)}`); | ||
return false; | ||
@@ -44,3 +38,22 @@ } | ||
return _bluebird2.default.map(entitiesToPublish, function (entity, index) { | ||
if (entitiesToPublish.length === 0) { | ||
_logging.logEmitter.emit('info', 'Skipping publishing since zero valid entities passed'); | ||
return _bluebird2.default.resolve([]); | ||
} | ||
var entity = entities[0].original || entities[0]; | ||
var type = entity.sys.type || 'unknown type'; | ||
_logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`); | ||
return runQueue(entitiesToPublish).then(function (result) { | ||
_logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`); | ||
return result; | ||
}); | ||
} | ||
function runQueue(queue, result) { | ||
if (!result) { | ||
result = []; | ||
} | ||
return _bluebird2.default.map(queue, function (entity, index) { | ||
_logging.logEmitter.emit('info', `Publishing ${entity.sys.type} ${(0, _getEntityName2.default)(entity)}`); | ||
@@ -55,6 +68,29 @@ return entity.publish().then(function (entity) { | ||
}); | ||
}, { concurrency: 1 }).then(function (result) { | ||
_logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s.`); | ||
}, { concurrency: 1 }).then(function (entities) { | ||
return entities.filter(function (entity) { | ||
return entity; | ||
}); | ||
}).then(function (publishedEntities) { | ||
result = [].concat(_toConsumableArray(result), _toConsumableArray(publishedEntities)); | ||
var publishedEntityIds = publishedEntities.map(function (entitiy) { | ||
return entitiy.sys.id; | ||
}); | ||
var unpublishedEntities = queue.filter(function (entity) { | ||
return !publishedEntityIds.includes(entity.sys.id); | ||
}); | ||
return unpublishedEntities; | ||
}).then(function (unpublishedEntities) { | ||
if (unpublishedEntities.length > 0) { | ||
if (queue.length === unpublishedEntities.length) { | ||
// Fail when queue could not publish at least one item | ||
var unpublishedEntityNames = unpublishedEntities.map(_getEntityName2.default).join(', '); | ||
_logging.logEmitter.emit('error', `Could not publish the following entities: ${unpublishedEntityNames}`); | ||
} else { | ||
// Rerun queue with unpublished entities | ||
return runQueue(unpublishedEntities, result); | ||
} | ||
} | ||
// Return only published entities + last result | ||
return result; | ||
}); | ||
} |
{ | ||
"name": "contentful-batch-libs", | ||
"version": "6.0.2", | ||
"version": "6.0.3", | ||
"description": "Library modules used by contentful batch utility CLI tools.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57571
1218