Skip to content

Commit 3431eeb

Browse files
committed
simplify git options and config
1 parent b5b4086 commit 3431eeb

File tree

10 files changed

+43
-49
lines changed

10 files changed

+43
-49
lines changed

generators/base-application/types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ export type Application<E extends Entity> = BaseSimpleApplicationApplication &
412412

413413
skipClient?: boolean;
414414
skipServer?: boolean;
415-
monorepository?: boolean;
416415

417416
blueprints?: { name: string; version: string }[];
418417
testFrameworks?: string[];

generators/base-core/types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export type Options = YeomanOptions & {
6060
generateApplications?: boolean | (() => Promise<void>);
6161
generateWorkspaces?: boolean;
6262
generateWith?: string;
63-
monorepository?: boolean;
6463
workspaces?: boolean;
6564
workspacesFolders?: string[];
6665
};

generators/git/generator.ts

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,44 @@ import type { Config as GitConfig, Options as GitOptions } from './types.js';
2626

2727
export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
2828
gitInitialized!: boolean;
29-
skipGit!: boolean;
30-
forceGit!: boolean;
3129
existingRepository!: boolean;
32-
commitMsg!: string;
3330

3431
async beforeQueue() {
3532
if (!this.fromBlueprint) {
3633
await this.composeWithBlueprints();
3734
}
3835
}
3936

