Todd Wolfson

Software Engineer

January 19, 2014

For small projects, a high level dependency solution (e.g. bower, component) can take up more time than it's worth. As a result, I opt for a combination of grunt tasks that download and extract my dependencies.

Benefits to this approach include:

  • No opt-in support required from repositories
  • Keep record of where dependencies came from
  • Manage sets of options for compiled libraries (e.g. highlightjs)
  • Blends in to normal grunt workflow

Below is a stripped down set of what is used for twolfson.com:

grunt.initConfig({
  curl: {
    // Micro libraries via http://microjs.com/
    'public/js/ready.js': 'https://raw.github.com/ded/domready/b3ba502dcd41b67fc2fcd06416b9d0be27a8dce2/ready.js',
    'public/js/gator.js': 'https://raw.github.com/ccampbell/gator/1.2.2/gator.js',
    'public/js/gator-legacy.js': 'https://raw.github.com/ccampbell/gator/1.2.2/plugins/gator-legacy.js',

    // Example of complex flags
    highlight: {
      dest: 'tmp/highlight.zip',
      src: {
        url: 'http://highlightjs.org/download/',
        method: 'post',
        form: {'bash.js': 'on', 'css.js': 'on'/*, ... */}
      }
    }
  },
  unzip: {
    highlight: {
      src: 'tmp/highlight.zip',
      dest: 'tmp/highlight'
    }
  },
  copy: {
    'public/css/base/highlight.scss': 'tmp/highlight/styles/github.css',
    'public/js/highlight.js': 'tmp/highlight/highlight.pack.js'
  }
});

// Combine all actions into a single task
grunt.registerTask('install', ['curl', 'unzip', 'copy']);

Running grunt install yields:

Running "curl:public/js/ready.js" (curl) task
File "public/js/ready.js" created.

Running "curl:public/js/gator.js" (curl) task
File "public/js/gator.js" created.

Running "curl:public/js/gator-legacy.js" (curl) task
File "public/js/gator-legacy.js" created.

Running "unzip:highlight" (unzip) task
File "tmp/highlight" created.

Running "copy:public/css/base/highlight.scss" (copy) task
Copied 1 files

Running "copy:public/js/highlight.js" (copy) task
Copied 1 files

Done, without errors.

The tasks used above were:

This was originally inspired by Bootstrap's customize feature. I wanted a solution to download a compiled custom flavor of Bootstrap.

The original proof of concept downloaded the uncustomized version and can be found at: https://gist.github.com/twolfson/4526992

Top articles

Lessons of a startup engineer

Lessons from being a 3x first engineer, former Uber engineer, and working at even more startups

Develop faster

Removing the tedium from creating, developing, and publishing repos.

Sexy bash prompt

A bash prompt with colors, git statuses, and git branches.