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

Adjusts for dotnetcore blueprint #23616

Merged
merged 4 commits into from
Sep 25, 2023
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
2,501 changes: 1,248 additions & 1,253 deletions generators/angular/__snapshots__/generator.spec.mts.snap

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions generators/angular/files-angular.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
* limitations under the License.
*/

import { clientApplicationTemplatesBlock, clientSrcTemplatesBlock } from '../client/support/files.mjs';
import { clientApplicationTemplatesBlock, clientRootTemplatesBlock, clientSrcTemplatesBlock } from '../client/support/files.mjs';

export const files = {
common: [
jhipsterProject: [
{
templates: ['README.md.jhi.client.angular'],
},
],
common: [
clientRootTemplatesBlock({
templates: [
'package.json',
'tsconfig.json',
Expand All @@ -37,7 +42,7 @@ export const files = {
'webpack/webpack.custom.js',
'webpack/logo-jhipster.png',
],
},
}),
],
sass: [
{
Expand All @@ -56,10 +61,10 @@ export const files = {
},
],
microfrontend: [
{
clientRootTemplatesBlock({
condition: generator => generator.microfrontend,
templates: ['webpack/webpack.microfrontend.js'],
},
}),
{
condition: generator => generator.microfrontend && generator.applicationTypeGateway,
...clientApplicationTemplatesBlock(),
Expand Down
9 changes: 6 additions & 3 deletions generators/angular/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ export default class AngularGenerator extends BaseApplicationGenerator {
localEntities?: any[];

async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_CLIENT);
await this.dependsOnJHipster(GENERATOR_LANGUAGES);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_ANGULAR);
}

if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_CLIENT);
await this.dependsOnJHipster(GENERATOR_LANGUAGES);
}
}

