diff --git a/README.md b/README.md index 9199281a..1c88d31f 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,6 @@ This project generates a Micronaut based JHipster application 😎. It is based - Monolith only - maven or gradle - ## ❤️ for community Interested in contributing, check out our [contributing guide](https://github.com/jhipster/generator-jhipster-micronaut/blob/master/CONTRIBUTING.md) to get started. - -Any questions [sendilkumarn](https://twitter.com/sendilkumarn) diff --git a/generators/app/index.js b/generators/app/index.js index 738830ff..a6b97722 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -3,6 +3,8 @@ const chalk = require('chalk'); const AppGenerator = require('generator-jhipster/generators/app'); // const jhipsterPackagejs = require('generator-jhipster/package.json'); +const prompts = require('./prompts'); + module.exports = class extends AppGenerator { // /** // * Override yeoman standard storage function for yo-rc.json @@ -40,11 +42,11 @@ module.exports = class extends AppGenerator { this.log(`${chalk.blue(' ██║╚██╔╝██║')}${chalk.green(' ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║')}`); this.log(`${chalk.blue(' ██║ ╚═╝ ██║')}${chalk.green(' ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗')}`); this.log(`${chalk.blue(' ╚═╝ ╚═╝')}${chalk.green(' ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝')}\n`); - this.log(chalk.white.bold(' https://www.jhipster.tech\n')); - this.log(chalk.white('Welcome to MHipster 🤓 :: Running Micronaut version 1.3.0')); - this.log(chalk.white('This blueprint generates your backend as a Micronaut Java project.')); + this.log(chalk.white.bold(' https://www.jhipster.tech')); + this.log(chalk.blue.bold(' https://micronaut.io\n')); + this.log(chalk.white(' Welcome to MHipster 🤓 :: Running Micronaut version 1.3.4')); + this.log(chalk.white(' This blueprint generates your backend as a Micronaut Java project.')); this.log(chalk.green(' _______________________________________________________________________________________________________________\n')); - this.log(chalk.white(` For any questions or improvements refer to the stream lead at ${chalk.yellow('https://github.com/willbuck')}`)); this.log( chalk.white( ` If you find MHipster useful, support and star the project at ${chalk.yellow( @@ -65,17 +67,17 @@ module.exports = class extends AppGenerator { get prompting() { const defaultPhaseFromJHipster = super._prompting(); - const mhipsterPromptingPhaseSteps = { + return { + ...defaultPhaseFromJHipster, + askForApplicationType: prompts.askForApplicationType }; - - return Object.assign(defaultPhaseFromJHipster, mhipsterPromptingPhaseSteps); } get configuring() { const configuringPhaseFromJHipster = super._configuring(); - const jhipsterConfigureAppPhaseSteps = { + const mhipsterConfigureAppPhaseSteps = { composeServer() { if (this.skipServer) return; const options = this.options; @@ -114,12 +116,17 @@ module.exports = class extends AppGenerator { } }; - return Object.assign(configuringPhaseFromJHipster, jhipsterConfigureAppPhaseSteps); + return Object.assign(configuringPhaseFromJHipster, mhipsterConfigureAppPhaseSteps); } get default() { - // Here we are not overriding this phase and hence its being handled by JHipster - return super._default(); + const jhipsterDefault = super._default(); + + return { + ...jhipsterDefault, + askForTestOpts: prompts.askForTestOpts, + askForMoreModules: undefined + }; } get writing() { diff --git a/generators/app/prompts.js b/generators/app/prompts.js new file mode 100644 index 00000000..0e3f8170 --- /dev/null +++ b/generators/app/prompts.js @@ -0,0 +1,85 @@ +/** + * Copyright 2013-2020 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const chalk = require('chalk'); + +module.exports = { + askForApplicationType, + askForTestOpts +}; + +function askForApplicationType(meta) { + if (!meta && this.existingProject) return; + + const DEFAULT_APPTYPE = 'monolith'; + + const applicationTypeChoices = [ + { + value: DEFAULT_APPTYPE, + name: 'Monolithic application (recommended for simple projects)' + } + ]; + + const PROMPT = { + type: 'list', + name: 'applicationType', + message: `Which ${chalk.yellow('*type*')} of application would you like to create?`, + choices: applicationTypeChoices, + default: DEFAULT_APPTYPE + }; + + if (meta) return PROMPT; // eslint-disable-line consistent-return + + const done = this.async(); + + this.prompt(PROMPT).then(prompt => { + this.applicationType = this.configOptions.applicationType = prompt.applicationType; + done(); + }); +} + +function askForTestOpts(meta) { + if (!meta && this.existingProject) return; + + const choices = []; + const defaultChoice = []; + + if (meta || !this.skipClient) { + // all client side test frameworks should be added here + choices.push({ name: 'Protractor', value: 'protractor' }); + } else { + return; + } + + const PROMPT = { + type: 'checkbox', + name: 'testFrameworks', + message: 'Besides JUnit and Jest, which testing frameworks would you like to use?', + choices, + default: defaultChoice + }; + + if (meta) return PROMPT; // eslint-disable-line consistent-return + + const done = this.async(); + + this.prompt(PROMPT).then(prompt => { + this.testFrameworks = prompt.testFrameworks; + done(); + }); +} diff --git a/generators/server/index.js b/generators/server/index.js index ff2eb03c..f3fd8713 100644 --- a/generators/server/index.js +++ b/generators/server/index.js @@ -18,6 +18,7 @@ */ /* eslint-disable consistent-return */ const chalk = require('chalk'); +const os = require('os'); const ServerGenerator = require('generator-jhipster/generators/server'); const constants = require('generator-jhipster/generators/generator-constants'); const writeFiles = require('./files').writeFiles; @@ -56,7 +57,6 @@ module.exports = class extends ServerGenerator { return { askForModuleName: prompts.askForModuleName, askForServerSideOpts: prompts.askForServerSideOpts, - askForOptionalItems: prompts.askForOptionalItems, askFori18n: prompts.askFori18n, setSharedConfigOptions() { @@ -106,7 +106,25 @@ module.exports = class extends ServerGenerator { } */ get end() { - // Here we are not overriding this phase and hence its being handled by JHipster - return super._end(); + return { + end() { + this.log(chalk.green.bold('\nServer application generated successfully.\n')); + + let executable = 'mvnw'; + if (this.buildTool === 'gradle') { + executable = 'gradlew'; + } + + let logMsgComment = ''; + if (os.platform() === 'win32') { + logMsgComment = ` (${chalk.yellow.bold(executable)} if using Windows Command Prompt)`; + } + this.log( + chalk.green( + `Run your ${chalk.blue.bold('Micronaut')} application:\n${chalk.yellow.bold(`./${executable}`)}${logMsgComment}` + ) + ); + } + }; } }; diff --git a/generators/server/prompts.js b/generators/server/prompts.js index 3a813274..dad68efc 100644 --- a/generators/server/prompts.js +++ b/generators/server/prompts.js @@ -19,14 +19,12 @@ const chalk = require('chalk'); -const constants = require('generator-jhipster/generators/generator-constants'); const { getBase64Secret, getRandomHex } = require('generator-jhipster/generators/utils'); -const { logger } = require('generator-jhipster/generators/utils'); +const { logger } = require('generator-jhipster/cli/utils'); module.exports = { askForModuleName, askForServerSideOpts, - askForOptionalItems, askFori18n }; @@ -41,6 +39,17 @@ function askForServerSideOpts(meta) { const applicationType = this.applicationType; + const dbOptions = [ + { + value: 'mysql', + name: 'MySQL' + }, + { + value: 'postgresql', + name: 'PostgreSQL' + } + ]; + if (applicationType !== 'monolith') { logger.error('Application should be only monolith for this blueprint'); return; @@ -125,12 +134,6 @@ function askForServerSideOpts(meta) { name: 'JWT authentication (stateless, with a token)' } ]; - if (applicationType === 'monolith' && response.serviceDiscoveryType !== 'eureka') { - opts.push({ - value: 'session', - name: 'HTTP Session Authentication (stateful, default Spring Security mechanism)' - }); - } if (!reactive) { opts.push({ value: 'oauth2', @@ -172,7 +175,7 @@ function askForServerSideOpts(meta) { if (!reactive) { opts.push({ value: 'sql', - name: 'SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL)' + name: 'SQL (H2, MySQL, PostgreSQL)' }); } // TODO enable when we support these things @@ -205,7 +208,7 @@ function askForServerSideOpts(meta) { type: 'list', name: 'prodDatabaseType', message: `Which ${chalk.yellow('*production*')} database would you like to use?`, - choices: constants.SQL_DB_OPTIONS, + choices: dbOptions, default: 0 }, { @@ -223,33 +226,19 @@ function askForServerSideOpts(meta) { value: 'h2Memory', name: 'H2 with in-memory persistence' } - ].concat(constants.SQL_DB_OPTIONS.find(it => it.value === response.prodDatabaseType)), + ].concat(dbOptions.find(it => it.value === response.prodDatabaseType)), default: 0 }, { when: () => !reactive, type: 'list', name: 'cacheProvider', - message: 'Do you want to use the Spring cache abstraction?', + message: "Do you want to use Micronaut's cache abstraction?", choices: [ { value: 'ehcache', name: 'Yes, with the Ehcache implementation (local cache, for a single node)' }, - { - value: 'hazelcast', - name: - 'Yes, with the Hazelcast implementation (distributed cache, for multiple nodes, supports rate-limiting for gateway applications)' - }, - { - value: 'infinispan', - name: '[BETA] Yes, with the Infinispan implementation (hybrid cache, for multiple nodes)' - }, - { - value: 'memcached', - name: - 'Yes, with Memcached (distributed cache) - Warning, when using an SQL database, this will disable the Hibernate 2nd level cache!' - }, { value: 'no', name: 'No - Warning, when using an SQL database, this will disable the Hibernate 2nd level cache!' @@ -353,64 +342,6 @@ function askForServerSideOpts(meta) { }); } -function askForOptionalItems(meta) { - if (!meta && this.existingProject) return; - - const applicationType = this.applicationType; - const choices = []; - const defaultChoice = []; - if (!this.reactive) { - if (this.databaseType === 'sql' || this.databaseType === 'mongodb') { - choices.push({ - name: 'Search engine using Elasticsearch', - value: 'searchEngine:elasticsearch' - }); - } - if (applicationType === 'monolith' || applicationType === 'gateway') { - choices.push({ - name: 'WebSockets using Spring Websocket', - value: 'websocket:spring-websocket' - }); - } - choices.push({ - name: 'Asynchronous messages using Apache Kafka', - value: 'messageBroker:kafka' - }); - } - choices.push({ - name: 'API first development using OpenAPI-generator', - value: 'enableSwaggerCodegen:true' - }); - - const PROMPTS = { - type: 'checkbox', - name: 'serverSideOptions', - message: 'Which other technologies would you like to use?', - choices, - default: defaultChoice - }; - - if (meta) return PROMPTS; // eslint-disable-line consistent-return - - const done = this.async(); - if (choices.length > 0) { - this.prompt(PROMPTS).then(prompt => { - this.serverSideOptions = prompt.serverSideOptions; - this.websocket = this.getOptionFromArray(this.serverSideOptions, 'websocket'); - this.searchEngine = this.getOptionFromArray(this.serverSideOptions, 'searchEngine'); - this.messageBroker = this.getOptionFromArray(this.serverSideOptions, 'messageBroker'); - this.enableSwaggerCodegen = this.getOptionFromArray(this.serverSideOptions, 'enableSwaggerCodegen'); - // Only set this option if it hasn't been set in a previous question, as it's only optional for monoliths - if (!this.serviceDiscoveryType) { - this.serviceDiscoveryType = this.getOptionFromArray(this.serverSideOptions, 'serviceDiscoveryType'); - } - done(); - }); - } else { - done(); - } -} - function askFori18n() { if (this.existingProject || this.configOptions.skipI18nQuestion) return;