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

grunt-environmental

v0.1.5

Published

Load process.env from environmental-style shell scripts for subsequent grunt tasks.

Downloads

10

Readme

grunt-environmental

Load process.env from environmental-style shell scripts for subsequent grunt tasks.

NPM version Build Status Dependency Status Development Dependency Status

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-environmental --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-environmental');

The "environmental" Task

This task is intended to make environment variables configured using the conventions of the environmental package available to subsequent tasks run within the same Grunt instance.

General

The environmental package uses shell scripts to establish the desired configuration, but invoking them just via exec has no effect on the environment available in the node interpreter. This task evaluates the environment, executes environmental's script, re-checks the shell environment afterward, and then the changes the script made to the environment it ran within, are made to the environment in node's process.env.

When the environmental Grunt task is invoked with a target, it uses that target as the name of the environmental shell script to execute. For example, running the Grunt task environmental:staging loads environment variables by executing the script ./envs/staging.sh. Specifying a target name that doesn't have a matching shell script in the envs directory will produce an error. If the task is invoked without a target name, the default is development (and an error will occur if the script ./envs/development.sh can't be found).

Configuration

There are two keys that the environmental task looks for within its options hash in the overall Grunt configuration,

  • envsPath By default, the environmental task looks for scripts to execute within the directory ./envs. If this isn't the correct directory in your system, use envsPath to specify a string that gives the path of the directory where shell scripts should be found.

  • inject The environmental task can also insert items into node's environment from a hash literal in the Grunt configuration. The hash of environment variables that should be injected is determined by the third part of the Grunt task name that is used to invoke it--that is the options argument name that follows the target name. When a third task name component is present, the environmental task will look for an inject key in its options, and for the task argument as a key within the inject hash. It will then take the entire content of the hash under that key and populate it into the current environment.

The keys in each injected hash are used to create the injected environment variable names. Complete names are created by appending the keys to the value in the NODE_APP_PREFIX environment variable. This will not work correctly unless the shell script executed has, in fact, set NODE_APP_PREFIX as is environmental's convention.

For example, this configuration in Gruntfile.js

  grunt.initConfig({
    environmental: {
      options: {
        envsPath: "deploys"),
        inject: {
          "greek": {
            INJECTED_A: "alpha",
            INJECTED_B: "omega"
          }
        }
      }
    }
  });

Would set deploys as the name of the directory that will be used as the location for environmental shell scripts. And, if NODE_APP_PREFIX is equal to ALPHABET, then invoking the task environmental:test:greek will load the node environment by executing deploys/test.sh and then setting the environment variables ALPHABET_INJECTED_A and ALPHABET_INJECTED_B.

Use in Task Registration

Here are two Grunt task definitions using grunt-environmental:

grunt.registerTask("test", "run automated tests", ["environmental:test", "mochacli:unit"]);
grunt.registerTask("start", "start the server in the development environment",
  ["environmental", "server-start"]);

With this configuration, the test task will be run with the environment variables set by the script ./envs/test.sh and the start task will be run with the environment established by ./envs/development.sh.

Bonus Task

This package also contains a Grunt task named "printenv", equivalent to the *nix printenv(1) command. It's used by the unit tests to sample Grunt's environment before and after the primary task executes.

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test our code using Grunt.