Skip to content

Commit

Permalink
stop relaying on commonjs features
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Oct 6, 2022
1 parent 48876f9 commit 304efaa
Show file tree
Hide file tree
Showing 46 changed files with 370 additions and 309 deletions.
14 changes: 1 addition & 13 deletions generators/app/generator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ const { OptionNames } = require('../../jdl/jhipster/application-options');
const { NO: CLIENT_FRAMEWORK_NO } = require('../../jdl/jhipster/client-framework-types');

const { JHI_PREFIX, BASE_NAME, JWT_SECRET_KEY, PACKAGE_NAME, PACKAGE_FOLDER, REMEMBER_ME_KEY } = OptionNames;
const {
GENERATOR_COMMON,
GENERATOR_ENTITIES,
GENERATOR_LANGUAGES,
GENERATOR_CLIENT,
GENERATOR_PAGE,
GENERATOR_SERVER,
} = require('../generator-list.cjs');
const { GENERATOR_COMMON, GENERATOR_LANGUAGES, GENERATOR_CLIENT, GENERATOR_PAGE, GENERATOR_SERVER } = require('../generator-list.cjs');

module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
constructor(args, options, features) {
Expand Down Expand Up @@ -476,11 +469,6 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
this.config.set(config);
},

async composeEntities() {
if (!this.options.withEntities) return;
await this.composeWithJHipster(GENERATOR_ENTITIES, { skipInstall: true }, true);
},

