contentful-migration
Version:
Migration tooling for contentful
69 lines • 2.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base_intent_1 = __importDefault(require("./base-intent"));
const field_move_1 = require("../action/field-move");
const chalk_1 = __importDefault(require("chalk"));
class FieldMoveIntent extends base_intent_1.default {
isFieldMove() {
return true;
}
groupsWith(other) {
const sameContentType = other.getContentTypeId() === this.getContentTypeId();
return ((other.isContentTypeUpdate() ||
other.isContentTypeCreate() ||
other.isContentTypeAnnotate() ||
other.isFieldCreate() ||
other.isFieldUpdate() ||
other.isFieldMove()) &&
sameContentType);
}
endsGroup() {
return false;
}
getPivotId() {
return this.payload.movement.pivot;
}
getFieldMovementKey() {
return [this.getContentTypeId(), this.getFieldId()].join('/');
}
getDirection() {
return this.payload.movement.direction;
}
toActions() {
return [
new field_move_1.FieldMoveAction(this.getContentTypeId(), this.getFieldId(), this.getDirection(), this.getPivotId())
];
}
toPlanMessage() {
const direction = this.getDirection();
const pivot = this.getPivotId();
let humanizedMovement;
if (direction === 'toTheTop') {
humanizedMovement = `to the first position`;
}
if (direction === 'toTheBottom') {
humanizedMovement = `to the last position`;
}
if (direction === 'afterField') {
humanizedMovement = (0, chalk_1.default) `after field {yellow ${pivot}}`;
}
if (direction === 'beforeField') {
humanizedMovement = (0, chalk_1.default) `before field {yellow ${pivot}}`;
}
return {
heading: (0, chalk_1.default) `Update Content Type {bold.yellow ${this.getContentTypeId()}}`,
sections: [
{
heading: (0, chalk_1.default) `{bold Move field {yellow ${this.getFieldId()}} ${humanizedMovement}}`,
details: []
}
],
details: []
};
}
}
exports.default = FieldMoveIntent;
//# sourceMappingURL=field-move.js.map