# Abu - a little helper for Tetra.js projects

## Overview

`abu` helps you setup Tetra.js projects and its Jasmine test specs.

But remember - **you should write your tests *before* you write your code!**

## Installing

1. Install the latest version of Node
2. Run `npm install -g abu`
3. Once install has finished, run `abu --help`

## Updating

Run `npm update -g abu` (or `npm update -g` to update all global libraries)

## Configuring

By default, `abu` will expect a Maven-configured project, with Tetra.js resources residing in the following folders

* Application code at `src\main\webapp\javascript\coremvc\apps`
* Global tetra models at `src\main\webapp\javascript\coremvc\model`
* Test spec code at `src\test\javascript\coremvc`

You can override these defaults by creating a file named `abu.json` in the project root. Consult the file `abu.sample.json`
to see how this file should be formatted.

## Commands

### `abu make [project]`

`abu` can build empty model, view and controller skeletons for new projects, along with test skeletons and empty fixtures.

1. Open a command prompt and go to your project root directory (e.g. `C:\projects\myProject`)
2. Run `abu make myApp`, where myApp is the name of the application you want to create

`abu` will create

* empty model, view and controller skeletons in the `coremvc\apps\myApp` directory
* empty test skeletons in the `src\test\javascript\coremvc\myApp` location
* an empty fixture at `src\test\javascript\fixtures\myApp`

#### Options

* `--model [model]` Make only this named model
* `--controller [controller]` Make only this named controller
* `--view [view]` Make only this named view
* `--scope [scope]` Name of the scope to use (defaults to the name of the application)
* `--overwrite` Overwrite any existing source files or test specs

### `abu test [project]`

`abu` can generate partially completed Jasmine test specs for an existing project.

1. Open a command prompt and go to the project root directory (e.g. `C:\projects\myProject`)
2. Run `abu test myApp`, where myApp is the name of the application you want to test

`abu` will run a check on the code, and then create

* partially complete model, view and test specs in the `src\test\javascript\coremvc\myApp` location, for *all* models,
views and controllers found in the project
* an empty fixture at `src\test\javascript\fixtures\myApp`

#### Options

* `--controller [controller]` Make specs only for this named controller
* `--view [view]` Make specs only for this named view
* `--overwrite` Overwrite any existing test specs

### `abu validate [project]`

`abu` can run some basic validations on existing Tetra.js code.

1. Open a command prompt and go to the project root directory (e.g. `C:\projects\myProject`)
2. Run `abu validate myApp`, where myApp is the name of the application you want to check

If `abu` finds a `jshint.json` configuration file in the root directory, then JSHINT errors will be included in the output.
Consult the file `jshint.sample.json` for an example.

If `abu` finds an `abu.json` configuration file with the options `cyclomaticComplexityCeiling` or `maintainabilityFloor`, it
will also output complexity statistics for files and functions with a cyclomatic complexity greater than the `cyclomaticComplexityCeiling`
value, or files with a Halstead maintainability index less than the `maintainabilityFloor` value.

#### Options

* `--model [model]` Only validate this named model
* `--controller [controller]` Only validate this named controller
* `--view [view]` Only validate this named view

## Examples

### Making a new project

Here's a few example commands and the files they create. Remember - `abu make` will create empty test and MVC skeletons for
a **new** project. `abu test` will create partially-completed test skeletons generated from an **existing** project.

#### `abu make foo`

* [tetra-app-dir]/foo/model/foo.class.js
* [tetra-app-dir]/foo/controller/foo.ctrl.js
* [tetra-app-dir]/coremvc/foo/view/foo.ui.js
* [test-dir]/coremvc/foo/foo.ctrl.spec.js
* [test-dir]/coremvc/foo/foo.ui.spec.js
* [test-dir]/fixtures/foo/foo.html

#### `abu make foo --model bar`

* [tetra-app-dir]/foo/model/bar.class.js

#### `abu make foo --controller bar`

* [tetra-app-dir]/foo/controller/bar.ctrl.js
* [test-dir]/coremvc/foo/bar.ctrl.spec.js

#### `abu make foo --controller bar --scope baz`

* [tetra-app-dir]/foo/controller/bar.ctrl.js
* [test-dir]/coremvc/foo/bar.ctrl.spec.js

With scope set to the value 'baz'

#### `abu make foo --view bar`

* [tetra-app-dir]/coremvc/foo/view/bar.ui.js
* [test-dir]/coremvc/foo/bar.ui.spec.js
* [test-dir]/fixtures/foo/bar.html

### Testing an existing project

#### `abu test lightReco`

* [test-dir]/coremvc/lightReco/lightReco.ctrl.spec.js
* [test-dir]/coremvc/lightReco/lightReco.ui.spec.js
* [test-dir]/fixtures/lightReco/lightReco.html

#### `abu test lightReco --model lightReco`

* Nothing is generated, as we don't test models directly

#### `abu test lightReco --controller lightReco`

* [test-dir]/coremvc/lightReco/lightReco.ctrl.spec.js

#### `abu test lightReco --view lightReco`

* [test-dir]/coremvc/lightReco/lightReco.ui.spec.js
* [test-dir]/fixtures/lightReco/lightReco.html

#### `abu test miniprofile`

Nothing will be created as, in this case, all the test spec files already exist

#### `abu test miniprofile --overwrite`

* [test-dir]/coremvc/miniprofile/miniprofile.ctrl.spec.js
* [test-dir]/coremvc/miniprofile/miniprofile.ui.spec.js
* [test-dir]/fixtures/miniprofile/miniprofile.html

### Validating an existing project

#### `abu validate miniprofile`

* Validates all models, views and controllers

Pass `--model [model]`, `--controller [controller]` or `--view [view]`, to limit the validation to a single file.

#### `abu validate miniprofile > report.txt` (Windows)

* Validates all models, views and controllers and passes the output to the file `report.txt`.

## Who is `abu`?

`abu` is the kleptomaniac monkey from Disney's Aladdin. Say `abu hello` and he'll say hi.
