-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3d4e05b
Showing
16 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"stage": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.{md,markdown}] | ||
# Allow <br/> from Markdown | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
extends: eslint:recommended | ||
|
||
ecmaFeatures: | ||
modules: true | ||
|
||
env: | ||
es6: true | ||
browser: true | ||
node: true | ||
|
||
rules: | ||
indent: [2, 2] # 2 spaces indentation | ||
max-len: [2, 80, 4] | ||
quotes: [2, "double"] | ||
semi: [2, "never"] | ||
no-multiple-empty-lines: [2, {"max": 1}] | ||
|
||
brace-style: [2, "stroustrup"] | ||
comma-dangle: [2, "always-multiline"] | ||
comma-style: [2, "last"] | ||
computed-property-spacing: [2, "never"] | ||
dot-location: [2, "property"] | ||
|
||
one-var: [2, "never"] | ||
no-var: [2] | ||
prefer-const: [2] | ||
no-bitwise: [2] | ||
|
||
object-curly-spacing: [2, "never"] | ||
array-bracket-spacing: [2, "never"] | ||
space-unary-ops: [2, {"words": true, "nonwords": false}] | ||
space-after-keywords: [2, "always"] | ||
space-before-blocks: [2, "always"] | ||
space-before-function-paren: [2, "never"] | ||
space-in-parens: [2, "never"] | ||
spaced-comment: [2, "always"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
language: node_js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 1.0.0 - 2015-08-04 | ||
|
||
✨ First release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Maxime Thirouin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# rc-loader [![Build Status](https://travis-ci.org/MoOx/rc-loader.svg?branch=master)](https://travis-ci.org/MoOx/rc-loader) | ||
|
||
> Runtime configuration loader that supports YAML, JSON or JS. | ||
This module supercharges [rc](https://github.com/dominictarr/rc) to provide | ||
a smarter parser that can handle the following: | ||
|
||
- YAML | ||
- JSON | ||
- JS (`module.exports = {...}` or `exports = {...}`) | ||
|
||
## Installation | ||
|
||
```console | ||
$ npm install rc-loader | ||
``` | ||
|
||
## Usage | ||
|
||
See original [rc](https://github.com/dominictarr/rc) documentation. | ||
|
||
--- | ||
|
||
## [Changelog](CHANGELOG.md) | ||
|
||
## [License](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "rc-loader", | ||
"version": "1.0.0", | ||
"description": "Runtime configuration loader that supports YAML, JSON or JS", | ||
"keywords": [ | ||
"rc", | ||
"rcloader", | ||
"config" | ||
], | ||
"author": "Maxime Thirouin", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/MoOx/rc-loader.git" | ||
}, | ||
"homepage": "https://github.com/MoOx/rc-loader", | ||
"bugs": { | ||
"url": "https://github.com/MoOx/rc-loader/issues" | ||
}, | ||
"main": "dist/index.js", | ||
"files": [ | ||
"dist", | ||
"!**/__tests__" | ||
], | ||
"dependencies": { | ||
"eval": "^0.1.0", | ||
"js-yaml": "^3.3.1", | ||
"rc": "^1.1.0", | ||
"strip-json-comments": "^1.0.4" | ||
}, | ||
"devDependencies": { | ||
"babel": "^5.8.20", | ||
"babel-tape-runner": "^1.1.0", | ||
"eslint": "^1.0.0", | ||
"rimraf": "^2.4.2", | ||
"tape": "^4.0.2" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"tape": "babel-tape-runner 'src/**/__tests__/*.js'", | ||
"test": "npm run lint && npm run tape", | ||
"prepublish": "rimraf dist && babel src --out-dir dist" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const value = "js" | ||
|
||
module.exports = { | ||
prop: value, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"prop": "json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
prop: yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import path from "path" | ||
import tape from "tape" | ||
import rcLoader from ".." | ||
|
||
function loadRc(ext) { | ||
const result = rcLoader("whatever", {}, { | ||
config: path.join(__dirname, `fixture.${ext}`), | ||
}) | ||
if (!typeof result === "object") { | ||
throw new Error(`Cannot parse 'fixture.${ext}'`) | ||
} | ||
|
||
return result | ||
} | ||
|
||
tape("rc-loader", function(t) { | ||
function test(ext) { | ||
try { | ||
t.equal( | ||
loadRc(ext).prop, | ||
ext, | ||
`should parse ${ext}` | ||
) | ||
} | ||
catch (e) { | ||
t.fail(`cannot parse ${ext}`) | ||
throw e | ||
} | ||
} | ||
|
||
test("js") | ||
test("json") | ||
test("yml") | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import rc from "rc" | ||
import rcParser from "./parser" | ||
|
||
export default function rcLoader(name, defaults, argv, parser) { | ||
return rc(name, defaults, argv, parser || rcParser) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import evalModule from "eval" | ||
import yaml from "js-yaml" | ||
import stripJsonComments from "strip-json-comments" | ||
|
||
export default function parser(content, file) { | ||
try { | ||
return yaml.safeLoad(stripJsonComments(content)) | ||
} | ||
catch(e) { | ||
// `(module.)exports` = JS ? | ||
if (/exports/.test(content)) { | ||
return evalModule(content) | ||
} | ||
|
||
throw new Error( | ||
"Cannot parse runtime configuration as YAML, JSON or JS" + | ||
(file ? `from '${file}'` : "") | ||
) | ||
} | ||
} |