1"use strict";(globalThis.webpackChunkjhipster_website=globalThis.webpackChunkjhipster_website||[]).push([[503],{14752(e,n,t){t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>i,default:()=>c,frontMatter:()=>o,metadata:()=>r,toc:()=>p});const r=JSON.parse('{"id":"modules/creating-a-module","title":"Creating a module","description":"Creating a stand alone Blueprint (aka module)","source":"@site/docs/modules/creating-a-module.mdx","sourceDirName":"modules","slug":"/modules/creating-a-module/","permalink":"/modules/creating-a-module/","draft":false,"unlisted":false,"editUrl":"https://github.com/jhipster/jhipster.github.io/tree/main/docs/modules/creating-a-module.mdx","tags":[],"version":"current","lastUpdatedAt":1449340800000,"frontMatter":{"title":"Creating a module","slug":"/modules/creating-a-module/","last_update":{"date":"2015-12-05T18:40:00.000Z"}},"sidebar":"docsSidebar","previous":{"title":"Blueprint Basics","permalink":"/modules/extending-and-customizing/"},"next":{"title":"Creating a Blueprint","permalink":"/modules/creating-a-blueprint/"}}');var a=t(74848),s=t(28453);const o={title:"Creating a module",slug:"/modules/creating-a-module/",last_update:{date:new Date("2015-12-05T18:40:00.000Z")}},i=void 0,l={},p=[{value:"Creating a stand alone Blueprint (aka module)",id:"creating-a-stand-alone-blueprint-aka-module",level:2},{value:"Example",id:"example",level:2},{value:"Migration",id:"migration",level:2},{value:"Hooks",id:"hooks",level:3}];function d(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.h2,{id:"creating-a-stand-alone-blueprint-aka-module",children:"Creating a stand alone Blueprint (aka module)"}),"\n",(0,a.jsx)(n.p,{children:"As of JHipster v7.9.0, module support was merged into blueprint support. So the same rules apply."}),"\n",(0,a.jsxs)(n.p,{children:["Before creating a Blueprint, make sure you have read ",(0,a.jsx)(n.a,{href:"/modules/extending-and-customizing/",children:"Blueprint Basics"})]}),"\n",(0,a.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.a,{href:"https://github.com/jhipster/generator-jhipster-ionic",children:"JHipster Ionic"})," was converted from a module to a blueprint."]}),"\n",(0,a.jsx)(n.h2,{id:"migration",children:"Migration"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:"Rename your module app and entity generators (if they exist) to something else like app-module and entity-module"}),"\n"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"mv generators/app generators/app-module\nmv generators/entity generators/entity-module\n"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:"Rename every other generator that matches a generator-jhipster generator (otherwise they will be called as a blueprint).\nAnd update references."}),"\n",(0,a.jsxs)(n.li,{children:["Add a custom cli (",(0,a.jsx)(n.code,{children:"cli/cli.mjs"}),")"]}),"\n"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"#!/usr/bin/env node\n\nimport { runJHipster, done, logger } from 'generator-jhipster/cli';\nimport { readFile } from 'fs/promises';\nimport { fileURLToPath } from 'url';\nimport { dirname, basename } from 'path';\n\n// Get package name to use as namespace.\n// Allows blueprints to be aliased.\nconst packagePath = dirname(dirname(fileURLToPath(import.meta.url)));\nconst packageFolderName = basename(packagePath);\n\n(async () => {\n const { version, bin } = JSON.parse(await readFile(new URL('../package.json', import.meta.url)));\n const executableName = Object.keys(bin)[0];\n\n runJHipster({\n executableName,\n executableVersion: version,\n defaultCommand: 'app-module', // Generator to be used as entry point to replace `yo` command\n blueprints: {\n [packageFolderName]: version,\n },\n lookups: [{ packagePaths: [packagePath], lookups: ['generators'] }],\n }).catch(done);\n})();\n\nprocess.on('unhandledRejection', up => {\n logger.error('Unhandled promise rejection at:');\n logger.fatal(up);\n});\n"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:["Add the cli to ",(0,a.jsx)(n.code,{children:"package.json"})]}),"\n"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-json",children:'{\n "bin": {\n "jhipster-module": "cli/cli.mjs"\n }\n}\n'})}),"\n",(0,a.jsx)(n.h3,{id:"hooks",children:"Hooks"}),"\n",(0,a.jsx)(n.p,{children:"Hooks support will be removed for JHipster 8. For migration, you can use the following side-by-side blueprints to simulate hooks."}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:"Add the following generators."}),"\n"]}),"\n",(0,a.jsxs)(n.p,{children:["App generator (",(0,a.jsx)(n.code,{children:"generators/app/index.mjs"}),") for post app hooks:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"import
1chalk from 'chalk';\nimport GeneratorBaseApplication from 'generator-jhipster/generators/base-application';\nimport { INSTALL_PRIORITY } from 'generator-jhipster/priorities';\n\nexport default class extends GeneratorBaseApplication {\n constructor(args, opts, features) {\n super(args, opts, features);\n\n if (this.options.help) return;\n\n if (!this.options.jhipsterContext) {\n throw new Error(`This is a JHipster blueprint and should be used only like ${chalk.yellow('jhipster --blueprints myBlueprint')}`);\n }\n\n this.sbsBlueprint = true;\n }\n\n get [GeneratorBaseApplication.INSTALL]() {\n return {\n async afterRunHook() {\n await this.composeWithJHipster(`my-blueprint:app-module`, {\n appConfig: this.configOptions,\n });\n },\n };\n }\n}\n"})}),"\n",(0,a.jsxs)(n.p,{children:["Entity generator (",(0,a.jsx)(n.code,{children:"generators/entity/index.mjs"}),") for post entity hooks:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"import chalk from 'chalk';\nimport GeneratorBaseApplication from 'generator-jhipster/generators/base-application';\n\nexport default class extends GeneratorBaseApplication {\n constructor(args, opts, features) {\n super(args, opts, features);\n\n if (this.options.help) return;\n\n if (!this.options.jhipsterContext) {\n throw new Error(`This is a JHipster blueprint and should be used only like ${chalk.yellow('jhipster --blueprints myBlueprint')}`);\n }\n\n this.sbsBlueprint = true;\n }\n\n get [GeneratorBaseApplication.INSTALL]() {\n return {\n async afterRunHo
1ok() {\n await this.composeWithJHipster(`my-blueprint:entity-module`, {\n entityConfig: this.options.jhipsterContext.context,\n });\n },\n };\n }\n}\n"})})]})}function c(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(d,{...e})}):d(e)}},28453(e,n,t){t.d(n,{R:()=>o,x:()=>i});var r=t(96540);const a={},s=r.createContext(a);function o(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.