async composePages() {
if (!this.jhipsterConfig.pages || this.jhipsterConfig.pages.length === 0 || this.configOptions.skipComposePage) return;
this.configOptions.skipComposePage = true;
Expand Down
2 changes: 2 additions & 0 deletions generators/base/generator-base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class JHipsterBaseGenerator extends PrivateBase {
/** @type {Record<string, any>} */
dependabotPackageJson;

sbsBlueprint;

constructor(args, options, features) {
super(args, options, features);

Expand Down
39 changes: 39 additions & 0 deletions generators/generator-constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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 constants from './generator-constants.cjs';

const {
GENERATOR_JHIPSTER,
SERVER_MAIN_SRC_DIR,
SERVER_MAIN_RES_DIR,
SERVER_TEST_SRC_DIR,
SERVER_TEST_RES_DIR,
CLIENT_MAIN_SRC_DIR,
CLIENT_TEST_SRC_DIR,
} = constants;

export {
GENERATOR_JHIPSTER,
SERVER_MAIN_SRC_DIR,
SERVER_MAIN_RES_DIR,
SERVER_TEST_SRC_DIR,
SERVER_TEST_RES_DIR,
CLIENT_MAIN_SRC_DIR,
CLIENT_TEST_SRC_DIR,
};
26 changes: 16 additions & 10 deletions generators/languages/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import chalk from 'chalk';
import _ from 'lodash';

import BaseApplication from '../base-application/generator.cjs';
import BaseApplicationGenerator from '../base-application/generator.cjs';

import { askForLanguages, askI18n } from './prompts.mjs';
import statistics from '../statistics.cjs';
Expand All @@ -38,7 +38,13 @@ const { writeEntityFiles } = entityFiles;
const { translationDefaultConfig } = generatorDefaults;
const { SERVER_TEST_SRC_DIR } = constants;

export default class LanguagesGenerator extends BaseApplication {
/**
* This is the base class for a generator that generates entities.
*
* @class
* @extends {BaseApplicationGenerator}
*/
export default class LanguagesGenerator extends BaseApplicationGenerator {
constructor(args, options, features) {
super(args, options, { unique: 'namespace', ...features });

Expand Down Expand Up @@ -121,7 +127,7 @@ export default class LanguagesGenerator extends BaseApplication {
};
}

get [BaseApplication.INITIALIZING]() {
get [BaseApplicationGenerator.INITIALIZING]() {
if (this.delegateToBlueprint) return {};
return this.initializing;
}
Expand All @@ -142,7 +148,7 @@ export default class LanguagesGenerator extends BaseApplication {
};
}

get [BaseApplication.PROMPTING]() {
get [BaseApplicationGenerator.PROMPTING]() {
if (this.delegateToBlueprint) return {};
return this.prompting;
}
Expand Down Expand Up @@ -177,7 +183,7 @@ export default class LanguagesGenerator extends BaseApplication {
};
}

get [BaseApplication.CONFIGURING]() {
get [BaseApplicationGenerator.CONFIGURING]() {
if (this.delegateToBlueprint) return {};
return this.configuring;
}
Expand All @@ -204,7 +210,7 @@ export default class LanguagesGenerator extends BaseApplication {
};
}

get [BaseApplication.PREPARING]() {
get [BaseApplicationGenerator.PREPARING]() {
if (this.delegateToBlueprint) return {};
return this.preparing;
}
Expand All @@ -217,7 +223,7 @@ export default class LanguagesGenerator extends BaseApplication {
};
}

get [BaseApplication.DEFAULT]() {
get [BaseApplicationGenerator.DEFAULT]() {
if (this.delegateToBlueprint) return {};
return this.default;
}
Expand Down Expand Up @@ -252,7 +258,7 @@ export default class LanguagesGenerator extends BaseApplication {
};
}

get [BaseApplication.WRITING]() {
get [BaseApplicationGenerator.WRITING]() {
if (this.delegateToBlueprint) return {};
return this.writing;
}
Expand All @@ -263,7 +269,7 @@ export default class LanguagesGenerator extends BaseApplication {
};
}

get [BaseApplication.WRITING_ENTITIES]() {
get [BaseApplicationGenerator.WRITING_ENTITIES]() {
if (this.delegateToBlueprint) return {};
return this.writingEntities;
}
Expand Down Expand Up @@ -295,7 +301,7 @@ export default class LanguagesGenerator extends BaseApplication {
};
}

get [BaseApplication.POST_WRITING]() {
get [BaseApplicationGenerator.POST_WRITING]() {
if (this.delegateToBlueprint) return {};
return this.postWriting;
}
Expand Down
15 changes: 8 additions & 7 deletions test/app/composing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { createEnv } = require('yeoman-environment');

const { dryRunHelpers: helpers } = require('../utils/utils');
const { JHIPSTER_CONFIG_DIR } = require('../../generators/generator-constants.cjs');
const { getGenerator } = require('../support/index.cjs');

const mockedComposedGenerators = [
'jhipster:common',
Expand All @@ -24,7 +25,7 @@ describe('jhipster:app composing', () => {
let runContext;
let runResult;
before(async () => {
runContext = helpers.create(require.resolve('../../generators/app/index.mjs'));
runContext = helpers.create(getGenerator('app'));
runResult = await runContext
.withOptions({
baseName: 'jhipster',
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('jhipster:app composing', () => {
let runContext;
let runResult;
before(async () => {
runContext = helpers.create(require.resolve('../../generators/app/index.mjs'));
runContext = helpers.create(getGenerator('app'));
runResult = await runContext
.withOptions({
baseName: 'jhipster',
Expand Down Expand Up @@ -123,7 +124,7 @@ describe('jhipster:app composing', () => {
let runContext;
let runResult;
before(async () => {
runContext = helpers.create(require.resolve('../../generators/app/index.mjs'));
runContext = helpers.create(getGenerator('app'));
runResult = await runContext
.withOptions({
baseName: 'jhipster',
Expand Down Expand Up @@ -170,7 +171,7 @@ describe('jhipster:app composing', () => {
let runContext;
let runResult;
before(async () => {
runContext = helpers.create(require.resolve('../../generators/app/index.mjs'));
runContext = helpers.create(getGenerator('app'));
runResult = await runContext
.withOptions({
baseName: 'jhipster',
Expand Down Expand Up @@ -209,7 +210,7 @@ describe('jhipster:app composing', () => {
assert(LanguagesGenerator.calledOnce);
});
it('should compose with entities generator once', () => {
assert.equal(runResult.mockedGenerators['jhipster:entities'].callCount, 1);
assert.equal(runResult.mockedGenerators['jhipster:entities'].callCount, 0);
});
it('should not compose with entity generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:entity'];
Expand All @@ -225,7 +226,7 @@ describe('jhipster:app composing', () => {
let runContext;
let runResult;
before(async () => {
runContext = helpers.create(require.resolve('../../generators/app/index.mjs'));
runContext = helpers.create(getGenerator('app'));
runResult = await runContext
.withOptions({
baseName: 'jhipster',
Expand Down Expand Up @@ -280,7 +281,7 @@ describe('jhipster:app composing', () => {
let runContext;
let runResult;
before(async () => {
runContext = helpers.create(require.resolve('../../generators/app/index.mjs'));
runContext = helpers.create(getGenerator('app'));
runResult = await runContext
.withOptions({
baseName: 'jhipster',
Expand Down
7 changes: 4 additions & 3 deletions test/app/database-changelog.spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const path = require('path');
const fse = require('fs-extra');
const helpers = require('yeoman-test');
const { createMockedConfig } = require('../support/mock-config.cjs');
const createMockedConfig = require('../support/mock-config.cjs');

const { SERVER_MAIN_RES_DIR } = require('../../generators/generator-constants.cjs');
const { getEntityTemplatePath, getGenerator } = require('../support/index.cjs');

describe('jhipster:app database changelogs', () => {
context('when regenerating the application', () => {
describe('with cassandra database', () => {
let runResult;
before(() =>
helpers
.create(require.resolve('../../generators/app/index.mjs'))
.create(getGenerator('app'))
.doInDir(dir => {
createMockedConfig('05-cassandra', dir, { appDir: '' });
fse.copySync(path.join(__dirname, '../templates/.jhipster/Simple.json'), path.join(dir, '.jhipster/Foo.json'));
fse.copySync(getEntityTemplatePath('Simple'), path.join(dir, '.jhipster/Foo.json'));
})
.withOptions({ withEntities: true, force: true, skipClient: true })
.run()
Expand Down
3 changes: 2 additions & 1 deletion test/app/prompts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { JWT } = require('../../jdl/jhipster/authentication-types');
const { CYPRESS } = require('../../jdl/jhipster/test-framework-types');
const { ANGULAR } = require('../../jdl/jhipster/client-framework-types');
const { MAVEN } = require('../../jdl/jhipster/build-tool-types');
const { getGenerator } = require('../support/index.cjs');

const mockedComposedGenerators = ['jhipster:common', 'jhipster:server', 'jhipster:client', 'jhipster:languages', 'jhipster:entity'];

Expand All @@ -16,7 +17,7 @@ describe('jhipster:app prompts', () => {
let runResult;
before(() => {
return helpers
.create(require.resolve('../../generators/app/index.mjs'))
.create(getGenerator('app'))
.withOptions({
fromCli: true,
skipInstall: true,
Expand Down
17 changes: 9 additions & 8 deletions test/blueprint/app-blueprint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const fse = require('fs-extra');
const { jestExpect } = require('mocha-expect-snapshot');
const jhipsterVersion = require('../../package.json').version;
const EnvironmentBuilder = require('../../cli/environment-builder');
const { getGenerator, getTemplatePath } = require('../support/index.cjs');

describe('JHipster application generator with blueprint', () => {
describe('generate application with a version-compatible blueprint', () => {
Expand All @@ -24,7 +25,7 @@ describe('JHipster application generator with blueprint', () => {
};
const fakeBlueprintModuleDir = path.join(dir, 'node_modules/generator-jhipster-myblueprint');
fse.ensureDirSync(fakeBlueprintModuleDir);
fse.copySync(path.join(__dirname, '../../test/templates/fake-blueprint'), fakeBlueprintModuleDir);
fse.copySync(getTemplatePath('fake-blueprint'), fakeBlueprintModuleDir);
fse.writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
})
.withOptions({
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('JHipster application generator with blueprint', () => {
it('throws an error', () =>
jestExpect(() =>
helpers
.run(path.join(__dirname, '../../generators/app/index.mjs'))
.run(getGenerator('app'))
.inTmpDir(dir => {
// Fake the presence of the blueprint in node_modules
const packagejs = {
Expand All @@ -68,7 +69,7 @@ describe('JHipster application generator with blueprint', () => {
};
const fakeBlueprintModuleDir = path.join(dir, 'node_modules/generator-jhipster-myblueprint');
fse.ensureDirSync(fakeBlueprintModuleDir);
fse.copySync(path.join(__dirname, '../../test/templates/fake-blueprint'), fakeBlueprintModuleDir);
fse.copySync(getTemplatePath('fake-blueprint'), fakeBlueprintModuleDir);
fse.writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
})
.withOptions({
Expand All @@ -84,7 +85,7 @@ describe('JHipster application generator with blueprint', () => {
describe('generating application with a git blueprint', () => {
it('should succeed', () =>
helpers
.run(path.join(__dirname, '../../generators/app/index.mjs'))
.run(getGenerator('app'))
.inTmpDir(dir => {
// Fake the presence of the blueprint in node_modules
const packagejs = {
Expand All @@ -96,7 +97,7 @@ describe('JHipster application generator with blueprint', () => {
};
const fakeBlueprintModuleDir = path.join(dir, 'node_modules/generator-jhipster-myblueprint');
fse.ensureDirSync(fakeBlueprintModuleDir);
fse.copySync(path.join(__dirname, '../../test/templates/fake-blueprint'), fakeBlueprintModuleDir);
fse.copySync(getTemplatePath('fake-blueprint'), fakeBlueprintModuleDir);
fse.writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
})
.withOptions({
Expand All @@ -123,7 +124,7 @@ describe('JHipster application generator with blueprint', () => {
};
const fakeBlueprintModuleDir = path.join(dir, 'node_modules/generator-jhipster-myblueprint');
fse.ensureDirSync(fakeBlueprintModuleDir);
fse.copySync(path.join(__dirname, '../../test/templates/fake-blueprint'), fakeBlueprintModuleDir);
fse.copySync(getTemplatePath('fake-blueprint'), fakeBlueprintModuleDir);
fse.writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
})
.withOptions({
Expand Down Expand Up @@ -155,7 +156,7 @@ describe('JHipster application generator with blueprint', () => {
it('throws an error', () =>
jestExpect(() =>
helpers
.run(path.join(__dirname, '../../generators/app/index.mjs'))
.run(getGenerator('app'))
.inTmpDir(dir => {
// Fake the presence of the blueprint in node_modules
const packagejs = {
Expand All @@ -167,7 +168,7 @@ describe('JHipster application generator with blueprint', () => {
};
const fakeBlueprintModuleDir = path.join(dir, 'node_modules/generator-jhipster-myblueprint');
fse.ensureDirSync(fakeBlueprintModuleDir);
fse.copySync(path.join(__dirname, '../../test/templates/fake-blueprint'), fakeBlueprintModuleDir);
fse.copySync(getTemplatePath('fake-blueprint'), fakeBlueprintModuleDir);
fse.writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
})
.withOptions({
Expand Down
4 changes: 2 additions & 2 deletions test/blueprint/client-blueprint-custom-path.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const expectedFiles = require('../utils/expected-files');
Expand All @@ -7,6 +6,7 @@ const { MYSQL } = require('../../jdl/jhipster/database-types');
const { ANGULAR } = require('../../jdl/jhipster/client-framework-types');
const { JWT } = require('../../jdl/jhipster/authentication-types');
const { MAVEN } = require('../../jdl/jhipster/build-tool-types');
const { getGenerator } = require('../support/index.cjs');

const mockBlueprintSubGen = class extends ClientGenerator {
constructor(args, opts, features) {
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('JHipster client generator with blueprint with path customizer', () =>
describe(`generate client with blueprint option '${blueprintName}'`, () => {
before(() =>
helpers
.run(path.join(__dirname, '../../generators/client/index.mjs'))
.run(getGenerator('client'))
.withOptions({
fromCli: true,
build: MAVEN,
Expand Down
Loading

0 comments on commit 304efaa

Please sign in to comment.