'use strict';

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

module.exports.cleanPackage = (pkg) => {

  return Promise.resolve()
    .then(() => {
      tools.logInfo('Cleaning dist')
      if (pkg.standalone) {
        return tools.rimraf(pkg.paths.root + '/dist');
      } else {
        return tools.rimraf(pkg.paths.root + '/**/dist');
      }
    })
    .then(() => {
      tools.logInfo('Cleaning out-tsc')
      return tools.rimraf(pkg.paths.root + '/**/out-tsc');
    })
    .then(() => {
      tools.logInfo('Cleaning temp js files')
      return tools.rimraf(pkg.paths.root + '**/src/lib/**/*.js');
    })
    .then(() => {
      tools.logInfo('Cleaning temp js map files')
      return tools.rimraf(pkg.paths.root + '**/src/lib/**/*.js.map');
    })
    .then(() => {
      tools.logInfo('Cleaning test files')
      if (pkg.standalone) {
        return tools.rimraf(pkg.paths.root + '/test');
      } else {
        return tools.rimraf(pkg.paths.root + '/**/test');
      }
    })
    .then(() => {
      tools.logSuccess();
    })
    .catch((e) => {
      throw e;
    })
}
