Yeoman generator to create an AngularJS component library
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
$ yo angularjs-library
Answer the questions and the generator will create the boilerplate for your library:
The generator automatically:
srcdirectory structure with the boilerplate code for your AngularJS library
testdirectory structure to store your unit tests and e2e tests
gulpfile.jsto build, minify and uglify your library
karma-src.conf.jsto let karma run your unit tests
karma-dist-concatenated.conf.jsto let karma run your unit tests
karma-dist-minified.conf.jsto let karma run your unit tests
bower.jsonwith necessary devDependencies and appropriate ignore files
package.jsonfile for your library
.travis.ymlfile to enable travis support
.jshintrcto support angular global during syntax check
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
The basic library structure is automatically created for you in the
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:
First gulp will
to make sure the code is fine.
Then all files in the
src directory will be concatenated into 2 files in the
<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
The generator creates 3 configurations for unit testing:
karma-src.conf.js: run unit tests using
karma-dist-concatenated.conf.js: run unit tests using
karma-dist-minified.conf.js: run unit tests using
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:
Then you write a test like this:
Help make this project better - fork and send a PR or create an issue.
-in case of capital as first character