'use strict';

// UTILS
const tools = require('../../../utils/tools');
const configUtils = require('../../config/config-utils');

// INNER MODULES
const innerReleaseVirtualRemote = require('./release-virtual-remote');
const innerReleaseUi = require('./release-ui');
const innerReleaseOldRemote = require('./release-old-remote');


module.exports.run = () => {

  // TESTING a release pipeline in DRY-RUN mode :
  // virtual remotes
  // npm run pkg:release mywp-dashboard-eui15-remote-el-ui -- --dryRun --branch master --envTarget DEV --skipInstall --debug --build

  // normal UI package / old style remote
  // npm run pkg:release mywp-shell-ui -- --dryRun --branch master --skipLint --skipInstall --skipTest --skipDoc --skipClone --skipAudit --debug --debugNotification --build --ci --pipelineId 99999


  return Promise.resolve()
    // LOGGING CURRENT eUI TOOLS VERSION
    .then(() => {
      tools.logVersion();
    })

    // CHECKING if release is for virtual remote or normal UI package (including normal remote)
    .then(() => {
      const pkgName = tools.getArgs().root;
      const isVirtualRemote = configUtils.remotes.isVirtualRemote(pkgName);
      const isOldRemote = configUtils.packages.isRemote(pkgName);

      if (isVirtualRemote) {
        return innerReleaseVirtualRemote.run();
      } else if (isOldRemote) {
        return innerReleaseOldRemote.run();
      } else {
        return innerReleaseUi.run();
      }
    })

    .catch((e) => {
      throw e;
    })
}
