Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use derived constants in kubernetes base #14767

Merged
merged 9 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions generators/azure-app-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const { defaultConfig } = require('../generator-defaults');
// Global constants
const constants = require('../generator-constants');

const { OptionNames } = require('../../jdl/jhipster/application-options');

const { MAVEN } = require('../../jdl/jhipster/build-tool-types');
const { GENERATOR_AZURE_APP_SERVICE } = require('../generator-list');

Expand Down Expand Up @@ -70,7 +68,7 @@ module.exports = class extends BaseBlueprintGenerator {

_initializing() {
return {
getConfig() {
sayHello() {
if (!this.options.fromCli) {
this.warning(
`Deprecated: JHipster seems to be invoked using Yeoman command. Please use the JHipster CLI. Run ${chalk.red(
Expand All @@ -79,8 +77,12 @@ module.exports = class extends BaseBlueprintGenerator {
);
}
this.log(chalk.bold('Azure App Service configuration is starting'));
this.baseName = this.config.get(OptionNames.BASE_NAME);
this.buildTool = this.config.get(OptionNames.BUILD_TOOL);
},
getSharedConfig() {
this.loadAppConfig();
this.loadServerConfig();
},
getConfig() {
this.azureAppServiceResourceGroupName = ''; // This is not saved, as it is better to get the Azure default variable
this.azureLocation = this.config.get('azureLocation');
this.azureAppServicePlan = this.config.get('azureAppServicePlan');
Expand Down Expand Up @@ -484,16 +486,19 @@ which is free for the first 30 days`);
return this._default();
}

_loadPlatformConfig(config = _.defaults({}, this.jhipsterConfig, defaultConfig), dest = this) {
super.loadPlatformConfig(config, dest);
_computeDerivedConfig(config = _.defaults({}, this.jhipsterConfig, defaultConfig), dest = this) {
Copy link
Member

@mshima mshima Jul 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to after priorities, it's not a priority.
Or drop the method and put in the task.

this.loadAppConfig();
this.loadServerConfig();
super.loadDerivedServerConfig(config, dest);
super.loadDerivedAppConfig(config, dest);
dest.azureAppInsightsInstrumentationKeyEmpty = config.azureAppInsightsInstrumentationKey === '';
}

// Public API method used by the getter and also by Blueprints
_loading() {
return {
loadSharedConfig() {
this._loadPlatformConfig();
this._computeDerivedConfig();
},
};
}
Expand Down
89 changes: 52 additions & 37 deletions generators/azure-spring-cloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ const BaseBlueprintGenerator = require('../generator-base-blueprint');
const statistics = require('../statistics');

const constants = require('../generator-constants');
const { OptionNames } = require('../../jdl/jhipster/application-options');

const cacheTypes = require('../../jdl/jhipster/cache-types');
const { MEMCACHED } = require('../../jdl/jhipster/cache-types');

const NO_CACHE_PROVIDER = cacheTypes.NO;

const { MAVEN, GRADLE } = require('../../jdl/jhipster/build-tool-types');
const { MAVEN } = require('../../jdl/jhipster/build-tool-types');
const { GENERATOR_AZURE_SPRING_CLOUD } = require('../generator-list');
const { JWT } = require('../../jdl/jhipster/authentication-types');

let useBlueprints;
/* eslint-disable consistent-return */
Expand All @@ -58,37 +56,36 @@ module.exports = class extends BaseBlueprintGenerator {
}

_initializing() {
if (!this.options.fromCli) {
this.warning(
`Deprecated: JHipster seems to be invoked using Yeoman command. Please use the JHipster CLI. Run ${chalk.red(
'jhipster <command>'
)} instead of ${chalk.red('yo jhipster:<command>')}`
);
}
this.log(chalk.bold('Azure Spring Cloud configuration is starting'));
this.env.options.appPath = this.config.get('appPath') || constants.CLIENT_MAIN_SRC_DIR;
this.baseName = this.config.get(OptionNames.BASE_NAME);
this.packageName = this.config.get(OptionNames.PACKAGE_NAME);
this.packageFolder = this.config.get(OptionNames.PACKAGE_FOLDER);
this.authenticationType = this.config.get(OptionNames.AUTHENTICATION_TYPE);
this.jwtSecretKey = this.config.get(OptionNames.JWT_SECRET_KEY);
this.cacheProvider = this.config.get(OptionNames.CACHE_PROVIDER) || NO_CACHE_PROVIDER;
this.enableHibernateCache =
this.config.get(OptionNames.ENABLE_HIBERNATE_CACHE) && ![NO_CACHE_PROVIDER, MEMCACHED].includes(this.cacheProvider);
this.databaseType = this.config.get(OptionNames.DATABASE_TYPE);
this.prodDatabaseType = this.config.get(OptionNames.PROD_DATABASE_TYPE);
this.searchEngine = this.config.get(OptionNames.SEARCH_ENGINE);
this.frontendAppName = this.getFrontendAppName();
this.buildTool = this.config.get(OptionNames.BUILD_TOOL);
this.applicationType = this.config.get(OptionNames.APPLICATION_TYPE);
this.serviceDiscoveryType = this.config.get(OptionNames.SERVICE_DISCOVERY_TYPE);
this.azureSpringCloudResourceGroupName = ''; // This is not saved, as it is better to get the Azure default variable
this.azureSpringCloudServiceName = ''; // This is not saved, as it is better to get the Azure default variable
this.azureSpringCloudAppName = this.config.get('azureSpringCloudAppName');
this.azureSpringCloudDeploymentType = this.config.get('azureSpringCloudDeploymentType');
return {
sayHello() {
if (!this.options.fromCli) {
this.warning(
`Deprecated: JHipster seems to be invoked using Yeoman command. Please use the JHipster CLI. Run ${chalk.red(
'jhipster <command>'
)} instead of ${chalk.red('yo jhipster:<command>')}`
);
}
this.log(chalk.bold('Azure Spring Cloud configuration is starting'));
},
getSharedConfig() {
this.loadAppConfig();
this.loadServerConfig();
this.loadPlatformConfig();
},
getConfig() {
this.env.options.appPath = this.config.get('appPath') || constants.CLIENT_MAIN_SRC_DIR;
this.cacheProvider = this.cacheProvider || NO_CACHE_PROVIDER;
this.enableHibernateCache = this.enableHibernateCache && ![NO_CACHE_PROVIDER, MEMCACHED].includes(this.cacheProvider);
this.frontendAppName = this.getFrontendAppName();
this.azureSpringCloudResourceGroupName = ''; // This is not saved, as it is better to get the Azure default variable
this.azureSpringCloudServiceName = ''; // This is not saved, as it is better to get the Azure default variable
this.azureSpringCloudAppName = this.config.get('azureSpringCloudAppName');
this.azureSpringCloudDeploymentType = this.config.get('azureSpringCloudDeploymentType');
},
};
}

initializing() {
get initializing() {
if (useBlueprints) return;
return this._initializing();
}
Expand Down Expand Up @@ -311,14 +308,32 @@ ${chalk.red('az extension add --name spring-cloud')}`
}
);
},
};
}

get default() {
if (useBlueprints) return;
return this._default();
}

_loading() {
return {
derivedProperties() {
this.isPackageNameJhipsterTech = this.packageName !== 'tech.jhipster';
this.isAuthenticationTypeJwt = this.authenticationType === JWT;
this.buildToolMaven = this.buildTool === MAVEN;
this.buildToolGradle = this.buildTool === GRADLE;
this.loadDerivedServerConfig();
this.loadDerivedPlatformConfig();
this.loadDerivedAppConfig();
},
};
}

get loading() {
if (useBlueprints) return;
return this._loading();
}

_writing() {
return {
copyAzureSpringCloudFiles() {
if (this.abort) return;
this.log(chalk.bold('\nCreating Azure Spring Cloud deployment files'));
Expand All @@ -340,9 +355,9 @@ ${chalk.red('az extension add --name spring-cloud')}`
};
}

get default() {
get writing() {
if (useBlueprints) return;
return this._default();
return this._writing();
}

_end() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ logging:
level:
ROOT: INFO
tech.jhipster: INFO
<%_ if (!isPackageNameJhipsterTech) { _%>
<%_ if (!isPackageNameJhipsterTech) { _%>
<%= packageName %>: INFO
<%_ } _%>
<%_ } _%>

eureka:
client:
Expand All @@ -55,7 +55,7 @@ spring:
# ===================================================================

jhipster:
<%_ if (isAuthenticationTypeJwt) { _%>
<%_ if (authenticationTypeJwt) { _%>
security:
authentication:
jwt:
Expand All @@ -68,4 +68,4 @@ jhipster:
# Token is valid 24 hours
token-validity-in-seconds: 86400
token-validity-in-seconds-for-remember-me: 2592000
<%_ } _%>
<%_ } _%>
50 changes: 16 additions & 34 deletions generators/ci-cd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,10 @@ const { defaultConfig } = require('../generator-defaults');
const prompts = require('./prompts');
const BaseBlueprintGenerator = require('../generator-base-blueprint');
const statistics = require('../statistics');
const packagejs = require('../../package.json');
const constants = require('../generator-constants');
const { OptionNames } = require('../../jdl/jhipster/application-options');
const { MAVEN, GRADLE } = require('../../jdl/jhipster/build-tool-types');
const { GENERATOR_CICD } = require('../generator-list');

const {
BASE_NAME,
APPLICATION_TYPE,
DATABASE_TYPE,
PROD_DATABASE_TYPE,
SKIP_CLIENT,
SKIP_SERVER,
CLIENT_PACKAGE_MANAGER,
BUILD_TOOL,
REACTIVE,
CLIENT_FRAMEWORK,
TEST_FRAMEWORKS,
CACHE_PROVIDER,
} = OptionNames;

const REACT = constants.SUPPORTED_CLIENT_FRAMEWORKS.REACT;

let useBlueprints;
Expand Down Expand Up @@ -103,29 +86,25 @@ module.exports = class extends BaseBlueprintGenerator {
validateFromCli() {
this.checkInvocationFromCLI();
},

sayHello() {
this.log(chalk.white('🚀 Welcome to the JHipster CI/CD Sub-Generator 🚀'));
},

getSharedConfig() {
this.loadAppConfig();
this.loadClientConfig();
this.loadServerConfig();
this.loadPlatformConfig();
},

getConfig() {
this.jhipsterVersion = packagejs.version;
const configuration = this.config;
this.baseName = configuration.get(BASE_NAME);
this.dasherizedBaseName = _.kebabCase(this.baseName);
this.applicationType = configuration.get(APPLICATION_TYPE);
this.databaseType = configuration.get(DATABASE_TYPE);
this.prodDatabaseType = configuration.get(PROD_DATABASE_TYPE);
this.skipClient = configuration.get(SKIP_CLIENT);
this.skipServer = configuration.get(SKIP_SERVER);
this.clientPackageManager = configuration.get(CLIENT_PACKAGE_MANAGER);
this.buildTool = configuration.get(BUILD_TOOL);
this.reactive = configuration.get(REACTIVE);
this.herokuAppName = configuration.get('herokuAppName');
if (this.herokuAppName === undefined) {
this.herokuAppName = _.kebabCase(this.baseName);
}
this.clientFramework = configuration.get(CLIENT_FRAMEWORK);
this.testFrameworks = configuration.get(TEST_FRAMEWORKS);
this.cacheProvider = configuration.get(CACHE_PROVIDER);
this.autoconfigureTravis = this.options.autoconfigureTravis;
this.autoconfigureJenkins = this.options.autoconfigureJenkins;
this.autoconfigureGitlab = this.options.autoconfigureGitlab;
Expand All @@ -134,10 +113,12 @@ module.exports = class extends BaseBlueprintGenerator {
this.autoconfigureCircleCI = this.options.autoconfigureCircle;
this.abort = false;
},

initConstants() {
this.NODE_VERSION = constants.NODE_VERSION;
this.NPM_VERSION = constants.NPM_VERSION;
},

getConstants() {
this.DOCKER_DIR = constants.DOCKER_DIR;
this.SERVER_MAIN_RES_DIR = constants.SERVER_MAIN_RES_DIR;
Expand Down Expand Up @@ -194,9 +175,8 @@ module.exports = class extends BaseBlueprintGenerator {
return this._configuring();
}

_loadPlatformConfig(config = _.defaults({}, this.jhipsterConfig, defaultConfig), dest = this) {
super.loadPlatformConfig(config, dest);
dest.cicdIntegrationsSnyk = config.cicdIntegrations || [];
_loadCiCdConfig(config = _.defaults({}, this.jhipsterConfig, defaultConfig), dest = this) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better move to after priorities to don't mix priority and api.

dest.cicdIntegrations = dest.cicdIntegrations || config.cicdIntegrations || [];
dest.cicdIntegrationsSnyk = dest.cicdIntegrations.includes('snyk');
dest.cicdIntegrationsSonar = dest.cicdIntegrations.includes('sonar');
dest.cicdIntegrationsHeroku = dest.cicdIntegrations.includes('heroku');
Expand All @@ -216,7 +196,9 @@ module.exports = class extends BaseBlueprintGenerator {
this.loadServerConfig();
this.loadDerivedServerConfig();
this.loadTranslationConfig();
this._loadPlatformConfig();
this._loadCiCdConfig();
this.loadPlatformConfig();
this.loadDerivedPlatformConfig();
},
};
}
Expand Down
18 changes: 11 additions & 7 deletions generators/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,23 @@ module.exports = class JHipsterClientGenerator extends BaseBlueprintGenerator {
this.checkInvocationFromCLI();
},

displayLogo() {
if (this.logo) {
this.printJHipsterLogo();
}
},

setupClientConstants() {
setupConstants() {
// Make constants available in templates
this.MAIN_SRC_DIR = this.CLIENT_MAIN_SRC_DIR;
this.TEST_SRC_DIR = this.CLIENT_TEST_SRC_DIR;
this.packagejs = packagejs;
this.LOGIN_REGEX = constants.LOGIN_REGEX_JS;
this.ANGULAR = ANGULAR;
this.REACT = REACT;
this.VUE = VUE;
this.NODE_VERSION = constants.NODE_VERSION;
},

displayLogo() {
if (this.logo) {
this.printJHipsterLogo();
}
},
};
}

Expand Down Expand Up @@ -194,6 +197,7 @@ module.exports = class JHipsterClientGenerator extends BaseBlueprintGenerator {
this.loadDerivedClientConfig();
this.loadServerConfig();
this.loadDerivedServerConfig();
this.loadPlatformConfig();
this.loadTranslationConfig();
},

Expand Down
Loading