ecostanzi
ecostanzi

Reputation: 342

Override file templates with Jhipster blueprint

I'd like to use a different sequence for each jpa entity in my jhipster project. I'm considering a jhipster blueprint to do this for my project.

Now, I saw I could do this by changing file Entity.java.ejs file template and change the row from:

@SequenceGenerator(name = "sequenceGenerator")

to

@SequenceGenerator(name = "sequenceGenerator", sequenceName = "<%= entityInstance %>_seq")

What is the simplest way to include my custom template in a jhipster blueprint?

I can do this by combining the default yeoman writing phase to my blueprint custom writing phase. But I'm wondering if there's a better/simpler way to do this.

Thank you

Upvotes: 1

Views: 1748

Answers (1)

Avdev4j
Avdev4j

Reputation: 211

I did something like this some weeks ago. I called it 'merge blueprint'. I wanted to add my files with new content and override some base files to change their behaviour (like you want to do).

You can check my project here: https://github.com/avdev4j/generator-jhipster-mergeBP

Example with angular files

I have two constants declared to store paths :

const ORIGINAL_ANGULAR_TEMPLATE_PATH = '../../../node_modules/generator-jhipster/generators/client/templates/angular';
const CURRENT_ANGULAR_TEMPLATE_PATH = 'angular';

Then I call "writeFilesToDisk" for both path. Indeed the first call have to ,always, take the jhipster base path and the second our path (to be sur our files will not be overwrite).

function writeFiles() {
this.writeFilesToDisk(angularFiles, this, false, ORIGINAL_ANGULAR_TEMPLATE_PATH); // always originals first
this.writeFilesToDisk(files, this, false, CURRENT_ANGULAR_TEMPLATE_PATH);

}

By the way I checked the kotlin deepu blueprint (the blueprint creator) and he did something close (I think) https://github.com/jhipster/jhipster-kotlin

I plan to write a blueprint next days.Your feedbacks on this thread will be really appreciate.

For sur we should override base files carrefully because it will make upgrades more complexify.

This is the way I choose to do this, don't know if there is a simplier way but it should be helpfull.

we keep in touch ;)

Upvotes: 2

Related Questions