How to apply cruft/cookiecutter template to existing Git/GitHub project? - cookiecutter

What's the best way to apply a cruft (or cookiecutter) template to an existing Git/GitHub project, which doesn't use any cookiecutter template so far?

In most cases, this would be a bad idea. Cookiecutter will override the contents of your folder. Any existing files, matching to template files, will be overridden with the template ones. So if you already have real logic inside those files, it gets lost.
If you want to adopt some good practices from the template, better do it manually and not by applying it on the existing project.

Related

How to override hybris platform files other than customize

So, I can see many files under customize folder under platform.
Is there any other way to oveerride platform in general other than putting it in customize folder?
If we have to override some OOTB file there are two ways:
1) If its in some extension, we can create customized extension and do our changes.
2) Add stuff into customize folder and do ant customize.
What if OOTB file is in platform? Is there any other way?
I expect to customize platform without adding it to customize folder.
Is the function/bean you want to override is injected through Spring?
If no, and you need to override say some jar, class or xml. You have choice of ant customize or buildcallbacks.xml
If yes, it's no different than overriding any other beans from parent extension. The only thing is that you will not need to create an extension dependency as platform is available globally.
For example : If you wish to override some function in DefaultCatalogDao to give your own implementation. You can do it like...
Create your own implementation extending the platform related service
Inject your custom bean with alias of the defaultCatalogDao
<alias alias="catalogDao" name="customCatalogDao"/>
<bean id="customCatalogDao" class="......CustomCatalogDao" parent="defaultCatalogDao"/>
For Commerce Cloud
You can change platform files using customize folder in Commerce Cloud V2 too. You would need to create a folder in your custom repository with name _CUSTOMIZE_ and then as you do in non cloud version, add your files (with exact folder structure as in platform).
Once you creare above folder, CCV2 build strategy automatically picks and deploys it, without any additional configuration.
Hope it helps!
Using buildcallbacks you can replace the files even the files in platform jar .
You can simply copy paste your file or write your own shell script to execute it and copy file to platform but how would it be different from ant customize. And why would you want to go away from standard hybris practices? Would that give you any extra benefit? I am sure that would only lead to issues during upgrade etc. Its not spring bean injection where you could tell your platform to use your implementation instead on other. There is no sense in wasting time in finding something which doesnt go along with product best practices.

How to use custom template in JHipster blueprint?

I am trying to override the a template Entity.java.ejs in my custom blueprint to add some extra functionality. Unfortunately JHipster uses its default one if generate an entity. I don’t want to overwrite the whole writing. Is there a possibility to override only certain ones and use JHipster default templates for the rest?
Helo friend,
in this period I see an application jhipster with a partial custom .ejs defining a default for others components.
The problem is that the overriding is very huge, and cabled only for a specific version 6.9.1 of jhipster.
If this is a good idea to custom a particolar application with a particolar version and with a specific cabling code ok, but is not good if you want a generic custom generator jhipster context, where you can "inject" only custom files, giving overriding of all scope original generator.
I try to search some answers searching on web, and your question is anyway a good clue to define a better solution that I see now.
The problem that I see is that jhipster environment dont have a "handling" approach about .ejs templates, when is very strong and straighweird when you use .jdl file .
An easly customization of templates of any jhipster application created with command "jhipster", ad example.
And searching I see this link https://github.com/jhipster/generator-jhipster/issues/1749
an issue of original jhipster generator where someone consider a good idea to use "subgenerator" using yeoman to modulerize this templates and with all benefits.
This is a another clue to understand somethings.
good luck and thanks

JHipster, Customization of generated code

i'm newbie in JHipster and i'm trying to figure this, when i create a new entity JHipster generates several files, angular, html and java classes, now if i want a common code for all this generated code i must edit each time that i use the yeoman generator? what i want is:
Custom Index template, and pages, is secure to edit them?.
Customize the entity tables, entity forms using angular, maybe extending yeoman generators
Customize generate java classes, maybe i think using AOP
So i need to edit each time for each generated code? and is a good practice this or what i want? for clarify more i want to use a Custom Bootstrap/angular Dashboard template like Minovate, i see how to customize bootstrap in the documentation but not about what i'm asking for, Thanks.
JHipster is just a code generator, once generated the code is yours.
For angular screens I would say do as much as you can in CSS/SASS.
But it's very likely that you will need to build some screen mixing several entities and change the structure of entity screens.
So you should rather consider them as a starting point and do your own stuff in another folder so that it does not get overwritten by next re-generations.
This way you can still update your entity definitions in .jhipster folder and re-run yo jhispter:entity <entity name> on the entities you modified.
Customising java Entities is usually much simpler and you can easiliy achieve this by merging generated code with git and defining your service classes.
AOP seems overkill here.
Extending a yeoman generator is a lot of work.
I suggest to use some VSC (git, subversion or whatever you like) have a branch dedicated to plain jhipster generated code and another one where you make customization.
Eventually regenerate on jhipster branch and merge back on yours.
You should at least reduce manual intervention.

Can I change Angular-Fullstack's automatic naming conventions?

When I use generator-angular-fullstack's API to build routes, controllers, directives, whathaveyou, it appends naming conventions I don't like. For instance for all the module declarations it appends "App", and I'd prefer to not have "App" appended to my app name. Also, it uses "Ctrl" instead of "Controller", and so on.
I'm not seeing a json file that controls this behavior in my app or my angular-fullstack npm files. There's a good chance I'm overlooking something or not even looking in the right place.
Thanks!
You cannot edit the templates directly. You can either go back and rename them, or generate your own templates by replacing the routing through your .yo-rc.json file. It's located in the root folder of the project in all angular-fullstack apps unless removed.
It looks like angular-fullstack uses the generator-ng-component node module for the templates, here's a link to the github repo for controller template specifically. You could also make your own, fork it, then use it as your own generator.
https://github.com/DaftMonk/generator-ng-component/blob/master/templates/controller/name.controller.js

Using XPages with Freemarker help needed

I would like to use Freemarker template engine in my XPages app but cant get it to work in XPages environment. The problem I have is related to template path which I don't know how to setup correctly. Freemarker simply assumes that templates resides somewhere on file system. I put my template file into the same directory as related java class exists. The path to such file is something like this xspnsf://server:0/xpages_tests.nsf/WEB-INF/classes/tcl/ which doesn't work for me. Is there anyone having experience with this? I simply need directory path to nsf that is accepted by File() constructor. This virtual xspnsf://.... is not understandable for java File object.
Here is the template path code for Freemarker:
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File("??????"));
Template temp = cfg.getTemplate("tmp.ftl");
Since you are storing the templates together with the classes (if I understand well), can't you use cfg.setClassForTemplateLoading(SomeClassFromThere.class, "/com/example/yourapplication/templates")?
Try to use Velocity (http://velocity.apache.org/) instead. It allows You to create custom resources loaders which can easily load templates from any place (for example from documents from notes db).
I have seen it used many times in different xpage projects and it works great.

Resources