Skip to content

Commit

Permalink
Add default config & readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tengattack committed Nov 21, 2016
1 parent 63a3af7 commit 47c6af2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# hane-config

Config parser for hanejs.

## Default

default config ([`./hane.yml`](./hane.yml)):

```yaml
render:
type: markdown
html: false
linkify: true
```
## LICENSE
MIT
4 changes: 4 additions & 0 deletions hane.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

render:
type: markdown
html: true
12 changes: 12 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _path = require('path');

var _path2 = _interopRequireDefault(_path);
Expand All @@ -19,13 +21,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
const configValidFields = ['render', 'deployer'];

class HaneConfig {
static getDefault() {
if (!HaneConfig.defaultConfig) {
const root = _path2.default.join(__dirname, '..');
HaneConfig.defaultConfig = new HaneConfig(root).config;
}
}
constructor(root) {
let config;
try {
const configPath = _path2.default.join(root, 'hane.yml');
const data = fs.readFileSync(configPath, 'utf8');
config = _jsYaml2.default.safeLoad(data);
config = (0, _lodash.pick)(config, configValidFields);
config = _extends({}, HaneConfig.defaultConfig, config);
} catch (e) {
config = {};
}
Expand All @@ -36,5 +45,8 @@ class HaneConfig {
}
}

HaneConfig.defaultConfig = null;
HaneConfig.getDefault();

exports.default = HaneConfig;

10 changes: 10 additions & 0 deletions src/index.es
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ import { pick } from 'lodash'
const configValidFields = [ 'render', 'deployer' ]

class HaneConfig {
static defaultConfig = null
static getDefault() {
if (!HaneConfig.defaultConfig) {
const root = path.join(__dirname, '..')
HaneConfig.defaultConfig = new HaneConfig(root).config
}
}
constructor(root) {
let config
try {
const configPath = path.join(root, 'hane.yml')
const data = fs.readFileSync(configPath, 'utf8')
config = yaml.safeLoad(data)
config = pick(config, configValidFields)
config = { ...HaneConfig.defaultConfig, ...config }
} catch (e) {
config = {}
}
Expand All @@ -23,4 +31,6 @@ class HaneConfig {
}
}

HaneConfig.getDefault()

export default HaneConfig

0 comments on commit 47c6af2

Please sign in to comment.