Skip to content

Commit

Permalink
add clientRootDir
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 25, 2023
1 parent f1ebd8c commit 9cf46b9
Show file tree
Hide file tree
Showing 30 changed files with 3,023 additions and 3,050 deletions.
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
2 changes: 1 addition & 1 deletion generators/angular/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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
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
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
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
6 changes: 1 addition & 5 deletions generators/client/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ 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;

Expand Down Expand Up @@ -235,7 +231,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
73 changes: 47 additions & 26 deletions generators/client/support/files.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { WriteFileBlock } from '../../base/api.mjs';
import type CoreGenerator from '../../base-core/index.mjs';
import { CLIENT_MAIN_SRC_DIR, CLIENT_TEST_SRC_DIR } from '../../generator-constants.mjs';

export const replaceEntityFilePath = (data: any, filepath: string) =>
Expand All @@ -7,52 +8,72 @@ export const replaceEntityFilePath = (data: any, filepath: string) =>
.replace(/_entityFile_/, data.entityFileName)
.replace(/_entityModel_/, data.entityModelFileName);

const srcRenameTo = (relativePath: string) => (data: any, filepath: string) =>
`${data.clientSrcDir}${relativePath}${replaceEntityFilePath(data, filepath)}`;

const appRenameTo = (relativePath: string) => (data: any, filepath: string) =>
`${data.clientSrcDir}app/${relativePath}${replaceEntityFilePath(data, filepath)}`;

const testRenameTo = (relativePath: string) => (data: any, filepath: string) =>
`${data.clientTestDir}${relativePath}${replaceEntityFilePath(data, filepath)}`;

const CLIENT_TEMPLATES_SRC_DIR = CLIENT_MAIN_SRC_DIR;
const CLIENT_TEMPLATES_APP_DIR = `${CLIENT_MAIN_SRC_DIR}app/`;

type RelativeWriteFileBlock = WriteFileBlock & { relativePath?: string };

export function clientRootTemplatesBlock(blockOrRelativePath?: string): Pick<WriteFileBlock, 'path' | 'renameTo'>;
export function clientRootTemplatesBlock(blockOrRelativePath: RelativeWriteFileBlock): WriteFileBlock;
export function clientRootTemplatesBlock(blockOrRelativePath: string | RelativeWriteFileBlock = ''): Partial<WriteFileBlock> {
return clientBlock({
srcPath: '',
destProperty: 'clientRootDir',
blockOrRelativePath,
});
}

export function clientSrcTemplatesBlock(blockOrRelativePath?: string): Pick<WriteFileBlock, 'path' | 'renameTo'>;
export function clientSrcTemplatesBlock(blockOrRelativePath: RelativeWriteFileBlock): WriteFileBlock;
export function clientSrcTemplatesBlock(blockOrRelativePath: string | RelativeWriteFileBlock = ''): Partial<WriteFileBlock> {
const block: RelativeWriteFileBlock | undefined = typeof blockOrRelativePath !== 'string' ? blockOrRelativePath : undefined;
const relativePath: string = typeof blockOrRelativePath === 'string' ? blockOrRelativePath : blockOrRelativePath.relativePath ?? '';
return {
path: `${CLIENT_TEMPLATES_SRC_DIR}${relativePath}`,
renameTo: srcRenameTo(relativePath),
...block,
};
return clientBlock({
srcPath: CLIENT_TEMPLATES_SRC_DIR,
destProperty: 'clientSrcDir',
blockOrRelativePath,
});
}

export function clientApplicationTemplatesBlock(blockOrRelativePath?: string): Pick<WriteFileBlock, 'path' | 'renameTo'>;
export function clientApplicationTemplatesBlock(blockOrRelativePath: RelativeWriteFileBlock): WriteFileBlock;
export function clientApplicationTemplatesBlock(blockOrRelativePath: string | RelativeWriteFileBlock = ''): Partial<WriteFileBlock> {
const block: RelativeWriteFileBlock | undefined = typeof blockOrRelativePath !== 'string' ? blockOrRelativePath : undefined;
const relativePath: string = typeof blockOrRelativePath === 'string' ? blockOrRelativePath : blockOrRelativePath.relativePath ?? '';
return {
path: `${CLIENT_TEMPLATES_APP_DIR}${relativePath}`,
renameTo: appRenameTo(relativePath),
...block,
};
return clientBlock({
srcPath: CLIENT_TEMPLATES_SRC_DIR,
relativeToSrc: 'app/',
destProperty: 'clientSrcDir',
blockOrRelativePath,
});
}

