2.0.10 • Published 2 years ago

@blast-engine/context v2.0.10

Weekly downloads
28
License
-
Repository
-
Last release
2 years ago

Context

This is a package to help control different contexts on your node/web application.

Installation Guide

Run yarn add @blast-engine/context or npm i @blast-engine/context.

Usage

Run yarn context:select to select a previously declared context.

Run yarn context:current to see the currently selected context.

Run yarn context:set [context] to explicitly set your current context to the specified context name.

Setting Up Different Contexts

On the root directory of your application, create a file called contexts.config.js. In this file, you need to declare your different contexts. Your contexts.config.js file should follow this format:

module.exports = () => ({
  onSelect: context => null,
  // after selecting a context using `yarn context:select`,
  // this function will be called with the selected contexts values
  // as a parameter to the function
  contexts: {
    prod: {
      _showInSelect: true, 
      // if set to false, the context will not appear
      // in `yarn context:select`
      yourConfigKeys: {
        apiKey: "apiKey"
      },
      importantEnvParamForContext: "super important"
    },
    dev1: {
      _showInSelect: true,
      yourConfigKeys: {
        apiKey: "apiKey"
      },
      importantEnvParamForContext: "less important"
    }
  }
})

After selecting a context, a file called active-context will be automatically generated, listing your active context. Make sure to add active-context file to your .gitignore.

To have access to the environment parameters based on different context, you can edit the onSelect function such that it would write the specified parameters in the context into a file:

onSelect: context => fs.writeFileSync(
  './__env_config__.json', 
  JSON.stringify(context.yourConfigKeys)
)
2.0.7

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.1

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

0.1.2

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago