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

desublimate

v2.2.0

Published

desublimate: Create configuration file from environment variables

Downloads

8,601

Readme

desublimate

desublimate: Create a configuration file from env variables

Why

Why indeed. This little script was inspired by Gitlab CI and outside of CI/CD, there might not be too much use for this. In CI/CD pipelines it is sometimes useful to generate configuration files depending on the target environment and sometimes using tools such as Ansible or Terraform can be overkill if the intention is to just generate simple files. Since most of the information is relayed via environment variables, templating and/or automatic creation of the said configuration files is a tempting option.

This little script does just that. In CI environment one can define variables for example PRODUCTION_DOMAIN or STAGING_DOMAIN and this script does the rest so that just the DOMAIN part ends up in the configuration file. At simplest the files are plain JSON or YAML, but can be more complex. For that use case this tool supports Handlebars templates.

Installation

npm install -g desublimate for global install or npm install desublimate for local.

Usage

Notice

Currently, by default, the tool assumes that all the files are encoded with UTF-8. Support for other character encodings is coming up!

Command line parameters:

--envFile | -e:
    Description: Variable file (dotenv-like). Used for additional variables and is applied AFTER filtering with varPrefix and varSuffix. Accepts multiple files separated with a comma.

--debug | -d:
    Description: Show debug prints.

--doNotStrip | -D:
    Description: Do not strip prefix and suffix from the environment variable.
    Default value: false

--help | -h:
    Description: This command

--ignoreEnvironment | -I:
    Description: Ignore the environment variables completely for safety and to clarify that environment is being ignored.
    Default value: false

--output | -o:
    Description: Output target.
    Possible values: file, stdout, stderr
    Default value: stdout

--outputFile | -O:
    Description: Filename and path of the file when using file output. Sets '--output file' automatically.

--parseSubobject | -b:
    Description: Create multilevel objects from environment variables

--renderer | -r:
    Description: Renderer used to format the configuration.
    Possible values: dotenv, json, yaml, handlebars
    Default value: json

--silent | -s:
    Description: Suppress all log output.
    Default value: false

--subobjectSeparator | -B:
    Description: Character or characters used to separate the different object level in the environment variables.
    Default value: __

--template | -t:
    Description: Filename and path of the Handlebars template file.

--version | -v:
    Description: undefined

--varPrefix | -P:
    Description: Variable prefix used to filter the environment variables.
    Default value:

--varSuffix | -S:
    Description: Variable suffix used to filter the environment variables.
    Default value:

Configuration file

Now a configuration file can be used to configure the... configuration file creating tool (I honestly did not realize how meta this is until writing this down :D ). The configuration file is named .e2crc and must be placed to the working directory. The order of evaluation for configuration is: 1. Defaults, 2. .e2crc 3. CLI arguments. The configuration file uses JSON format and the options are the same as when used via CLI (e.g. "envFile": "./.myenv" or "debug": true).

.env file

desublimate supports now dotenv-like .env file. By this I mean that just like with dotenv, the file is placed to the working directory and variables are defined <KEY>=<VALUE>, the formatting done to the variables, however, does differentiate from dotenv. This means that while comments (lines starting with #) are supported, features like quote conversion and multiline are missing. While it is not guaranteed that at some point down the line the tool would have full dotenv file support, it is also not guaranteed that it will happen, only time will tell.

By default, desublimate will look for .env file, but this can be overridden either in the configuration file or on command line.

Following examples assume that the package is installed globally.

Example using handlebars template:

BAR_SOMETHING_ELSE_FOO=000 BAR_SOMETHING_FOO=123 BAR_SOME=456 SOME_FOO=789 desublimate --renderer handlebars --varSuffix _FOO --varPrefix BAR_ --template test.hb --output file --outputFile ../foobar

Example with default json output and stdout:

BAR_SOMETHING_ELSE_FOO=000 BAR_SOMETHING_FOO=123 BAR_SOME=456 SOME_FOO=789 desublimate --varSuffix _FOO --varPrefix BAR_

Example with multiple .env source files and dotenv output:

desublimate -I --envFile first.env,second.env,third.env --renderer dotenv

Evaluation order

The evaluation order is:

  1. .env file
    1. If using multiple source .env files, then those are evaluated in the order they are given.
  2. environment variables

This way the file can be used to set the default values which then can be overridden with environment variables.

Notice

In the configuration file when not using a handlebars template, the prefix and suffix are stripped from the variable name.