Yeoman generator to create standalone AngularJS component libraries in seconds!
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:
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.
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:
The generator automatically:
src
directory structure with the boilerplate code for your AngularJS librarytest
directory structure to store your unit tests and e2e teststest/unit/
directorygulpfile.js
to build, minify and uglify your librarykarma-src.conf.js
to let karma run your unit testskarma-dist-concatenated.conf.js
to let karma run your unit testskarma-dist-minified.conf.js
to let karma run your unit testsbower.json
with necessary devDependencies and appropriate ignore filespackage.json
file for your library.travis.yml
file to enable travis support.jshintrc
to support angular global during syntax checkREADME.md
fileLICENSE
fileRunning 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
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
src/**/*.js
src
directoryto 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 environmentThe 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
This allows you to unit test the different builds of your code to ensure they all work as expected.
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');
});
});
Help make this project better - fork and send a PR or create an issue.
-
in case of capital as first character.travis.yml
MIT