Ship/unship features using flags defined with declarative DSL
npm install flagshipShip/unship features using flags defined with declarative DSL.
JavaScript implementation of Flagship (Ruby)
Run below command in a directory which has package.json.
```
$ npm i --save flagship
Or if you are using yark,
``
$ yarn add flagship
`js
import Flagship from 'flagship';
const flagship = new Flagship;
flagship.define('app', (feature) => {
feature.enable('stable_feature');
feature.enable('experimental_feature', (context) => context.get('current_user').isStaff());
feature.disable('deprecated_feature');
});
flagship.selectFlagset('app');
`
`js`
if (flagship.enabled('some_feature')) {
// Implement the feature here
}
`js
// Set a value
flagship.setContext('foo', 'FOO');
// Set a function
flagship.setContext('foo', () => 'FOO');
`
`js
flagship.define('common', (feature) => {
feature.enable('stable_feature');
});
flagship.define('development', {extend: 'common'}, (feature) => {
feature.enable('experimental_feature');
});
flagship.define('production', {extend: 'common'}, (feature) => {
feature.disable('experimental_feature');
});
if (process.env.NODE_ENV === 'production') {
flagship.selectFlagset('production');
} else {
flagship.selectFlagset('development');
}
`
You can override flags with ENV named FLAGSHIP_*1.
Assuming that there is a flag "foo", you can override it with ENV FLAGSHIP_FOO=1.