Skip to content

Commit

Permalink
Restructure project and add CLI management.
Browse files Browse the repository at this point in the history
This commit contain changes needed to land v1.0. It's a work in progress but all of the functionality is mostly there.
Will continue working on documentation and tests going forward and updating other projects to match the new structure used here.
  • Loading branch information
dlmr committed Dec 17, 2015
1 parent bdaf193 commit a21eafe
Show file tree
Hide file tree
Showing 19 changed files with 851 additions and 456 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# roc-config
Configuration manager for the Roc ecosystem.

![stability alpha](https://img.shields.io/badge/stability-alpha-red.svg)
[![roc](https://img.shields.io/npm/v/roc-config.svg)](https://www.npmjs.com/package/roc-config)
[![Build Status](https://travis-ci.org/vgno/roc-config.svg)](https://travis-ci.org/vgno/roc-config)
[![Coverage Status](https://coveralls.io/repos/vgno/roc-config/badge.svg?branch=master&service=github)](https://coveralls.io/github/vgno/roc-config?branch=master)
Expand All @@ -11,8 +10,8 @@ Configuration manager for the Roc ecosystem.

## Important

This project will look for two environment variables; `ROC_CONFIG` and `ROC_CONFIG_OBJECT`.
If `ROC_CONFIG_OBJECT` is found those will be used **instead** of what has been appended during runtime elsewhere.
This project will look for two environment variables; `ROC_CONFIG_PATH` and `ROC_CONFIG_SETTINGS`.
If `ROC_CONFIG_SETTINGS` is found those will be used **instead** of what has been appended during runtime elsewhere at that point.

If there is a conflict where both an environment variable is set and something is appended manually, there will a a clear warning given to the user.

Expand All @@ -23,21 +22,21 @@ Once imported to your project **the configuration and all its internal states**
To generate documentation please run `npm run docs`.

## Configuration source priority
Configurations provided by environment `ROC_CONFIG_OBJECT` have highest priority amongst appends. This **overwrites all other appended properties without merge**.
Configurations provided by environment `ROC_CONFIG_SETTINGS` have highest priority amongst appends. This **overwrites the other settings without merge**.

If a configuration file path is provided by environment `ROC_CONFIG` it will load this instead of a configuration file within the project, without merging the two. Note that it _is_ subject to programmatic appends, it just loads from a different file.

`getFinalConfig()` will merge any appended programmatic configuration (or environment object) into configurations loaded from file and then finally merge this into it's own optional configuration parameter.
If a configuration file path is provided by environment `ROC_CONFIG_PATH` it will load this instead of a configuration file within the project, without merging the two. Note that it _is_ subject to programmatic appends, it just loads from a different file.

## Application Configuration Format

For _roc-config_ to understand a `roc.config.js` provided by the CLI or `ROC_CONFIG` it needs to export an object with a `config` key. This example should give a basic idea. Configurations will vary amongst Roc extensions, but they must always expose the `config` key at the time that it is called.
For _roc-config_ to understand a `roc.config.js` provided by the CLI or `ROC_CONFIG_PATH` it needs to export an object with a `settings` key. This example should give a basic idea. Configurations will vary amongst Roc extensions.

```js
module.exports = {
config: {
port: 8080,
serve: 'files',
settings: {
runtime: {
port: 8080,
serve: 'files',
},
build: {
entry: {
client: 'client.js',
Expand All @@ -55,27 +54,28 @@ This example works with `roc-web`

## API Examples

Use configuration:
Get configuration:
```js
import { getFinalConfig } from 'roc-config';
import { getConfig } from 'roc-config';

const config = getFinalConfig();
const config = getConfig();

```

Extend configuration with custom configuration and use it:
```js
import { getFinalConfig } from 'roc-config';
import { appendConfig } from 'roc-config';

const customConfig = {
property: 'value'
};

const config = getFinalConfig(customConfig);
const config = appendConfig(customConfig);
```

Perform multiple modifications and use:
```js
import { getFinalConfig, appendConfig } from 'roc-config';
import { appendConfig, getConfig } from 'roc-config';

// deep merges parameter to current appended configuration state
appendConfig({
Expand All @@ -87,5 +87,5 @@ appendConfig({
});

// config will hold { "value": "value", "value2": "value2" }
const config = getFinalConfig();
const config = getConfig();
```
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@
"rimraf": "~2.4.3"
},
"dependencies": {
"chalk": "~1.1.1",
"colors": "~1.1.2",
"deep-extend": "~0.4.0",
"lodash": "~3.10.1",
"minimist": "~1.2.0",
"resolve": "~1.1.6",
"source-map-support": "~0.3.3",
"strip-ansi": "~3.0.0"
}
Expand Down
Loading

0 comments on commit a21eafe

Please sign in to comment.