/generator-dp

Digital Primate's Yeoman generator.

Primary LanguageJavaScriptMIT LicenseMIT

What's Included?

The Tools

Yeoman provides scaffolding.
Bower manages dependencies.
Grunt manages build tasks.

Grunt Plugins

  1. copy - allows grunt to copy generated files
  2. uglify - minify js files
  3. compass - compile sass
  4. jshint - error check js files
  5. watch - watch for file changes to kick off tasks
  6. open - allows Grunt to open files
  7. connect - development web server
  8. concurrent - run grunt tasks concurrently
  9. clean - removes previously generated files
  10. env - provides environment variables
  11. preprocess - preprocesses files allowing for integration with environment variables

Built-In Frameworks

  1. AngularJS
  2. JS-Signals
  3. SASS

Optional Stuff

Frameworks

Several frameworks are available right from Yeoman. Adding a framework from Yeomon will download the files and add references to them in the appropriate places.

  1. JQuery $ yo dp:jquery
  2. Bootstrap $ yo dp:bootstrap
  3. Foundation $ yo dp:foundation

Using Bower

Pretty much any other framework can be installed via Bower.

  1. Find a package to install via command line $ bower search [<name>] or from here.
  2. Install the package. $ bower install <package_name>
  3. The contents of the package will be in app/libs. Include the required files in the appropriate location(s).

Getting Started

Prerequisite Installation

  1. Install nodejs.
  2. Install Grunt. $ npm install -g grunt-cli
  3. Install Bower. $ npm install -g bower
  4. Windows Only Install ruby.
  5. Install Compass, which will install SASS. $ gem update --system && gem install compass

Quick Start

  1. Clone repo.

  2. Download dependencies.

$ npm install
$ bower install

Grunt Options:

Lint all of the JavaScript files.

$ grunt lint

Just build distribution files:

$ grunt build

Run the grunt server. As you change files the page will automatically refresh.

$ grunt server

Environment and Preprocessing

Description

The env and preprocess grunt plugins allow the use of basic logic statements to alter the final produced HTML/JavaScript/CSS code. The act in similar ways to global variables for conditional compilation in ActionScript.

By default the application is configured with development and production environments. The development environment is used with the grunt server command. The production environment is used with the grunt build command.

The process module allows for various types of logical statements. The most common will be to conditionally include/exclude code and to echo environment variables.

Only include code in a production build (HTML):

<!-- @if NODE_ENV='production' -->
<link rel="stylesheet" href="dist/styles/app.min.css">
<!-- @endif -->

Only include code if the DEBUG environment variable is true (HTML):

<!-- @ifdef DEBUG -->
<h1>Debugging mode - <!-- @echo RELEASE_TAG --> </h1>
<!-- @endif -->

Write the values of two environment variables into the code (JavaScript):

console.log("Environment: " + '/* @echo NODE_ENV */' + " | Version: " + '/* @echo VERSION */');

Set the background color of the application based on environment (CSS):

body {
	/* @if NODE_ENV=='development' */
	background-color: red;
	/* @endif */
}

All of the available directives are:

  1. @if VAR='value' / @endif - This will include the enclosed block if your test passes
  2. @ifdef VAR / @endif - This will include the enclosed block if VAR is defined (typeof !== 'undefined')
  3. @ifndef VAR / @endif - This will include the enclosed block if VAR is not defined (typeof === 'undefined')
  4. @include - This will include the source from an external file. If the included source ends with a newline then the following line will be space indented to the level the @include was found.
  5. @exclude / @endexclude - This will remove the enclosed block upon processing
  6. @echo VAR - This will include the environment variable VAR into your source

For more information go here.

Scaffolding Options

Application Creation

$ yo dp

This is give you a skeleton project containing...

  1. An index.html file which defines an ng-app on the html tag.
  2. Angular, Angular Resource, and JS Signals are included by default.
  3. A controller attached to the body tag.
  4. The application modules will include service, directive, and filter modules.
  5. A SASS file is generated at styles/main.scss.
  6. A Grunt task to jslint files.
  7. A Grunt task to minify JavaScript and CSS files.
  8. A Grunt task to launch a web server that will automatically refresh as you modify code.

Angular

  1. Controller
$ yo dp:controller Name
[?] Which dependencies would you like to include? (space separated list, blank for none)

This will generate a controller with the given name (NameController). Dependencies are optional. If provided they will automatically be included in the controller declaration.

  1. JSON Service
$ yo dp:json-service Name url

This will generate a service with the given name, which can be referenced by the name as a dependency. The service will fetch URL and return the contents.

Usage:

$ yo dp:json-service Items data/items.json
app.controller('TestController', function($scope, Items) {
	Items.query(function (data) {
		$scope.streams = data.items;
	});
}
  1. HTTP Service
$ yo dp:http-service Name url type
[?] Which dependencies would you like to include? (space separated list, blank for none)
[?] Which properties would you like to include? (space separated list, blank for none)

This will generate a service with the given name, which can be referenced by the name as a dependency. The service will invoke the given URL using the provided type (get/post/etc) method.
type is optional and will default to "get".
If provided, the provided dependencies and properties will be automatically included.

  1. Data Service
$ yo dp:model-service Name

This will create a service that operates as a data model. The model will have the methods get and set. A changed signal will be available as a property of the model.

  1. State Router
$ yo dp:state-router
[?] What is the route's name? One
[?] What is the route's url? /one
[?] What is the route's templateUrl? /one.t.html
[?] Make another route? Yes
[?] What is the route's name? Two
[?] What is the route's url? /two
[?] What is the route's templateUrl? /two.t.html
[?] Make another route? No
[?] What is the default route url? /one

This will create a state router with the given parameters. For details on how to use the state router, see here.