简体   繁体   中英

how to override yeoman generators?

I am trying to find a way how can I edit the default generators of generator-angular. In rails I can edit or create new generators here I am trying to create a scaffold like generator .

I want to edit this.

 yo angular:controller user

it is generating :

app/scripts/controllers/user.js:
angular.module('myMod').controller('UserCtrl', function ($scope) {

// ... });

Is there any way I can create my own sub command like :

 yo angular:scaffold user 

which should generate views + route + controller I like yoman but I am unable to find this .

You can use the routes generator to create scaffold it is not a pure scaffold but for that you can edit the generators first you can use this command :

yo angular:route myroute

This will generate :

app/scripts/controllers/myroute.js

 angular.module('myMod').controller('MyrouteCtrl', function ($scope) {
 // ...
});

app/views/myroute.html

If you want to customize the view file you can go to node_modules global file yo can find it here :

/usr/lib/node_modules/generator-angular

And you will see a list of files you can see it here : https://github.com/yeoman/generator-angular

here you need to change the file called :

/templates/common/app/views/view.html

here you can add you custom materials for you site and if you want to edit the controller for that you need to go to :

generator-angular/route/index.js

here you can edit how your generator behave , you can see this for more info how to edit or create yeoman generator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM