From 3cbfeaebe3597377fd11073f6711a16c53ff963f Mon Sep 17 00:00:00 2001 From: Charlie Mordant Date: Wed, 30 Jul 2025 21:19:50 +0200 Subject: [PATCH 1/3] simplify git options and config --- generators/base-application/types.d.ts | 1 - generators/base-core/types.d.ts | 1 - generators/git/generator.ts | 65 ++++++++++------------- generators/git/types.d.ts | 8 ++- generators/jdl/types.d.ts | 3 +- generators/workspaces/generator.ts | 6 +-- generators/workspaces/types.d.ts | 5 +- lib/types/application-config-all.d.ts | 1 - lib/types/application-options-all.d.ts | 1 - lib/types/application-properties-all.d.ts | 1 - 10 files changed, 43 insertions(+), 49 deletions(-) diff --git a/generators/base-application/types.d.ts b/generators/base-application/types.d.ts index dbc691ecb28b..24add83376fa 100644 --- a/generators/base-application/types.d.ts +++ b/generators/base-application/types.d.ts @@ -412,7 +412,6 @@ export type Application = BaseSimpleApplicationApplication & skipClient?: boolean; skipServer?: boolean; - monorepository?: boolean; blueprints?: { name: string; version: string }[]; testFrameworks?: string[]; diff --git a/generators/base-core/types.d.ts b/generators/base-core/types.d.ts index fbde37d9d1cf..5672a2d6c2ec 100644 --- a/generators/base-core/types.d.ts +++ b/generators/base-core/types.d.ts @@ -60,7 +60,6 @@ export type Options = YeomanOptions & { generateApplications?: boolean | (() => Promise); generateWorkspaces?: boolean; generateWith?: string; - monorepository?: boolean; workspaces?: boolean; workspacesFolders?: string[]; }; diff --git a/generators/git/generator.ts b/generators/git/generator.ts index 189c3370fc96..1c0310356027 100644 --- a/generators/git/generator.ts +++ b/generators/git/generator.ts @@ -26,10 +26,7 @@ import type { Config as GitConfig, Options as GitOptions } from './types.js'; export default class GitGenerator extends BaseGenerator { gitInitialized!: boolean; - skipGit!: boolean; - forceGit!: boolean; existingRepository!: boolean; - commitMsg!: string; async beforeQueue() { if (!this.fromBlueprint) { @@ -37,22 +34,36 @@ export default class GitGenerator extends BaseGenerator { } } + async initializeGitRepository() { + try { + const git = this.createGit(); + if (await git.checkIsRepo()) { + if (await git.checkIsRepo('root' as any)) { + this.log.info('Using existing git repository.'); + } else { + this.log.info('Using existing git repository at parent folder.'); + } + this.existingRepository = true; + } else if (await git.init()) { + this.log.ok('Git repository initialized.'); + } + this.gitInitialized = true; + } catch (error) { + this.log.warn(`Failed to initialize Git repository.\n ${error}`); + } + } + get initializing() { return this.asInitializingTaskGroup({ async checkGit() { - if (!this.skipGit) { + if (!this.options.skipGit) { const gitInstalled = (await this.createGit().version()).installed; if (!gitInstalled) { this.log.warn('Git repository will not be created, as Git is not installed on your system'); - this.skipGit = true; + this.options.skipGit = true; } } }, - async initializeMonorepository() { - if (!this.skipGit && this.jhipsterConfig.monorepository) { - await this.initializeGitRepository(); - } - }, }); } @@ -63,7 +74,7 @@ export default class GitGenerator extends BaseGenerator { get preparing() { return this.asPreparingTaskGroup({ async preparing() { - if (!this.skipGit) { + if (!this.options.skipGit) { // Force write .yo-rc.json to disk, it's used to check if the application is regenerated this.jhipsterConfig.monorepository ??= undefined; } @@ -91,7 +102,7 @@ export default class GitGenerator extends BaseGenerator { return this.asPostWritingTaskGroup({ /** Husky commit hook install at install priority requires git to be initialized */ async initGitRepo() { - if (!this.skipGit && !this.jhipsterConfig.monorepository) { + if (!this.options.skipGit && !this.jhipsterConfig.monorepository) { await this.initializeGitRepository(); } }, @@ -106,25 +117,26 @@ export default class GitGenerator extends BaseGenerator { return this.asEndTaskGroup({ /** Initial commit to git repository after package manager install for package-lock.json */ async gitCommit() { - if (this.skipGit) return; + if (this.options.skipGit) return; if (!this.gitInitialized) { this.log.warn('The generated application could not be committed to Git, as a Git repository could not be initialized.'); return; } const commitFiles = async () => { - this.debug('Committing files to git'); + this.log.debug('Committing files to git'); const git = this.createGit(); const repositoryRoot = await git.revparse(['--show-toplevel']); + const msg = await git.log(['-n', '1']).catch(() => ({ total: 0 })); const result = await git.log(['-n', '1', '--', '.yo-rc.json']).catch(() => ({ total: 0 })); const existingApplication = result.total > 0; - if (existingApplication && !this.forceGit) { + if (existingApplication && !this.options.forceGit) { this.log.info( `Found .yo-rc.json in Git from ${repositoryRoot}. So we assume this is application regeneration. Therefore automatic Git commit is not done. You can do Git commit manually.`, ); return; } - if (!this.forceGit) { + if (!this.options.forceGit) { const statusResult = await git.status(); if (statusResult.staged.length > 0) { this.log.verboseInfo(`The repository ${repositoryRoot} has staged files, skipping commit.`); @@ -133,7 +145,7 @@ export default class GitGenerator extends BaseGenerator { } try { let commitMsg = - this.commitMsg ?? + this.options.commitMsg ?? (existingApplication ? `Regenerated ${this.jhipsterConfig.baseName} using generator-jhipster@${this.jhipsterConfig.jhipsterVersion}` : `Initial version of ${this.jhipsterConfig.baseName} generated by generator-jhipster@${this.jhipsterConfig.jhipsterVersion}`); @@ -163,23 +175,4 @@ export default class GitGenerator extends BaseGenerator { get [BaseGenerator.END]() { return this.delegateTasksToBlueprint(() => this.end); } - - async initializeGitRepository() { - try { - const git = this.createGit(); - if (await git.checkIsRepo()) { - if (await git.checkIsRepo('root' as any)) { - this.log.info('Using existing git repository.'); - } else { - this.log.info('Using existing git repository at parent folder.'); - } - this.existingRepository = true; - } else if (await git.init()) { - this.log.ok('Git repository initialized.'); - } - this.gitInitialized = true; - } catch (error) { - this.log.warn(`Failed to initialize Git repository.\n ${error}`); - } - } } diff --git a/generators/git/types.d.ts b/generators/git/types.d.ts index c11ca9c4d1da..70be2f21510c 100644 --- a/generators/git/types.d.ts +++ b/generators/git/types.d.ts @@ -16,7 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { HandleCommandTypes } from '../../lib/command/types.js'; +import type { Simplify } from 'type-fest'; +import type { ExportGeneratorOptionsFromCommand, HandleCommandTypes } from '../../lib/command/types.js'; import type { Config as ProjectNameConfig, Options as ProjectNameOptions, Source as ProjectNameSource } from '../project-name/types.js'; import type { Application as BaseApplicationApplication, Entity as BaseApplicationEntity } from '../base-application/types.js'; import type command from './command.ts'; @@ -25,7 +26,10 @@ type Command = HandleCommandTypes; export type Config = Command['Config'] & ProjectNameConfig; -export type Options = Command['Options'] & ProjectNameOptions; +export type Options = Command['Options'] & + ProjectNameOptions & + // eslint-disable-next-line @typescript-eslint/consistent-type-imports + Simplify>; export { ProjectNameSource as Source, BaseApplicationEntity as Entity }; diff --git a/generators/jdl/types.d.ts b/generators/jdl/types.d.ts index 0a20ac4a83f6..ac7ebd397524 100644 --- a/generators/jdl/types.d.ts +++ b/generators/jdl/types.d.ts @@ -1,6 +1,7 @@ import type { HandleCommandTypes } from '../../lib/command/types.js'; import type { ApplicationType } from '../../lib/core/application-types.ts'; import type { Config as BaseConfig, Options as BaseOptions } from '../base/types.js'; +import type { Options as GitOptions } from '../git/types.js'; import type command from './command.js'; type Command = HandleCommandTypes; @@ -13,4 +14,4 @@ type JdlOptions = { export type Config = BaseConfig & JdlOptions & Command['Config']; -export type Options = BaseOptions & JdlOptions & Command['Options']; +export type Options = BaseOptions & JdlOptions & Command['Options'] & GitOptions; diff --git a/generators/workspaces/generator.ts b/generators/workspaces/generator.ts index dd2c202d8a31..748878a37512 100644 --- a/generators/workspaces/generator.ts +++ b/generators/workspaces/generator.ts @@ -56,7 +56,7 @@ export default class WorkspacesGenerator extends BaseWorkspacesGenerator & ExportStoragePropertiesFromCommand & - ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & diff --git a/lib/types/application-options-all.d.ts b/lib/types/application-options-all.d.ts index da3239d967af..ba750d9686bf 100644 --- a/lib/types/application-options-all.d.ts +++ b/lib/types/application-options-all.d.ts @@ -15,7 +15,6 @@ export type OptionsAll = Simplify< ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & - ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & diff --git a/lib/types/application-properties-all.d.ts b/lib/types/application-properties-all.d.ts index d28d2f6b36c1..c69a36cd8aee 100644 --- a/lib/types/application-properties-all.d.ts +++ b/lib/types/application-properties-all.d.ts @@ -29,6 +29,5 @@ export type ApplicationAll = BaseApplication ClientApplication & DockerApplication & LiqbuibaseApplication & - ExportApplicationPropertiesFromCommand & ExportApplicationPropertiesFromCommand & ExportApplicationPropertiesFromCommand; From ded47f938ae8c6a056d5e41f160d15a073d89ba7 Mon Sep 17 00:00:00 2001 From: Charlie Mordant Date: Thu, 31 Jul 2025 20:02:42 +0200 Subject: [PATCH 2/3] use config in monorepository for git generator --- generators/git/generator.ts | 41 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/generators/git/generator.ts b/generators/git/generator.ts index 1c0310356027..d004a3f4259b 100644 --- a/generators/git/generator.ts +++ b/generators/git/generator.ts @@ -34,25 +34,6 @@ export default class GitGenerator extends BaseGenerator { } } - async initializeGitRepository() { - try { - const git = this.createGit(); - if (await git.checkIsRepo()) { - if (await git.checkIsRepo('root' as any)) { - this.log.info('Using existing git repository.'); - } else { - this.log.info('Using existing git repository at parent folder.'); - } - this.existingRepository = true; - } else if (await git.init()) { - this.log.ok('Git repository initialized.'); - } - this.gitInitialized = true; - } catch (error) { - this.log.warn(`Failed to initialize Git repository.\n ${error}`); - } - } - get initializing() { return this.asInitializingTaskGroup({ async checkGit() { @@ -60,7 +41,7 @@ export default class GitGenerator extends BaseGenerator { const gitInstalled = (await this.createGit().version()).installed; if (!gitInstalled) { this.log.warn('Git repository will not be created, as Git is not installed on your system'); - this.options.skipGit = true; + this.gitInitialized = false; } } }, @@ -127,7 +108,6 @@ export default class GitGenerator extends BaseGenerator { this.log.debug('Committing files to git'); const git = this.createGit(); const repositoryRoot = await git.revparse(['--show-toplevel']); - const msg = await git.log(['-n', '1']).catch(() => ({ total: 0 })); const result = await git.log(['-n', '1', '--', '.yo-rc.json']).catch(() => ({ total: 0 })); const existingApplication = result.total > 0; if (existingApplication && !this.options.forceGit) { @@ -175,4 +155,23 @@ export default class GitGenerator extends BaseGenerator { get [BaseGenerator.END]() { return this.delegateTasksToBlueprint(() => this.end); } + + async initializeGitRepository() { + try { + const git = this.createGit(); + if (await git.checkIsRepo()) { + if (await git.checkIsRepo('root' as any)) { + this.log.info('Using existing git repository.'); + } else { + this.log.info('Using existing git repository at parent folder.'); + } + this.existingRepository = true; + } else if (await git.init()) { + this.log.ok('Git repository initialized.'); + } + this.gitInitialized = true; + } catch (error) { + this.log.warn(`Failed to initialize Git repository.\n ${error}`); + } + } } From 38762e44b15058b7e9d4c61784a7d326d0a82297 Mon Sep 17 00:00:00 2001 From: Charlie Mordant Date: Thu, 31 Jul 2025 20:57:39 +0200 Subject: [PATCH 3/3] adapt types inheritance --- generators/git/types.d.ts | 9 ++++++--- generators/jdl/types.d.ts | 4 ++-- generators/workspaces/generator.ts | 2 +- generators/workspaces/types.d.ts | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/generators/git/types.d.ts b/generators/git/types.d.ts index 70be2f21510c..c288d0fea7fc 100644 --- a/generators/git/types.d.ts +++ b/generators/git/types.d.ts @@ -17,19 +17,22 @@ * limitations under the License. */ import type { Simplify } from 'type-fest'; -import type { ExportGeneratorOptionsFromCommand, HandleCommandTypes } from '../../lib/command/types.js'; +import type { ExportGeneratorOptionsFromCommand, ExportStoragePropertiesFromCommand, HandleCommandTypes } from '../../lib/command/types.js'; import type { Config as ProjectNameConfig, Options as ProjectNameOptions, Source as ProjectNameSource } from '../project-name/types.js'; import type { Application as BaseApplicationApplication, Entity as BaseApplicationEntity } from '../base-application/types.js'; import type command from './command.ts'; type Command = HandleCommandTypes; -export type Config = Command['Config'] & ProjectNameConfig; +export type Config = Command['Config'] & + ProjectNameConfig & + // eslint-disable-next-line @typescript-eslint/consistent-type-imports + Simplify>; export type Options = Command['Options'] & ProjectNameOptions & // eslint-disable-next-line @typescript-eslint/consistent-type-imports - Simplify>; + Simplify>; export { ProjectNameSource as Source, BaseApplicationEntity as Entity }; diff --git a/generators/jdl/types.d.ts b/generators/jdl/types.d.ts index ac7ebd397524..7eb70d21b43d 100644 --- a/generators/jdl/types.d.ts +++ b/generators/jdl/types.d.ts @@ -1,7 +1,7 @@ import type { HandleCommandTypes } from '../../lib/command/types.js'; import type { ApplicationType } from '../../lib/core/application-types.ts'; import type { Config as BaseConfig, Options as BaseOptions } from '../base/types.js'; -import type { Options as GitOptions } from '../git/types.js'; +import type { Options as WorkspaceOptions } from '../workspaces/types.js'; import type command from './command.js'; type Command = HandleCommandTypes; @@ -14,4 +14,4 @@ type JdlOptions = { export type Config = BaseConfig & JdlOptions & Command['Config']; -export type Options = BaseOptions & JdlOptions & Command['Options'] & GitOptions; +export type Options = BaseOptions & JdlOptions & Command['Options'] & WorkspaceOptions; diff --git a/generators/workspaces/generator.ts b/generators/workspaces/generator.ts index 748878a37512..9fc89dedc92d 100644 --- a/generators/workspaces/generator.ts +++ b/generators/workspaces/generator.ts @@ -92,7 +92,7 @@ export default class WorkspacesGenerator extends BaseWorkspacesGenerator; export type Options = BaseWorkspacesOptions & GitOptions;