Generating an AngularJS project with Custom Templates

In “Generating an AngularJS project with ITE Architecture” we looked at using the basic sub-generators of cg-angular to set up a modular architecture which we have adopted as our standard approach for AngularJS projects.

Now we are going to look at customising the output of the sub-generators so that you can set up and maintain a standard in a team build and save yourself some time.

Here is the simplest example: adding a text file of your own to the sub-generator output

Basically you can configure what files the sub-generators create.  If you need to do more than that you might
just have to create your own sub-generators with yeoman.

For example, if you want the sub-generator for partials to create an extra file called partial.txt, then follow these steps:

Create a directory called templates/partial.

Copy all the files from this directory into that directory: https://github.com/cgross/generator-cg-angular/tree/master/partial/templates
That is the standard template files for the partial sub-generator. Now add a new file called partial.txt in that directory. Now go into your .yo-rc.json file and add a “partialTemplates” property under “generator-cg-angular” with the value of “templates/partial”.

Now when you run “yo cg-angular:partial whatever” it will create all
the files you’re used to and additionally create a whatever.txt file.

Have you read this?

https://github.com/cgross/generator-cg-angular/blob/master/CUSTOMIZING.md

That might help a bit.

 

 

Leave a Reply