'use strict';
/**
 * Plugin configuration.
 */

const _ = require('lodash');

/**
 * Plugin defaults
 */
const DefaultConfig = {
  webpackConfig: 'webpack.config.js',
  includeModules: false,
  packager: 'npm',
  packagerOptions: {},
  keepOutputDirectory: false,
  config: null,
  serializedCompile: false
};

class Configuration {
  constructor(custom) {
    this._config = {};
    this._hasLegacyConfig = false;

    // Set configuration from sls.service.custom. We fall back to the
    // old configuration to keep backwards compatibility.
    if (custom) {
      if (custom.webpackIncludeModules) {
        this._config.includeModules = custom.webpackIncludeModules;
        this._hasLegacyConfig = true;
      }
      if (_.isString(custom.webpack)) {
        this._config.webpackConfig = custom.webpack;
        this._hasLegacyConfig = true;
      } else {
        _.assign(this._config, custom.webpack || {});
      }
    }

    // Set defaults for all missing properties
    _.defaults(this._config, DefaultConfig);
  }

  get webpackConfig() {
    return this._config.webpackConfig;
  }

  get includeModules() {
    return this._config.includeModules;
  }

  get excludeFiles() {
    return this._config.excludeFiles;
  }
  
  get excludeRegex() {
    return this._config.excludeRegex;
  }

  get packager() {
    return this._config.packager;
  }

  get packagerOptions() {
    return this._config.packagerOptions;
  }

  get config() {
    return this._config.config;
  }

  get hasLegacyConfig() {
    return this._hasLegacyConfig;
  }

  get keepOutputDirectory() {
    return this._config.keepOutputDirectory;
  }

  get serializedCompile() {
    return this._config.serializedCompile;
  }

  toJSON() {
    return _.omitBy(this._config, _.isNil);
  }
}

module.exports = Configuration;

'use strict';
/**
 * Plugin configuration.
 */

const _ = require('lodash');

/**
 * Plugin defaults
 */
const DefaultConfig = {
  webpackConfig: 'webpack.config.js',
  includeModules: false,
  packager: 'npm',
  packagerOptions: {},
  keepOutputDirectory: false,
  config: null,
  concurrency: undefined
};

class Configuration {
  constructor(custom) {
    this._config = {};
    this._hasLegacyConfig = false;

    // Set configuration from sls.service.custom. We fall back to the
    // old configuration to keep backwards compatibility.
    if (custom) {
      if (custom.webpackIncludeModules) {
        this._config.includeModules = custom.webpackIncludeModules;
        this._hasLegacyConfig = true;
      }
      if (_.isString(custom.webpack)) {
        this._config.webpackConfig = custom.webpack;
        this._hasLegacyConfig = true;
      } else {
        _.assign(this._config, custom.webpack || {});
      }
    }

    // Set defaults for all missing properties
    _.defaults(this._config, DefaultConfig);
  }

  get webpackConfig() {
    return this._config.webpackConfig;
  }

  get includeModules() {
    return this._config.includeModules;
  }

  get excludeFiles() {
    return this._config.excludeFiles;
  }
  
  get excludeRegex() {
    return this._config.excludeRegex;
  }

  get packager() {
    return this._config.packager;
  }

  get packagerOptions() {
    return this._config.packagerOptions;
  }

  get config() {
    return this._config.config;
  }

  get hasLegacyConfig() {
    return this._hasLegacyConfig;
  }

  get keepOutputDirectory() {
    return this._config.keepOutputDirectory;
  }

  get concurrency() {
    return this._config.concurrency;
  }

  toJSON() {
    return _.omitBy(this._config, _.isNil);
  }
}

module.exports = Configuration;

Rename to concurrency