UNPKG

contentful-migration

Version:
59 lines 2.81 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.renderRuntimeErrors = exports.renderValidationErrors = exports.renderPlan = void 0; const chalk_1 = __importDefault(require("chalk")); const renderBatch = function (batch, isQuiet = false) { const planMessage = batch.intent.toPlanMessage(); const message = []; message.push((0, chalk_1.default) `{bold.underline ${planMessage.heading}}`); if (!isQuiet) { for (const detail of planMessage.details) { message.push((0, chalk_1.default) ` - ${detail}`); } } for (const section of planMessage.sections) { message.push((0, chalk_1.default) `\n {bold ${section.heading}}`); if (!isQuiet) { for (const sectionDetail of section.details) { message.push((0, chalk_1.default) ` - ${sectionDetail}`); } } } console.log(message.join('\n')); }; const renderPlan = (batches, environment, isQuiet = false) => { console.log((0, chalk_1.default) `{bold.green The following migration has been planned}\n`); console.log((0, chalk_1.default) `{bold.underline Environment}: {bold.yellow ${environment}}\n`); for (const batch of batches) { renderBatch(batch, isQuiet); if (batch.validationErrors.length > 0) { console.log('\n'); } for (const error of batch.validationErrors) { console.error((0, chalk_1.default) `{red.bold Error: ${error.message}}`); } if (batch.intent.shouldPublish()) { console.log((0, chalk_1.default) `\n{bold.underline Publish Content Type} {bold.yellow ${batch.intent.getContentTypeId()}}`); } } }; exports.renderPlan = renderPlan; const renderValidationErrors = (batches, environment) => { console.error((0, chalk_1.default) `{bold.red The following migration has been planned but cannot be run because it contains errors}\n\n`); renderPlan(batches, environment); console.error((0, chalk_1.default) `🚨 {bold.red Migration unsuccessful}`); }; exports.renderValidationErrors = renderValidationErrors; const renderRuntimeErrors = (batches, filename) => { for (const batch of batches) { renderBatch(batch); const errorCount = batch.runtimeErrors.length; console.error((0, chalk_1.default) `\n{red ${errorCount.toString()} errors while transforming this content. Please check the errors log for details: ${filename}}\n`); console.error((0, chalk_1.default) `🚨 {bold.red Migration unsuccessful}`); } }; exports.renderRuntimeErrors = renderRuntimeErrors; //# sourceMappingURL=render-migration.js.map