'use strict';

// GLOBAL

// LOCAL
const tools = require('../tools');
const mavenUtils = require('../maven-utils');

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


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

  return Promise.resolve()
    .then(() => {
      if (pkg.build.publish) {
        if (dryRun) {
          tools.logInfo('DRY-RUN...skipping');

        } else {
          return mavenUtils.execute(pkg.paths.root, 'clean deploy -DskipTests');
        }

      } else {
        tools.logInfo('Publish flag not set or false ==> skipping');
      }
    })

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