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

gruntfile

v0.1.0

Published

Gruntfile helper for making modular gruntfiles.

Downloads

55

Readme

gruntfile

Gruntfile helper for making modular gruntfiles. This module will always set the current working directory relative to the gruntfile. This allows you to use a gruntfile as a module.

example

We have a gruntfile that loads common things across many projects.

First npm install gruntfile --save in a module and setup your gruntfile:

./node_modules/modulargrunt/Gruntfile.js

module.exports = require('gruntfile')(function(grunt) {
  // These will become a default configs for inherited gruntfiles
  grunt.initConfig({
    browserify: {
      dev: {
        src: ['js/*.js'],
        dest: 'dist/js/index.js',
      },
    },
    compass: {
      dev: {
        options: {
          sassDir: 'scss',
          cssDir: 'dist/css',
        },
      },
    },
    jshint: {
      all: ['js/*.js'],
    },
  });
  // All tasks must be loaded relative to the module in node_modules
  // This should also be --save as they're now dependencies
  grunt.loadNpmTasks('grunt-contrib-compass');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-browserify');
});

Now you can install your module with npm install (if published) or npm link as a local development dependency:

./Gruntfile.js

module.exports = function(grunt) {

  // Init our modular gruntfile and return the tasks it uses
  var tasks = require('modulargrunt')(grunt);

  grunt.initConfig({
    // Add new task config
    watch: {
      livereload: {
        options: { livereload: true },
        files: ['dist/**/*'],
      },
      js: {
        files: ['js/*.js', 'Gruntfile.js'],
        tasks: ['browserify'],
      },
      css: {
        files: ['scss/*.scss'],
        tasks: ['compass'],
      },
    },
    // Override inherited task config
    browserify: {
      dev: {
        src: ['js/*.js'],
        dest: 'i/now/go/somewhere/else.js',
      },
    },
  });

  grunt.loadNpmTasks('grunt-contrib-watch');

  // Run the tasks from modulargrunt and append the watch task at the end
  grunt.registerTask('default', tasks.concat('watch'));
};

api

require('gruntfile')(gruntfile)

It accepts a gruntfile function as the only argument and returns a wrapped gruntfile like function(grunt, parentCWD).

Will default the cwd relative to the gruntfile. If parentCWD is false then the gruntfile has no parent otherwise it will be the path to the parent that called the child gruntfile.

By default it will return the tasks initialized within the modular gruntfile. You can override this and return whatever you like instead:

module.exports = require('gruntfile')(function(grunt, parentCWD) {

  /* gruntfile stuff */

  return ['some', 'other', 'tasks'];
});

Is this a good idea?

I don't know. Probably not but a lot of people keep asking for this. FWIW, I've used a similar setup to this and it worked well. But I was always careful to keep my gruntfiles as simple as possible.

Release History

  • 0.1.0 initial release

License

Copyright (c) 2013 Kyle Robinson Young
Licensed under the MIT license.