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-config-factory

v1.2.0

Published

Reduce the size of Gruntfile.js and easily find configuration by building a config from individual JSON or Javascript configuration files.

Downloads

9

Readme

Grunt Configuration Factory

Reduce the size of Gruntfile.js and easily find configuration by building a config from individual JSON or Javascript configuration files.

Install

npm install grunt-config-factory

When to choose JSON or Javascript

Choose JSON configuration when your plugin configuration is static.

Choose Javascript configuration when your plugin requires injecting an object such as global settings (e.g. project name to be used by multiple plugins).

Getting Started

Create a directory within your project to house your individual JSON or Javascript configuration files.

mkdir grunt_config

JSON Configuration Files

Create a JSON file which will house the plugin's configuration.

Note: The filename must match the plugin's expected configuration property name.

As an example, if we wanted to configure grunt-contrib-connect we need to call the file connect.json because grunt-contrib-connect expects the property name to be connect.

touch grunt_config/connect.json

The contents of the file:

# grunt_config/connect.json
{
  "server": {
    "options": {
      "port": 9001,
      "base": "www-root"
    }
  }
}

Javascript Configuration Files

Create a Javascript file which will house the plugin's configuration.

Note: The filename must match the plugin's expected configuration property name.

As an example, if we wanted to configure grunt-contrib-connect we need to call the file connect.js because grunt-contrib-connect expects the property name to be connect.

touch grunt_config/connect.js

The contents of the file:

# grunt_config/connect.js
module.exports = function(context) {
  return {
    server: {
      options: {
        port: context.connect.port,
        base: "www-root"
      }
    }
  };
};

Configuring Gruntfile.js

Generate the configuration within your Gruntfile.js

# Gruntfile.js

module.exports = function(grunt) {
  var context = { connect: { port: 8000 } }; // Optional. You could pass grunt around.
  var config = require('grunt-config-factory').build('./grunt_config', context); // Second parameter is optional. Will only be passed to Javascript files.
  grunt.initConfig(config);

  grunt.registerTask('default', []);
  grunt.loadNpmTasks('grunt-contrib-connect');
};

What the plugin does

It gets a list of JSON and/or Javascript files from the given configuration directory and creates a configuration object much the same way you would do manually.

Given the following grunt plugins:

  • grunt-contrib-connect
  • grunt-karma

And using the following configuration directory:

grunt_config/
 - connect.json
 - karma.js

The returned object would be the same as if we had returned:

{
  connect: require('./grunt_config/connect.json'),
  karma: require('./grunt_config/karma.js')(context)
}