npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-cli-flagpole

v0.1.1

Published

An ember-cli addon for painlessly configuring feature flags

Downloads

2

Readme

ember-cli-flagpole 🎏

Introduction

This addon provides a harness for expressing feature flags for an Ember application in an opinionated way. It is especially useful for configuring feature flags per-environment, along with default values for all environments.

// config/flagpole.js
module.exports = function(flag) {
  flag('myCoolFeature')
    .default(true)
    .env('production', false);

  flag('anotherGreatFeature')
    .env('development', true)
    .env('staging', false)
    .env('production', false);
};

or, an alternate object syntax...

// config/flagpole.js
module.exports = {
  myCoolFeature: {
    default: true,
    environments: {
      production: false
    }
  },

  anotherGreatFeature: {
    environments: {
      development: true,
      staging: false,
      production: false
    }
  }
};

then, at runtime...

import config from 'my-app/config/environment';

console.log(config.featureFlags); // ->
// in 'development': { myCoolFeature: true, anotherGreatFeature: true }
// in 'staging': { myCoolFeature: true, anotherGreatFeature: false }
// in 'production': { myCoolFeature: false, anotherGreatFeature: false }

Part of ember-cli-flagpole's intent is to provide some build-time safety for configuring feature flags "in the large" by making certain expressions that are likely to be mistakes, like duplicate flag declarations or redeclaring a default value for a flag that already has one, build-time errors.

Installation

  • ember install ember-cli-flagpole

A default blueprint is included that generates the config/flagpole.js file for you.

Why do I need this?

Chances are good that you don't, in case you don't have very many feature flags or you don't need to manage feature flags for mixes of different environments.

But, if you do fit either of those descriptions, you may feel a need for a mechanism to configure per-environment feature flags that's more succinct than passing the config object through a bunch of conditional checks and writes. You may have already written some custom glue code to enable default settings. You may have concocted a custom object format for configuring flags more conveniently.

ember-cli-flagpole is designed to make those cases fit with the Ember philosophy of "convention over configuration". There's no escaping the actual configuration of flags, but you shouldn't have to configure how those flags are transformed to be appropriate per build environment. ember-cli-flagpole helps to centralize where your flags are declared and offers a simple mechanism for declaring them.

Usage

Flagpole looks for a file named flagpole.js (default path: config/flagpole). This file should export either a function that accepts the flag helper as its sole argument, or an object that adheres to a specific structure.

In either syntax, if a default setting is omitted, the flag will default to false for any environments that are not more granularly configured.

The flag syntax

If flagpole.js exports a function, flagpole will call this function (passing the flag helper) to configure your set of feature flags. flag is helper function passed in by Flagpole at build time, allowing you to declare flags in a chained, declarative style. (See example above).

flag(name: string): <chain>

You should call flag once per feature flag. It only accepts one argument, which must be a non-empty string to be used as the key for the feature flag's eventual value. It returns an object that exposes chainable methods for configuring the named flag's value across different environments.

<chain>.default(setting: bool): <chain>

default sets the default/base value for the feature flag represented by the chaining object. The default value takes effect for any environment which has not been more granularly configured using .env().

<chain>.env(environment: string, setting: bool): <chain>

env configures a feature flag for a single environment, named by its first argument, taking the value of the second argument (which must strictly be a Boolean).

The object syntax

If flagpole.js exports an object, flagpole will attempt to read the structure and contents of this object to configure your set of feature flags.

The basic shape is:

{
  [featureFlagName: string]: {
    default?: boolean,
    environments?: {
      [environmentName]: boolean
    }
  }
}

See an example usage above.

Addon options

Some features of ember-cli-flagpole can be configured by passing options to EmberApp in your ember-cli-build.js.

// ember-cli-build.js
module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    // Configure `ember-cli-flagpole` by declaring a property by its name in the `options` argument to `EmberApp`.
    'ember-cli-flagpole': {
      // configPath: string
      // Tell flagpole where it should look for flagpole.js if you don't want to use the default location. Omit the extension.
      // default: 'config/flagpole'
      configPath: 'path/to/my/flagpole',

      // propertyName: string
      // Tell flagpole which property it should add to your app's environment config to hold the flag values.
      // default: 'featureFlags'
      propertyName: 'featureFlags',

      // omitFalseFlags: bool
      // Tell flagpole to completely omit feature flag keys whose value is `false` for the current environment, instead of including them with the value `false`.
      // default: false
      omitFalseFlags: false,
    },
  });

  return app.toTree();
};

Developing

Running Tests

A unit test suite is included:

  • npm test - runs tests using Mocha/Chai
  • npm test:watch - runs tests using Mocha/Chai and reruns tests automatically when files change
  • npm test:acceptance - runs a sh script to build the dummy application using a variety of flagpole configs to ensure that the correct config/environment results in each build.

Building

  • ember build

For more information on using ember-cli, visit https://ember-cli.com/.