@jungvonmatt/sb-migrate
Version:
CLI tool for managing Storyblok schema and content migrations
51 lines • 2.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleDeleteComponentGroup = void 0;
const api_1 = require("../../utils/api");
const picocolors_1 = __importDefault(require("picocolors"));
/**
* Handles the deletion of a component group based on the provided migration schema.
* This function performs the following operations:
* 1. Checks if the operation is a dry run
* 2. Retrieves existing component groups
* 3. Deletes the specified component group
* 4. Logs the deletion status
*
* @param {Object} migration - The migration object containing the component group ID
* @param {number | string} migration.id - The ID of the component group 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 group deletion fails
*/
const handleDeleteComponentGroup = async (migration, options) => {
console.log(`${picocolors_1.default.blue("-")} Deleting component group: ${migration.id}`);
if (options.isDryrun) {
console.log(`${picocolors_1.default.yellow("!")} Dry run - not deleting component group`);
return;
}
try {
const response = await api_1.api.componentGroups.getAll();
const existingGroups = response.data.component_groups || [];
// Find component group by ID or name
const existingGroup = existingGroups.find((g) => g.id === migration.id ||
(typeof migration.id === "string" && g.name === migration.id));
if (!existingGroup) {
throw new Error(`Component group "${migration.id}" not found`);
}
if (!existingGroup.id) {
throw new Error(`Component group "${migration.id}" has no ID`);
}
console.log(`${picocolors_1.default.blue("-")} Deleting group: ${existingGroup.name}`);
await api_1.api.componentGroups.delete(existingGroup.id);
console.log(`${picocolors_1.default.green("✓")} Component group deleted successfully`);
}
catch (error) {
console.error(`${picocolors_1.default.red("✗")} Failed to delete component group:`, error);
throw error;
}
};
exports.handleDeleteComponentGroup = handleDeleteComponentGroup;
//# sourceMappingURL=delete.js.map