Skip to content

Commit 77fd61f

Browse files
committed
first commit
0 parents  commit 77fd61f

File tree

19 files changed

+275
-0
lines changed

19 files changed

+275
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
.DS_*
3+
yarn.lock
4+
package-lock.json
5+
6+
node_modules/

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_*
2+
node_modules
3+
*.sublime*
4+
psd
5+
thumb
6+
*.log

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- "stable"

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016 lsong
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## kelp-config
2+
3+
:sparkles: Simple light-weight configuration for kelp
4+
5+
![npm](https://badge.fury.io/js/kelp-config.png)
6+
[![Build Status](https://travis-ci.org/song940/kelp-config.svg?branch=master)](https://travis-ci.org/song940/kelp-config)
7+
8+
### Installation
9+
````
10+
$ npm install kelp-config --save
11+
````
12+
13+
### Example
14+
15+
config/default.js
16+
17+
```js
18+
module.exports = {
19+
name: 'default'
20+
};
21+
```
22+
23+
config/test.js
24+
25+
```js
26+
module.exports = {
27+
name: 'test'
28+
};
29+
```
30+
31+
config/production.js
32+
33+
```js
34+
module.exports = {
35+
name: 'production'
36+
};
37+
```
38+
39+
40+
````bash
41+
~$ node
42+
> require('kelp-config').name //-> default
43+
````
44+
45+
````bash
46+
~$ NODE_ENV=production node
47+
> require('kelp-config').name //-> production
48+
````
49+
50+
### Contributing
51+
- Fork this repo
52+
- Clone your repo
53+
- Install dependencies
54+
- Checkout a feature branch
55+
- Feel free to add your features
56+
- Make sure your features are fully tested
57+
- Open a pull request, and enjoy <3
58+
59+
### MIT license
60+
Copyright (c) 2016 lsong
61+
62+
Permission is hereby granted, free of charge, to any person obtaining a copy
63+
of this software and associated documentation files (the &quot;Software&quot;), to deal
64+
in the Software without restriction, including without limitation the rights
65+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
66+
copies of the Software, and to permit persons to whom the Software is
67+
furnished to do so, subject to the following conditions:
68+
69+
The above copyright notice and this permission notice shall be included in
70+
all copies or substantial portions of the Software.
71+
72+
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
73+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
74+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
75+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
76+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
77+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
78+
THE SOFTWARE.
79+
80+
---

config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
const fs = require('fs');
3+
const pkg = require('./package');
4+
const extend = require('extend');
5+
const resolve = require('resolve');
6+
7+
const root = process.cwd();
8+
const { CONFIG_DIR = 'config', NODE_ENV = 'development' } = process.env;
9+
10+
const load = name => {
11+
var filename;
12+
try {
13+
filename = resolve.sync(name, {
14+
basedir: root,
15+
moduleDirectory: CONFIG_DIR,
16+
extensions: ['.js', '.json', '.yaml', '.yml'],
17+
});
18+
} catch (e) { }
19+
if (!filename) return {};
20+
if (/\.ya?ml$/.test(filename)) {
21+
const data = fs.readFileSync(filename, 'utf8')
22+
return require('js-yaml').safeLoad(data);
23+
}
24+
return require(filename);
25+
};
26+
27+
const config = defaults => {
28+
return extend(true,
29+
defaults,
30+
pkg,
31+
load('default'),
32+
load(NODE_ENV),
33+
load('local'),
34+
);
35+
};
36+
37+
module.exports = config;

example/config/default.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
port: 3000,
3+
middleware: [
4+
'a',
5+
'b',
6+
'c'
7+
]
8+
};

example/config/development.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
module.exports = {
3+
middleware: [
4+
'a,'
5+
]
6+
};

example/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const config = require('..');
2+
3+
console.log(config);

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
const config = require('./config');
3+
4+
module.exports = config({});

0 commit comments

Comments
 (0)