jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.53k stars 4.02k forks source link

custom commands are not accepting jhipster 8.5.0 #27404

Closed Saurabhrok09 closed 4 weeks ago

Saurabhrok09 commented 4 weeks ago

when I'm passing custom commands via cmd or launch.json getting below error :

.... Debugger attached. Debugger attached. INFO! No custom commands found within blueprint: generator-jhipster-utx-migrate-six-to-eight at xyz\generator-jhipster-utx-migrate-six-to-eight error: unknown option '--custom-question' Waiting for the debugger to disconnect... Waiting for the debugger to disconnect...

I have added custom-question option in generator.js this.option('custom-question', { desc: 'baseName for Application', type: Boolean, });

as custom-question is type boolean, with 7.9.4 it's working but with 8.5.0 giving unknown option error.

mshima commented 4 weeks ago

Since v8 cli loads options/configs from generators command. Or set loadGeneratorOptions in command to use generator's option().

You should add command.js to generator folder and export in index.js.

Next JHipster version will always add command.js in generate-blueprint command.

mshima commented 2 weeks ago

The most simple fix is to add to generator's index.js:

export const command = { loadGeneratorOptions: true, configs: {} };
Saurabhrok09 commented 2 weeks ago

firstly thanks for your valuable time

Now below error is coming... @mshima