37+
async initializeGitRepository() {
38+
try {
39+
const git = this.createGit();
40+
if (await git.checkIsRepo()) {
41+
if (await git.checkIsRepo('root' as any)) {
42+
this.log.info('Using existing git repository.');
43+
} else {
44+
this.log.info('Using existing git repository at parent folder.');
45+
}
46+
this.existingRepository = true;
47+
} else if (await git.init()) {
48+
this.log.ok('Git repository initialized.');
49+
}
50+
this.gitInitialized = true;
51+
} catch (error) {
52+
this.log.warn(`Failed to initialize Git repository.\n ${error}`);
53+
}
54+
}
55+
4056
get initializing() {
4157
return this.asInitializingTaskGroup({
4258
async checkGit() {
43-
if (!this.skipGit) {
59+
if (!this.options.skipGit) {
4460
const gitInstalled = (await this.createGit().version()).installed;
4561
if (!gitInstalled) {
4662
this.log.warn('Git repository will not be created, as Git is not installed on your system');
47-
this.skipGit = true;
63+
this.options.skipGit = true;
4864
}
4965
}
5066
},
51-
async initializeMonorepository() {
52-
if (!this.skipGit && this.jhipsterConfig.monorepository) {
53-
await this.initializeGitRepository();
54-
}
55-
},
5667
});
5768
}
5869

@@ -63,7 +74,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
6374
get preparing() {
6475
return this.asPreparingTaskGroup({
6576
async preparing() {
66-
if (!this.skipGit) {
77+
if (!this.options.skipGit) {
6778
// Force write .yo-rc.json to disk, it's used to check if the application is regenerated
6879
this.jhipsterConfig.monorepository ??= undefined;
6980
}
@@ -91,7 +102,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
91102
return this.asPostWritingTaskGroup({
92103
/** Husky commit hook install at install priority requires git to be initialized */
93104
async initGitRepo() {
94-
if (!this.skipGit && !this.jhipsterConfig.monorepository) {
105+
if (!this.options.skipGit && !this.jhipsterConfig.monorepository) {
95106
await this.initializeGitRepository();
96107
}
97108
},
@@ -106,25 +117,26 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
106117
return this.asEndTaskGroup({
107118
/** Initial commit to git repository after package manager install for package-lock.json */
108119
async gitCommit() {
109-
if (this.skipGit) return;
120+
if (this.options.skipGit) return;
110121
if (!this.gitInitialized) {
111122
this.log.warn('The generated application could not be committed to Git, as a Git repository could not be initialized.');
112123
return;
113124
}
114125

115126
const commitFiles = async () => {
116-
this.debug('Committing files to git');
127+
this.log.debug('Committing files to git');
117128
const git = this.createGit();
118129
const repositoryRoot = await git.revparse(['--show-toplevel']);
130+
const msg = await git.log(['-n', '1']).catch(() => ({ total: 0 }));
119131
const result = await git.log(['-n', '1', '--', '.yo-rc.json']).catch(() => ({ total: 0 }));
120132
const existingApplication = result.total > 0;
121-
if (existingApplication && !this.forceGit) {
133+
if (existingApplication && !this.options.forceGit) {
122134
this.log.info(
123135
`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.`,
124136
);
125137
return;
126138
}
127-
if (!this.forceGit) {
139+
if (!this.options.forceGit) {
128140
const statusResult = await git.status();
129141
if (statusResult.staged.length > 0) {
130142
this.log.verboseInfo(`The repository ${repositoryRoot} has staged files, skipping commit.`);
@@ -133,7 +145,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
133145
}
134146
try {
135147
let commitMsg =
136-
this.commitMsg ??
148+
this.options.commitMsg ??
137149
(existingApplication
138150
? `Regenerated ${this.jhipsterConfig.baseName} using generator-jhipster@${this.jhipsterConfig.jhipsterVersion}`
139151
: `Initial version of ${this.jhipsterConfig.baseName} generated by generator-jhipster@${this.jhipsterConfig.jhipsterVersion}`);
@@ -163,23 +175,4 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
163175
get [BaseGenerator.END]() {
164176
return this.delegateTasksToBlueprint(() => this.end);
165177
}
166-
167-
async initializeGitRepository() {
168-
try {
169-
const git = this.createGit();
170-
if (await git.checkIsRepo()) {
171-
if (await git.checkIsRepo('root' as any)) {
172-
this.log.info('Using existing git repository.');
173-
} else {
174-
this.log.info('Using existing git repository at parent folder.');
175-
}
176-
this.existingRepository = true;
177-
} else if (await git.init()) {
178-
this.log.ok('Git repository initialized.');
179-
}
180-
this.gitInitialized = true;
181-
} catch (error) {
182-
this.log.warn(`Failed to initialize Git repository.\n ${error}`);
183-
}
184-
}
185178
}

generators/git/types.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
import type { HandleCommandTypes } from '../../lib/command/types.js';
19+
import type { Simplify } from 'type-fest';
20+
import type { ExportGeneratorOptionsFromCommand, HandleCommandTypes } from '../../lib/command/types.js';
2021
import type { Config as ProjectNameConfig, Options as ProjectNameOptions, Source as ProjectNameSource } from '../project-name/types.js';
2122
import type { Application as BaseApplicationApplication, Entity as BaseApplicationEntity } from '../base-application/types.js';
2223
import type command from './command.ts';
@@ -25,7 +26,10 @@ type Command = HandleCommandTypes<typeof command>;
2526

2627
export type Config = Command['Config'] & ProjectNameConfig;
2728

28-
export type Options = Command['Options'] & ProjectNameOptions;
29+
export type Options = Command['Options'] &
30+
ProjectNameOptions &
31+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
32+
Simplify<ExportGeneratorOptionsFromCommand<typeof import('../../generators/git/command.ts').default>>;
2933

3034
export { ProjectNameSource as Source, BaseApplicationEntity as Entity };
3135

generators/jdl/types.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { HandleCommandTypes } from '../../lib/command/types.js';
22
import type { ApplicationType } from '../../lib/core/application-types.ts';
33
import type { Config as BaseConfig, Options as BaseOptions } from '../base/types.js';
4+
import type { Options as GitOptions } from '../git/types.js';
45
import type command from './command.js';
56

67
type Command = HandleCommandTypes<typeof command>;
@@ -13,4 +14,4 @@ type JdlOptions = {
1314

1415
export type Config = BaseConfig & JdlOptions & Command['Config'];
1516

16-
export type Options = BaseOptions & JdlOptions & Command['Options'];
17+
export type Options = BaseOptions & JdlOptions & Command['Options'] & GitOptions;

generators/workspaces/generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class WorkspacesGenerator extends BaseWorkspacesGenerator<any, Wo
5656
return this.asInitializingTaskGroup({
5757
loadConfig() {
5858
// Generate workspaces file if workspace option is passed, or if workspace option is ommitted and monorepository is enabled, or if regenerating.
59-
this.generateWorkspaces = (this.workspaces ?? this.jhipsterConfig.monorepository) || Boolean(this.packageJson?.get('workspaces'));
59+
this.generateWorkspaces = (this.workspaces ?? this.options.monorepository) || Boolean(this.packageJson?.get('workspaces'));
6060

6161
// When generating workspaces, save to .yo-rc.json. Use a dummy config otherwise.
6262
this.workspacesConfig = this.generateWorkspaces ? this.jhipsterConfig : {};
@@ -92,7 +92,7 @@ export default class WorkspacesGenerator extends BaseWorkspacesGenerator<any, Wo
9292
get composing() {
9393
return this.asComposingTaskGroup({
9494
async composeGit() {
95-
if (this.options.monorepository || this.jhipsterConfig.monorepository) {
95+
if (this.options.monorepository) {
9696
await this.composeWithJHipster(GENERATOR_GIT);
9797
await this.composeWithJHipster('jhipster:javascript:prettier', { generatorOptions: { monorepositoryRoot: true } });
9898
}
@@ -122,7 +122,7 @@ export default class WorkspacesGenerator extends BaseWorkspacesGenerator<any, Wo
122122
get loading() {
123123
return this.asLoadingTaskGroup({
124124
checkWorkspaces() {
125-
if (this.generateWorkspaces && !this.jhipsterConfig.monorepository) {
125+
if (this.generateWorkspaces && !this.options.monorepository) {
126126
throw new Error('Workspaces option is only supported with monorepositories.');
127127
}
128128
},

generators/workspaces/types.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* limitations under the License.
1818
*/
1919
import type { Config as BaseWorkspacesConfig, Options as BaseWorkspacesOptions } from '../base-workspaces/types.d.ts';
20+
import type { Options as GitOptions } from '../git/types.d.ts';
2021
export type { WorkspacesApplication } from '../base-workspaces/types.js';
2122

22-
export type Config = BaseWorkspacesConfig & { baseName: string; monorepository: boolean };
23-
export type Options = BaseWorkspacesOptions & { monorepository: boolean };
23+
export type Config = BaseWorkspacesConfig & { baseName: string };
24+
export type Options = BaseWorkspacesOptions & GitOptions;

lib/types/application-config-all.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export type ConfigAll = Simplify<
2222
microfrontends?: { baseName: string }[];
2323
} & ExportStoragePropertiesFromCommand<typeof import('../../generators/app/command.ts').default> &
2424
ExportStoragePropertiesFromCommand<typeof import('../../generators/bootstrap-application-base/command.ts').default> &
25-
ExportStoragePropertiesFromCommand<typeof import('../../generators/git/command.ts').default> &
2625
ExportStoragePropertiesFromCommand<typeof import('../../generators/jdl/command.ts').default> &
2726
ExportStoragePropertiesFromCommand<typeof import('../../generators/languages/command.ts').default> &
2827
ExportStoragePropertiesFromCommand<typeof import('../../generators/liquibase/command.ts').default> &

lib/types/application-options-all.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export type OptionsAll = Simplify<
1515
ExportGeneratorOptionsFromCommand<typeof import('../../generators/base/command.ts').default> &
1616
ExportGeneratorOptionsFromCommand<typeof import('../../generators/bootstrap-application-base/command.ts').default> &
1717
ExportGeneratorOptionsFromCommand<typeof import('../../generators/client/command.ts').default> &
18-
ExportGeneratorOptionsFromCommand<typeof import('../../generators/git/command.ts').default> &
1918
ExportGeneratorOptionsFromCommand<typeof import('../../generators/java/generators/bootstrap/command.ts').default> &
2019
ExportGeneratorOptionsFromCommand<typeof import('../../generators/java/generators/build-tool/command.ts').default> &
2120
ExportGeneratorOptionsFromCommand<typeof import('../../generators/java/generators/graalvm/command.ts').default> &

lib/types/application-properties-all.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ export type ApplicationAll<E extends EntityAll = EntityAll> = BaseApplication<E>
2929
ClientApplication<E> &
3030
DockerApplication &
3131
LiqbuibaseApplication<E> &
32-
ExportApplicationPropertiesFromCommand<typeof import('../../generators/git/command.ts').default> &
3332
ExportApplicationPropertiesFromCommand<typeof import('../../generators/project-name/command.ts').default> &
3433
ExportApplicationPropertiesFromCommand<typeof import('../../generators/spring-boot/command.ts').default>;

0 commit comments

Comments
 (0)