• Stars
    star
    117
  • Rank 292,405 (Top 6 %)
  • Language
    JavaScript
  • Created almost 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A generator for Yeoman to generate the boilerplate for creating an AngularJS library

AngularJS component library generator

Yeoman generator to create standalone AngularJS component libraries in seconds!

Build Status

generator-angularjs-library

In short

If you want to create a standalone library with filters, directives, services, etc for use in your AngularJS applications, then this generator may just be what you need.

The generator automatically:

  • creates a complete directory structure with boilerplate code for your AngularJS library
  • creates a complete directory structure for your tests
  • configures Gulp to build your code and automate testing
  • sets up Karma to run your unit tests using Mocha, Chai and Sinon

This generator is NOT made to generate complete AngularJS applications. If you want to generate a complete AngularJS web application with routes, views, etc then please use generator-angular.

Quick start

Make sure you have yeoman installed:

$ npm install -g yo

Install the generator:

$ npm install -g generator-angularjs-library

Create a new project directory:

$ mkdir sample-project
$ cd sample-project

Run:

$ yo angularjs-library

Answer the questions and the generator will create the boilerplate for your library:

yo-angularjs-library

What the generator does for you

The generator automatically:

  • creates a src directory structure with the boilerplate code for your AngularJS library
  • creates a test directory structure to store your unit tests and e2e tests
  • creates initial unit tests in the test/unit/ directory
  • creates a custom gulpfile.js to build, minify and uglify your library
  • creates a custom karma-src.conf.js to let karma run your unit tests
  • creates a custom karma-dist-concatenated.conf.js to let karma run your unit tests
  • creates a custom karma-dist-minified.conf.js to let karma run your unit tests
  • creates a custom bower.json with necessary devDependencies and appropriate ignore files
  • creates a custom package.json file for your library
  • creates a custom .travis.yml file to enable travis support
  • creates a custom .jshintrc to support angular global during syntax check
  • creates a custom README.md file
  • creates a custom LICENSE file

Running the generator using library name "Your Library" will result in the following files being generated for you:

.
├── .bowerrc                                  # Configure bower directory for development
├── .editorconfig                             # Editor configuration for code consistency
├── .gitignore                                # Includes files that Git should ignore
├── .jshintrc                                 # JSHint config with angular global support
├── LICENSE                                   # Custom license file with your name in it
├── README.md                                 # Basic README.md with title of your library
├── bower.json                                # Bower configuration with custom devDependencies and ignore files
├── dist                                      # This folder and contents is generated by running gulp
│   ├── sample-library.js                     # Your library, ready to use in your development environment
│   └── sample-library.min.js                 # Your library, ready to use in your production environment
├── gulpfile.js                               # Gulp configuration with definition to build your library
├── karma-dist-concatenated.conf.js           # Karma configuration to run unit tests using sample-library.js
├── karma-dist-minified.conf.js               # Karma configuration to run unit tests using sample-library.min.js
├── karma-src.conf.js                         # Karma configuration to run unit tests using src/**/*.js
├── package.json                              # Npm configuration with necessary dependencies for development
├── src                                       # Source directory
│   └── sample-library
│       ├── directives                        # Directory where you can store directives
│       ├── filters                           # Directory where you can store filters
│       ├── sampleLibrary.module.js           # Main module file
│       └── services                          # Directory where you can store services
└── test
    ├── e2e
    │   └── sample-library                    # Directory where you can store E2E tests
    └── unit
        └── sample-library
            ├── directives                    # Directory where you can store unit tests for directives
            ├── filters                       # Directory where you can store unit tests for filters
            ├── sampleLibrarySpec.js          # Unit tests for main module
            └── services                      # Directory where you can store unit tests for services

How to use the generated boilerplate

The basic library structure is automatically created for you in the src folder.

You can edit the existing files or add additional files in the src folder to add components to your library.

Once you have added files in the src directory, you can update the files in the dist directory using:

$ gulp

First gulp will

  • check the JavaScript syntax of src/**/*.js
  • run all unit tests using the code in your src directory

to make sure the code is fine.

Then all files in the src directory will be concatenated into 2 files in the dist directory:

  • <your-library-name>.js: regular version of your library to use in a development environment
  • <your-library-name>.min.js: minified version of your library to use in a production environment

gulp

Manually testing your code

The generator creates 3 configurations for unit testing:

  • karma-src.conf.js: run unit tests using src/**/*.js
  • karma-dist-concatenated.conf.js: run unit tests using dist/<your-library-name>.js
  • karma-dist-minified.conf.js: run unit tests using dist/<your-library-name>.min.js

By default, gulp will run karma-src.conf.js, but you can use the following preconfigured Gulp tasks to specify the suite you want to run:

# Run unit tests using src/**/*.js
$ gulp test-src

# Run unit tests using dist/<your-library-name>.js
$ gulp test-dist-concatenated

# Run unit tests using dist/<your-library-name>.min.js
$ gulp test-dist-minified

gulp-test-src

This allows you to unit test the different builds of your code to ensure they all work as expected.

How to write a test

Suppose you have a service:

// src/my-lib/services/some-service.js
angular.module('myLib.services')
  .service('someService', function() {
    this.foo = function() {
      return 1234;
    };
  });

