Skip to content

Commit

Permalink
feat(prettier): switch to prettier (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 authored Sep 5, 2017
1 parent 5290336 commit 31b435c
Show file tree
Hide file tree
Showing 4 changed files with 1,527 additions and 59 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

[![serverless](https://img.shields.io/badge/serverless-1.0-dda415.svg)](http://www.serverless.com)
[![npm version](https://img.shields.io/npm/v/serverless-elasticsearch-client.svg)](https://www.npmjs.org/package/serverless-elasticsearch-client)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-dbb30b.svg)](https://standardjs.com)
[![CircleCI](https://circleci.com/gh/goldcaddy77/serverless-elasticsearch-client/tree/master.svg?style=shield)](https://circleci.com/gh/goldcaddy77/serverless-elasticsearch-client/tree/master)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](#badge)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)


## AWS Elasticsearch Client

Wrapper around [elasticsearch-js](https://github.com/elastic/elasticsearch-js) client that plays nicely with AWS and serverless. Features include:
Expand Down
44 changes: 24 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
'use strict'
'use strict';

const AWS = require('aws-sdk')
const elasticsearch = require('elasticsearch')
const httpAWSESClass = require('http-aws-es')
const AWS = require('aws-sdk');
const elasticsearch = require('elasticsearch');
const httpAWSESClass = require('http-aws-es');

module.exports = {
createClient: createClient,
getOptions: getOptions
}
};

function getOptions (options) {
options = options || {}
function getOptions(options) {
options = options || {};

// serverless-offline will set IS_OFFLINE based on whether we're offline
const devMode = Boolean(process.env.IS_OFFLINE)
const devMode = Boolean(process.env.IS_OFFLINE);

const prefix = options.envPrefix || 'AWS'
const region = options.region || process.env[`${prefix}_REGION`]
const host = options.host || process.env[`${prefix}_HOST`]
const prefix = options.envPrefix || 'AWS';
const region = options.region || process.env[`${prefix}_REGION`];
const host = options.host || process.env[`${prefix}_HOST`];

delete (options.region) // this doesn't belong in ES options
delete options.region; // this doesn't belong in ES options

if (!region) { throw new TypeError('region is required') }
if (!host) { throw new TypeError('host is required') }
if (!region) {
throw new TypeError('region is required');
}
if (!host) {
throw new TypeError('host is required');
}

const credentials = options.credentials || new AWS.EnvironmentCredentials(prefix)
const credentials = options.credentials || new AWS.EnvironmentCredentials(prefix);

const config = Object.assign({}, options, {
host: host,
amazonES: {
region,
credentials
}
})
});

// don't sign the request in offline mode
if (!devMode) {
config.connectionClass = httpAWSESClass
config.connectionClass = httpAWSESClass;
}

return config
return config;
}

function createClient (options) {
return new elasticsearch.Client(getOptions(options))
function createClient(options) {
return new elasticsearch.Client(getOptions(options));
}
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@
"description": "Elasticsearch client for AWS that plays nicely with serverless-offline and signed requests",
"main": "index.js",
"scripts": {
"precommit": "npm test",
"prepush": "npm test",
"preversion": "npm test",
"precommit": "lint-staged && npm test",
"preversion": "lint-staged && npm test",
"test": "./node_modules/.bin/ava --verbose",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
"type": "git",
"url": "https://github.com/goldcaddy77/serverless-elasticsearch-client.git"
},
"keywords": [
"elasticsearch",
"aws",
"serverless",
"serverless-offline"
],
"keywords": ["elasticsearch", "aws", "serverless", "serverless-offline"],
"author": "Dan Caddigan",
"license": "ISC",
"bugs": {
Expand All @@ -35,8 +29,17 @@
"aws-sdk": "^2.23.0",
"condition-circle": "^1.5.0",
"husky": "^0.13.2",
"lint-staged": "^4.1.0",
"prettier": "^1.6.1",
"semantic-release": "^7.0.2"
},
"lint-staged": {
"*.{js,json}": ["prettier --write", "git add"]
},
"prettier": {
"printWidth": 120,
"singleQuote": true
},
"release": {
"verifyConditions": "condition-circle"
}
Expand Down
Loading

0 comments on commit 31b435c

Please sign in to comment.