Skip to content

Commit

Permalink
generate-blueprint: adjusts (#27424)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Sep 26, 2024
1 parent a8fa515 commit 988e792
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 42 deletions.
8 changes: 4 additions & 4 deletions cli/program.mts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ type BuildCommands = {
loadCommand?: (key: string) => Promise<(...args: any[]) => Promise<any>>;
defaultCommand?: string;
entrypointGenerator?: string;
printLogo?: () => void;
silent?: boolean;
printBlueprintLogo?: () => void;
printLogo?: () => void | Promise<void>;
printBlueprintLogo?: () => void | Promise<void>;
createEnvBuilder: (options?: BaseEnvironmentOptions) => Promise<EnvironmentBuilder>;
};

Expand Down Expand Up @@ -270,8 +270,8 @@ export const buildCommands = ({
}

if (!silent) {
printLogo();
printBlueprintLogo();
await printLogo();
await printBlueprintLogo();
}

const command = this;
Expand Down
3 changes: 3 additions & 0 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"cacheProviderRedis": false,
"camelizedBaseName": "jhipster",
"capitalizedBaseName": "Jhipster",
"caret": undefined,
"cjsExtension": ".cjs",
"clientDistDir": "target/classes/static/",
"clientFramework": "angular",
Expand Down Expand Up @@ -891,6 +892,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"cacheProviderRedis": false,
"camelizedBaseName": "jhipster",
"capitalizedBaseName": "Jhipster",
"caret": undefined,
"cjsExtension": ".cjs",
"clientDistDir": "target/classes/static/",
"clientFramework": "angular",
Expand Down Expand Up @@ -1525,6 +1527,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"cacheProviderRedis": false,
"camelizedBaseName": "jhipster",
"capitalizedBaseName": "Jhipster",
"caret": undefined,
"cjsExtension": ".cjs",
"clientDistDir": "target/classes/static/",
"clientFramework": "no",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ exports[`generator - generate-blueprint with all option should match snapshot 1`
"README.md": {
"stateCleared": "modified",
},
"cli/cli-customizations.cjs": {
"stateCleared": "modified",
},
"cli/cli.cjs": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -889,6 +892,9 @@ exports[`generator - generate-blueprint with default config should write files a
"README.md": {
"stateCleared": "modified",
},
"cli/cli-customizations.cjs": {
"stateCleared": "modified",
},
"cli/cli.cjs": {
"stateCleared": "modified",
},
Expand Down
7 changes: 7 additions & 0 deletions generators/generate-blueprint/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ import {

const command = {
configs: {
caret: {
cli: {
description: 'Use caret in package.json engines',
type: Boolean,
},
scope: 'storage',
},
recreatePackageLock: {
description: 'Recreate package lock',
cli: {
Expand Down
11 changes: 7 additions & 4 deletions generators/generate-blueprint/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ export const files = asWriteFilesSection<any>({
'.blueprint/generate-sample/index.mjs',
// Always write cli for devBlueprint usage
'cli/cli.cjs',
{ sourceFile: 'cli/cli-customizations.cjs', override: false },
],
},
{
condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION] && ctx.githubWorkflows && !ctx.skipWorkflows,
condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION] && ctx.githubWorkflows,
templates: [
'.blueprint/github-build-matrix/build-matrix.mjs',
'.blueprint/github-build-matrix/generator.mjs',
'.blueprint/github-build-matrix/index.mjs',
'.github/workflows/build-cache.yml',
'.github/workflows/samples.yml',
],
},
{
condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION] && ctx.githubWorkflows && !ctx.skipWorkflows,
templates: ['.github/workflows/build-cache.yml', '.github/workflows/samples.yml'],
},
{
condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION] && !ctx.sampleWritten,
templates: ['.blueprint/generate-sample/templates/samples/sample.jdl'],
Expand Down Expand Up @@ -88,7 +91,7 @@ export const generatorFiles = asWriteFilesSection<any>({
path: 'generators/generator',
to: ctx => `${ctx.application.blueprintsPath}${ctx.generator}`,
condition(ctx) {
return ((this as any).options.force || !ctx.written) && ctx.priorities.find(priority => priority.name === 'writing');
return !ctx.written && ctx.priorities.find(priority => priority.name === 'writing');
},
transform: false,
templates: [
Expand Down
26 changes: 11 additions & 15 deletions generators/generate-blueprint/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,26 +354,22 @@ export default class extends BaseGenerator {
addGeneratorJHipsterDependency() {
if (this.jhipsterConfig[LOCAL_BLUEPRINT_OPTION]) return;
const { packagejs } = this.application;
const exactDependency = {
'generator-jhipster': `${packagejs.version}`,
};
const caretDependency = {
'generator-jhipster': `^${packagejs.version}`,
};
if (this.jhipsterConfig.dynamic) {
this.packageJson.merge({
devDependencies: {
'generator-jhipster': `${packagejs.version}`,
},
peerDependencies: {
'generator-jhipster': `^${packagejs.version}`,
},
engines: {
'generator-jhipster': `^${packagejs.version}`,
},
devDependencies: exactDependency,
peerDependencies: caretDependency,
engines: caretDependency,
});
} else {
this.packageJson.merge({
dependencies: {
'generator-jhipster': `${packagejs.version}`,
},
engines: {
'generator-jhipster': `${packagejs.version}`,
},
dependencies: exactDependency,
engines: this.jhipsterConfig.caret ? caretDependency : exactDependency,
});
}
},
Expand Down
14 changes: 12 additions & 2 deletions generators/generate-blueprint/templates/README.md.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,23 @@ npm install -g generator-jhipster-<%= baseName %>

To use this blueprint, run the below command

```bash
<%_ if (cli) { _%>
```bash
<%= cliName %>
<%_ if (caret) { _%>
```
or
```bash
jhipster --blueprints <%= baseName %>
```
<%_ } _%>
<%_ } else { _%>
```bash
jhipster --blueprints <%= baseName %>
<%_ } _%>
```
<%_ } _%>

You can look for updated <%= baseName %> blueprint specific options by running

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file will not be overwritten by generate-blueprint
module.exports = {};
3 changes: 2 additions & 1 deletion generators/generate-blueprint/templates/cli/cli.cjs.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ const blueprint = packageFolderName.startsWith('jhipster-') ? `generator-${packa
[blueprint]: version,
},
printBlueprintLogo: () => {
console.log('===================== JHipster <%= baseName %> =====================');
console.log('===================== JHipster <%= humanizedBaseName %> =====================');
console.log('');
},
lookups: [{ packagePaths: [packagePath] }],
...require('./cli-customizations.cjs'),
}).catch(done);

process.on('unhandledRejection', up => {
Expand Down
24 changes: 8 additions & 16 deletions test-integration/generate-blueprint-samples/default/.yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"install",
"end"
],
"sbs": false,
"written": true
"sbs": false
},
"common": {
"command": false,
Expand All @@ -50,8 +49,7 @@
"install",
"end"
],
"sbs": false,
"written": true
"sbs": false
},
"cypress": {
"command": false,
Expand All @@ -74,8 +72,7 @@
"install",
"end"
],
"sbs": false,
"written": true
"sbs": false
},
"server": {
"command": false,
Expand All @@ -98,8 +95,7 @@
"install",
"end"
],
"sbs": false,
"written": true
"sbs": false
},
"jdl": {
"command": true,
Expand All @@ -126,8 +122,7 @@
"postInstall",
"end"
],
"sbs": false,
"written": true
"sbs": false
},
"spring-data-relational": {
"command": true,
Expand All @@ -154,8 +149,7 @@
"postInstall",
"end"
],
"sbs": false,
"written": true
"sbs": false
},
"languages": {
"command": true,
Expand All @@ -182,8 +176,7 @@
"postInstall",
"end"
],
"sbs": false,
"written": true
"sbs": false
},
"angular": {
"command": true,
Expand All @@ -210,8 +203,7 @@
"postInstall",
"end"
],
"sbs": false,
"written": true
"sbs": false
}
},
"jhipsterVersion": "7.5.0",
Expand Down

0 comments on commit 988e792

Please sign in to comment.