Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
generator-cg-angular
Advanced tools
#generator-cg-angular
Yeoman Generator for Enterprise Angular Projects
This generator follows the Angular Best Practice Guidelines for Project Structure.
Features
$inject
or (['$scope','$http',...
.grunt serve
task allows you to run a simple development server with watch/livereload enabled. Additionally, JSHint and the appropriate unit tests are run for the changed files.grunt test
and they run automatically during the grunt watch that is active during grunt serve
.All subgenerators prompt the user to specify where to save the new files. Thus you can create any directory structure you desire, including nesting. The generator will create a handful of files in the root of your project including index.html
, app.js
, and app.less
. You determine how the rest of the project will be structured.
In this example, the user has chosen to group the app into an admin
folder, a search
folder, and a service
folder.
app.less ....................... main app-wide styles
app.js ......................... angular module initialization and route setup
index.html ..................... main HTML file
Gruntfile.js ................... Grunt build file
/admin ......................... example admin module folder
admin.js ..................... admin module initialization and route setup
admin.less ................... admin module LESS
/admin-directive1 ............ angular directives folder
admin-directive1.js ........ example simple directive
admin-directive1-spec.js.... example simple directive unit test
/admin-directive2 ............ example complex directive (contains external partial)
admin-directive2.js ........ complex directive javascript
admin-directive2.html ...... complex directive partial
admin-directive2.less ...... complex directive LESS
admin-directive2-spec.js ... complex directive unit test
/admin-partial ............... example partial
admin-partial.html ......... example partial html
admin-partial.js ........... example partial controller
admin-partial.less ......... example partial LESS
admin-partial-spec.js ...... example partial unit test
/search ........................ example search component folder
my-filter.js ................. example filter
my-filter-spec.js ............ example filter unit test
/search-partial .............. example partial
search-partial.html ........ example partial html
search-partial.js .......... example partial controller
search-partial.less ........ example partial LESS
search-partial-spec.js ..... example partial unit test
/service ....................... angular services folder
my-service.js .............. example service
my-service-spec.js ......... example service unit test
my-service2.js ............. example service
my-service2-spec.js ........ example service unit test
/img ........................... images (not created by default but included in /dist if added)
/dist .......................... distributable version of app built using grunt and Gruntfile.js
/bower_component................ 3rd party libraries managed by bower
/node_modules .................. npm managed libraries used by grunt
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
Now that the project is created, you have 3 simple Grunt commands available:
grunt serve #This will run a development server with watch & livereload enabled.
grunt test #Run local unit tests.
grunt build #Places a fully optimized (minified, concatenated, and more) in /dist
When grunt serve
is running, any changed javascript files will be linted using JSHint as well as have their appropriate unit tests executed. Only the unit tests that correspond to the changed file will be run. This allows for an efficient test driven workflow.
There are a set of subgenerators to initialize empty Angular components. Each of these generators will:
script
tags.There are generators for directive
,partial
,service
, filter
, module
, and modal
.
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
yo cg-angular:module my-module
yo cg-angular:modal my-modal
The name paramater passed (i.e. 'my-awesome-directive') will be used as the file names. The generators will derive appropriate class names from this parameter (ex. 'my-awesome-directive' will convert to a class name of 'MyAwesomeDirective'). Each sub-generator will ask for the folder in which to create the new skeleton files. You may override the default folder for each sub-generator in the .yo-rc.json
file.
The modal subgenerator is a convenient shortcut to create partials that work as modals for Bootstrap v3 and Angular-UI-Bootstrap v1.3 (both come preconfigured with this generator). If you choose not to use either of these libraries, simply don't use the modal subgenerator.
Subgenerators are also customizable. Please read CUSTOMIZING.md for details.
Submodules allow you to more explicitly separate parts of your application. Use the yo cg-angular:module my-module
command and specify a new subdirectory to place the module into. Once you've created a submodule, running other subgenerators will now prompt you to select the module in which to place the new component.
The new app will have a handful of preconfigured libraries included. This includes Angular 1.5, Bootstrap 3, AngularUI Bootstrap, FontAwesome, JQuery, LoDash, LESS, and Momentx. You may of course add to or remove any of these libraries. But the work to integrate them into the app and into the build process has already been done for you.
The project will include a ready-made Grunt build that will:
index.html
with the minified CSS and JS files./img
.index.html
.The resulting build loads only a few highly compressed files.
The build process uses grunt-dom-munger to pull script references from the index.html
. This means that your index.html is the single source of truth about what makes up your app. Adding a new library, new controller, new directive, etc does not require that you update the build file. Also the order of the scripts in your index.html
will be maintained when they're concatenated.
Importantly, grunt-dom-munger uses CSS attribute selectors to manage the parsing of the script and link tags. Its very easy to exclude certain scripts or stylesheets from the concatenated files. This is often the case if you're using a CDN. This can also be used to prevent certain development scripts from being included in the final build.
To prevent a script or stylesheet from being included in concatenation, put a data-concat="false"
attribute on the link or script tag. This is currently applied for the livereload.js
and less.js
script tags.
To prevent a script or link tag from being removed from the finalized index.html
, use a data-remove="false"
attribute.
angular-ui-router
is now available when initializing a new project. js/setup.js
and css/app.less
moved to app.js
and app.less
. grunt server
is now grunt serve
. Inside index.html
all user script tags are grouped together instead of split out into groups for services/filters/etc. New ability to customize the subgenerators.grunt server
allowing for an easy and efficient test-driven workflow.yo cg-angular:service
subgenerator./lib
back to /bower_components
as clarity trumps brevity. Renamed /bin
to /dist
. Fixed spelling error in generated directive's js template location. Moved up to later version of yeoman-generator
dependency to solve "Cannot read bold of undefined" error coming from Yeoman. JSHint options now read from .jshintrc
. And more small stuff.grunt watch
by no longer watching the lib
folder.grunt-regarde
with grunt-contrib-watch
. Fixed and tweaked the unit test specs and grunt test
. Fixed issues with the build. Generator is now ready for real use.FAQs
Yeoman Generator for Enterprise Angular projects.
We found that generator-cg-angular demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.