Skip to content
Yeoman generator for AngularJS + Go server
CSS JavaScript CoffeeScript Go
Find file
Latest commit 405fbdc Sep 8, 2013 @teerapap 0.1.1
Failed to load latest commit information.
app feat(go): add a simple go server and integrate it to Gruntfile.js Sep 3, 2013
common chore(misc): code style Apr 20, 2013
constant docs(usage): updated angular names to go-angular Sep 3, 2013
controller docs(usage): updated angular names to go-angular Sep 3, 2013
decorator docs(usage): updated angular names to go-angular Sep 3, 2013
directive docs(usage): updated angular names to go-angular Sep 3, 2013
factory docs(usage): updated angular names to go-angular Sep 3, 2013
filter docs(usage): updated angular names to go-angular Sep 3, 2013
main allow movement of app and test folder via component.json Feb 22, 2013
provider docs(usage): updated angular names to go-angular Sep 3, 2013
route docs(usage): updated angular names to go-angular Sep 3, 2013
service docs(usage): updated angular names to go-angular Sep 3, 2013
templates fix(Gruntfile): use separate listening port in each server target Sep 8, 2013
test feat(go): add a simple go server and integrate it to Gruntfile.js Sep 3, 2013
value docs(usage): updated angular names to go-angular Sep 3, 2013
view docs(usage): updated angular names to go-angular Sep 3, 2013
.editorconfig chore(misc): update editorconfig Apr 20, 2013
.gitattributes Add dotfiles Nov 24, 2012
.gitignore fix(build): Ignore test subfolder Apr 20, 2013
.jshintrc chore(repo): maintenance Jul 23, 2013
.travis.yml fix(test): add Node 0.10 to travis file Apr 20, 2013
CHANGELOG.md v0.4.0 Aug 22, 2013
Gruntfile.js chore(misc): code style Apr 20, 2013
contributing.md fix(docs): add contributing info to contributing file Aug 7, 2013
package.json 0.1.1 Sep 8, 2013
readme.md fix(readme): change travis-ci image url Sep 3, 2013
script-base.js chore(gen): revert modular project structure Aug 20, 2013
util.js chore(style): Code consistency Apr 7, 2013

readme.md

AngularJS + Go generator Build Status

Maintainer: Teerapap Changwichukarn

Forked from generator-angular maintained by Brian Ford. Based on angular-seed

This project extends the upstream with a simple go server. The grunt toolchain uses the go server instead of the connect middleware. So you can develop a AngularJS application as a frontend and Go as a backend service with Yeoman workflow.

Usage

Install generator-go-angular:

npm install -g generator-go-angular

Make a new directory, and cd into it:

mkdir my-new-project && cd $_

Run yo go-angular, optionally passing an app name:

yo go-angular [app-name]

Generators

Available generators:

Note: Generators are to be run from the root directory of your app.

App

Sets up a new AngularJS app with a simple go server instead of connect, generating all the boilerplate you need to get started. The app generator also optionally installs Twitter Bootstrap and additional AngularJS modules, such as angular-resource.

Example:

yo go-angular

Route

Generates a controller and view, and configures a route in app/scripts/app.js connecting them.

Example:

yo go-angular:route myroute

Produces app/scripts/controllers/myroute.js:

angular.module('myMod').controller('MyrouteCtrl', function ($scope) {
  // ...
});

Produces app/views/myroute.html:

<p>This is the myroute view</p>

Controller

Generates a controller in app/scripts/controllers.

Example:

yo go-angular:controller user

Produces app/scripts/controllers/user.js:

angular.module('myMod').controller('UserCtrl', function ($scope) {
  // ...
});

Directive

Generates a directive in app/scripts/directives.

Example:

yo go-angular:directive myDirective

Produces app/scripts/directives/myDirective.js:

angular.module('myMod').directive('myDirective', function () {
  return {
    template: '<div></div>',
    restrict: 'E',
    link: function postLink(scope, element, attrs) {
      element.text('this is the myDirective directive');
    }
  };
});