ERROR! Cannot convert undefined or null to object TypeError: Cannot convert undefined or null to object at Function.entries () at JHipsterCommand.addJHipsterOptions (file:///xxxxxxxx/node_modules/generator-jhipster/dist/cli/jhipster-command.mjs:160:16) at addCommandGeneratorOptions (file:///xxxxx/generator-jhipster/dist/cli/program.mjs:88:17) at async JHipsterCommand._lazyBuildCommandCallBack (file:///C:/xxxxxx/generator-jhipster/dist/cli/program.mjs:211:25) at async JHipsterCommand._parseCommand (file:///xxxxxxxx/generator-jhipster/dist/cli/jhipster-command.mjs:75:13) at async JHipsterCommand.parseAsync (xxxxxxxxx\node_modules\generator-jhipster\node_modules\commander\lib\command.js:1092:5) Waiting for the debugger to disconnect... Waiting for the debugger to disconnect...

index.js :
` // export { default } from './generator.js'; // export { default as command } from './command.js';

export const command = { loadGeneratorOptions: true, configs: {} };`

launch.js :
{ "type": "node", "request": "launch", "name": "Debug Jhipster microservice", // "preLaunchTask": "Build", "runtimeExecutable": "npx", "runtimeArgs": [ "jhipster", "--blueprints", "generator-jhipster-test-app", "--custQuest", "--skip-git", "--skip-install", "--force" ], "console": "integratedTerminal", "cwd": "C:/WORK/Testing/TEST-BP-gen-code" },

generator.js: `import AppGenerator from 'generator-jhipster/generators/app';

export default class extends AppGenerator { constructor(args, opts, features) { super(args, opts, { ...features, checkBlueprint: true, // Dropped it once migration is done. jhipster7Migration: true, });

this.option('cust-quest', {
  description: 'Skips building the application',
  type: Boolean,
  default: false,
});

}

async beforeQueue() { await super.beforeQueue(); }

get [AppGenerator.INITIALIZING]() { return this.asInitializingTaskGroup({ ...super.initializing, async initializingTemplateTask() { if(this.options.custQuest){ console.log("question passed"); } this.parseJHipsterArguments(command.arguments); this.parseJHipsterOptions(command.options); }, }); }

get [AppGenerator.PROMPTING]() { if(this.options.custQuest){ console.log("question passed"); } }

get [AppGenerator.CONFIGURING]() { return this.asConfiguringTaskGroup({ ...super.configuring, async configuringTemplateTask() {}, }); }

get [AppGenerator.COMPOSING]() { return this.asComposingTaskGroup({ ...super.composing, async composingTemplateTask() {}, }); }

get [AppGenerator.COMPOSING_COMPONENT]() { return this.asComposingComponentTaskGroup({ ...super.composingComponent, async composingComponentTemplateTask() {}, }); }

get [AppGenerator.LOADING]() { return this.asLoadingTaskGroup({ ...super.loading, async loadingTemplateTask() {}, }); }

get [AppGenerator.PREPARING]() { return this.asPreparingTaskGroup({ ...super.preparing, async preparingTemplateTask() {}, }); }

get [AppGenerator.CONFIGURING_EACH_ENTITY]() { return this.asConfiguringEachEntityTaskGroup({ ...super.configuringEachEntity, async configuringEachEntityTemplateTask() {}, }); }

get [AppGenerator.LOADING_ENTITIES]() { return this.asLoadingEntitiesTaskGroup({ ...super.loadingEntities, async loadingEntitiesTemplateTask() {}, }); }

get [AppGenerator.PREPARING_EACH_ENTITY]() { return this.asPreparingEachEntityTaskGroup({ ...super.preparingEachEntity, async preparingEachEntityTemplateTask() {}, }); }

get [AppGenerator.PREPARING_EACH_ENTITY_FIELD]() { return this.asPreparingEachEntityFieldTaskGroup({ ...super.preparingEachEntityField, async preparingEachEntityFieldTemplateTask() {}, }); }

get [AppGenerator.PREPARING_EACH_ENTITY_RELATIONSHIP]() { return this.asPreparingEachEntityRelationshipTaskGroup({ ...super.preparingEachEntityRelationship, async preparingEachEntityRelationshipTemplateTask() {}, }); }

get [AppGenerator.POST_PREPARING_EACH_ENTITY]() { return this.asPostPreparingEachEntityTaskGroup({ ...super.postPreparingEachEntity, async postPreparingEachEntityTemplateTask() {}, }); }

get [AppGenerator.DEFAULT]() { return this.asDefaultTaskGroup({ ...super.default, async defaultTemplateTask() {}, }); }

get [AppGenerator.WRITING]() { return this.asWritingTaskGroup({ ...super.writing, async writingTemplateTask({ application }) { await this.writeFiles({ sections: { files: [{ templates: ['template-file-app'] }], }, context: application, }); }, }); }

get [AppGenerator.WRITING_ENTITIES]() { return this.asWritingEntitiesTaskGroup({ ...super.writingEntities, async writingEntitiesTemplateTask() {}, }); }

get [AppGenerator.POST_WRITING]() { return this.asPostWritingTaskGroup({ ...super.postWriting, async postWritingTemplateTask() {}, }); }

get [AppGenerator.POST_WRITING_ENTITIES]() { return this.asPostWritingEntitiesTaskGroup({ ...super.postWritingEntities, async postWritingEntitiesTemplateTask() {}, }); }

get [AppGenerator.LOADING_TRANSLATIONS]() { return this.asLoadingTranslationsTaskGroup({ ...super.loadingTranslations, async loadingTranslationsTemplateTask() {}, }); }

get [AppGenerator.INSTALL]() { return this.asInstallTaskGroup({ ...super.install, async installTemplateTask() {}, }); }

get [AppGenerator.POST_INSTALL]() { return this.asPostInstallTaskGroup({ ...super.postInstall, async postInstallTemplateTask() {}, }); }

get [AppGenerator.END]() { return this.asEndTaskGroup({ ...super.end, async endTemplateTask() {}, }); } } `

yo-rc.json

{ "generator-jhipster": { "additionalSubGenerators": "", "baseName": "test-app", "cli": true, "entities": [], "generators": { "app": { "command": false, "priorities": [ "initializing", "prompting", "configuring", "composing", "composingComponent", "loading", "preparing", "configuringEachEntity", "loadingEntities", "preparingEachEntity", "preparingEachEntityField", "preparingEachEntityRelationship", "postPreparingEachEntity", "default", "writing", "writingEntities", "postWriting", "postWritingEntities", "loadingTranslations", "install", "postInstall", "end" ], "sbs": false, "written": true } }, "jhipsterVersion": "8.5.0", "localBlueprint": false, "sampleWritten": true, "subGenerators": ["app"] } }