UNPKG

@becklyn/contentful-adapter

Version:

[![CI](https://github.com/Becklyn-Studios/contentful-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/Becklyn-Studios/contentful-adapter/actions/workflows/ci.yml)

47 lines (46 loc) 1.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMigrationsFromGenerators = void 0; const migration_1 = __importDefault(require("./migration")); const getMigrationsFromGenerators = async (language, generators) => { if (!generators) { return []; } const migrations = []; const migrationKeys = []; generators.forEach(getMigration => { const migrationFile = getMigration(language); Object.keys(migrationFile.migrations).forEach(key => { const migration = migrationFile.migrations[key]; const migrationKey = `${migrationFile.component}-${key}`; if (migrationKeys.includes(migrationKey)) { throw new Error(`Migration with migrationKey ${migrationKey} already exists`); } migrationKeys.push(migrationKey); migrations.push({ key: migrationKey, migration, }); }); }); if (!migrationKeys.includes("migration-1")) { const migrationFile = (0, migration_1.default)(language); Object.keys(migrationFile.migrations).forEach(key => { const migration = migrationFile.migrations[key]; const migrationKey = `${migrationFile.component}-${key}`; if (migrationKeys.includes(migrationKey)) { throw new Error(`Migration with migrationKey ${migrationKey} already exists`); } migrationKeys.push(migrationKey); migrations.unshift({ key: migrationKey, migration, }); }); } return migrations; }; exports.getMigrationsFromGenerators = getMigrationsFromGenerators;