'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var discovery = require('@backstage/backend-defaults/discovery');
var pluginTechdocsNode = require('@backstage/plugin-techdocs-node');
var utility = require('../../lib/utility.cjs.js');
var PublisherConfig = require('../../lib/PublisherConfig.cjs.js');

async function migrate(opts) {
  const logger = utility.createLogger({ verbose: opts.verbose });
  const config = PublisherConfig.PublisherConfig.getValidConfig(opts);
  const discovery$1 = discovery.HostDiscovery.fromConfig(config);
  const publisher = await pluginTechdocsNode.Publisher.fromConfig(config, { logger, discovery: discovery$1 });
  if (!publisher.migrateDocsCase) {
    throw new Error(`Migration not implemented for ${opts.publisherType}`);
  }
  const { isAvailable } = await publisher.getReadiness();
  if (!isAvailable) {
    throw new Error("");
  }
  const removeOriginal = opts.removeOriginal;
  const numericConcurrency = parseInt(opts.concurrency, 10);
  if (!Number.isInteger(numericConcurrency) || numericConcurrency <= 0) {
    throw new Error(
      `Concurrency must be a number greater than 1. ${opts.concurrency} provided.`
    );
  }
  await publisher.migrateDocsCase({
    concurrency: numericConcurrency,
    removeOriginal
  });
}

exports.default = migrate;
//# sourceMappingURL=migrate.cjs.js.map
