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-env

v1.0.1

Published

Specify an ENV configuration for future tasks in the chain

Downloads

120,416

Readme

grunt-env Build Status

Specify an ENV configuration as a task, e.g.

grunt.registerTask('dev', ['env:dev', 'lint', 'server', 'watch']);
grunt.registerTask('build', ['env:build', 'lint', 'other:build:tasks']);

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-env

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-env');

Configuration

  env : {
    options : {
 	//Shared Options Hash
    },
    dev : {
      NODE_ENV : 'development',
      DEST     : 'temp'
    },
    build : {
      NODE_ENV : 'production',
      DEST     : 'dist',
      concat   : {
        PATH     : {
          'value': 'node_modules/.bin',
          'delimiter': ':'
        }
      }
    },
    functions: {
      BY_FUNCTION: function() {
        var value = '123';
        grunt.log.writeln('setting BY_FUNCTION to ' + value);
        return value;
      }
    }
  }

Using external files

You can specify environment values in INI, JSON or YAML style and load them via the src option.

  env : {
    dev : {
      src : "dev.json"
    },
    prod: {
      src: "settings.yaml"
    }
    heroku : {
      src : ".env"
    }
  }

Using envdir

You can specify files to read environment variables from, similar to the daemontools envdir utility.

  env : {
    dev : {
      src : ["envdir/*"],
      options: {
        envdir: true
      }
    }
  }

Dynamic ENV configuration

The following directives can be specified in the options to alter the environment in more specific ways

  • add
    • This will add the variables only if they don't already exist
  • replace
    • Will replace the variable with the value specified
  • unshift
    • Will prepend the value to the variable specified, optionally specifying a 'delimiter'
  • push
    • Same as unshift, but at the end of the value.
  • concat
    • Functionally same as push, added for readability
yourtask : {
  USER : 'you',
  PATH : '/bin:/usr/bin'

  options : {
    add : {
      VERBOSE : '1' // will only be added if VERBOSE isn't already set
    },
    replace : {
      USER : 'me'
    },
    push : {
      PATH : {
        value : '~/bin',
        delimiter : ':'
      }
    },
    unshift : {
      PATH : '/sbin:'
    }
  }
}

Environment-specific configuration

In order to configure your tasks based on the environment, you need to define a task and use templates:


grunt.initConfig({
  env: {
    dev: {
      MY_CONST: 'a'
    },
    prod: {
      MY_CONST: 'b'
    }
  },
  myTask: {
    options: {
      myOpt: <%= MY_CONST %>
    }
  }
});

grunt.registerTask('loadconst', 'Load constants', function() {
    grunt.config('MY_CONST', process.env.MY_CONST);
});

grunt.registerTask('default', [
    'env:dev',
    'loadconst',
    'myTask'
]);

Important note on data types

Environment variables are strings only. If you attempt to assign complex objects, they will be converted to strings.

Contributing

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

Release History

  • 0.4.0 Removed automatic parse, added ability to add ini or json style src files
  • 0.3.0 Automatically parses .env files now
  • 0.2.1 fixed npm install
  • 0.2.0 grunt 0.4.0 support, simplified
  • 0.1.0 Initial release

License

Licensed under the Apache 2.0 license.

Author

Jarrod Overson