Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
MoOx committed Aug 4, 2015
0 parents commit 3d4e05b
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"stage": 0
}
13 changes: 13 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .eslintignore
37 changes: 37 additions & 0 deletions .eslintrc
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"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: node_js
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.0.0 - 2015-08-04

✨ First release
20 changes: 20 additions & 0 deletions LICENSE
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.
26 changes: 26 additions & 0 deletions README.md
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)
44 changes: 44 additions & 0 deletions package.json
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"
}
}
5 changes: 5 additions & 0 deletions src/__tests__/fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const value = "js"

module.exports = {
prop: value,
}
3 changes: 3 additions & 0 deletions src/__tests__/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prop": "json"
}
1 change: 1 addition & 0 deletions src/__tests__/fixture.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prop: yml
36 changes: 36 additions & 0 deletions src/__tests__/index.js
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()
})
6 changes: 6 additions & 0 deletions src/index.js
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)
}
20 changes: 20 additions & 0 deletions src/parser.js
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}'` : "")
)
}
}

0 comments on commit 3d4e05b

Please sign in to comment.