Comparing version 0.1.4 to 0.2.4
@@ -41,3 +41,33 @@ # Featurama | ||
### featurama.on(featureName) | ||
Enable the indicated feature | ||
**Parameters** | ||
**featureName**: `String`, Enable the indicated feature | ||
### featurama.off(featureName) | ||
Disable the indicated feature | ||
**Parameters** | ||
**featureName**: `String`, Disable the indicated feature | ||
### featurama.enabled(featureName) | ||
Return the on/off status of the indicated feature | ||
**Parameters** | ||
**featureName**: `String`, Return the on/off status of the indicated feature | ||
* * * | ||
@@ -44,0 +74,0 @@ |
{ | ||
"name": "featurama", | ||
"version": "0.1.4", | ||
"version": "0.2.4", | ||
"description": "Enable/Disable features via JS config files.", | ||
@@ -5,0 +5,0 @@ "main": "src/featurama.js", |
# Featurama | ||
[![Circle CI](https://circleci.com/gh/sparkbox/featurama.svg?style=svg)](https://circleci.com/gh/sparkbox/featurama) | ||
@@ -7,2 +8,6 @@ Removing the chaos from your features. | ||
Featurama gives you feature flags for enabling front-end features **at build-time and run-time**, while using the same configuration. | ||
## Installation | ||
``` | ||
@@ -12,4 +17,6 @@ npm install featurama | ||
To use: | ||
## Usage | ||
To use build-time featurama: | ||
``` | ||
@@ -22,2 +29,8 @@ var featurama = require('featurama')({ | ||
To use run-time featurama: | ||
1. Include `featurama-client.js` into your client-side javascript build. | ||
2. Set up a build-task that adds the run-time configuration file to your client-side javscript assests (See: `featurama.buildRunTimeConfigFile()` in the [API section](#api) below). | ||
## Configuration Setup | ||
In `/features` (or whatever you specified as the `featurePath`): | ||
@@ -41,46 +54,86 @@ | ||
## API | ||
### Run-time Methods | ||
* * * | ||
**featurama.enabled(featureName)** | ||
### featurama.isBuildTimeEnabled(buildTimeEnabled) | ||
Given a feature name, this indicates if it is enabled or not. | ||
Return the boolean value or execute the function that defines if this feature is enabled or not. | ||
| Parameter | Type | Description | | ||
|---|---|---| | ||
| `featureName` | `string` | the name of the feature | | ||
| Returns: | `boolean` | `true` if enabled | | ||
**Parameters** | ||
**featurama.on(featureName)** | ||
**buildTimeEnabled**: `boolean | function`, data from the config file that indicates enabled status | ||
Given a feature name, this enables that feature. | ||
**Returns**: `boolean`, `true` if enabled | ||
| Parameter | Type | Description | | ||
|---|---|---| | ||
| `featureName` | `string` | the name of the feature | | ||
**featurama.off(featureName)** | ||
### featurama.buildFeatureExclusions() | ||
Given a feature name, this disables that feature. | ||
Build a list of files to exclude | ||
| Parameter | Type | Description | | ||
|---|---|---| | ||
| `featureName` | `string` | the name of the feature | | ||
**Returns**: `object`, object of arrays containing files to exclude | ||
* * * | ||
### featurama.buildFeatureInclusions() | ||
### Build-time Methods | ||
Build a list of files to include | ||
**featurama.isBuildTimeEnabled(buildTimeEnabled)** | ||
**Returns**: `object`, object of arrays containing files to include | ||
Return the boolean value or executes the function that defines if this feature is enabled or not. | ||
| Parameter | Type | Description | | ||
|---|---|---| | ||
| `buildTimeEnabled` | `boolean | function` | data from the config file that indicates enabled status | | ||
| Returns: | `boolean` | `true` if enabled | | ||
### featurama.featureValuesList() | ||
Get a list of all of the declared features, teir states, and file lists | ||
**featurama.buildFeatureExclusions** | ||
**Returns**: `object`, Combined feature configs | ||
Build a list of files to exclude | ||
| | Type | Description | | ||
|---|---|---| | ||
| Returns: | `object` | object of arrays containing files to exclude | | ||
### featurama.featureList() | ||
**featurama.buildFeatureInclusions()** | ||
Build a list of files to include | ||
| | Type | Description | | ||
|---|---|---| | ||
| Returns: | `object` | object of arrays containing files to include | | ||
**featurama.featureValuesList()** | ||
Get a list of all of the declared features, their states, and file lists | ||
| | Type | Description | | ||
|---|---|---| | ||
| Returns: | `object` | combined feature configs | | ||
**featurama.featureList()** | ||
Build a key:value list of features and their enabled states | ||
**Returns**: `object`, key: value pairs | ||
| | Type | Description | | ||
|---|---|---| | ||
| Returns: | `object` | key: value pairs | | ||
**featurama.buildRunTimeConfigFile(outputFolder, outputType)** | ||
Generates a config file (named `runTimeFlags.js`) to be included in your client-side code. This file bridges the gap between your featurama configuration and your run-time feature flags. | ||
* * * | ||
| Parameter | Type | Description | | ||
|---|---|---| | ||
| `outputFolder` | `string` | path to the folder where you want to generate `runTimeFlags.js`; example: `path/to/my/scripts`. | | ||
| `outputType` | `string` | The type of output ['var', 'ES6'] | ||
| |
@@ -143,3 +143,17 @@ 'use strict'; | ||
function buildRunTimeConfigFile(outputFolder) { | ||
/** | ||
* Wrap the flags in either a variable declaration or module | ||
* | ||
* @param {String} flags - The list of flags to save to file | ||
* @param {String} type - The type of output ['var', 'ES6'] | ||
*/ | ||
function flagWrapper(flags, type) { | ||
if (type.toLowerCase() === 'es6') { | ||
return `const featuramaRunTimeFlags = ${flags}\n\nexport {featuramaRunTimeFlags};`; | ||
} else { | ||
return `var featuramaRunTimeFlags = ${flags}`; | ||
} | ||
} | ||
function buildRunTimeConfigFile(outputFolder, outputType) { | ||
const files = _getFeatureFiles(); | ||
@@ -163,3 +177,3 @@ let runTimeFlags = '{'; | ||
runTimeFlags = _.trim(runTimeFlags, ',') + '};'; | ||
fs.writeFile(path.resolve(outputFolder, 'runTimeFlags.js'), 'var featuramaRunTimeFlags = ' + runTimeFlags); | ||
fs.writeFile(path.resolve(outputFolder, 'runTimeFlags.js'), flagWrapper(runTimeFlags, outputType || 'var')); | ||
@@ -166,0 +180,0 @@ return JSON.stringify(runTimeFlags) |
331481
68
5861
136