Skip to content

Commit

Permalink
Merge pull request #23332 from mshima/skip_ci-cleanup
Browse files Browse the repository at this point in the history
Cleanup more todo methods
  • Loading branch information
DanielFran authored Aug 29, 2023
2 parents 884a57b + de0fa31 commit 4e01560
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 89 deletions.
3 changes: 2 additions & 1 deletion generators/azure-spring-cloud/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { cacheTypes, buildToolTypes } from '../../jdl/jhipster/index.mjs';
import { GENERATOR_AZURE_SPRING_CLOUD } from '../generator-list.mjs';
import { mavenProfile } from './templates.mjs';
import { createPomStorage } from '../maven/support/pom-store.mjs';
import { getFrontendAppName } from '../base/support/index.mjs';

const { MEMCACHED } = cacheTypes;

Expand Down Expand Up @@ -82,7 +83,7 @@ export default class AzureSpringCloudGenerator extends BaseGenerator {
this.env.options.appPath = this.config.get('appPath') || 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.frontendAppName = getFrontendAppName({ baseName: this.jhipsterConfig.baseName });
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');
Expand Down
4 changes: 2 additions & 2 deletions generators/base-application/support/prepare-entity.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import pluralize from 'pluralize';

import type BaseGenerator from '../../base-core/index.mjs';
import { getDatabaseTypeData, hibernateSnakeCase } from '../../server/support/index.mjs';
import { createFaker, parseChangelog, stringHashCode, upperFirstCamelCase } from '../../base/support/index.mjs';
import { createFaker, parseChangelog, stringHashCode, upperFirstCamelCase, getMicroserviceAppName } from '../../base/support/index.mjs';
import { fieldToReference } from './prepare-field.mjs';
import { getTypescriptKeyType, getEntityParentPathAddition } from '../../client/support/index.mjs';
import {
Expand Down Expand Up @@ -153,7 +153,7 @@ export default function prepareEntity(entityWithConfig, generator, application)
if (!entityWithConfig.microserviceName) {
throw new Error('Microservice name for the entity is not found. Entity cannot be generated!');
}
entityWithConfig.microserviceAppName = generator.getMicroserviceAppName(entityWithConfig.microserviceName);
entityWithConfig.microserviceAppName = getMicroserviceAppName({ microserviceName: entityWithConfig.microserviceName });
entityWithConfig.skipServer = true;
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion generators/base-core/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* limitations under the License.
*/

export { default } from './generator-base.mjs';
export { default } from './generator.mjs';
34 changes: 2 additions & 32 deletions generators/base/generator-base-todo.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
removeFieldsWithNullishValues,
parseCreationTimestamp,
getHipster,
getFrontendAppName,
} from './support/index.mjs';
import { detectLanguage, loadLanguagesConfig } from '../languages/support/index.mjs';
import {
Expand Down Expand Up @@ -182,15 +183,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene
return formatDateForChangelog(now);
}

/**
* @private
* Get a name suitable for microservice
* @param {string} microserviceName
*/
getMicroserviceAppName(microserviceName) {
return _.camelCase(microserviceName) + (microserviceName.endsWith('App') ? '' : 'App');
}

/**
* @private
* get a table column name in JHipster preferred style.
Expand Down Expand Up @@ -267,16 +259,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene
this.log.ok(msg);
}

/**
* @private
* get the frontend application name.
* @param {string} baseName of application - (defaults to <code>this.jhipsterConfig.baseName</code>)
*/
getFrontendAppName(baseName = this.jhipsterConfig.baseName) {
const name = _.camelCase(baseName) + (baseName.endsWith('App') ? '' : 'App');
return name.match(/^\d/) ? 'App' : name;
}

/**
* get the an upperFirst camelCase value.
* @param {string} value string to convert
Expand All @@ -285,18 +267,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene
return upperFirstCamelCase(value);
}

/**
* @private
* get the java main class name.
* @param {string} baseName of application
*/
getMainClassName(baseName = (this as any).baseName) {
const main = _.upperFirst((this as any).getMicroserviceAppName(baseName));
const acceptableForJava = new RegExp('^[A-Z][a-zA-Z0-9_]*$');

return acceptableForJava.test(main) ? main : 'Application';
}

/**
* build a generated application.
*
Expand Down Expand Up @@ -963,7 +933,7 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
dest.clientThemeDark = dest.clientThemeVariant === 'dark';

if (dest.baseName) {
dest.frontendAppName = (this as any).getFrontendAppName(dest.baseName);
dest.frontendAppName = getFrontendAppName({ baseName: dest.baseName });
}
}

Expand Down
40 changes: 0 additions & 40 deletions generators/base/generator-base-todo.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,6 @@ BaseGenerator.log = msg => {
BaseGenerator.logger = createJHipsterLogger();

describe('generator - base', () => {
describe('getFrontendAppName', () => {
describe('when called with name having App', () => {
it('returns the frontend app name', () => {
BaseGenerator.jhipsterConfig = { baseName: 'myAmazingApp' };
expect(BaseGenerator.getFrontendAppName()).to.equal('myAmazingApp');
});
});
describe('when called with name', () => {
it('returns the frontend app name with the App suffix added', () => {
BaseGenerator.jhipsterConfig = { baseName: 'myAwesomeProject' };
expect(BaseGenerator.getFrontendAppName()).to.equal('myAwesomeProjectApp');
});
});
describe('when called with name starting with a digit', () => {
it('returns the default frontend app name - App', () => {
BaseGenerator.jhipsterConfig = { baseName: '1derful' };
expect(BaseGenerator.getFrontendAppName()).to.equal('App');
});
});
});
describe('getMainClassName', () => {
describe('when called with name', () => {
it('return the app name', () => {
BaseGenerator.baseName = 'myTest';
expect(BaseGenerator.getMainClassName()).to.equal('MyTestApp');
});
});
describe('when called with name having App', () => {
it('return the app name', () => {
BaseGenerator.baseName = 'myApp';
expect(BaseGenerator.getMainClassName()).to.equal('MyApp');
});
});
describe('when called with name having invalid java chars', () => {
it('return the default app name', () => {
BaseGenerator.baseName = '9myApp';
expect(BaseGenerator.getMainClassName()).to.equal('Application');
});
});
});
describe('dateFormatForLiquibase', () => {
let base;
let options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { mergeBlueprints, parseBluePrints, loadBlueprintsFromConfiguration, norm
import { PRIORITY_NAMES } from './priorities.mjs';
import { BaseGeneratorDefinition, GenericTaskGroup } from './tasks.mjs';
import { JHipsterGeneratorFeatures, JHipsterGeneratorOptions } from './api.mjs';
import CoreGenerator from '../base-core/generator-base.mjs';
import CoreGenerator from '../base-core/index.mjs';
import { LOCAL_BLUEPRINT_PACKAGE_NAMESPACE } from './support/constants.mjs';

/**
Expand Down
2 changes: 1 addition & 1 deletion generators/base/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* limitations under the License.
*/

export { default } from './generator-base-blueprint.mjs';
export { default } from './generator.mjs';
export { default as command } from './command.mjs';
15 changes: 15 additions & 0 deletions generators/base/support/basename.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import _ from 'lodash';

const { camelCase } = _;

/**
* get the frontend application name.
*/
export const getFrontendAppName = ({ baseName }: { baseName: string }) => {
const name = camelCase(baseName) + (baseName.endsWith('App') ? '' : 'App');
return name.match(/^\d/) ? 'App' : name;
};

export const getMicroserviceAppName = ({ microserviceName }: { microserviceName: string }) => {
return camelCase(microserviceName) + (microserviceName.endsWith('App') ? '' : 'App');
};
22 changes: 22 additions & 0 deletions generators/base/support/basename.spec.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect, describe, it } from 'esmocha';
import { getFrontendAppName } from './basename.mjs';

