lib/pact-publisher.js
function PactPublisher (configOrVersion, brokerBaseUrl, pacts) {
  var _version, _brokerBaseUrl, _pacts;
  if (!_.contains(['object', 'string'], typeof configOrVersion)) {
    throw new TypeError('Invalid first parameter provided constructing Pact Publisher. Expected a config object or version string for first parameter.');
  }
  _version        = configOrVersion.appVersion || configOrVersion;
  _brokerBaseUrl  = configOrVersion.brokerBaseUrl || brokerBaseUrl;
  _pacts          = configOrVersion.pacts || pacts;
  _logging        = _.isBoolean(configOrVersion.logging) ? configOrVersion.logging : true;
  if (!_.isString(_version)) {
    throw new Error("Expected a string for version number parameter.");
  }
  if (!_.isString(_brokerBaseUrl)) {
    throw new Error("Expected a string for broker base URL parameter.");
  }
  if (_pacts !== undefined && !(_.isString(_pacts) || _.isArray(_pacts))) {
    throw new Error("Expected a string or array for pacts parameter.");
  }
  this._appVersion          = _version;
  this._pactBrokerBaseUrl   = _brokerBaseUrl;
  this._pactUrl             = "{pactBaseUrl}/pacts/provider/{provider}/consumer/{consumer}/version/{version}".replace("{pactBaseUrl}", this._pactBrokerBaseUrl).replace('{version}', this._appVersion);
  this._logging             = _logging;
  if (_.isString(_pacts)) {
    if (!fs.existsSync(_pacts)) {
      throw new Error("Pact directory " + _pacts + " does not exist");
    }
    this._enqueuedPactFiles = fs.readdirSync(_pacts).filter(function (file) {
      return path.extname(file) === '.json';
    }).map(function (file) {
      return _pacts + '/' + file;
    });
  } else if (_.isArray(_pacts)) {
    this._enqueuedPactFiles = _pacts;
  } else {
    this._enqueuedPactFiles = [];
  }
}
function PactPublisher (configOrVersion, brokerBaseUrl, pacts) {
  var _version, _brokerBaseUrl, _pacts;
  if (!_.contains(['object', 'string'], typeof configOrVersion)) {
    throw new TypeError('Invalid first parameter provided constructing Pact Publisher. Expected a config object or version string for first parameter.');
  }
  _version        = configOrVersion.appVersion || configOrVersion;
  _brokerBaseUrl  = configOrVersion.brokerBaseUrl || brokerBaseUrl;
  _pacts          = configOrVersion.pacts || pacts;
  _logging        = _.isBoolean(configOrVersion.logging) ? configOrVersion.logging : true;
  if (!_.isString(_version)) {
    throw new Error("Expected a string for version number parameter.");
  }
  if (!_.isString(_brokerBaseUrl)) {
    throw new Error("Expected a string for broker base URL parameter.");
  }
  if (_pacts !== undefined && !(_.isString(_pacts) || _.isArray(_pacts))) {
    throw new Error("Expected a string or array for pacts parameter.");
  }
  this._appVersion          = _version;
  this._pactBrokerBaseUrl   = _brokerBaseUrl;
  this._pactUrl             = "{pactBaseUrl}/pacts/provider/{provider}/consumer/{consumer}/version/{version}".replace("{pactBaseUrl}", this._pactBrokerBaseUrl).replace('{version}', this._appVersion);
  this._logging             = _logging;
  if (_.isString(_pacts)) {
    if (!fs.existsSync(_pacts)) {
      throw new Error("Pact directory " + _pacts + " does not exist");
    }
    this._enqueuedPactFiles = fs.readdirSync(_pacts).filter(function (file) {
      return path.extname(file) === '.json';
    }).map(function (file) {
      return _pacts + '/' + file;
    });
  } else if (_.isArray(_pacts)) {
    this._enqueuedPactFiles = _pacts;
  } else {
    this._enqueuedPactFiles = [];
  }
}
function PactPublisher ( configOrVersion , brokerBaseUrl , pacts ) { var _version , _brokerBaseUrl , _pacts ; if ( ! _ . contains ( [ 'object' , 'string' ] , typeof configOrVersion ) ) { throw new TypeError ( 'Invalid first parameter provided constructing Pact Publisher. Expected a config object or version string for first parameter.' ) ; } _version = configOrVersion . appVersion || configOrVersion ; _brokerBaseUrl = configOrVersion . brokerBaseUrl || brokerBaseUrl ; _pacts = configOrVersion . pacts || pacts ; _logging = _ . isBoolean ( configOrVersion . logging ) ? configOrVersion . logging : true ; if ( ! _ . isString ( _version ) ) { throw new Error ( "Expected a string for version number parameter." ) ; } if ( ! _ . isString ( _brokerBaseUrl ) ) { throw new Error ( "Expected a string for broker base URL parameter." ) ; } if ( _pacts !== undefined && ! ( _ . isString ( _pacts ) || _ . isArray ( _pacts ) ) ) { throw new Error ( "Expected a string or array for pacts parameter." ) ; } this . _appVersion = _version ; this . _pactBrokerBaseUrl = _brokerBaseUrl ; this . _pactUrl = "{pactBaseUrl}/pacts/provider/{provider}/consumer/{consumer}/version/{version}" . replace ( "{pactBaseUrl}" , this . _pactBrokerBaseUrl ) . replace ( '{version}' , this . _appVersion ) ; this . _logging = _logging ; if ( _ . isString ( _pacts ) ) { if ( ! fs . existsSync ( _pacts ) ) { throw new Error ( "Pact directory " + _pacts + " does not exist" ) ; } this . _enqueuedPactFiles = fs . readdirSync ( _pacts ) . filter ( function ( file ) { return path . extname ( file ) === '.json' ; } ) . map ( function ( file ) { return _pacts + '/' + file ; } ) ; } else if ( _ . isArray ( _pacts ) ) { this . _enqueuedPactFiles = _pacts ; } else { this . _enqueuedPactFiles = [ ] ; } }
A pact publisher
@param  {Object|String}  configOrVersion Config object or version number.
If config object is provided, it's
just an object containing:
- {String} appVersion
- {String} brokerBaseUrl
- {Array|String} pact
- {Boolean} logging (if set to
false, no logs will be output)
@param  {String}         brokerBaseUrl   Base url of the remote pact broker.
@param  {Array|String}   pacts           Where pact contracts are located.
Optional parameter. If array is
provided, then it's expected that
this will contain absolute paths
of every pact JSON file. If string
then it's expected that this is a
directory containing pact JSON
contracts and will publish every
JSON file in that directory.
A pact publisher