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

gulp-config-grabber

v1.1.1

Published

Combine multiple config.json files using a flag to distinguish different environments.

Downloads

40

Readme

Gulp Config Grabber

Combine multiple config.json files using a flag to distinguish different environments.

Installation

npm i gulp-config-grabber
const configs = require('gulp-config-grabber');

If you're just trying to include a config.json file, there is no need to install this module. You can do this natively:

const config = require('./config.json');

How to use:

Pass in an object of options. See below details on the options available.

const config = configs.grab({
	file : "config.json",
	env : "production",
	flag : "site2",
	directory : "src"
});

or if you're just passing in a different config file, you can pass in a single string:

const config = configs.grab("config.json");

Options

| Param | Default | Description | |--|--|--| | file | config.json | The name of the file that should be included | env | - | Some objects in the config file can be merged based on a environment name | flag | - | Force a command flag to target a specific site directory | directory | /src | Define a directory to search for your site flag | dynamic | ['paths'] | Define a selection of keys that contain dynamic variables. These will be checked against all properties and manage the dynamic variables, e.g. {images}

You can pass in a default argument to be used on each gulp call.

const config = configs.grab({'env':'src', 'directory':'site1');

To distinguish what config file Gulp should use, pass in an arguments flag that matches all or part of your site directory.

gulp default --site2

You can also manually pass in a environmental command to overwrite any in the config files.

gulp default --site2 --production

This will grab the config.json file in your site2 project and deep merge everything to your default config.json in the root. Note, Gulp Config Grabber will only use the first argument flag.

Use Case

Assume you have a project that looks like this:

project/
├── gulpfile.js
├── config.json
├── package.json
└── src/
    ├── site1/
    └── site2/

Your root config.json file has all the settings you need. But you need to add some bespoke options for site2 only. You could create a new config.json.

But if you update one config.json, you'll need to manage the changes for all your config.json files.

This is where Gulp Config Grabber comes in. Create a config.json for each site with ONLY the changes that need to be merged into your root config.json (default) file.

project/
├── gulpfile.js
├── config.json
├── package.json
└── src/
    ├── site1/
    │  └── config.json
    └── site2/
       └── config.json

You can use special variable names that will be passed any nested objects.

Example:

{
  "project" : "My Awesome Site",
  "site"    : "site1",
  "host"    : "www.site1.loc",

  "paths" : {
    "public"  : "public_html/{site}",
    "scripts" : "src/{site}/scripts",
    "sass"    : "src/{site}/sass"
  }
}

Will return this:

{
  "project" : "My Awesome Site",
  "site"    : "site1",
  "host"    : "www.site1.loc",

  "paths" : {
    "public"  : "public_html/site1",
    "scripts" : "src/site1/scripts",
    "sass"    : "src/site1/sass"
  }
}

All objects can have special environmental nested options. If the first level of a nested object contains environment variables, (which are defined either in the initial set up or via a command flag)... then that object will be flattened respectively.

const config = configs.grab({'env':'dev');

Example config.json:

{
  "project" : "My Awesome Site",
  "site"    : "site1",
  "host"    : "www.site1.loc",

  "settings" : {
    "*" : {
      "sourceMaps"  : false,
      "minify"	    : false,
      "versioning"  : true,
    },
    "production" : {
      "minify"	    : true,
    },
    "dev" : {
      "sourceMaps"  : true,
      "minify"	    : true,
      "special"	    : true,
    }
  }
}

Will return this in a dev environment:

{
  "project" : "My Awesome Site",
  "site"    : "site1",
  "host"    : "www.site1.loc",

  "settings" : {
      "sourceMaps"  : true,
      "minify"	    : true,
      "versioning"  : true,
      "special"	    : true,
  }
}

Create

Instead of grab, you can use create instead:

const config = configs.create({'env': environment})

This does exactly the same as grab, only it generates a config.lock in the root path. This will contain the JSON code with environments managed and dynamic variable handled. The purpose of this is to avoid server-side languages (php) having to perform all the same logic.