describe('generator > base', () => {
describe('getFrontendAppName', () => {
describe('when called with name having App', () => {
it('returns the frontend app name', () => {
expect(getFrontendAppName({ baseName: 'myAmazingApp' })).toBe('myAmazingApp');
});
});
describe('when called with name', () => {
it('returns the frontend app name with the App suffix added', () => {
expect(getFrontendAppName({ baseName: 'myAwesomeProject' })).toBe('myAwesomeProjectApp');
});
});
describe('when called with name starting with a digit', () => {
it('returns the default frontend app name - App', () => {
expect(getFrontendAppName({ baseName: '1derful' })).toBe('App');
});
});
});
});
1 change: 1 addition & 0 deletions generators/base/support/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './basename.mjs';
export * from './configuration-helpers/options.mjs';
export * from './config.mjs';
export * from './contents.mjs';
Expand Down
2 changes: 1 addition & 1 deletion generators/base/support/needles.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import assert from 'assert';
import _ from 'lodash';
import escapeStringRegexp from 'escape-string-regexp';
import CoreGenerator from '../../base-core/generator-base.mjs';
import CoreGenerator from '../../base-core/index.mjs';
import { CascatedEditFileCallback, EditFileCallback } from '../api.mjs';
import { joinCallbacks } from './write-files.mjs';

