'use strict';

// GLOBAL
const path = require('path');

// LOCAL
const tools = require('../tools');

// INNER MODULES
const innerNpm = require('./npm');
const innerMaven = require('./maven');

// FETCH ARGS
const { dryRun } = tools.getArgs();


module.exports.publish = (pkg) => {
  tools.logTitle(`Publishing package ${pkg.name}`);

  if (pkg.backend) {
    return innerMaven.publish(pkg);
  } else {
    return innerNpm.publish(pkg);
  }
}

module.exports.postPublish = (pkg) => {
  const postpublishScript = path.join(pkg.paths.root, 'post-publish.js');
  if (!dryRun && tools.isFileExists(postpublishScript)) {
    return tools.runScript(`node ${postpublishScript}`);
  } else {
    tools.logInfo('DRY-RUN OR post-publish.js script not found in package root --- SKIPPING');
  }
}