get loading() {
Expand Down Expand Up @@ -119,7 +122,7 @@ export default class AngularGenerator extends BaseApplicationGenerator {
};

source.addWebpackConfig = args => {
const webpackPath = 'webpack/webpack.custom.js';
const webpackPath = `${application.clientRootDir}webpack/webpack.custom.js`;
const ignoreNonExisting = this.sharedData.getControl().ignoreNeedlesError && 'Webpack configuration file not found';
this.editFile(
webpackPath,
Expand Down
25 changes: 8 additions & 17 deletions generators/angular/generator.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ describe(`generator - ${clientFramework}`, () => {
});

Object.entries(testSamples).forEach(([name, sampleConfig]) => {
const { clientRootDir = '' } = sampleConfig;

describe(name, () => {
let runResult;

Expand All @@ -110,26 +112,15 @@ describe(`generator - ${clientFramework}`, () => {
runResult.assertFileContent('.yo-rc.json', new RegExp(`"clientFramework": "${clientFramework}"`));
});
it('should not contain version placeholders at package.json', () => {
runResult.assertNoFileContent('package.json', /VERSION_MANAGED_BY_CLIENT_COMMON/);
runResult.assertNoFileContent('package.json', /VERSION_MANAGED_BY_CLIENT_ANGULAR/);
runResult.assertNoFileContent('package.json', /VERSION_MANAGED_BY_CLIENT_REACT/);
runResult.assertNoFileContent('package.json', /VERSION_MANAGED_BY_CLIENT_VUE/);
});

describe('skipJhipsterDependencies', () => {
const { skipJhipsterDependencies } = sampleConfig;
const skipJhipsterDependenciesTitle = skipJhipsterDependencies
? 'should not add generator-jhipster to package.json'
: 'should add generator-jhipster to package.json';
it(skipJhipsterDependenciesTitle, () => {
const assertion = (...args) =>
skipJhipsterDependencies ? runResult.assertNoFileContent(...args) : runResult.assertFileContent(...args);
assertion('package.json', 'generator-jhipster');
});
runResult.assertNoFileContent(`${clientRootDir}package.json`, /VERSION_MANAGED_BY_CLIENT_COMMON/);
runResult.assertNoFileContent(`${clientRootDir}package.json`, /VERSION_MANAGED_BY_CLIENT_ANGULAR/);
runResult.assertNoFileContent(`${clientRootDir}package.json`, /VERSION_MANAGED_BY_CLIENT_REACT/);
runResult.assertNoFileContent(`${clientRootDir}package.json`, /VERSION_MANAGED_BY_CLIENT_VUE/);
});

describe('withAdminUi', () => {
const { applicationType, withAdminUi, clientSrcDir = CLIENT_MAIN_SRC_DIR } = sampleConfig;
const { applicationType, withAdminUi, clientRootDir = '' } = sampleConfig;
const clientSrcDir = `${clientRootDir}${CLIENT_MAIN_SRC_DIR}`;
const generateAdminUi = applicationType !== 'microservice' && withAdminUi;
const adminUiComponents = generateAdminUi ? 'should generate admin ui components' : 'should not generate admin ui components';

Expand Down
21 changes: 12 additions & 9 deletions generators/angular/support/translate-angular.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function getTranslationValue(getWebappTranslation, key, data) {
*/
function replaceTranslationKeysWithText(getWebappTranslation, content, regexSource, { keyIndex = 1, replacementIndex = 1, escape } = {}) {
const regex = new RegExp(regexSource, 'g');
let match = regex.exec(content);
while (match !== null) {
const allMatches = content.matchAll(regex);
for (const match of allMatches) {
// match is now the next match, in array form and our key is at index 1, index 1 is replace target.
const key = match[keyIndex];
const target = match[replacementIndex];
Expand All @@ -54,7 +54,6 @@ function replaceTranslationKeysWithText(getWebappTranslation, content, regexSour
translation = escape(translation, match);
}
content = content.replace(target, translation);
match = regex.exec(content);
}
return content;
}
Expand All @@ -67,9 +66,14 @@ function replaceTranslationKeysWithText(getWebappTranslation, content, regexSour
* @returns string with jsKey value replaced
*/
function replaceJSTranslation(getWebappTranslation, content, jsKey) {
return replaceTranslationKeysWithText(getWebappTranslation, content, `${jsKey}\\s?:\\s?['|"]([a-zA-Z0-9.\\-_]+)['|"]`, {
escape: (translation, match) => translation.replaceAll(match[0].slice(-1), `\\${match[0].slice(-1)}`),
});
return replaceTranslationKeysWithText(
getWebappTranslation,
content,
`${jsKey}\\s?:\\s?['|"]([a-zA-Z0-9.\\-_]+\\.[a-zA-Z0-9.\\-_]+)['|"]`,
{
escape: (translation, match) => translation.replaceAll(match[0].slice(-1), `\\${match[0].slice(-1)}`),
},
);
}

/**
Expand Down Expand Up @@ -113,10 +117,9 @@ export const createTranslationReplacer = (getWebappTranslation, enableTranslatio
content = content.replace(new RegExp(TRANSLATE_REGEX, 'g'), '');
content = replacePlaceholders(getWebappTranslation, content);
}
content = htmlJhiTranslateReplacer(content);
content = htmlJhiTranslateStringifyReplacer(content);
}
if (/\.ts$/.test(filePath)) {
// Translate html files and inline templates.
if (/(:?\.html|component\.ts)$/.test(filePath)) {
content = htmlJhiTranslateReplacer(content);
content = htmlJhiTranslateStringifyReplacer(content);
}
Expand Down
6 changes: 0 additions & 6 deletions generators/angular/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@
"eslint": "<%= nodeDependencies['eslint'] %>",
"eslint-config-prettier": "<%= nodeDependencies['eslint-config-prettier'] %>",
"eslint-webpack-plugin": "<%= nodeDependencies['eslint-webpack-plugin'] %>",
<%_ if (!skipJhipsterDependencies) { _%>
"generator-jhipster": "<%= jhipsterVersion %>",
<%_ blueprints.forEach(blueprint => { _%>
"<%= blueprint.name %>": "<%= blueprint.version %>",
<%_ }); _%>
<%_ } _%>
"jest": "<%= nodeDependencies['jest'] %>",
"jest-environment-jsdom": "<%= nodeDependencies['jest'] %>",
"jest-preset-angular": "<%= nodeDependencies['jest-preset-angular'] %>",
Expand Down
3 changes: 3 additions & 0 deletions generators/app/__snapshots__/generator.spec.mts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"clientFrameworkReact": false,
"clientFrameworkVue": false,
"clientPackageManager": "npm",
"clientRootDir": "",
"clientSrcDir": "src/main/webapp/",
"clientTestDir": "src/test/javascript/",
"clientTheme": "none",
Expand Down Expand Up @@ -677,6 +678,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"clientFrameworkReact": false,
"clientFrameworkVue": false,
"clientPackageManager": "npm",
"clientRootDir": "",
"clientSrcDir": "src/main/webapp/",
"clientTestDir": "src/test/javascript/",
"clientTheme": "none",
Expand Down Expand Up @@ -1230,6 +1232,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"clientFrameworkReact": false,
"clientFrameworkVue": false,
"clientPackageManager": "npm",
"clientRootDir": "",
"clientSrcDir": "src/main/webapp/",
"clientTestDir": "src/test/javascript/",
"clientTheme": undefined,
Expand Down
5 changes: 4 additions & 1 deletion generators/app/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator {
async beforeQueue() {
loadStoredAppOptions.call(this);

await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_BASE);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_APP);
}

if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_BASE);
}
}

get initializing() {
Expand Down
1 change: 1 addition & 0 deletions generators/base-application/types.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export type CommonClientServerApplication = BaseApplication &
SpringBootApplication &
ClientApplication &
ApplicationType & {
clientRootDir: string;
clientSrcDir: string;
clientTestDir?: string;
clientDistDir?: string;
Expand Down
5 changes: 4 additions & 1 deletion generators/ci-cd/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ export default class CiCdGenerator extends BaseApplicationGenerator {
}

async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_CI_CD);
}

if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
}
}

// Public API method used by the getter and also by Blueprints
Expand Down
11 changes: 7 additions & 4 deletions generators/client/files-common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { clientSrcTemplatesBlock } from './support/files.mjs';
import { clientRootTemplatesBlock, clientSrcTemplatesBlock } from './support/files.mjs';

export const files = {
common: [
{
templates: ['.eslintignore', 'README.md.jhi.client'],
templates: ['README.md.jhi.client'],
},
{
clientRootTemplatesBlock({
templates: ['.eslintignore'],
}),
clientRootTemplatesBlock({
condition: generator => generator.microfrontend && (generator.clientFrameworkVue || generator.clientFrameworkReact),
templates: ['webpack/webpack.microfrontend.js.jhi'],
},
}),
{
...clientSrcTemplatesBlock(),
templates: [
Expand Down
16 changes: 7 additions & 9 deletions generators/client/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,21 @@ import command from './command.mjs';
const { ANGULAR, VUE, REACT, NO: CLIENT_FRAMEWORK_NO } = clientFrameworkTypes;
const { CYPRESS } = testFrameworkTypes;

/**
* @class
* @extends {BaseApplicationGenerator<import('./types.mjs').ClientApplication>}
*/
export default class JHipsterClientGenerator extends BaseApplicationGenerator {
command = command;

async beforeQueue() {
loadStoredAppOptions.call(this);

// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_CLIENT.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnJHipster(GENERATOR_COMMON);

if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_CLIENT);
}

if (!this.delegateToBlueprint) {
// TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_CLIENT.
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnJHipster(GENERATOR_COMMON);
}
}

get initializing() {
Expand Down Expand Up @@ -235,7 +233,7 @@ export default class JHipsterClientGenerator extends BaseApplicationGenerator {
get postWriting() {
return this.asPostWritingTaskGroup({
packageJsonScripts({ application }) {
const packageJsonStorage = this.createStorage('package.json');
const packageJsonStorage = this.createStorage(this.destinationPath(application.clientRootDir, 'package.json'));
const scriptsStorage = packageJsonStorage.createStorage('scripts');

const packageJsonConfigStorage = packageJsonStorage.createStorage('config').createProxy();
Expand Down
5 changes: 3 additions & 2 deletions generators/client/support/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export const loadClientConfig = ({ config, application }: { config: any; applica
(application as any).clientThemeVariant = config.clientThemeVariant;
(application as any).devServerPort = config.devServerPort;

(application as any).clientSrcDir = config.clientSrcDir ?? CLIENT_MAIN_SRC_DIR;
(application as any).clientTestDir = config.clientTestDir ?? CLIENT_TEST_SRC_DIR;
(application as any).clientRootDir = config.clientRootDir ?? '';
(application as any).clientSrcDir = config.clientSrcDir ?? `${application.clientRootDir}${CLIENT_MAIN_SRC_DIR}`;
(application as any).clientTestDir = config.clientTestDir ?? `${application.clientRootDir}${CLIENT_TEST_SRC_DIR}`;
};

/**
Expand Down
Loading