UNPKG

@jungvonmatt/sb-migrate

Version:

CLI tool for managing Storyblok schema and content migrations

59 lines 2.83 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleCreateComponentGroup = void 0; const picocolors_1 = __importDefault(require("picocolors")); const api_1 = require("../../utils/api"); /** * Handles the creation of component groups 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. Creates new component groups that don't already exist * 4. Logs the creation status for each group * * @param {Object} migration - The migration object containing the component groups to create * @param {ComponentGroupMigration[]} migration.groups - Array of component group definitions * @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 creation fails */ const handleCreateComponentGroup = async (migration, options) => { console.log(`${picocolors_1.default.blue("-")} Creating component groups`); if (options.isDryrun) { console.log(`${picocolors_1.default.yellow("!")} Dry run - not creating component groups`); console.log(migration.groups); return; } try { const response = await api_1.api.componentGroups.getAll(); const existingGroups = response.data.component_groups || []; for (const group of migration.groups) { if (!existingGroups.some((g) => g.name === group.name)) { console.log(`${picocolors_1.default.blue("-")} Creating group: ${group.name}`); try { const result = await api_1.api.componentGroups.create({ name: group.name, }); console.log(`${picocolors_1.default.green("✓")} Group created with ID: ${result.data?.component_group?.id}`); } catch (e) { console.error(`${picocolors_1.default.red("✗")} Creation error details:`, e); throw e; } } else { console.log(`${picocolors_1.default.yellow("!")} Group already exists: ${group.name}`); } } console.log(`${picocolors_1.default.green("✓")} Component groups created successfully`); } catch (error) { console.error(`${picocolors_1.default.red("✗")} Failed to create component groups:`, error); throw error; } }; exports.handleCreateComponentGroup = handleCreateComponentGroup; //# sourceMappingURL=create.js.map