Skip to content
Open
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
82 changes: 82 additions & 0 deletions generators/generate-blueprint/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,88 @@ describe(`generator - ${generator}`, () => {
});
});
});
describe('defaults option with selected sub-generator', () => {
before(async () => {
await helpers.runJHipster().withOptions({ defaults: true, subGenerators: ['app'] }).withMockedGenerators(mockedGenerators);
});
it('should compose with init generator', () => {
result.assertGeneratorComposedOnce('jhipster:init');
});
it('should write the selected generator without prompting for sub-generator answers', () => {
expect(result.getStateSnapshot()).toMatchInlineSnapshot(`
{
".blueprint/cli/commands.ts": {
"stateCleared": "modified",
},
".blueprint/generate-sample/command.ts": {
"stateCleared": "modified",
},
".blueprint/generate-sample/generator.ts": {
"stateCleared": "modified",
},
".blueprint/generate-sample/index.ts": {
"stateCleared": "modified",
},
".blueprint/generate-sample/templates/samples/sample.jdl": {
"stateCleared": "modified",
},
".github/workflows/generator.yml": {
"stateCleared": "modified",
},
".yo-rc.json": {
"stateCleared": "modified",
},
"README.md": {
"stateCleared": "modified",
},
"cli/cli-customizations.cts": {
"stateCleared": "modified",
},
"cli/cli.cts": {
"stateCleared": "modified",
},
"generators/app/command.ts": {
"stateCleared": "modified",
},
"generators/app/generator.spec.ts": {
"stateCleared": "modified",
},
"generators/app/generator.ts": {
"stateCleared": "modified",
},
"generators/app/index.ts": {
"stateCleared": "modified",
},
"generators/base-generator.ts": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
"tsconfig.json": {
"stateCleared": "modified",
},
"vitest.config.ts": {
"stateCleared": "modified",
},
"vitest.test-setup.ts": {
"stateCleared": "modified",
},
}
`);
});
it('should store default sub-generator config', () => {
result.assertJHipsterConfigContent({
generators: {
app: {
sbs: true,
command: false,
priorities: [],
},
},
});
});
});
describe('local-blueprint option', () => {
before(async () => {
await helpers.runJHipster().withOptions({ localBlueprint: true }).withMockedGenerators(mockedGenerators);
Expand Down
23 changes: 15 additions & 8 deletions generators/generate-blueprint/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ export default class extends GenerateBlueprintBaseGenerator {
super(args, options, { storeJHipsterVersion: true, ...features });
}

applySubGeneratorDefaults(subGenerator: string, allPriorities?: boolean) {
const subGeneratorStorage = this.getSubGeneratorStorage(subGenerator);
if (this.options.defaults) {
subGeneratorStorage.defaults({
...defaultSubGeneratorConfig(),
...(allPriorities ? { [PRIORITIES]: BASE_PRIORITY_NAMES_LIST } : {}),
});
} else if (allPriorities) {
subGeneratorStorage.defaults({ [PRIORITIES]: BASE_PRIORITY_NAMES_LIST });
}
return subGeneratorStorage;
}

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints();
Expand Down Expand Up @@ -90,10 +103,7 @@ export default class extends GenerateBlueprintBaseGenerator {
const { allPriorities } = this.options;
const subGenerators = (this.jhipsterConfig.subGenerators ?? []) as string[];
for (const subGenerator of subGenerators) {
const subGeneratorStorage = this.getSubGeneratorStorage(subGenerator);
if (allPriorities) {
subGeneratorStorage.defaults({ [PRIORITIES]: BASE_PRIORITY_NAMES_LIST });
}
const subGeneratorStorage = this.applySubGeneratorDefaults(subGenerator, allPriorities);
await this.prompt(subGeneratorPrompts({ subGenerator, localBlueprint, additionalSubGenerator: false }), subGeneratorStorage);
}
},
Expand All @@ -105,10 +115,7 @@ export default class extends GenerateBlueprintBaseGenerator {
.split(',')
.map(sub => sub.trim())
.filter(Boolean)) {
const subGeneratorStorage = this.getSubGeneratorStorage(subGenerator);
if (allPriorities) {
subGeneratorStorage.defaults({ [PRIORITIES]: BASE_PRIORITY_NAMES_LIST });
}
const subGeneratorStorage = this.applySubGeneratorDefaults(subGenerator, allPriorities);
await this.prompt(subGeneratorPrompts({ subGenerator, localBlueprint, additionalSubGenerator: true }), subGeneratorStorage);
}
},
Expand Down
Loading