UNPKG

@jungvonmatt/sb-migrate

Version:

CLI tool for managing Storyblok schema and content migrations

46 lines 2.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleDeleteDatasource = void 0; const picocolors_1 = __importDefault(require("picocolors")); const api_1 = require("../../utils/api"); /** * Handles the deletion of a datasource based on the provided migration schema. * This function performs the following operations: * 1. Checks if the operation is a dry run * 2. Verifies the datasource exists * 3. Deletes the datasource from the API * 4. Logs the deletion status * * @param {Object} migration - The migration object containing the datasource ID * @param {number | string} migration.id - The ID of the datasource 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 datasource deletion fails */ const handleDeleteDatasource = async (migration, options) => { console.log(`${picocolors_1.default.blue("-")} Deleting datasource: ${migration.id}`); if (options.isDryrun) { console.log(`${picocolors_1.default.yellow("!")} Dry run - not deleting datasource`); return; } try { // First verify the datasource exists const response = await api_1.api.datasources.get(migration.id); const datasource = response.data.datasource; if (!datasource) { throw new Error(`Datasource with ID "${migration.id}" not found`); } console.log(`${picocolors_1.default.blue("-")} Deleting datasource: ${datasource.name}`); await api_1.api.datasources.delete(migration.id); console.log(`${picocolors_1.default.green("✓")} Datasource deleted successfully: ${datasource.name}`); } catch (error) { // Don't rethrow - let the calling function handle it console.error(`${picocolors_1.default.red("✗")} Failed to delete datasource:`, error); } }; exports.handleDeleteDatasource = handleDeleteDatasource; //# sourceMappingURL=delete.js.map