Skip to content
Open
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
746 changes: 746 additions & 0 deletions generators/app/__snapshots__/generator.spec.mts.snap

Large diffs are not rendered by default.

44 changes: 0 additions & 44 deletions generators/app/generator.spec.mjs

This file was deleted.

105 changes: 105 additions & 0 deletions generators/app/generator.spec.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Copyright 2013-2022 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
*
* https://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.
*/
import { jestExpect as expect } from 'mocha-expect-snapshot';
import lodash from 'lodash';
import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';

import testSupport from '../../test/support/index.cjs';
import { defaultHelpers as helpers } from '../../test/utils/utils.mjs';
import Generator from './index.js';

const { snakeCase } = lodash;
const { testBlueprintSupport } = testSupport;

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const generator = basename(__dirname);
const generatorPath = join(__dirname, 'index.mjs');

describe(`JHipster ${generator} generator`, () => {
it('generator-list constant matches folder name', async () => {
await expect((await import('../generator-list.js')).default[`GENERATOR_${snakeCase(generator).toUpperCase()}`]).toBe(generator);
});
it('should support features parameter', () => {
const instance = new Generator([], { help: true }, { bar: true });
expect(instance.features.bar).toBe(true);
});
describe('blueprint support', () => testBlueprintSupport(generator));
describe('with', () => {
describe('default config', () => {
let runResult;
before(async () => {
runResult = await helpers.run(generatorPath).withOptions({
defaults: true,
baseName: 'jhipster',
skipPriorities: ['writing', 'postWriting', 'writingEntities', 'postWritingEntities'],
});
});

it('should match snapshot', () => {
expect(runResult.env.sharedOptions.sharedData.applications.jhipster.sharedApplication).toMatchSnapshot({
user: expect.any(Object),
jhipsterPackageJson: expect.any(Object),
jwtSecretKey: expect.any(String),
});
});
});

describe('gateway', () => {
let runResult;
before(async () => {
runResult = await helpers.run(generatorPath).withOptions({
defaults: true,
baseName: 'jhipster',
applicationType: 'gateway',
skipPriorities: ['writing', 'postWriting', 'writingEntities', 'postWritingEntities'],
});
});

it('should match snapshot', () => {
expect(runResult.env.sharedOptions.sharedData.applications.jhipster.sharedApplication).toMatchSnapshot({
user: expect.any(Object),
jhipsterPackageJson: expect.any(Object),
jwtSecretKey: expect.any(String),
});
});
});

describe('microservice', () => {
let runResult;
before(async () => {
runResult = await helpers.run(generatorPath).withOptions({
defaults: true,
baseName: 'jhipster',
applicationType: 'microservice',
skipPriorities: ['writing', 'postWriting', 'writingEntities', 'postWritingEntities'],
});
});

it('should match snapshot', () => {
expect(runResult.env.sharedOptions.sharedData.applications.jhipster.sharedApplication).toMatchSnapshot({
jhipsterPackageJson: expect.any(Object),
jwtSecretKey: expect.any(String),
});
});
});
});
});
6 changes: 5 additions & 1 deletion generators/base-application/generator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ class BaseApplicationGenerator extends BaseGenerator {
/** @type {SharedData<ApplicationType>} */
#sharedData;

/**
* @param {string | string[]} args
* @param {import('../base/api').GeneratorOptions} options
* @param {import('../base/api').GeneratorFeatures} features
*/
constructor(args, options, features) {
super(args, options, { priorityArgs: true, taskPrefix: PRIORITY_PREFIX, ...features });

if (this.options.help) {
return;
}
Expand Down
17 changes: 16 additions & 1 deletion generators/base/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import type { OptionConfig } from 'yeoman-generator';
import type { OptionConfig, GeneratorOptions, GeneratorFeatures } from 'yeoman-generator';

export type ApplicationWithConfig = {
config: {
[key: string]: string | boolean | number | string[];
};
entities: Record<string, unknown>;
};

interface JHipsterGeneratorOptions extends GeneratorOptions {
applicationWithConfig: ApplicationWithConfig;
}

type JHipsterGeneratorFeatures = GeneratorFeatures;

export type { JHipsterGeneratorOptions, JHipsterGeneratorFeatures, GeneratorFeatures };

// eslint-disable-next-line no-use-before-define
export type EditFileCallback<Generator> = (this: Generator, content: string, filePath: string) => CascatedEditFileCallback<Generator>;
Expand Down
5 changes: 5 additions & 0 deletions generators/base/generator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class BaseGenerator extends JHipsterBaseBlueprintGenerator {

static END = asPriority(END);

/**
* @param {string | string[]} args
* @param {import('./api').GeneratorOptions} options
* @param {import('./api').GeneratorFeatures} features
*/
constructor(args, options, features) {
super(args, options, { tasksMatchingPriority: true, taskPrefix: PRIORITY_PREFIX, ...features });
}
Expand Down
8 changes: 6 additions & 2 deletions generators/bootstrap-application-base/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import utils from '../../utils/index.js';
import userUtils from '../../utils/user.js';
import constants from '../generator-constants.js';
import type { CommonClientServerApplication } from './types.js';
import type { JHipsterOptions, GeneratorFeatures } from '../base/api.js';

const { prepareEntityForTemplates } = entityUtils;
const { prepareFieldForTemplates } = fieldUtils;
Expand All @@ -40,7 +41,7 @@ const { NODE_VERSION } = constants;
* @extends { BaseApplicationGenerator<CommonClientServerApplication> }
*/
export default class BootStrapApplicationBase extends BaseApplicationGenerator<CommonClientServerApplication> {
constructor(args: any, options: any, features: any) {
constructor(args: string | string[], options: JHipsterOptions, features: GeneratorFeatures) {
super(args, options, { unique: 'namespace', ...features });

if (this.options.help) return;
Expand Down Expand Up @@ -99,9 +100,12 @@ export default class BootStrapApplicationBase extends BaseApplicationGenerator<C

get configuringEachEntity() {
return this.asConfiguringEachEntityTaskGroup({
configureEntity({ entityStorage, entityConfig }) {
configureEntity({ entityStorage, entityConfig, entityName }) {
entityStorage.defaults({ fields: [], relationships: [] });

if (entityConfig.name === undefined) {
entityConfig.name = entityName;
}
if (entityConfig.changelogDate === undefined) {
entityConfig.changelogDate = this.dateFormatForLiquibase();
}
Expand Down
51 changes: 49 additions & 2 deletions generators/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,24 @@ const { packageJson: packagejs } = require('../../lib/index.js');
const constants = require('../generator-constants');
const statistics = require('../statistics');
const { clientDefaultConfig } = require('../generator-defaults');
const { GENERATOR_CYPRESS, GENERATOR_COMMON, GENERATOR_LANGUAGES, GENERATOR_CLIENT } = require('../generator-list');
const {
GENERATOR_CYPRESS,
GENERATOR_COMMON,
GENERATOR_LANGUAGES,
GENERATOR_CLIENT,
GENERATOR_ENTITY_CLIENT,
GENERATOR_ENTITY_I_18_N,
} = require('../generator-list');

const { ANGULAR } = constants.SUPPORTED_CLIENT_FRAMEWORKS;
const { CYPRESS } = require('../../jdl/jhipster/test-framework-types');
const { OAUTH2 } = require('../../jdl/jhipster/authentication-types');
const databaseTypes = require('../../jdl/jhipster/database-types');

const NO_DATABASE = databaseTypes.NO;
const { NO: NO_DATABASE } = databaseTypes;
const { CommonDBTypes } = require('../../jdl/jhipster/field-types');
const { GENERATOR_BOOTSTRAP_APPLICATION } = require('../generator-list');
const { prepareReactEntity } = require('../../utils/entity.js');

const TYPE_STRING = CommonDBTypes.STRING;
const TYPE_UUID = CommonDBTypes.UUID;
Expand Down Expand Up @@ -254,6 +262,21 @@ module.exports = class JHipsterClientGenerator extends BaseApplicationGenerator
return this.asPreparingTaskGroup(this.delegateToBlueprint ? {} : this.preparing);
}

// Public API method used by the getter and also by Blueprints
get preparingEachEntity() {
return this.asPreparingEachEntityTaskGroup({
react({ application, entity }) {
if (application.clientFrameworkReact) {
prepareReactEntity({ entity, application });
}
},
});
}

get [BaseApplicationGenerator.PREPARING_EACH_ENTITY]() {
return this.asPreparingEachEntityTaskGroup(this.delegateToBlueprint ? {} : this.preparingEachEntity);
}

// Public API method used by the getter and also by Blueprints
get default() {
return this.asDefaultTaskGroup({
Expand Down Expand Up @@ -306,6 +329,30 @@ module.exports = class JHipsterClientGenerator extends BaseApplicationGenerator
return this.asWritingTaskGroup(this.delegateToBlueprint ? {} : this.writing);
}

get writingEntities() {
return this.asWritingEntitiesTaskGroup({
async composeEachEntity({ application, entities }) {
for (const entity of entities.filter(entity => !entity.builtIn && !entity.skipClient)) {
const entityName = entity.name;
await this.composeWithJHipster(GENERATOR_ENTITY_CLIENT, [entityName], {
context: entity,
application,
});
if (application.enableTranslation) {
await this.composeWithJHipster(GENERATOR_ENTITY_I_18_N, [entityName], {
context: entity,
application,
});
}
}
},
});
}

get [BaseApplicationGenerator.WRITING_ENTITIES]() {
return this.asWritingEntitiesTaskGroup(this.delegateToBlueprint ? {} : this.writingEntities);
}

get postWriting() {
return this.asPostWritingTaskGroup({
packageJsonScripts({ application }) {
Expand Down
Loading