Giter Club home page Giter Club logo

generator-angm's Introduction

Generator-angm NPM Downloads npm version

AngularJS Modular Generator

AngularJS Yeoman Generator to help you getting started with a new project based on AngularJS/Angular Material or Bootstrap to build large scale applications.

Modular AngularJS Applications with Generator-angm

Disclaimer

The main reason for creating this project, and do not use any other, was the need to optimize the creation time of each application from scratch. It was built using the best practices of development with AngularJS and uses the latest stable version (1.5.0.). The project does not intend to migrate to the new version(2.0) in a short time, we have in mind that this version is very stable and meets most web projects, so when version 2.0 is reasonably stable we do the migration.

Getting Started

Installing Yeoman

Open your Terminal/Shell and type:

npm install -g yo

Installing the ANGM Generator

To install generator-angm from npm, run:

npm install -g generator-angm

Installing Grunt CLI

To run Grunt commands from our terminal, we'll need grunt-cli:

npm install -g grunt-cli

Installing bower-installer

npm install -g bower-installer

The building process will use bower-installer plugin.

Starting an application

From the command line, initiate the generator:

yo angm

You'll receive some prompts to fill with useful informations as Project name, author, what UI: Bootstrap or Angular Material.

Running project on development

Open your Terminal/Shell and type:

grunt dev

After the command your application should start right in your default browser at localhost:4000.

NOTE: after using yo angm command, we recorded some useful informations on .yo-rc.json file created at the project root folder. So you can't execute the generator command to create the application more than one time per folder!

Running project on production

Open your Terminal/Shell and type:

grunt build

The Gruntfile.js already have some tasks like: Concat, Uglify, Injector and template cache.

NOTE: The command will concat and minify all (JS) application files and the HTML templates will be mixed in on file called templates.js, all this files will be injected on index.html.

Built in SubGenerators

Generator-angm have a subgenerator to create your application modules and directives.

  1. Modules
  2. Directives

Modules

To create a module just type on your Terminal/Shell:

yo angm:angm-module

After that, you must entry the module name and choose what files you want to include.

The subgenerator will produce the following directory structure:

	moduleName/
		moduleName.html
		moduleNameModule.js
		moduleNameCtrl.js
		moduleNameRoute.js
		moduleNameService.js
		moduleName-test.js

Note: Subgenerators are to be run from the root directory of your application.

Directives

To create a directive just type on your terminal window:

yo angm:angm-directive

After that you must entry the directive name and choose what dependencies you want, by default we using external templates and external controllers.

The subgenerator will produce the following directory structure:

shared/
		directives/
			directiveName/
				assets/ /* optional folder
				directiveName.html
				directiveNameCtrl.j
				directiveName-test.js

Application files:

View (Html Template)

File: app/modules/moduleName/moduleName.html.

Code:

<div>
	Content from: "Page = moduleName"
</div>

Controller

File: app/modules/moduleName/moduleNameCtrl.js.

Code:

'use strict';

/**
 * @ngdoc function
 * @name appName.controller:moduleNameCtrl
 * @description
 * # moduleNameCtrl
 * Controller of the appName
 */
angular.module('appName')
	.controller('ModuleNameCtrl', ModuleNameCtrl);

	ModuleNameCtrl.$inject = ['Array of Dependencies optional'];

	function ModuleNameCtrl ('Array of Dependencies is the same above') {

	}

Route

File: app/modules/moduleName/moduleNameRoute.js.

Code:

'use strict';

/**
 * @ngdoc function
 * @name appName.route:moduleNameRoute
 * @description
 * # moduleNameRoute
 * Route of the appName
 */
angular.module('appName')
	.config(function ($stateProvider) {
		$stateProvider
			.state('moduleName', {
				url: '/moduleName',
				templateUrl: 'appName/modules/moduleName/moduleName.html',
				controller: 'moduleNameCtrl',
				controllerAs: 'vm'
			});
	});

Module

File: app/modules/moduleName/moduleNameModule.js.

Code:

'use strict';

/**
 * @ngdoc function
 * @name appName.route:moduleNameModule
 * @description
 * # moduleNameModule
 * Route of the appName
 */

 (function() {
   'use strict';

   angular.module('moduleName', []);

 })();

App starter script

File: app/app.js.

Code:

(function() {
	'use strict';

	/**
	 * @ngdoc index
	 * @name app
	 * @description
	 * # app
	 *
	 * Main module of the application.
	 */

	angular.module('Application name', [
		'ngResource',
		'ngAria',
		 'ngMaterial',
		'ngMdIcons',
		'ngCookies',
		'ngAnimate',
		'ngSanitize',
		'ui.router',
		'home',
	]);

})();

App config script

File: app/app-config.js.

Code:

