normalize-config

Normalize a declarative configuration with any combination of src-dest mappings, files arrays, files objects and options into a consistent format. Uses globule to expand glob patterns and rte for dynamically generating destination paths. Inspired by Grunt

normalize-config

Normalize a declarative configuration with any combination of src-dest mappings, files arrays, files objects and options into a consistent format. Uses globule to expand glob patterns and rte for dynamically generating destination paths. Inspired by Grunt's normalizeMultiTaskFiles method.

* [Install](#install) * [Usage](#usage) * [Destination paths](#destination-paths) * [Config examples](#config-examples) * [API](#api) * [normalize](#normalize) * [.multi](#multi) * [.filePair](#filepair) * [.normalizeObj](#normalizeobj) * [Author](#author) * [License](#license)

Install with npm:

npm i normalize-config --save-dev
var normalize = require('normalize-config');
console.log(normalize({files: {'dist/': '*.js'}}));

Dynamically generate destination paths by defining a route property with the structure you want to use for the destination path(s).

Example:

var result = normalize({
  options: {
    route: 'foo/:dest/:basename.min.js'
  },
  src: ['*.js'],
  dest: 'scripts/'
});
 
//=> { files: [ { src: [ 'index.js' ], dest: 'foo/scripts/index.min.js' } ] } 

See rte for all related options.

All of these:

{files: {'dist/': '*.js'}}
{files: [{src: '*.js', dest: 'dist/'}]}
{src: '*.js', dest: 'dist/'}
{src: ['*.js'], dest: 'dist/'}

Would normalize to:

{files: [{src: ['index.js'], dest: 'dist/'}]}

All of the following:

var normalize = require('normalize-config');
 
var config = normalize({
  options: {
    expand: true,
    cwd: 'test/fixtures'
  },
  files: {
    'dist/a/': ['a/*.js'],
    'dist/b/': ['b/*.js']
  }
});
 
var result = normalize({
  options: {
    expand: true,
    cwd: 'test/fixtures'
  },
  files: [
    {dest: 'dist/a/', src: ['a/*.js']},
    {dest: 'dist/b/', src: ['b/*.js']}
  ]
});
 
var result = normalize({
  options: {
    cwd: 'test/fixtures'
  },
  files: [
    {expand: true, dest: 'dist/a/', src: ['a/*.js']},
    {expand: true, dest: 'dist/b/', src: ['b/*.js']}
  ]
});
 
var result = normalize({
  options: {
    cwd: 'test/fixtures'
  },
  files: [
    {options: {expand: true}, dest: 'dist/a/', src: ['a/*.js']},
    {options: {expand: true}, dest: 'dist/b/', src: ['b/*.js']}
  ]
});
 
console.log(config);

Would normalize to the following (see the test fixtures):

{ files:
   [ { src: [ 'a/x.js' ],
       dest: 'dist/a/a/x.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'a/*.js' ],
          dest: 'dist/a/' } },
     { src: [ 'a/y.js' ],
       dest: 'dist/a/a/y.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'a/*.js' ],
          dest: 'dist/a/' } },
     { src: [ 'b/x.js' ],
       dest: 'dist/b/b/x.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'b/*.js' ],
          dest: 'dist/b/' } },
     { src: [ 'b/y.js' ],
       dest: 'dist/b/b/y.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'b/*.js' ],
          dest: 'dist/b/' } },
     { src: [ 'b/z.js' ],
       dest: 'dist/b/b/z.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'b/*.js' ],
          dest: 'dist/b/' } } ] }

Normalize any combination of files arrays, files objects, src-dest pairings and options.

Example:

normalize({src: '*.js', dest: 'dist/'});

Params:

  • config {Object}: The config object to be normalized.
  • return{Object}

Normlize a config object with multiple files definitions.

Params:

  • config {Object}
  • options {Object}
  • return{Object}

Normalize src, dest and options definitions to an array of files objects.

Params:

  • config {Object}
  • return{Object}

Normalize files objects with varied formats to an array of files objects.

Params:

  • config {Object}
  • return{Object}

Options are passed to globule. Visit globule to see all supported options.

Jon Schlinkert

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on June 22, 2014.