Filter

Generates a filter in app/scripts/filters.

Example:

yo go-angular:filter myFilter

Produces app/scripts/filters/myFilter.js:

angular.module('myMod').filter('myFilter', function () {
  return function (input) {
    return 'myFilter filter:' + input;
  };
});

View

Generates an HTML view file in app/views.

Example:

yo go-angular:view user

Produces app/views/user.html:

<p>This is the user view</p>

Service

Generates an AngularJS service.

Example:

yo go-angular:service myService

Produces app/scripts/services/myService.js:

angular.module('myMod').service('myService', function () {
  // ...
});

You can also do yo go-angular:factory, yo go-angular:provider, yo go-angular:value, and yo go-angular:constant for other types of services.

Decorator

Generates an AngularJS service decorator.

Example:

yo go-angular:decorator serviceName

Produces app/scripts/decorators/serviceNameDecorator.js:

angular.module('myMod').config(function ($provide) {
    $provide.decorator('serviceName', function ($delegate) {
      // ...
      return $delegate;
    });
  });

Options

In general, these options can be applied to any generator, though they only affect generators that produce scripts.

CoffeeScript

For generators that output scripts, the --coffee option will output CoffeeScript instead of JavaScript.

For example:

yo go-angular:controller user --coffee

Produces app/scripts/controller/user.coffee:

angular.module('myMod')
  .controller 'UserCtrl', ($scope) ->

A project can mix CoffeScript and JavaScript files.

Minification Safe

By default, generators produce unannotated code. Without annotations, AngularJS's DI system will break when minified. Typically, these annotations the make minification safe are added automatically at build-time, after application files are concatenated, but before they are minified. By providing the --minsafe option, the code generated will out-of-the-box be ready for minification. The trade-off is between amount of boilerplate, and build process complexity.

Example

yo go-angular:controller user --minsafe

Produces app/controller/user.js:

angular.module('myMod').controller('UserCtrl', ['$scope', function ($scope) {
  // ...
}]);

Background

Unannotated:

angular.module('myMod').controller('MyCtrl', function ($scope, $http, myService) {
  // ...
});

Annotated:

angular.module('myMod').controller('MyCtrl',
  ['$scope', '$http', 'myService', function ($scope, $http, myService) {

    // ...
  }]);

The annotations are important because minified code will rename variables, making it impossible for AngularJS to infer module names based solely on function parameters.

The recommended build process uses ngmin, a tool that automatically adds these annotations. However, if you'd rather not use ngmin, you have to add these annotations manually yourself.

Bower Components

The following packages are always installed by the app generator:

  • angular
  • angular-mocks
  • angular-scenario

The following additional modules are available as components on bower, and installable via bower install:

  • angular-cookies
  • angular-loader
  • angular-resource
  • angular-sanitize

All of these can be updated with bower update as new versions of AngularJS are released.

Configuration

Yeoman generated projects can be further tweaked according to your needs by modifying project files appropriately.

Output

You can change the app directory by adding a appPath property to bower.json. For instance, if you wanted to easily integrate with Express.js, you could add the following:

{
  "name": "yo-test",
  "version": "0.0.0",
  ...
  "appPath": "public"
}

This will cause Yeoman-generated client-side files to be placed in public.

Testing

For tests to work properly, karma needs the angular-mocks bower package. This script is included in the bower.json in the devDependencies section, which will be available very soon, probably with the next minor release of bower.

While bower devDependencies are not yet implemented, you can fix it by running:

bower install angular-mocks

By running grunt test you should now be able to run your unit tests with karma.

Contribute

See the contributing docs

When submitting an issue, please follow the guidelines. Especially important is to make sure Yeoman is up-to-date, and providing the command or commands that cause the issue.

When submitting a PR, make sure that the commit messages match the AngularJS conventions.

When submitting a bugfix, write a test that exposes the bug and fails before applying your fix. Submit the test alongside the fix.

When submitting a new feature, add tests that cover the feature.

License

BSD license

Something went wrong with that request. Please try again.