((function () {
	'use strict';

	/**
	 * @ngdoc configuration file
	 * @name app.config:config
	 * @description
	 * # Config and run block
	 * Configutation of the app
	 */


	angular
		.module('ang-modular')
		.config(configure)
		.run(runBlock);

	configure.$inject = ['$stateProvider', '$urlRouterProvider', '$locationProvider', '$httpProvider'];

	function configure($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {

		$locationProvider.hashPrefix('!');

		// This is required for Browser Sync to work poperly
		$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';


		$urlRouterProvider
			.otherwise('/dashboard');

	}

	runBlock.$inject = ['$rootScope'];

	function runBlock($rootScope) {
		'use strict';

		console.log('AngularJS run() function...');
	}
})();

Gruntfile tasks

By default, new scripts are added to the index.html file. Using Grunt-injector, but only on setup configuration, after that you must run grunt injector or grunt dev every time you add a new module, directive or script.

Bower Components

The following packages are always installed by the angm-generator:

  • "json3"
  • "es5-shim"
  • "bootstrap"
  • "angular"
  • "angular-resource"
  • "angular-aria"
  • "angular-mocks"
  • "angular-touch"
  • "angular-bootstrap"
  • "angular-ui-router"

NOTE: Angular Material have the following dependencies:

  • angular-material-icons
  • angular-material
  • angular-messages

The following modules are optional on first install:

  • "angular-cookies"
  • "angular-animate"
  • "angular-sanitize"

All of these can be updated with bower update as new versions of AngularJS are released. Always on first install the generator will use the last stable version of all libraries.

Testing

We implemented only one kind of test at this moment: Unit tests. On next weeks e2e tests will be available too.

Running Tests

The tests are written in Jasmine, which we run with the [Karma Test Runner][karma]. We provide a Karma configuration file pre-configured with some default options to run them.

  • the configuration is found at karma.conf.js
  • the unit tests are found on each module created named as moduleName-test.js.

The easiest way to run the unit tests is to use the supplied npm script on package.json file:

npm test

This script will start the Karma test runner to execute the unit tests.

Contribute

To submitting an issue, please check if pass on travis. To submitting a bugfix, write a test that exposes the bug and fails before applying your fix. To submitting a new feature, add tests that cover the feature.

License

MIT

generator-angm's People

Contributors

baweaver avatar newaeonweb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

generator-angm's Issues

angm-directive and external assets folder

Hi!

First of all, thank you for this generator, it's pure awesomeness. I have learnt a lot about angular using it.

I have a question regarding directives and the assets folder. It's great that I can put all the assets needed for a directive within its own folder, because it's easier to maintain and distribute. But I have no idea how to get the URL for those assets.

I have a directive folder, with a controller, template and test, plus the assets folder. I have a big SVG file that goes with mu directive (basically the whole directive depends on that SVG). I was wondering how to embed it, what the URL to the SVG would be. And in case I add CSS/JS to the directive, how could I include it in the page when the directive is used?

What would happen if I have several instances of the directive? (not planning to, but I am curious).

Thanks!!!

Can update dependences versions?

When I used this on newest version OS X. It always tried to use phantomjs 1.9. But this version of phantomjs can not be executed on the newest version OS X.

missing ','

A comma is missing in the bower.json file after "angular-bootstrap": "~0.14.3" .

Errors in jshint

Linting Gruntfile.js ...ERROR
Running "jshint:gruntfile" (jshint) task
Linting Gruntfile.js ...ERROR
[L4:C15] W109: Strings must use singlequote.
"use strict";
Linting Gruntfile.js ...ERROR
[L119:C1] W099: Mixed spaces and tabs.
'app/app.config.js',
Linting Gruntfile.js ...ERROR
[L119:C19] W015: Expected 'app/app.config.js' to have an indentation at 13 instead at 19.
'app/app.config.js',
Linting Gruntfile.js ...ERROR
[L162:C29] W109: Strings must use singlequote.
grunt.registerTask("build", [
Linting Gruntfile.js ...ERROR
[L163:C13] W109: Strings must use singlequote.
"jshint",
Linting Gruntfile.js ...ERROR
[L164:C11] W109: Strings must use singlequote.
"exec",
Linting Gruntfile.js ...ERROR
[L165:C13] W109: Strings must use singlequote.
"concat",
Linting Gruntfile.js ...ERROR
[L166:C18] W109: Strings must use singlequote.
"ngtemplates",
Linting Gruntfile.js ...ERROR
[L167:C26] W109: Strings must use singlequote.
"injector:production",
Linting Gruntfile.js ...ERROR
[L168:C17] W109: Strings must use singlequote.
"concurrent",
Linting Gruntfile.js ...ERROR
[L169:C12] W109: Strings must use singlequote.
"clean"

Warning: Task "jshint:gruntfile" failed. Used --force, continuing.

Running "jshint:app" (jshint) task
Linting app/modules/home/homeCtrl.js ...ERROR
[L24:C16] W003: 'Home' was used before it was defined.
function Home(homeService) {
Linting app/modules/home/homeCtrl.js ...ERROR
[L27:C36] W109: Strings must use singlequote.
vm.title = "Hello, alpha-bank!";
Linting app/modules/home/homeCtrl.js ...ERROR
[L28:C25] W109: Strings must use singlequote.
vm.version = "1.0.0";
Linting app/modules/home/homeModule.js ...ERROR
[L1:C10] W013: Missing space after 'function'.
(function() {
Linting app/modules/home/homeModule.js ...ERROR
[L12:C5] W015: Expected 'angular' to have an indentation at 3 instead at 5.
angular.module('home', []);
Linting app/modules/home/homeService.js ...ERROR
[L17:C23] W003: 'homeService' was used before it was defined.
function homeService($http) {
Linting app/modules/home/homeService.js ...ERROR
[L20:C17] W109: Strings must use singlequote.
{"feature": "Implemented Best Practices, following: John Papa's Guide"},
Linting app/modules/home/homeService.js ...ERROR
[L20:C77] W109: Strings must use singlequote.
{"feature": "Implemented Best Practices, following: John Papa's Guide"},
Linting app/modules/home/homeService.js ...ERROR
[L21:C17] W109: Strings must use singlequote.
{"feature": "Using Controller AS syntax"},
Linting app/modules/home/homeService.js ...ERROR
[L21:C47] W109: Strings must use singlequote.
{"feature": "Using Controller AS syntax"},
Linting app/modules/home/homeService.js ...ERROR
[L22:C17] W109: Strings must use singlequote.
{"feature": "Wrap Angular components in an Immediately Invoked Function Expression (IIFE)"},
Linting app/modules/home/homeService.js ...ERROR
[L22:C97] W109: Strings must use singlequote.
{"feature": "Wrap Angular components in an Immediately Invoked Function Expression (IIFE)"},
Linting app/modules/home/homeService.js ...ERROR
[L23:C17] W109: Strings must use singlequote.
{"feature": "Declare modules without a variable using the setter syntax"},
Linting app/modules/home/homeService.js ...ERROR
[L23:C79] W109: Strings must use singlequote.
{"feature": "Declare modules without a variable using the setter syntax"},
Linting app/modules/home/homeService.js ...ERROR
[L24:C17] W109: Strings must use singlequote.
{"feature": "Using named functions"},
Linting app/modules/home/homeService.js ...ERROR
[L24:C42] W109: Strings must use singlequote.
{"feature": "Using named functions"},
Linting app/modules/home/homeService.js ...ERROR
[L25:C17] W109: Strings must use singlequote.
{"feature": "Including Unit test with Karma"},
Linting app/modules/home/homeService.js ...ERROR
[L25:C51] W109: Strings must use singlequote.
{"feature": "Including Unit test with Karma"},
Linting app/modules/home/homeService.js ...ERROR
[L26:C17] W109: Strings must use singlequote.
{"feature": "Including UI options for Bootstrap or Angular-Material"},
Linting app/modules/home/homeService.js ...ERROR
[L26:C75] W109: Strings must use singlequote.
{"feature": "Including UI options for Bootstrap or Angular-Material"},
Linting app/modules/home/homeService.js ...ERROR
[L27:C17] W109: Strings must use singlequote.
{"feature": "Including Angular-Material-Icons for Angular-Material UI"},
Linting app/modules/home/homeService.js ...ERROR
[L27:C77] W109: Strings must use singlequote.
{"feature": "Including Angular-Material-Icons for Angular-Material UI"},
Linting app/modules/home/homeService.js ...ERROR
[L28:C17] W109: Strings must use singlequote.
{"feature": "Dynamic Menu generator for both themes"},
Linting app/modules/home/homeService.js ...ERROR
[L28:C59] W109: Strings must use singlequote.
{"feature": "Dynamic Menu generator for both themes"},
Linting app/modules/home/homeService.js ...ERROR
[L29:C17] W109: Strings must use singlequote.
{"feature": "Grunt task for Production and Development"}
Linting app/modules/home/homeService.js ...ERROR
[L29:C62] W109: Strings must use singlequote.
{"feature": "Grunt task for Production and Development"}
Linting app/modules/home/homeService.js ...ERROR
[L36:C5] W026: Inner functions should be listed at the top of the outer function.
function getFeaturesList() {
Linting app/modules/home/homeService.js ...ERROR
[L36:C29] W003: 'getFeaturesList' was used before it was defined.
function getFeaturesList() {
Linting app/modules/home/homeService.js ...ERROR
[L37:C18] W033: Missing semicolon.
return list
Linting app/modules/layouts/nav-bar/navBarCtrl.js ...ERROR
[L24:C18] W003: 'NavBar' was used before it was defined.
function NavBar(homeService, MenuService) {
Linting app/modules/layouts/nav-bar/navBarCtrl.js ...ERROR
[L27:C28] W109: Strings must use singlequote.
vm.title = "alpha-bank";
Linting app/modules/layouts/nav-bar/navbarDirective.js ...ERROR
[L16:C18] W003: 'navBar' was used before it was defined.
function navBar() {
Linting app/modules/layouts/nav-bar/navbarDirective.js ...ERROR
[L32:C5] W026: Inner functions should be listed at the top of the outer function.
function link(scope, element, attrs, $location) {
Linting app/modules/layouts/nav-bar/navbarDirective.js ...ERROR
[L32:C18] W003: 'link' was used before it was defined.
function link(scope, element, attrs, $location) {
Linting app/modules/layouts/nav-bar/navbarDirective.js ...ERROR
[L44:C21] W003: 'control' was used before it was defined.
function control($scope, $location) {
Linting app/modules/layouts/nav-bar/navbarService.js ...ERROR
[L22:C16] W003: 'Menu' was used before it was defined.
function Menu($http) {
Linting app/modules/layouts/nav-bar/navbarService.js ...ERROR
[L36:C6] W033: Missing semicolon.
}

Warning: Task "jshint:app" failed. Used --force, continuing.

Gruntfile suggestion

Hi,

First of all, great generator. It's very simple and effective.

I started a simple project including angular-plotly library which depends on plotly. Using bower install angular-plotly --save works ok and grunt dev works as expected. However if I do a grunt build it fails with the following error:

Running "concat:build" (concat) task
Warning: Unable to read "app/assets/libs/plotly.js" file (Error code: EISDIR). Used --force, continuing.

The concat task was failing because it treated "plotly.js" as a file a not a folder the correction is easy, just add filter: 'isFile' to Gruntfile.js:

            build: {
                src: [
                    // Angular Project Dependencies,
                    'app/assets/libs/angular/angular.js',
                    'app/assets/libs/{,**/}*.js'
                ],
                filter: 'isFile',
                dest: 'app/assets/js/<%= pkg.name %>-angularbundle.js'
            }

In the future I suggest it should be included by default in the generator.

grunt build results in broken app

Hi
Just beginning to explore the opportunities your project might offer.
I am struggling a little to understand how to use it properly, as I can't see how to build some assets that could be included as part of a project.
If I use "grunt build" as you say to, then grunt starts a local server and seemingly lints and concats things. However - I don't understand why a local server is started, and the page it displays doesn't work... it's blank. Looking in the console, I can see that "angular is not defined" and it seems that looking at the resources, nothing in the way of bower components is being included!
Can you help?

third party component dependency injection issue

Hi @newaeonweb ,

I would like to know how can I inject 3rd party dependencies into my app? For eg. let's say I am using https://github.com/daniel-nagy/md-data-table
Now if I inject the dependency 'md.data.table' in my app.js, and if I create a new module by yo angm:angm-module, the 3rd party dependency 'md.data.table' that I injected previously is removed. I noticed the src code updateAppFile function, it gets the modules from the config & when I add a 3rd party bower component, it is niether added in the .yo-rc.json file nor does it exists in the _app.js file & hence I understand why the dependency gets removed when I add a new module.

So is app.js the wrong place to inject 3rd party dependencies ? What's the correct approach ?

I guess there should be an object array named dependencies in the .yo-rc.json which should be updated when I add/remove a bower component into my app & when app.js gets overwritten it should consider _app.js + modules (in .yo-rc.json file) + dependencies (in .yo-rc.json file)
Do I need to change the source file to support this or is there some another approach to achieve this?

Please advice. Thanks in advance.

Especificar pasta ao criar modulo

Parabéns pela sua iniciativa, tem ajudado muito.

Existe alguma forma de informar uma pasta ao criar novo modulo ?

Algo como:
yo angm:angm-module /Minhapasta/NomedoModulo

Ficando:
app
|__modules
|__minhapasta
|__modulocriado

SubGenerator calls new Application

When adding a new module with the SubGenerator example:

yo angm:angm-module

It loads the generator's default prompt to create a new application:

     _-----_
    |       |
    |--(o)--|   .--------------------------.
   `---------´  |    Welcome to Yeoman,    |
    ( _´U`_ )   |   ladies and gentlemen!  |
    /___A___\   '__________________________'
     |  ~  |
   __'.___.'__
 ´   `  |° ´ Y `


You're using the official Angm-generator.
[?] What would you like to call your application? (Angmodular) 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.