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

generate-blueprint: adjusts #27381

Merged
merged 6 commits into from
Sep 23, 2024
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
4 changes: 2 additions & 2 deletions .blueprint/generate-generator/templates/command.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
import type { JHipsterCommandDefinition } from '<%- generatorRelativePath %>base/api.js';

const command: JHipsterCommandDefinition = {
const command = {
configs: {},
import: [],
};
} as const satisfies JHipsterCommandDefinition;

export default command;
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default ts.config(
},
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/ban-ts-comment': ['off', { 'ts-nocheck': true }],
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-empty-function': 'off',
Expand Down
4 changes: 2 additions & 2 deletions generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ export default class AngularGenerator extends BaseApplicationGenerator {

get writing() {
return this.asWritingTaskGroup({
cleanup({ control }) {
control.cleanupFiles({
async cleanup({ control }) {
await control.cleanupFiles({
'8.6.1': ['.eslintrc.json', '.eslintignore'],
});
},
Expand Down
6 changes: 5 additions & 1 deletion generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti
!this.options.reproducibleTests &&
!this.jhipsterConfig.jhipsterVersion
) {
this.jhipsterConfig.jhipsterVersion = packageJson.version;
this.storeCurrentJHipsterVersion();
}
}

Expand Down Expand Up @@ -234,6 +234,10 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti
return super.usage().replace('yo jhipster:', 'jhipster ');
}

storeCurrentJHipsterVersion(): void {
this.jhipsterConfig.jhipsterVersion = packageJson.version;
}

/**
* @deprecated
*/
Expand Down
4 changes: 2 additions & 2 deletions generators/bootstrap/support/eslint-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export const createESLintTransform = function (
this?.log?.warn?.(errorMessage);
}
},
() => {
pool.destroy();
async () => {
await pool.destroy();
},
);
};
4 changes: 2 additions & 2 deletions generators/bootstrap/support/java-unused-imports-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const createRemoveUnusedImportsTransform = function (
}
}
},
() => {
pool.destroy();
async () => {
await pool.destroy();
},
);
};
4 changes: 2 additions & 2 deletions generators/bootstrap/support/prettier-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export const createPrettierTransform = async function (
this?.log?.warn?.(errorMessage);
}
},
() => {
pool?.destroy();
async () => {
await pool?.destroy();
},
);
};
4 changes: 2 additions & 2 deletions generators/common/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ export default class CommonGenerator extends BaseApplicationGenerator {
// Public API method used by the getter and also by Blueprints
get writing() {
return this.asWritingTaskGroup({
cleanup({ application, control }) {
control.cleanupFiles({
async cleanup({ application, control }) {
await control.cleanupFiles({
'7.1.1': [[!application.skipCommitHook, '.huskyrc']],
'7.6.1': [[application.skipClient, 'npmw', 'npmw.cmd']],
'8.0.0-rc.2': [[!application.skipCommitHook, '.lintstagedrc.js']],
Expand Down
4 changes: 2 additions & 2 deletions generators/docker-compose/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ export default class DockerComposeGenerator extends BaseWorkspacesGenerator {

get loadingWorkspaces() {
return {
loadBaseDeployment({ deployment }) {
async loadBaseDeployment({ deployment }) {
deployment.jwtSecretKey = this.jhipsterConfig.jwtSecretKey;

loadDockerDependenciesTask.call(this, { context: deployment });
await loadDockerDependenciesTask.call(this, { context: deployment });
},
loadPlatformConfig({ deployment }) {
this.loadDeploymentConfig({ deployment });
Expand Down
4 changes: 2 additions & 2 deletions generators/generate-blueprint/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
SUB_GENERATORS,
} from './constants.js';

const command: JHipsterCommandDefinition = {
const command = {
configs: {
recreatePackageLock: {
description: 'Recreate package lock',
Expand Down Expand Up @@ -106,6 +106,6 @@ const command: JHipsterCommandDefinition = {
},
},
import: [GENERATOR_INIT],
};
} as const satisfies JHipsterCommandDefinition;

export default command;
20 changes: 19 additions & 1 deletion generators/generate-blueprint/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ export default class extends BaseGenerator {

get composing() {
return this.asComposingTaskGroup({
storeCurrentVersion() {
this.storeCurrentJHipsterVersion();
},
async compose() {
if (this.jhipsterConfig[LOCAL_BLUEPRINT_OPTION]) return;
const initGenerator = await this.composeWithJHipster(GENERATOR_INIT, { generatorOptions: { packageJsonType: 'module' } });
Expand Down Expand Up @@ -344,7 +347,7 @@ export default class extends BaseGenerator {

get postInstall() {
return this.asPostInstallTaskGroup({
async addSnapshot() {
async addSnapshot({ control }) {
const { [LOCAL_BLUEPRINT_OPTION]: localBlueprint } = this.jhipsterConfig;
const {
skipInstall,
Expand Down Expand Up @@ -377,6 +380,21 @@ This is a new blueprint, executing '${chalk.yellow('npm run update-snapshot')}'
}
this.log.warn('Fail to generate snapshots');
}

if (control.jhipsterOldVersion) {
// Apply prettier and eslint to fix non generated files on upgrade.
try {
await this.spawnCommand('npm', ['run', 'prettier-format']);
} catch {
// Ignore error
}

try {
await this.spawnCommand('npm', ['run', 'lint-fix']);
} catch {
// Ignore error
}
}
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions generators/java/generators/openapi-generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default class OpenapiGeneratorGenerator extends BaseApplicationGenerator

get writing() {
return this.asWritingTaskGroup({
cleanup({ application, control }) {
control.cleanupFiles({
async cleanup({ application, control }) {
await control.cleanupFiles({
'8.6.1': [[application.buildToolGradle!, 'gradle/swagger.gradle']],
});
},
Expand Down
4 changes: 2 additions & 2 deletions generators/javascript/generators/bootstrap/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import type { JHipsterCommandDefinition } from '../../../../lib/command/index.js';

const command: JHipsterCommandDefinition = {
const command = {
configs: {
packageJsonNodeEngine: {
cli: {
Expand All @@ -39,6 +39,6 @@ const command: JHipsterCommandDefinition = {
},
},
import: [],
};
} as const satisfies JHipsterCommandDefinition;

export default command;
8 changes: 6 additions & 2 deletions generators/javascript/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import type { ExportApplicationPropertiesFromCommand } from '../../lib/command/types.js';
import type JavascriptBootstrapCommand from './generators/bootstrap/command.ts';

type JavascriptBootstrapProperties = ExportApplicationPropertiesFromCommand<typeof JavascriptBootstrapCommand>;

export type JavaScriptSourceType = {
mergePrettierConfig?: (config: Record<string, unknown>) => void;
addPrettierIgnore?: (newContent: string) => void;
Expand All @@ -6,9 +11,8 @@ export type JavaScriptSourceType = {
addEslintConfig?: (opts: { import?: string | string[]; config?: string | string[] }) => void;
};

export type JavaScriptApplication = {
export type JavaScriptApplication = JavascriptBootstrapProperties & {
packageJsonNodeEngine?: boolean | string;
packageJsonType?: string;
eslintConfigFile?: string;

addPrettierExtensions?: (extensions: string[]) => void;
Expand Down
4 changes: 2 additions & 2 deletions generators/react/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ export default class ReactGenerator extends BaseApplicationGenerator {

get writing() {
return this.asWritingTaskGroup({
cleanup({ control }) {
control.cleanupFiles({
async cleanup({ control }) {
await control.cleanupFiles({
'8.6.1': ['.eslintrc.json', '.eslintignore'],
});
},
Expand Down
4 changes: 2 additions & 2 deletions generators/spring-boot/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import cleanupOauth2 from './cleanup-oauth2.js';
* Removes server files that where generated in previous JHipster versions and therefore
* need to be removed.
*/
export default asWritingTask(function cleanupTask(this, taskParam) {
export default asWritingTask(async function cleanupTask(this, taskParam) {
const { application, control } = taskParam;
if (application.authenticationTypeOauth2) {
cleanupOauth2.call(this, taskParam);
Expand Down Expand Up @@ -209,7 +209,7 @@ export default asWritingTask(function cleanupTask(this, taskParam) {
this.removeFile(`${application.javaPackageSrcDir}config/LocaleConfiguration.java`);
}

control.cleanupFiles({
await control.cleanupFiles({
'8.6.1': [[application.authenticationTypeOauth2!, `${application.javaPackageSrcDir}security/oauth2/JwtGrantedAuthorityConverter.java`]],
});
});
4 changes: 2 additions & 2 deletions generators/spring-cloud/generators/gateway/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default class GatewayGenerator extends BaseApplicationGenerator {

get writing() {
return this.asWritingTaskGroup({
cleanup({ control, application }) {
control.cleanupFiles({
async cleanup({ control, application }) {
await control.cleanupFiles({
'8.6.1': [
[
application.reactive && (application as any).serviceDiscoveryAny,
Expand Down
4 changes: 2 additions & 2 deletions generators/vue/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export default class VueGenerator extends BaseApplicationGenerator {

get writing() {
return this.asWritingTaskGroup({
cleanup({ control }) {
control.cleanupFiles({
async cleanup({ control }) {
await control.cleanupFiles({
'8.6.1': ['.eslintrc.json', '.eslintignore'],
});
},
Expand Down
1 change: 1 addition & 0 deletions lib/types/application/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type ApplicationOptions = Simplify<
ExportGeneratorOptionsFromCommand<typeof import('../../../generators/client/command.js').default> &
ExportGeneratorOptionsFromCommand<typeof import('../../../generators/java/generators/bootstrap/command.js').default> &
ExportGeneratorOptionsFromCommand<typeof import('../../../generators/java/generators/build-tool/command.js').default> &
ExportGeneratorOptionsFromCommand<typeof import('../../../generators/javascript/generators/bootstrap/command.js').default> &
ExportGeneratorOptionsFromCommand<typeof import('../../../generators/javascript/generators/prettier/command.js').default> &
ExportGeneratorOptionsFromCommand<typeof import('../../../generators/jdl/command.js').default> &
ExportGeneratorOptionsFromCommand<typeof import('../../../generators/languages/command.js').default> &
Expand Down
1 change: 1 addition & 0 deletions lib/types/application/yo-rc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type ApplicationConfiguration = Simplify<
ExportStoragePropertiesFromCommand<typeof import('../../../generators/client/command.js').default> &
ExportStoragePropertiesFromCommand<typeof import('../../../generators/java/generators/bootstrap/command.js').default> &
ExportStoragePropertiesFromCommand<typeof import('../../../generators/java/generators/build-tool/command.js').default> &
ExportStoragePropertiesFromCommand<typeof import('../../../generators/javascript/generators/bootstrap/command.js').default> &
ExportStoragePropertiesFromCommand<typeof import('../../../generators/javascript/generators/prettier/command.js').default> &
ExportStoragePropertiesFromCommand<typeof import('../../../generators/jdl/command.js').default> &
ExportStoragePropertiesFromCommand<typeof import('../../../generators/languages/command.js').default> &
Expand Down
Loading