Book Image

Mastering Grunt

By : Daniel Li
Book Image

Mastering Grunt

By: Daniel Li

Overview of this book

<p>Grunt.js continues to excel as the build automation tool of choice. Along with its support for many third-party technologies, Grunt is packaged with a clean API for defining tasks. This powerful tool can streamline your workflow by automating the preparation tasks for production, such as compression, compilation, obfuscation, testing, and even pushing your web application live. This book will teach you how to master build automation and testing with Grunt. You will have the opportunity to utilize the latest and in-demand web tools, such as Git, Jade, CoffeeScript, Sass, and the Mocha testing engine, across several exciting projects by combining Grunt with them. You will also learn to create a project – a simple Bulletin Board System (BBS), which will explain the use of Grunt alongside the Mocha testing library to automate testing throughout the build process.</p> <p>Mastering Grunt will demonstrate how to leverage Grunt with other technologies to become an expert in build automation, teaching you the best practices for modern web development along the way.</p>
Table of Contents (12 chapters)

Introducing Git


Git is a version control and source code management system developed for the Linux kernel. Its speed, team-based flexibility, and related open source tools have led to Git's ubiquity in recent years. It supports the use of source code branching, revision histories, and bug tracking.

This book will use Git to pull in the base templates of projects used throughout this book. The steps that are required will be illustrated in subsequent chapters.

The following is a look into the official website for Git:

Using Git

Let's suppose that you have a large-scale project developed by several different programmers. Over time, you will need a feasible way to collaborate on the project without overriding each other's changes. You'll also need to be sure to keep a revision history in order to have the ability to optionally revert the changes when necessary. This way, you'll also be able to track where a bug in your code is, depending on when it was first found, by using the revision history. These are all use cases for which Git comes in handy.

Installing Git

There are various ways to install and run Git. The following steps will illustrate how to exactly do this on various operating systems.

Installing Git on Windows

Perform the following steps to install Git on Windows:

  1. Visit http://git-scm.com/downloads and click on the Windows link.

  2. Run the .exe file that was just downloaded.

  3. Follow the installation steps, and Git will be installed as a command-line utility alongside an optional GUI interface.

Installing Git on Mac OS X

Perform the following steps to install Git on Mac OS X:

  1. Visit http://git-scm.com/downloads and click on the Mac OS X link.

  2. Run the .dmg file that was just downloaded.

  3. Go through the graphical installer process and you will end up with Git installed as a command-line utility.

Installing Git on Linux

Perform the following steps to install Git on Linux:

  1. Visit http://git-scm.com/downloads and click on the Linux link.

  2. Follow the instructions on the page for your respective Linux distribution. After issuing the necessary commands in a terminal, you will end up with Git installed as a command-line utility.

Git basics

In order to initialize a directory such that it may be used alongside Git, one must issue the following command:

git init

Prior to making a revision, one must add the files they have changed to a commit. To do this, you would issue the following command:

git add <file>

For example, issue the following command:

git add main.js

Once all the changed files have been added to the current revision, you are able to issue a commit, as shown in the following command:

git commit -m <commit message>

For instance, issue the following command:

git commit -m "Initial import of main.js file"

The current state of a Git-initialized directory is important. Knowing what files have been added to the current commit at any given time can help to prevent a premature commit. To query the current state, one would have to issue the following command:

git status

It also helps to reveal the current branch being used for development, a concept that will not be explored in this book.

Next, you will look into how to download a public Git repository, which can be done by inputting the following:

git clone <Git URL>

An example is shown as follows:

git clone https://github.com/packt-mg/Chapter-2.git

This command will be used throughout the book in order to download the necessary base templates for development.