Search code examples
javascriptjhipsteryeomanjhipster-blueprint

Jhipster blueprint can't override the entire priority


I want to customize addEntityToMenu function. I created a blueprint with entities-client as sub-generator then override POST_WRITING_PRIORITY with my custom functions.

My purpose is creating a custom MenuItem and then add it to entities/Menu.tsx, which uses jhipster-needle-add-entity-to-menu to generate link entity items.

//generate.mjs
const files = import('myCustom.cjs');
//...
  get [POST_WRITING_PRIORITY]() {
    return {
      async addToMenu() {
        if (this.skipClient) return undefined;
        return (await files).addToMenu.call(this);
      }
    };
  }

the origin addToMenu function will generate a React component like this

my custom function will generate an object like:

{"label":"<a href=\"/movie\" target=\"_blank\" rel=\"noopener noreferrer\">\nMovie\n</a>","key":"movie"},

I also custom the Menu.tsx to accept that result.

But this is the result when I run

jhipster jdl app.jdl --blueprints generator-jhipster-my-custom
<MenuItem icon="asterisk" to="/movie">
<Translate contentKey="global.menu.entities.movie" />
</MenuItem>
{"label":<ahref=\"/movie\"target=\"_blank\"rel=\"noreferrer\">\nMovie\n</a>","key":"movie"},

Seem like the addEntitiesToMenu is run twice. One from generator-jhipster and one from generator-jhipster-my-custom. But the problem is I overridden it. I debugged and research a lot but don't know why. What's wrong? Thanks!

Additional: all of my code


Solution

  • The implemented blueprint is a side-by-side blueprint.

    Side-by-side blueprints does not change the original blueprint behavior. You can write new file, change or remove generated files, but you cannot make the original generator don't generate those files.

    To change the behavior (skip some parts), you need to implement a normal blueprint (remove sbsBlueprint property) and inherit every parts you need. Documentation https://www.jhipster.tech/modules/creating-a-blueprint/.