Skip to content

Commit

Permalink
Initial commit. Refactoring angular-project-template into yeoman gene…
Browse files Browse the repository at this point in the history
…rator.
  • Loading branch information
Chris Gross committed Jun 18, 2013
0 parents commit e41fe83
Show file tree
Hide file tree
Showing 38 changed files with 982 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
temp/
22 changes: 22 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"node": true,
"es5": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"white": true
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- '0.8'
- '0.10'
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2013 Chris Gross

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#generator-cg-angular

>Yeoman Generator for Enterprise Angular Projects
Features

* Provides a directory structure geared towards large Angular projects.
* Each controller, service, filter, and directive are placed in their own file.
* All files related to a conceptual unit are placed together. For example, the controller and HTML file for a partial are placed together in the same directory.
* Provides a ready-made Grunt build that produces an extremely optimized distribution.
* Integrates Bower for package management
* Includes Yeoman sub-generators for directives, services, partials, and filters
* Integrates LESS and includes Bootstrap via the source LESS files allowing you to reuse Bootstrap vars/mixins/etc.
* Testable - Included Yeoman sub-generators also build test skeletons. Run test via `grunt test`.

Directory Layout
-------------
Below is an explanation of the folder structure.

/css ........................................... usually only contains app.less
app.less ................................... main app-wide styles
/img ........................................... images (not created by default but included in bin if added)
/js ............................................ app global javascript files
setup.js ................................... angular module initialization and route setup
/directive. .................................... angular directives folder
my-directive.js ............................ example simple directive
/my-directive2 ............................. example complex directive (contains external partial)
my-directive2.js ....................... complex directive javascript
my-directive2.html ..................... complex directive partial
my-directive2.less ..................... complex directive LESS
/filter ........................................ angular filters folder
my-filter.js ............................... example filter
/partial ....................................... angular partials folder
/my-partial ................................ example partial
my-partial.html ........................ example partial html
my-partial.js .......................... example partial controller
my-partial.less ........................ example partial LESS
/service ....................................... angular services folder
my-service.js .............................. example service
/bin ........................................... distributable version of app built using grunt and Gruntfile.js
/lib ........................................... 3rd party libraries, managed by bower (renamed components to lib)
/node_modules .................................. npm managed libraries used by grunt

Getting Started
-------------

Prerequisites: Node, Grunt, Yeoman, and Bower. Once Node is installed, do:

npm install -g grunt-cli yo bower

Next, install this generator:

npm install -g generator-cg-angular

To create a project:

mkdir MyNewAwesomeApp
cd MyNewAwesomeApp
yo cg-angular

Grunt Tasks
-------------

Now that the project is created, you have 3 simple Grunt commands available:

grunt server #This will run a development server with watch & reload enabled.
grunt test #Run headless unit tests using PhantomJS.
grunt build #Places a fully optimized (minified, concatenated, and more) in /bin

Yeoman Subgenerators
-------------

There are a set of sub-generators to initialize empty Angular components. Each of these generators will:

* Create one or more skeleton files (javascript, LESS, html, etc) for the component type
* Create a skeleton unit test in /test
* Update index.html and add the necessary `script` tags.
* Update app.less and add the @import as needed.
* For partials, update the setup.js, adding the necessary route call if a route was entered in the generator prompts.

There are generators for `directive`,`partial`,`service`, and `filter`.

Running a generator:

yo cg-angular:directive my-awesome-directive
yo cg-angular:partial my-partial
yo cg-angular:service my-service
yo cg-angular:filter my-filter

The name paramater passed (i.e. 'my-awesome-directive') will be used for directory and/or file names. The generators will derive appropriate class names from this parameter (ex. 'my-awesome-directive' will convert to a class name of 'MyAwesomeDirective').

One quick note, each sub-generator pulls the Angular app/module name from the package.json. Therefore, if you choose to change the name of your Angular app/module, you must ensure that the name in the package.json stays in sync.

Release History
-------------

* 6/18/2013 v1.0.0 - Initial release of template as Yeoman generator.

41 changes: 41 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');


var CgangularGenerator = module.exports = function CgangularGenerator(args, options, config) {
yeoman.generators.Base.apply(this, arguments);

this.on('end', function () {
this.installDependencies({ skipInstall: options['skip-install'] });
});

this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
};

util.inherits(CgangularGenerator, yeoman.generators.Base);

CgangularGenerator.prototype.askFor = function askFor() {
var cb = this.async();

var prompts = [{
name: 'appname',
message: 'What would you like the angular app/module name to be?',
default: path.basename(process.cwd())
}];

this.prompt(prompts, function (props) {
this.appname = props.appname;

cb();
}.bind(this));
};

CgangularGenerator.prototype.app = function app() {
this.directory('skeleton/','./');
this.template('skeleton/js/setup.js','./js/setup.js');
this.template('skeleton/bower.json','./bower.json');
this.template('skeleton/index.html','./index.html');
this.template('skeleton/package.json','./package.json');
};
3 changes: 3 additions & 0 deletions app/templates/skeleton/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory" : "lib"
}
10 changes: 10 additions & 0 deletions app/templates/skeleton/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
22 changes: 22 additions & 0 deletions app/templates/skeleton/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"node": true,
"es5": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"white": true
}
Loading

0 comments on commit e41fe83

Please sign in to comment.