export function clientTestTemplatesBlock(blockOrRelativePath?: string): Pick<WriteFileBlock, 'path' | 'renameTo'>;
export function clientTestTemplatesBlock(blockOrRelativePath: RelativeWriteFileBlock): WriteFileBlock;
export function clientTestTemplatesBlock(blockOrRelativePath: string | RelativeWriteFileBlock = ''): Partial<WriteFileBlock> {
return clientBlock({
srcPath: CLIENT_TEST_SRC_DIR,
destProperty: 'clientTestDir',
blockOrRelativePath,
});
}

function clientBlock({
srcPath,
destProperty,
blockOrRelativePath = '',
relativeToSrc = '',
}: {
srcPath: string;
destProperty: string;
blockOrRelativePath: string | RelativeWriteFileBlock;
relativeToSrc?: string;
}): WriteFileBlock | Pick<WriteFileBlock, 'path' | 'renameTo'> {
const block: RelativeWriteFileBlock | undefined = typeof blockOrRelativePath !== 'string' ? blockOrRelativePath : undefined;
const blockRenameTo = typeof block?.renameTo === 'function' ? block.renameTo : undefined;
const relativePath: string = typeof blockOrRelativePath === 'string' ? blockOrRelativePath : blockOrRelativePath.relativePath ?? '';
return {
path: `${CLIENT_TEST_SRC_DIR}${relativePath}`,
renameTo: testRenameTo(relativePath),
path: `${srcPath}${relativeToSrc}${relativePath}`,
...block,
renameTo(this: CoreGenerator, data: any, filePath: string) {
return `${data[destProperty]}${relativeToSrc}${replaceEntityFilePath(data, relativePath) ?? ''}${
replaceEntityFilePath(data, blockRenameTo?.call?.(this, data, filePath) ?? filePath) ?? ''
}`;
},
};
}
7 changes: 4 additions & 3 deletions generators/common/__snapshots__/generator.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,13 @@ To configure CI for your project, run the ci-cd sub-generator (\`jhipster ci-cd\
},
"package.json": {
"contents": "{
"scripts": {
"prepare": "husky install"
},
"devDependencies": {
"generator-jhipster": "<%= jhipsterVersion %>",
"husky": "HUSKY_VERSION",
"lint-staged": "LINT_STAGED_VERSION"
},
"scripts": {
"prepare": "husky install"
}
}
",
Expand Down
10 changes: 10 additions & 0 deletions generators/common/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ export default class CommonGenerator extends BaseApplicationGenerator {

get postWriting() {
return this.asPostWritingTaskGroup({
addJHipsterDependencies({ application }) {
if (application.skipJhipsterDependencies) return;

this.packageJson.merge({
devDependencies: {
'generator-jhipster': '<%= jhipsterVersion %>',
...Object.fromEntries(application.blueprints.map(blueprint => [blueprint.name, blueprint.version])),
},
});
},
async formatSonarProperties() {
this.queueTransformStream(await createPrettierTransform.call(this, { extensions: 'properties', prettierProperties: true }), {
name: 'prettifying sonar-project.properties',
Expand Down
4 changes: 4 additions & 0 deletions generators/common/generator.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ describe(`generator - ${generator}`, () => {
it('should succeed', () => {
expect(runResult.getSnapshot()).toMatchSnapshot();
});

it('should add generator-jhipster to package.json', () => {
runResult.assertFileContent('package.json', 'generator-jhipster');
});
});
describe('Custom prettier', () => {
before(async () => {
Expand Down
Loading

0 comments on commit 9cf46b9

Please sign in to comment.