CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-grunt-env

Grunt plugin for specifying environment variable configurations in task chains

81

0.98x
Overview
Eval results
Files

task.mdevals/scenario-5/

Conditional Environment Merge

Configure a Grunt helper that merges environment values from a config file and inline defaults without clobbering existing settings. It should expose two environment targets, defaults and production, that can be run to populate process.env. Both targets should read key/value pairs from config/env.json before applying their conditional rules.

Capabilities

Adds defaults without overwriting existing values

  • Starting with process.env.LOG_LEVEL="warn" and no API_BASE, running the defaults target leaves LOG_LEVEL unchanged and sets API_BASE to http://localhost:4000. @test

Replaces only present keys

  • Starting with process.env.NODE_ENV="staging" and FEATURE_FLAG unset, running the production target updates NODE_ENV to production but leaves FEATURE_FLAG undefined. @test

Combines file values with conditional rules

  • Given config/env.json containing { "PORT": "9000", "SERVICE_NAME": "billing" } and process.env.SERVICE_NAME preset to frontend, running the production target yields PORT="9000" and SERVICE_NAME="billing" while preserving any other preexisting env entries. @test

Implementation

@generates

API

/**
 * Registers environment targets for conditional merging of process.env values.
 * @param {import('grunt')} grunt - Grunt instance used to configure and run tasks.
 */
module.exports = function configureEnv(grunt);

Dependencies { .dependencies }

grunt-env { .dependency }

Grunt plugin for applying environment configurations with conditional merges.

Install with Tessl CLI

npx tessl i tessl/npm-grunt-env

tile.json