Skip to content

Commit 27a8de1

Browse files
vdakalovnodkz
authored andcommitted
feat: add possibility to provide config via environment variables (#77)
* fix #76: reading options from environment * Add information to README.md and fix for eslint * Moved notice about env vars to another section of README.md * chore: upgrade babel till 7.0.0 * chore: update other dependencies * fix: reading default options from ENV variables
1 parent bbf75b8 commit 27a8de1

File tree

7 files changed

+2504
-902
lines changed

7 files changed

+2504
-902
lines changed

.babelrc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
{
1+
{
22
"presets": [
3-
["env", {
4-
"targets": {
5-
"node": 6
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": 6
8+
}
69
}
7-
}]
10+
],
11+
"@babel/preset-flow"
812
],
913
"plugins": [
10-
"transform-object-rest-spread",
11-
"transform-class-properties",
12-
"transform-flow-strip-types",
13-
["transform-runtime", {
14-
"helpers": false,
15-
"polyfill": false,
16-
"regenerator": true
17-
}]
14+
"@babel/plugin-proposal-object-rest-spread",
15+
"@babel/plugin-proposal-class-properties",
16+
"@babel/plugin-transform-flow-strip-types",
17+
["@babel/plugin-proposal-optional-chaining", { "loose": false }]
1818
]
1919
}

.flowconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
[options]
4141
esproposal.class_instance_fields=enable
4242
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
43+
esproposal.optional_chaining=enable

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ notifications:
99
email: true
1010
node_js:
1111
- "10"
12-
- "9"
1312
- "8"
1413
script:
1514
- yarn run test

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ const mongod = new MongodbMemoryServer({
6464
autoStart?: boolean, // by default true
6565
});
6666
```
67-
67+
Also you can use the environment variables for configure installation process
68+
```
69+
MONGOMS_DOWNLOAD_DIR=/path/to/mongodb/binaries
70+
MONGOMS_PLATFORM=linux
71+
MONGOMS_ARCH=x64
72+
MONGOMS_VERSION=3
73+
MONGOMS_DEBUG=1 # also available case-insensitive values: "on" "yes" "true"
74+
```
6875
### Simple test with MongoClient
6976
7077
Take a look at this [test file](https://github.com/nodkz/mongodb-memory-server/blob/master/src/__tests__/singleDB-test.js).

package.json

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,35 @@
2424
},
2525
"homepage": "https://github.com/nodkz/mongodb-memory-server",
2626
"devDependencies": {
27-
"babel-cli": "^6.26.0",
28-
"babel-eslint": "^8.2.6",
29-
"babel-jest": "^23.4.2",
30-
"babel-plugin-transform-class-properties": "^6.24.1",
31-
"babel-plugin-transform-flow-strip-types": "^6.22.0",
32-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
33-
"babel-plugin-transform-runtime": "^6.23.0",
34-
"babel-preset-env": "^1.7.0",
27+
"@babel/cli": "^7.0.0",
28+
"@babel/core": "^7.0.0",
29+
"@babel/plugin-proposal-class-properties": "^7.0.0",
30+
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
31+
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
32+
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
33+
"@babel/preset-env": "^7.0.0",
34+
"@babel/preset-flow": "^7.0.0",
35+
"babel-core": "^7.0.0-bridge.0",
36+
"babel-eslint": "^9.0.0",
37+
"babel-jest": "^23.6.0",
3538
"cz-conventional-changelog": "^2.1.0",
36-
"eslint": "^5.2.0",
37-
"eslint-config-airbnb-base": "^13.0.0",
38-
"eslint-config-prettier": "^2.9.0",
39+
"eslint": "^5.5.0",
40+
"eslint-config-airbnb-base": "^13.1.0",
41+
"eslint-config-prettier": "^3.0.1",
3942
"eslint-plugin-flowtype": "^2.50.0",
40-
"eslint-plugin-import": "^2.12.0",
43+
"eslint-plugin-import": "^2.14.0",
4144
"eslint-plugin-prettier": "^2.6.2",
42-
"flow-bin": "^0.77.0",
43-
"jest": "^23.4.2",
44-
"mongodb": "3.1.1",
45+
"flow-bin": "^0.80.0",
46+
"jest": "^23.6.0",
47+
"mongodb": "3.1.4",
4548
"npm-run-all": "^4.1.3",
46-
"prettier": "^1.14.0",
49+
"prettier": "^1.14.2",
4750
"rimraf": "^2.6.2",
48-
"semantic-release": "^15.9.3"
51+
"semantic-release": "^15.9.15"
4952
},
5053
"dependencies": {
51-
"babel-runtime": "^6.26.0",
52-
"debug": "^3.1.0",
54+
"@babel/runtime": "^7.0.0",
55+
"debug": "^4.0.1",
5356
"decompress": "^4.2.0",
5457
"get-port": "^4.0.0",
5558
"getos": "^3.1.0",

src/util/MongoBinary.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ export default class MongoBinary {
2222
static cache: MongoBinaryCache = {};
2323

2424
static async getPath(opts?: MongoBinaryOpts = {}): Promise<string> {
25-
const {
26-
downloadDir = path.resolve(os.homedir(), '.mongodb-binaries'),
27-
platform = os.platform(),
28-
arch = os.arch(),
29-
version = 'latest',
30-
} = opts;
25+
const defaultOptions = {
26+
downloadDir:
27+
process.env?.MONGOMS_DOWNLOAD_DIR || path.resolve(os.homedir(), '.mongodb-binaries'),
28+
platform: process.env?.MONGOMS_PLATFORM || os.platform(),
29+
arch: process.env?.MONGOMS_ARCH || os.arch(),
30+
version: process.env?.MONGOMS_VERSION || 'latest',
31+
debug:
32+
typeof process.env.MONGOMS_DEBUG === 'string'
33+
? ['1', 'on', 'yes', 'true'].indexOf(process.env.MONGOMS_DEBUG.toLowerCase()) !== -1
34+
: false,
35+
};
36+
37+
const { downloadDir, platform, arch, version } = Object.assign({}, defaultOptions, opts);
3138

3239
let debug;
3340
if (opts.debug) {

0 commit comments

Comments
 (0)