Skip to content

Instantly share code, notes, and snippets.

@robbschiller
Created December 6, 2013 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbschiller/7827828 to your computer and use it in GitHub Desktop.
Save robbschiller/7827828 to your computer and use it in GitHub Desktop.
Node User Group Meetup on Grunt.js
# Contents for the 1/15/14 Orlando Node User Group Meetup
Topic: Grunt.js
@TJkrusinski
Copy link

Basics

  • module.exports = function(grunt) {};
  • grunt.loadNpmTasks()
  • grunt.initConfig()
  • Sass, Less
  • Uglify, JSLint, JSHint
  • Watchify

@TJkrusinski
Copy link

Grunt-Cli Code

  • Grunt Cli just finds the grunt module relative to where you are
  • Not locked into a specific version of grunt
#!/usr/bin/env node

'use strict';

process.title = 'grunt';

// Especially badass external libs.
var findup = require('findup-sync');
var resolve = require('resolve').sync;

// Internal libs.
var options = require('../lib/cli').options;
var completion = require('../lib/completion');
var info = require('../lib/info');
var path = require('path');


var basedir = process.cwd();
var gruntpath;

// Do stuff based on CLI options.
if ('completion' in options) {
  completion.print(options.completion);
} else if (options.version) {
  info.version();
} else if (options.gruntfile) {
  basedir = path.resolve(path.dirname(options.gruntfile));
}

try {
  gruntpath = resolve('grunt', {basedir: basedir});
} catch (ex) {
  gruntpath = findup('lib/grunt.js');
  // No grunt install found!
  if (!gruntpath) {
    if (options.version) { process.exit(); }
    if (options.help) { info.help(); }
    info.fatal('Unable to find local grunt.', 99);
  }
}

// Everything looks good. Require local grunt and run it.
require(gruntpath).cli();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment