UNPKG

@jungvonmatt/sb-migrate

Version:

CLI tool for managing Storyblok schema and content migrations

44 lines 2.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleDeleteComponent = void 0; const picocolors_1 = __importDefault(require("picocolors")); const api_1 = require("../../utils/api"); /** * Handles the deletion of a component based on the provided migration schema. * This function performs the following operations: * 1. Checks if the component exists * 2. Deletes the component from the API * * @param {Object} migration - The migration object containing the component name * @param {string | number} migration.name - The name or ID of the component to delete * @param {RunMigrationOptions} options - Configuration options for the migration * @param {boolean} [options.isDryrun] - Whether to perform a dry run without making actual changes * @throws {Error} If the component deletion fails */ const handleDeleteComponent = async (migration, options) => { console.log(`${picocolors_1.default.blue("-")} Deleting component: ${migration.name}`); if (options.isDryrun) { console.log(`${picocolors_1.default.yellow("!")} Dry run - not deleting component`); return; } try { // First get all components to find the one we want to delete const response = await api_1.api.components.getAll(); const existingComponents = response.data.components || []; const componentToDelete = existingComponents.find((c) => c.name === migration.name || c.id === migration.name); if (!componentToDelete) { throw new Error(`Component "${migration.name}" not found`); } await api_1.api.components.delete(componentToDelete.id); console.log(`${picocolors_1.default.green("✓")} Component deleted successfully: ${migration.name}`); } catch (error) { console.error(`${picocolors_1.default.red("✗")} Failed to delete component:`, error); throw error; } }; exports.handleDeleteComponent = handleDeleteComponent; //# sourceMappingURL=delete.js.map