generator-cg-angular icon indicating copy to clipboard operation
generator-cg-angular copied to clipboard

module generator error

Open michaelsharpe opened this issue 9 years ago • 2 comments

I noticed a bug when generating a submodule. I was trying to generate it into the folder "src/app/home/" and it was modifying any file in "src/app/" which it could find. First it was modifying a file 'src/app/config.js', which is generated by a grunt task. It then threw the error that it couldn't find 'config.less'. After I removed that file, it did the same thing to a file 'src/app/templates.js'. Once I deleted that, it worked correctly.

I haven't delved into the internals of cg-angular, but I imagine it is looking at the root folder of the generated submodule as opposed to going to the root folder of the whole project to find "app.js" and "app.less". It is also a little strange that it was grabbing any '*.js' file that was present.

Thanks for the great tool! Its really speeding my development along.

michaelsharpe avatar Nov 13 '14 20:11 michaelsharpe

The module features of the generator try to automatically determine your modules structure. Its possible and desirable to have submodules of submodules so you can have a free hierarchy of modules in your project. To allow the generator to place a submodule inside a submodule, it searches up the directory tree looking for any modules in any .js file it finds. If it finds a module declaration in one of those parent .js files, it assumes that is what you want to be the parent module of that submodule. It will eventually find the app.js module declaration if no other submodules are found in the parent directory tree.

The way the Google's best practices describe modules, you'd generally only have one in a given folder. It sounds like you have a Grunt build creating some modules in other places. Thats confusing it. In the future the module subgenerator could ask explicitly what submodule you want to put it in.

cgross avatar Nov 13 '14 20:11 cgross

Ah, gotcha. That makes sense. I have two files which are core to the whole app directly inside the 'app' folder. This might not be a best practice. I will move them somewhere in my 'common' folder to keep them out of the way of the generator.

It does seem like a good idea for the generator to explicitly ask which module the new module should be hooked into, if for no other reason than to give people the feedback that that is what it is doing.

Thanks for the speedy reply! I hope to dig more into the generator code itself one day soon, if I ever get some free time at work XD

michaelsharpe avatar Nov 13 '14 20:11 michaelsharpe