Skip to content

Commit

Permalink
Cleans up input prompts to supported features (#1 #40)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonTypesCodes committed May 20, 2020
1 parent 4901451 commit 8e54d66
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 102 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
29 changes: 18 additions & 11 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
85 changes: 85 additions & 0 deletions generators/app/prompts.js
Original file line number Diff line number Diff line change
@@ -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();
});
}
24 changes: 21 additions & 3 deletions generators/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +57,6 @@ module.exports = class extends ServerGenerator {
return {
askForModuleName: prompts.askForModuleName,
askForServerSideOpts: prompts.askForServerSideOpts,
askForOptionalItems: prompts.askForOptionalItems,
askFori18n: prompts.askFori18n,

setSharedConfigOptions() {
Expand Down Expand Up @@ -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}`
)
);
}
};
}
};
101 changes: 16 additions & 85 deletions generators/server/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
},
{
Expand All @@ -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!'
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 8e54d66

Please sign in to comment.