Let Grunt.js Tell You Your Code Sucks – Brian Holt – Brian Holt



Let Grunt.js Tell You Your Code Sucks – Brian Holt – Brian Holt

0 0


grunt-pres

Presentation for SkiPHP 2014: Let Grunt Tell You Your Code Sucks

On Github btholt / grunt-pres

+

Let Grunt.js Tell You Your Code Sucks

Brian Holt

Brian Holt

Some Background

  • College Dropout
  • PHP Intern @ Nu Skin Enterprises
  • Junior PHP Developer @ KSL
  • Senior Front-End Developer @ Needle
  • Taught Null to Node
  • Director of redditgifts Front-End Development @ reddit

What is Grunt.JS?

Grunt.js is a taskrunner.

  • Accomplish similar tasks to make, rake, jake, or other build tools.
  • Grunt tasks are accomplished via plugins. There exist plugins for Sass complilation, JSHint, running shell tasks, AWS deployment, etc.
  • Put simply, Grunt.js is supposed to make often-run tasks easy and painless to run.

Why? Why Grunt.js?

  • It's easy to configure. You write Grunt in JavaScript.
  • Great ecosystem. Lots of plugins already exist.
  • Plugin doesn't exist for what you want to do? grunt-shell lets you run arbitrary commands from the shell. Or it's easy to make new ones!
  • Features like LiveReload and watch are trivial to set up.

The Biggest Wins

  • The worst kind of unit tests are the ones written but never run. You waste time writing them and over time your confidence in them degrades.
  • It makes linting and style testing easy.
  • It makes tools like {less} and Sass easy to introduce and use.
  • Make your style and testing a Git pre-hook.

Let's make our own Grunt project.

Basics

  • Grunt is based on node.js. Use npm to install Grunt and its plugins as dev dependencies.
  • Grunt consumes a Gruntfile.js. There is where all your tasks and configuration.
  • In addition, Grunt can consume your package.json if you want to keep your configurations in there (JSHint, for example.)

Let's Make a ... Gruntfile!

github.com/btholt/grunt-pres-php

Recap

  • Grunt.js is a taskrunner.
  • It easily runs tasks like compilations, linting, unit tests, or any arbitrary commands from the command line.
  • It even does watches and LiveReload.
  • The worst unit tests are those never run. Grunt.js helps you do that.
  • Easy to configure and easy to create new plugins.
  • Enforce styles and test by making it a Git hook.

Questions?

@holtbt