Giter Club home page Giter Club logo

envsub's People

Contributors

danday74 avatar gerhut avatar popovicsandras avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

envsub's Issues

Allow env/env-file to be used alongside system values

Currently if you use --env or --env-file, there is no way to also include system environment variables. For example:

# .env
ENV1=env1
ENV2=env2
# this will only substitute ENV3
$ export ENV3=env3 envsub file1 file2
# this will only substitute ENV1 and ENV2
$ export ENV3=env3 envsub file1 file2 --env-file .env

I think there are two possible ways to handle this:

  1. allow --system to work with --env-file like it works with --env
  2. provide another flag like --env-system that works similar to --env-file except it uses the system environment as well.

Support stdout

This could be a very useful utility for us. Unfortunately, it doesn't support writing the result to stdout which prevents us from using it. Could you consider adding an option for it?

Output file does not get created when running in a jest test.

I am trying to validate the creation and substitution of both template and output file in a jest test.
It works perfectly outside of a jest test --> plain js script. Am I missing out on something or is this a bug?

code(node js):

constant:

module.exports = Object.freeze({
    DEFAULT_ENVIRONMENT_SUBSTITUTION_OPTIONS: {
        all: true,
        diff: true,
        system: true,
        syntax: 'dollar-both', // env pattern: ${} and $
        envs: [{ name: 'release_version' }, { name: 'repo_suffix' }],
    }
});

function:

const substituteEnvForAllFiles = (filePathsArray, options=DEFAULT_ENVIRONMENT_SUBSTITUTION_OPTIONS) => {
    let outputFiles = [];
    filePathsArray.forEach((value) => {
        if (value === '') return;
        const output = value.replaceAll('.template', '');
        envsub({
            templateFile: value,
            outputFile: value.replaceAll('.template', ''),
            options,
        });
        outputFiles.push(output);
    });
    return outputFiles;
};

test:

const customEnvsubstOptions = {
    all: true,
    diff: true,
    system: true,
    syntax: 'dollar-both',
    envs: [{ name: 'test_env' }, { name: 'test_version' }],
};

const templateFilePaths = [
    "<cwd>/.gitlab/node/test/resource/someFileWithEnv-ci.template.yml",
    "<cwd>/.gitlab/node/test/resource/sub-dir/someFileWithEnv-ci.template.yml"
];

const resolvedTemplateFilePaths= [
    "<cwd>/.gitlab/node/test/resource/someFileWithEnv-ci.yml",
    "<cwd>/.gitlab/node/test/resource/sub-dir/someFileWithEnv-ci.yml"
];

it('should substitute all given files and write it out to a new file', () => {
    const outputFiles = substituteEnvForAllFiles(templateFilePaths, customEnvsubstOptions);
    assert.deepEqual(outputFiles, resolvedTemplateFilePaths);
});

files:
The yml files to substitute look like this.

.test-template: &test-template
    image: $test_env/bla/bla/image:$test_version
    tags:
        - test
        - nodejs

Thanks already :)

Quotes for .env file values are included in interpolation

If you have a .env file like this:

NAME="Value"

running envsub --env-file .env results in a substitution of ${NAME} for "Value".

However, running NAME="Value" envsub results in Value (not wrapped in quotes).

I think that quotes should be ignored when setting values from a key=value file as you might expect when sourcing the file in a shell environment.

The envs option does not work with envsubh

After looking through the code, it looks like envsub respects opts.envs, however envsubh just only uses the process.env for the handlebars templating, ignoring the provided option

Provide a synchronous API

Providing an asynchronous API that returns Promises forces an asynchronous approach instead of giving developers the flexibility to use the API in a synchronous or asynchronous way. I propose something like:

var result = envsub_sync(templateFile, outputFile, options);

Allow defaults for undefined variables

Would it be possible to allow a default value to be specified for undefined env vars? I've used envtpl before, which has this feature, and it was really useful. I'm not sure what it would look like here, but here's how envtpl does it:

{{ MY_VAR | default(3) }}

Thanks for this awesome module!

Bug on variable with quote and hash charater

When we add an '#' on quoted value this character is not escaped then the value we get it's not the right one.
MYVAR="any#notAcoment" we get this value "any
instead of any#notAcomment.
I already find the fix, here it's my pull request

Thanks in advance to make comment about my fix and merge it.

Ignore undefined variables

Great module.

I have a simple question - in order to be near compatible with envsubst, I was wondering if we could configure this to not replace template where variable is not found.

For example, if {{var1}} is not defined in environment, it remains as {{var1}} unlike the present behaviour, which simply removes this string.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.