02 Mar, 2018 · 9 minutes read
This article shows you how to start creating a new AngularJS module with re-usable components, directives & Services using a starter/seed project. The seed project can be found here
The seed project is very simple and the structure is something like this:-
seeder
src
.eslintrc.js
package.jsonLet us take a look at the various files in the project.
This is your main project file for a NodeJS project. You can think of it being analogous to a .csprojfile or .vbprojcreated with Visual Studio. The main properties here are:-
For a full list of all properties available in package.json refer to this documentation.
This is the manifest file for Bower where all the client side JavaScript libraries you want to use in your project must be defined. Here too you must declare the name & description for your project.
Gulp helps automate various tasks needed during the build processes. It is extensible via plugins using which you can do all kinds of things using a pipelining model that is very efficient.
This file contains all of the user settings for the gulp build process.
.min.jsThis file contains Gulp tasks that can be run as part of the build process to perform various tasks such as combining & minifying the source JavaScript files.
It has two tasks:-
The ESLint style we are going to use will extend from eslint:recommendedand because this is an AngularJS seed project – plugin:angular/johnpapa .
This file contains a list of all folders & files that are to be ignored by git for source control.
It has three entries:-
This is the JavaScript file in which your angular module is declared. It declares the name of your module “your-project” along with any dependencies inside the array [].
angular.module("your-project", []);
The readme file for the seed project with instructions on how to use it to create a new project
Create a new AngularJS Module
npm install -g bower
Gulp– This is our task runner which will be doing things like bundling, minification, linting, etc.
npm install -g gulp
ESLint– To maintain code quality we will use ESLint as our JavaScript linter.
npm install -g eslint
mams– The seeder binary I created for AngularJS projects.
npm install -g mams
Make sure you have all of these packages installed globally by running:-
npm list -g --depth=0
The output should include the following packages:-
+-- bower@1.8.2
+-- eslint@4.18.1
+-- gulp@3.9.1
+-- mams@1.0.5Go to the directory which holds your project. mamswill create a directory for your project.
cd C:\projects
Generate an Access Token so that the init script can create a GitHub repository for you. See the sectionbelow to see the steps on how to generate an access token
Initialize your project by giving it a suitable name, description, specifying the name of your compressed/minified JavaScript file and finally providing the access token you generated in the previous step
mams -p mx-angular-notify -d "AngularJS module for showing toast notifications" -g -t 72a8a3e2b8374bcb8acaf0d0f7f4a708
You should get an output like:-
Maxotek Angular Module Seeder v 1.0.5
Creating GitHub Repository
Listing repositories
Found: 31 repositories
Created project directory: mx-angular-notify
Seeder repository: https://github.com/maxotek/mx-angular-module-seed.git
Seeder repository cloned at: mx-angular-notify
Repository created at: https://github.com/maxotek/mx-angular-notify
Project: mx-angular-notify
Description: AngularJS module for showing toast notifications
Output File: mx-angular-notify.js
Project URL: https://github.com/maxotek/mx-angular-notify
HTTPS URL: https://github.com/maxotek/mx-angular-notify.git
SSH URL: git@github.com:maxotek/mx-angular-notify.git
mx-angular-notify/package.json updated
mx-angular-notify/bower.json updated
mx-angular-notify/build.conf.js updated
Renamed project file to: mx-angular-notify/src/mx-angular-notify.js
mx-angular-notify/src/mx-angular-notify.js updated
Updated project name in: mx-angular-notify/src/mx-angular-notify.js
mx-angular-notify/.git/config updatedSo, now you have an AngularJS module project locally along with a remote GitHub repository that you will be pushing to. Open up that favorite IDE of yours and start building your AngularJS module.
That is it, your new project is ready for development. If you want to go start creating your new AngularJS module. Check out my article on how to Create an AngularJS Service.
Alternatively, you can continue reading the article and understand the nitty gritty details of what’s happening under the hood.
Clone this repository and then change the following entires.