Giter Site home page Giter Site logo

sagely / load-grunt-config Goto Github PK

View Code? Open in Web Editor NEW

This project forked from firstandthird/load-grunt-config

0.0 16.0 0.0 237 KB

Grunt plugin that lets you break up your Gruntfile config by task

Home Page: firstandthird.github.io/load-grunt-config/

License: MIT License

JavaScript 99.41% CoffeeScript 0.59%

load-grunt-config's Introduction

#load-grunt-config

load-grunt-config is a Grunt library that allows you to break up your Gruntfile config by task. For most small projects a single Gruntfile.js is perfect. But as a project grows, the Gruntfile.js can quickly become unmanagable; this is where load-grunt-config comes in handy. It was heavily inspired by Thomas Boyt's "More Maintainable Gruntfiles".

##Features

##Installation

npm install -D load-grunt-config

##Example

Basic Gruntfile.js

module.exports = function(grunt) {

	require('load-grunt-config')(grunt);

};

Gruntfile.js with options

module.exports = function(grunt) {

	require('load-grunt-config')(grunt, {
		configPath: path.join(process.cwd(), 'grunt'), //path to task.js files, defaults to grunt dir
		init: true, //auto grunt.initConfig
		data: { //data passed into config.  Can use with <%= test %>
			test: false
		},
		loadGruntTasks: { //can optionally pass options to load-grunt-tasks.  If you set to false, it will disable auto loading tasks.
			pattern: 'grunt-*',
			config: require('./package.json'),
			scope: 'devDependencies'
		}
	});

};

###Grunt tasks files

Here's what the files in your grunt/ folder could look like. You can use either .js, .yaml, or .coffee - whatever you prefer and you can mix and match as you see fit.

Example js file returning an object - grunt/watch.js

module.exports = {
  all: {
    files: [
      '<%= jshint.all %>',
      'grunt/*.yaml'
    ],
    tasks: [
      'default'
    ]
  }
};

Example js file returning a function - grunt/jshint.js

module.exports = function (grunt, options) {
  return {
    all: [
      'Gruntfile.js',
      'grunt/*.js',
      'lib/*.js',
      'test/*.js',
      options.someFile
    ]
  };
};

Example yaml file - grunt/notify.yaml

default:
  options:
    message: 'Default finished'

Example coffee file - grunt/task.coffee

module.exports =
  options:
    bare: true

###Aliases

If your grunt/ folder contains an aliases.(js|yaml|coffee) file, load-grunt-config will use that to define your tasks aliases (like grunt.registerTask('default', ['jshint']);).

grunt/aliases.yaml

default:
  - 'jshint'
  - 'mocha'
  - 'notify'

Custom Config

There are certain scenarios where you might have a base config for your team, and you want to be able to override some of the config based on your personal setup. You can do that with the overridePath property. In this case, the library will merge the two, with the override path taking priority. For example:

module.exports = function(grunt) {

  require('load-grunt-config')(grunt, {
    configPath: path.join(process.cwd(), 'vendor'),
    overridePath: path.join(process.cwd(), 'config-'+process.env.USER)
  });

};

Config Grouping

load-grunt-config also supports grouping tasks. This is handy when you want to group all of your script or css tasks together. To do that, just add the suffix -tasks to your config filename and load-grunt-config will treat the filename as the task target and the top level keys as the task names.

Here's an example

Filename: /config/scripts-tasks.yaml

jshint:
  files:
    - '*.js'
watch:
  files:
    - '*.js'
  tasks:
    - 'scripts'

This would be the equivalent in your Gruntfile.js:

{
  jshint: {
    scripts: {
      files: [
        '*.js'
      ]
    }
  },
  watch: {
    scripts: {
      files: [
        '*.js'
      ],
      tasks: [
        'scripts'
      ]
    }
  }
}

load-grunt-config's People

Contributors

defaude avatar dylang avatar jgallen23 avatar khamasaki avatar pradeek avatar sebdeckers avatar shinnn avatar travi avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.