Expand Down
6 changes: 4 additions & 2 deletions generators/bootstrap-application-server/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import { prepareField as prepareFieldForLiquibaseTemplates } from '../liquibase/
import { dockerPlaceholderGenerator, getDockerfileContainers } from '../docker/utils.mjs';
import { GRADLE_VERSION } from '../gradle/constants.mjs';
import { normalizePathEnd } from '../base/support/path.mjs';
import { getFrontendAppName } from '../base/support/index.mjs';
import { getMainClassName } from '../java/support/index.mjs';

export default class BoostrapApplicationServer extends BaseApplicationGenerator {
constructor(args: any, options: any, features: any) {
Expand Down Expand Up @@ -100,8 +102,8 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator
prepareForTemplates({ application: app }) {
const application: any = app;
// Application name modified, using each technology's conventions
application.frontendAppName = this.getFrontendAppName(application.baseName);
application.mainClass = this.getMainClassName(application.baseName);
application.frontendAppName = getFrontendAppName({ baseName: application.baseName });
application.mainClass = getMainClassName({ baseName: application.baseName });

application.jhiTablePrefix = hibernateSnakeCase(application.jhiPrefix);

Expand Down
3 changes: 2 additions & 1 deletion generators/cloudfoundry/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import statistics from '../statistics.mjs';
import { CLIENT_MAIN_SRC_DIR, SERVER_MAIN_RES_DIR } from '../generator-constants.mjs';
import { GENERATOR_CLOUDFOUNDRY } from '../generator-list.mjs';
import { cacheTypes, buildToolTypes, databaseTypes } from '../../jdl/jhipster/index.mjs';
import { getFrontendAppName } from '../base/support/index.mjs';

const { MEMCACHED } = cacheTypes;
const { GRADLE, MAVEN } = buildToolTypes;
Expand Down Expand Up @@ -66,7 +67,7 @@ export default class CloudfoundryGenerator extends BaseGenerator {
this.env.options.appPath = configuration.get('appPath') || 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.frontendAppName = getFrontendAppName({ baseName: this.jhipsterConfig.baseName });
},
};
}
Expand Down
6 changes: 4 additions & 2 deletions generators/gae/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { applicationTypes, buildToolTypes, cacheTypes, databaseTypes } from '../
import { mavenProdProfileContent, mavenPluginConfiguration, mavenProfileContent } from './templates.mjs';
import { createPomStorage } from '../maven/support/pom-store.mjs';
import { addGradleDependencyCallback, addGradlePluginCallback, applyFromGradleCallback } from '../gradle/internal/needles.mjs';
import { getFrontendAppName } from '../base/support/index.mjs';
import { getMainClassName } from '../java/support/index.mjs';

const cacheProviders = cacheTypes;
const { MEMCACHED } = cacheTypes;
Expand Down Expand Up @@ -106,10 +108,10 @@ export default class GaeGenerator extends BaseGenerator {
loadConfig() {
const configuration = this.config;
this.env.options.appPath = configuration.get('appPath') || CLIENT_MAIN_SRC_DIR;
this.mainClass = this.getMainClassName();
this.mainClass = getMainClassName({ baseName: this.jhipsterConfig.baseName });
this.cacheProvider = this.cacheProvider || NO_CACHE_PROVIDER;
this.enableHibernateCache = this.enableHibernateCache && ![NO_CACHE_PROVIDER, MEMCACHED].includes(this.cacheProvider);
this.frontendAppName = this.getFrontendAppName();
this.frontendAppName = getFrontendAppName({ baseName: this.jhipsterConfig.baseName });
this.gcpProjectId = configuration.get('gcpProjectId');
this.gcpCloudSqlInstanceName = configuration.get('gcpCloudSqlInstanceName');
this.gcpCloudSqlUserName = configuration.get('gcpCloudSqlUserName');
Expand Down
3 changes: 2 additions & 1 deletion generators/heroku/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
import { mavenProfileContent } from './templates.mjs';
import { createPomStorage } from '../maven/support/pom-store.mjs';
import { addGradlePluginCallback, applyFromGradleCallback } from '../gradle/internal/needles.mjs';
import { getFrontendAppName } from '../base/support/index.mjs';

const cacheProviderOptions = cacheTypes;
const { MEMCACHED, REDIS } = cacheTypes;
Expand Down Expand Up @@ -103,7 +104,7 @@ export default class HerokuGenerator extends BaseGenerator {
this.env.options.appPath = configuration.get('appPath') || 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.frontendAppName = getFrontendAppName({ baseName: this.jhipsterConfig.baseName });
this.herokuAppName = configuration.get('herokuAppName');
this.dynoSize = 'Free';
this.herokuDeployType = configuration.get('herokuDeployType');
Expand Down
1 change: 1 addition & 0 deletions generators/java/support/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from './checks/index.mjs';
export * from './files.mjs';
export { default as generatedAnnotationTransform } from './generated-annotation-transform.mjs';
export { default as packageInfoTransform } from './package-info-transform.mjs';
export * from './util.mjs';
14 changes: 14 additions & 0 deletions generators/java/support/util.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import _ from 'lodash';
import { getMicroserviceAppName } from '../../base/support/index.mjs';

const { upperFirst } = _;

/**
* get the java main class name.
*/
export const getMainClassName = ({ baseName }: { baseName: string }) => {
const main = upperFirst(getMicroserviceAppName({ microserviceName: baseName }));
const acceptableForJava = new RegExp('^[A-Z][a-zA-Z0-9_]*$');

return acceptableForJava.test(main) ? main : 'Application';
};
22 changes: 22 additions & 0 deletions generators/java/support/util.spec.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'esmocha';
import { getMainClassName } from './util.mjs';

describe('generator > java', () => {
describe('getMainClassName', () => {
describe('when called with name', () => {
it('return the app name', () => {
expect(getMainClassName({ baseName: 'myTest' })).toBe('MyTestApp');
});
});
describe('when called with name having App', () => {
it('return the app name', () => {
expect(getMainClassName({ baseName: 'myApp' })).toBe('MyApp');
});
});
describe('when called with name having invalid java chars', () => {
it('return the default app name', () => {
expect(getMainClassName({ baseName: '9myApp' })).toBe('Application');
});
});
});
});
5 changes: 3 additions & 2 deletions generators/openapi-client/files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { SERVER_MAIN_SRC_DIR, OPENAPI_GENERATOR_CLI_VERSION } from '../generator
import { applicationOptions, buildToolTypes, applicationTypes, authenticationTypes } from '../../jdl/jhipster/index.mjs';
import { addGradleDependencyCallback, addGradlePropertyCallback } from '../gradle/internal/needles.mjs';
import { getPomVersionProperties } from '../server/support/dependabot-maven.mjs';
import { getMainClassName } from '../java/support/index.mjs';

const { OptionNames } = applicationOptions;
const { GRADLE, MAVEN } = buildToolTypes;
Expand Down Expand Up @@ -194,7 +195,7 @@ export function customizeFiles() {
}

this.javaDir = `${SERVER_MAIN_SRC_DIR + this.packageFolder}/`;
const mainClassFile = `${this.javaDir + this.getMainClassName()}.java`;
const mainClassFile = `${this.javaDir + getMainClassName({ baseName: this.jhipsterConfig.baseName })}.java`;

if (this.applicationType !== MICROSERVICE || ![JWT].includes(this.authenticationType)) {
this.rewriteFile(
Expand All @@ -212,7 +213,7 @@ export function customizeFiles() {
}

this.javaDir = `${SERVER_MAIN_SRC_DIR + this.packageFolder}/`;
const mainClassFile = `${this.javaDir + this.getMainClassName()}.java`;
const mainClassFile = `${this.javaDir + getMainClassName({ baseName: this.jhipsterConfig.baseName })}.java`;

this.rewriteFile(
mainClassFile,
Expand Down
3 changes: 2 additions & 1 deletion generators/spring-controller/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { askForControllerActions } from './prompts.mjs';
import statistics from '../statistics.mjs';
import { GENERATOR_SPRING_CONTROLLER } from '../generator-list.mjs';
import { applicationOptions, cacheTypes, messageBrokerTypes } from '../../jdl/jhipster/index.mjs';
import { getMainClassName } from '../java/support/index.mjs';

const { OptionNames } = applicationOptions;
const cacheProviders = cacheTypes;
Expand Down Expand Up @@ -168,7 +169,7 @@ export default class SpringControllerGenerator extends BaseGenerator {
? ['static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*']
: this.mockRequestImports;

this.mainClass = this.getMainClassName();
this.mainClass = getMainClassName({ baseName: this.jhipsterConfig.baseName });

this.controllerActions.forEach(action => {
action.actionPath = _.kebabCase(action.actionName);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"exclude": [],
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["mocha"]
"types": []
}
}

0 comments on commit 4e01560

Please sign in to comment.