Then you write a test like this:

describe('someService', function() {

  var someService;

  // load the module
  beforeEach(module('myLib.services'));

  // inject the service
  beforeEach(inject(function(_someService_) {
    someService = _someService_;
  }));
  
  it('should exist', function() {
    expect(someService).to.be.ok;
  });
  
  it('should have a method called foo', function() {
    expect(someService.foo).to.be.a('function');
  });
  
});

Want to contribute?

Help make this project better - fork and send a PR or create an issue.

Change log

v3.3.1

  • Fix issue where library name was prefixed with - in case of capital as first character

v3.3.0

  • Removed gruntfile from .gitignore
  • Added gulpfile and karma config files to .gitignore

v3.2.0

  • Added spec reporter to karma for better unit test progress output (thanks @simplesthing)

v3.1.0

  • Added JSHint for gulpfile.js and karma configuration files
  • Added angular as argument to module to further reduce minified output size
  • Fixed copy of .travis.yml

v3.0.0

  • Added JSHint syntax check
  • Added gulp-plumber support for better error handling
  • Gulp now starts watching for file changes by default for easier development
  • Removed prefix and suffix files in favor of AngularJS styleguide support
  • Moved bower dependencies to devDependencies to prevent version conflicts
  • Updated bower dependencies to automatically install latest versions
  • Let travis perform bower install before running tests
  • Set default version as 0.1.0 instead of 0.0.0
  • Added v3.x.x branch

v2.0.0

  • Completely rewritten to support newer version of Yeoman
  • Now uses Gulp instead of Grunt as task runner
  • Now uses Mocha as test framework instead of Jasmine
  • Added travis support

v1.4.0

  • Updated bower and npm package versions

v1.3.0

  • Added automatic creation of README.md
  • Added automatic creation of LICENSE.txt
  • Added support for author name and email

v1.2.1

  • Removed obsolete dependencies

v1.2.0

  • Added support for PhantomJS in Karma configuration
  • Fixed bower directory in gitignore

v1.1.0

  • Added support for library names with spaces and capitals

v1.0.3

  • Added chalk dependency

License

MIT

More Repositories

1

generator-angular2-library

Yeoman generator to create an Angular library
JavaScript
750
star
2

github-scrum-workflow

Collection of scrum labels to apply agile tactics to a GitHub repository
247
star
3

copy-github-labels-cli

CLI tool to copy GitHub labels from one repository to another
JavaScript
154
star
4

angular-growl-notifications

Growl notifications for AngularJS
JavaScript
142
star
5

angular-update-meta

Dynamically update meta tags for SEO purposes in your AngularJS application. Supports prerender.io.
JavaScript
135
star
6

copy-github-labels

Easily copy labels from one GitHub repository to another
JavaScript
84
star
7

angular-contentful

Angular module to access the Contentful content delivery API
JavaScript
82
star
8

angular-environment-variables-demo

How to use environment variables to configure your Angular application without a rebuild
TypeScript
47
star
9

contentful-webhook-server

Contentful webhook server is a lightweight server to handle Contentful webhook HTTP requests
JavaScript
35
star
10

angularcodereview-com

Collection of free checklists you can use to perform a code review of your Angular application.
HTML
26
star
11

angular-consent

Easily show consent messages that keep appearing until the user clicks them away.
JavaScript
24
star
12

angular-http-decelerator

A lightweight HTTP interceptor for AngularJS to slow down HTTP responses
JavaScript
21
star
13

angularjs-google-maps

AngularJS library for working with Google Maps
JavaScript
20
star
14

contentful-agent

Node.js module to fetch entries from Contentful
JavaScript
13
star
15

angular2-todo-app

Angular 2 Todo Application
TypeScript
13
star
16

generator-jabl

A generator for Yeoman to build a website with Jade, AngularJS, Bootstrap and LESS
JavaScript
12
star
17

generator-php-library

A generator for Yeoman to generate boilerplate for a PHP library with support for PHPUnit
JavaScript
10
star
18

Ogone

PHP Classes for working with Ogone payment services
PHP
9
star
19

angular-user-settings

Easily manage persistent user settings in your AngularJS application
JavaScript
6
star
20

hb-bootstrap

Harp Boilerplate of a Bootstrap website
CSS
6
star
21

angular-embed-codepen

Easily embed codepen pens in your AngularJS application. No coding or custom markup required!
JavaScript
6
star
22

awesome-badge

Web component to display awesome badge that links to Sindre Sorhus' awesome list
HTML
5
star
23

angular-filter-pack

AngularJS Filter Pack
JavaScript
4
star
24

zf2-event-logger

Zend Framework 2 module that logs all events to the error_log.
PHP
4
star
25

ZendService_Oauth2

Oauth2 service for Zend Framework 2
PHP
3
star
26

web-application-performance-optimization

Checklist for optimizing web application performance
2
star
27

deploy-harp-to-gh-pages-using-travis

JavaScript
2
star
28

todo-app

Angular Todo Application for SitePoint Article
TypeScript
1
star
29

copy-github-labels-test-destination

Test repository to try out copy GitHub labels
1
star
30

angularjs-directive-scope-inspector

A visual scope inspector for the different AngularJS directive scope settings
JavaScript
1
star