diff --git a/packages/nx-flutter/src/generators/preset/schema.json b/packages/nx-flutter/src/generators/preset/schema.json index edbb4671..418fc4b7 100644 --- a/packages/nx-flutter/src/generators/preset/schema.json +++ b/packages/nx-flutter/src/generators/preset/schema.json @@ -23,9 +23,8 @@ }, "name": { "type": "string", - "description": "Name of the project to generate.", + "description": "Name of the project.", "alias": "projectName", - "x-prompt": "What name would you like to use?", "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, diff --git a/packages/nx-flutter/src/generators/project/generator.spec.ts b/packages/nx-flutter/src/generators/project/generator.spec.ts index 9ab6b80b..5f7e3db0 100644 --- a/packages/nx-flutter/src/generators/project/generator.spec.ts +++ b/packages/nx-flutter/src/generators/project/generator.spec.ts @@ -46,7 +46,6 @@ describe('application generator', () => { let options: NormalizedSchema; const _options: ProjectGeneratorOptions = { directory: 'testapp', - name: 'testapp', template: 'app', }; diff --git a/packages/nx-flutter/src/generators/project/lib/normalize-options.ts b/packages/nx-flutter/src/generators/project/lib/normalize-options.ts index 8e62b5b9..f52a6f8e 100644 --- a/packages/nx-flutter/src/generators/project/lib/normalize-options.ts +++ b/packages/nx-flutter/src/generators/project/lib/normalize-options.ts @@ -1,16 +1,25 @@ import { Tree } from '@nx/devkit'; import { ProjectGeneratorOptions, NormalizedSchema } from '../schema'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; export async function normalizeOptions( tree: Tree, options: ProjectGeneratorOptions ): Promise { + const projectType = options.template === 'app' ? 'application' : 'library'; + await ensureProjectName( + tree, + options as ProjectGeneratorOptions, + projectType + ); const { projectName, projectRoot } = await determineProjectNameAndRootOptions( tree, { name: options.name, - projectType: options.template === 'app' ? 'application' : 'library', + projectType, directory: options.directory, //rootProject: options.rootProject, } diff --git a/packages/nx-flutter/src/generators/project/schema.json b/packages/nx-flutter/src/generators/project/schema.json index d7ad9eee..848ad254 100644 --- a/packages/nx-flutter/src/generators/project/schema.json +++ b/packages/nx-flutter/src/generators/project/schema.json @@ -18,9 +18,8 @@ }, "name": { "type": "string", - "description": "Name of the project to generate.", + "description": "Name of the project.", "alias": "projectName", - "x-prompt": "What name would you like to use?", "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, diff --git a/packages/nx-ktor/src/generators/preset/schema.json b/packages/nx-ktor/src/generators/preset/schema.json index 7d46ab53..7087fc15 100644 --- a/packages/nx-ktor/src/generators/preset/schema.json +++ b/packages/nx-ktor/src/generators/preset/schema.json @@ -21,14 +21,6 @@ }, "x-prompt": "Which directory do you want to create the project in?" }, - "name": { - "type": "string", - "description": "Name of the project to generate.", - "alias": "projectName", - "x-prompt": "What name would you like to use?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "ktorVersion": { "description": "Ktor version.", "type": "string", @@ -107,6 +99,13 @@ "x-prompt": "What artifactId would you like to use?", "x-priority": "important" }, + "name": { + "type": "string", + "description": "Name of the project.", + "alias": "projectName", + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" + }, "configurationLocation": { "description": "Configuratin Location.", "type": "string", diff --git a/packages/nx-ktor/src/generators/project/generator.spec.ts b/packages/nx-ktor/src/generators/project/generator.spec.ts index a08e90d2..ed9b402d 100644 --- a/packages/nx-ktor/src/generators/project/generator.spec.ts +++ b/packages/nx-ktor/src/generators/project/generator.spec.ts @@ -206,7 +206,6 @@ describe('project generator', () => { let options: NormalizedSchema; const _options: ProjectGeneratorOptions = { directory: 'ktapp', - name: 'ktapp', groupId: 'com.tinesoft', artifactId: 'ktapp', buildSystem: 'MAVEN', diff --git a/packages/nx-ktor/src/generators/project/lib/normalize-options.ts b/packages/nx-ktor/src/generators/project/lib/normalize-options.ts index fe4550b2..ccb772e5 100644 --- a/packages/nx-ktor/src/generators/project/lib/normalize-options.ts +++ b/packages/nx-ktor/src/generators/project/lib/normalize-options.ts @@ -1,11 +1,19 @@ import { Tree } from '@nx/devkit'; import { ProjectGeneratorOptions, NormalizedSchema } from '../schema'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; export async function normalizeOptions( tree: Tree, options: ProjectGeneratorOptions ): Promise { + await ensureProjectName( + tree, + options as ProjectGeneratorOptions, + 'application' + ); const { projectName, projectRoot } = await determineProjectNameAndRootOptions( tree, { diff --git a/packages/nx-ktor/src/generators/project/schema.json b/packages/nx-ktor/src/generators/project/schema.json index 55afec7a..de1c3d22 100644 --- a/packages/nx-ktor/src/generators/project/schema.json +++ b/packages/nx-ktor/src/generators/project/schema.json @@ -16,14 +16,6 @@ }, "x-prompt": "Which directory do you want to create the project in?" }, - "name": { - "type": "string", - "description": "Name of the project to generate.", - "alias": "projectName", - "x-prompt": "What name would you like to use?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "ktorVersion": { "description": "Ktor version.", "type": "string", @@ -102,6 +94,13 @@ "x-prompt": "What artifactId would you like to use?", "x-priority": "important" }, + "name": { + "type": "string", + "description": "Name of the project.", + "alias": "projectName", + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" + }, "configurationLocation": { "description": "Configuratin Location.", "type": "string", diff --git a/packages/nx-micronaut/src/generators/preset/schema.json b/packages/nx-micronaut/src/generators/preset/schema.json index 50506612..b19ca27c 100644 --- a/packages/nx-micronaut/src/generators/preset/schema.json +++ b/packages/nx-micronaut/src/generators/preset/schema.json @@ -28,9 +28,8 @@ }, "name": { "type": "string", - "description": "Name of the project to generate.", + "description": "Name of the project.", "alias": "projectName", - "x-prompt": "What name would you like to use?", "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, diff --git a/packages/nx-micronaut/src/generators/project/generator.spec.ts b/packages/nx-micronaut/src/generators/project/generator.spec.ts index c21565f3..dd22cfb7 100644 --- a/packages/nx-micronaut/src/generators/project/generator.spec.ts +++ b/packages/nx-micronaut/src/generators/project/generator.spec.ts @@ -197,7 +197,6 @@ describe('project generator', () => { let options: NormalizedSchema; const _options: ProjectGeneratorOptions = { directory: 'mnapp', - name: 'mnapp', projectType: 'default', basePackage: 'com.tinesoft', buildSystem: 'MAVEN', diff --git a/packages/nx-micronaut/src/generators/project/lib/normalize-options.ts b/packages/nx-micronaut/src/generators/project/lib/normalize-options.ts index 14943c13..6f2bf7a0 100644 --- a/packages/nx-micronaut/src/generators/project/lib/normalize-options.ts +++ b/packages/nx-micronaut/src/generators/project/lib/normalize-options.ts @@ -1,11 +1,19 @@ import { Tree } from '@nx/devkit'; import { ProjectGeneratorOptions, NormalizedSchema } from '../schema'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; export async function normalizeOptions( tree: Tree, options: ProjectGeneratorOptions ): Promise { + await ensureProjectName( + tree, + options as ProjectGeneratorOptions, + 'application' + ); const { projectName, projectRoot } = await determineProjectNameAndRootOptions( tree, { diff --git a/packages/nx-micronaut/src/generators/project/schema.json b/packages/nx-micronaut/src/generators/project/schema.json index 4150e19a..ad77c844 100644 --- a/packages/nx-micronaut/src/generators/project/schema.json +++ b/packages/nx-micronaut/src/generators/project/schema.json @@ -18,9 +18,8 @@ }, "name": { "type": "string", - "description": "Name of the project to generate.", + "description": "Name of the project.", "alias": "projectName", - "x-prompt": "What name would you like to use?", "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, diff --git a/packages/nx-quarkus/src/generators/preset/schema.json b/packages/nx-quarkus/src/generators/preset/schema.json index d7c145f2..919fbf53 100644 --- a/packages/nx-quarkus/src/generators/preset/schema.json +++ b/packages/nx-quarkus/src/generators/preset/schema.json @@ -21,14 +21,6 @@ }, "x-prompt": "Which directory do you want to create the project in?" }, - "name": { - "type": "string", - "description": "Name of the project to generate.", - "alias": "projectName", - "x-prompt": "What name would you like to use?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "projectType": { "description": "Type of project.", "default": "application", @@ -116,6 +108,13 @@ "x-prompt": "What artifactId would you like to use?", "x-priority": "important" }, + "name": { + "type": "string", + "description": "Name of the project.", + "alias": "projectName", + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" + }, "skipFormat": { "description": "Skip formatting files (using Spotless plugin).", "type": "boolean", diff --git a/packages/nx-quarkus/src/generators/project/generator.spec.ts b/packages/nx-quarkus/src/generators/project/generator.spec.ts index 65567416..7406b089 100644 --- a/packages/nx-quarkus/src/generators/project/generator.spec.ts +++ b/packages/nx-quarkus/src/generators/project/generator.spec.ts @@ -94,7 +94,6 @@ describe('project generator', () => { let options: NormalizedSchema; const _options: ProjectGeneratorOptions = { directory: 'quarkusapp', - name: 'quarkusapp', projectType: 'application', groupId: 'com.tinesoft', artifactId: 'demo', diff --git a/packages/nx-quarkus/src/generators/project/lib/normalize-options.ts b/packages/nx-quarkus/src/generators/project/lib/normalize-options.ts index e2e873cc..51d4c90d 100644 --- a/packages/nx-quarkus/src/generators/project/lib/normalize-options.ts +++ b/packages/nx-quarkus/src/generators/project/lib/normalize-options.ts @@ -1,11 +1,19 @@ import { Tree } from '@nx/devkit'; import { ProjectGeneratorOptions, NormalizedSchema } from '../schema'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; export async function normalizeOptions( tree: Tree, options: ProjectGeneratorOptions ): Promise { + await ensureProjectName( + tree, + options as ProjectGeneratorOptions, + options.projectType + ); const { projectName, projectRoot } = await determineProjectNameAndRootOptions( tree, { diff --git a/packages/nx-quarkus/src/generators/project/schema.json b/packages/nx-quarkus/src/generators/project/schema.json index 08fe7ff5..18aafba2 100644 --- a/packages/nx-quarkus/src/generators/project/schema.json +++ b/packages/nx-quarkus/src/generators/project/schema.json @@ -16,14 +16,6 @@ }, "x-prompt": "Which directory do you want to create the project in?" }, - "name": { - "type": "string", - "description": "Name of the project to generate.", - "alias": "projectName", - "x-prompt": "What name would you like to use?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "projectType": { "description": "Type of project.", "default": "application", @@ -111,6 +103,13 @@ "x-prompt": "What artifactId would you like to use?", "x-priority": "important" }, + "name": { + "type": "string", + "description": "Name of the project.", + "alias": "projectName", + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" + }, "skipFormat": { "description": "Skip formatting files (using Spotless plugin).", "type": "boolean", diff --git a/packages/nx-spring-boot/src/generators/preset/generator.spec.ts b/packages/nx-spring-boot/src/generators/preset/generator.spec.ts index 73943665..c2a9eb27 100644 --- a/packages/nx-spring-boot/src/generators/preset/generator.spec.ts +++ b/packages/nx-spring-boot/src/generators/preset/generator.spec.ts @@ -50,7 +50,7 @@ describe('preset generator', () => { it('should run successfully', async () => { await presetGenerator(tree, options); - const config = readProjectConfiguration(tree, 'bootapp'); + const config = readProjectConfiguration(tree, options.name); expect(config).toBeDefined(); }); }); diff --git a/packages/nx-spring-boot/src/generators/preset/schema.json b/packages/nx-spring-boot/src/generators/preset/schema.json index d11d747c..63651799 100644 --- a/packages/nx-spring-boot/src/generators/preset/schema.json +++ b/packages/nx-spring-boot/src/generators/preset/schema.json @@ -30,14 +30,6 @@ }, "x-prompt": "Which directory do you want to create the project in?" }, - "name": { - "type": "string", - "description": "Name of the project to generate.", - "alias": "projectName", - "x-prompt": "What name would you like to use?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "projectType": { "description": "Type of project.", "default": "application", @@ -177,6 +169,13 @@ "x-prompt": "What artifactId would you like to use?", "x-priority": "important" }, + "name": { + "description": "Name of the project.", + "type": "string", + "default": "demo", + "alias": "projectName", + "x-priority": "important" + }, "packageName": { "description": "Name of the main package of the project.", "type": "string", @@ -187,6 +186,7 @@ "description": { "description": "Description of the project.", "type": "string", + "default": "Demo project for Spring Boot", "x-priority": "internal" }, "skipFormat": { diff --git a/packages/nx-spring-boot/src/generators/project/generator.spec.ts b/packages/nx-spring-boot/src/generators/project/generator.spec.ts index fb268bf2..5288c9bd 100644 --- a/packages/nx-spring-boot/src/generators/project/generator.spec.ts +++ b/packages/nx-spring-boot/src/generators/project/generator.spec.ts @@ -128,7 +128,6 @@ describe('project generator', () => { let options: NormalizedSchema; const _options: ProjectGeneratorOptions = { directory: 'bootapp', - name: 'bootapp', projectType: 'application', springInitializerUrl: DEFAULT_SPRING_INITIALIZR_URL, language: 'java', @@ -398,34 +397,29 @@ describe('project generator', () => { } ); - it.each` - projectType | expectedAction - ${'application'} | ${'keep as-is'} - ${'library'} | ${'disable'} - `( - `should $expectedAction the Spring Boot Gradle plugin in build.gradle when generating a '$projectType'`, - async ({ projectType }) => { - const opts: ProjectGeneratorOptions = { - ...options, - buildSystem: 'gradle-project', - projectType, - }; + it('should $expectedAction the Spring Boot Gradle plugin in build.gradle when generating', async () => { + const projectType = 'application'; + const opts: ProjectGeneratorOptions = { + ...options, + buildSystem: 'gradle-project', + projectType, + }; - const zipFiles = [ - { filePath: 'build.gradle', fileContent: BUILD_GRADLE }, - 'gradlew', - 'README.md', - ]; - // mock the zip content returned by the real call to Spring Initializer - jest - .spyOn(mockedResponse.body, 'pipe') - .mockReturnValue(mockZipStream(zipFiles)); + const zipFiles = [ + { filePath: 'build.gradle', fileContent: BUILD_GRADLE }, + 'gradlew', + 'README.md', + ]; + // mock the zip content returned by the real call to Spring Initializer + jest + .spyOn(mockedResponse.body, 'pipe') + .mockReturnValue(mockZipStream(zipFiles)); - await projectGenerator(tree, opts); + await projectGenerator(tree, opts); - const buildGradle = tree.read(`./${options.name}/build.gradle`, 'utf-8'); + const buildGradle = tree.read(`./${options.name}/build.gradle`, 'utf-8'); - const dependencyManagement = stripIndent` + const dependencyManagement = stripIndent` dependencyManagement { imports { mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES @@ -433,19 +427,18 @@ describe('project generator', () => { } `; - if (projectType === 'application') { - expect(buildGradle).not.toContain( - `id 'org.springframework.boot' version '2.6.2' apply false` - ); - expect(buildGradle).not.toContain(dependencyManagement); - } else { - expect(buildGradle).toContain( - `id 'org.springframework.boot' version '2.6.2' apply false` - ); - expect(buildGradle).toContain(dependencyManagement); - } + if (projectType === 'application') { + expect(buildGradle).not.toContain( + `id 'org.springframework.boot' version '2.6.2' apply false` + ); + expect(buildGradle).not.toContain(dependencyManagement); + } else { + expect(buildGradle).toContain( + `id 'org.springframework.boot' version '2.6.2' apply false` + ); + expect(buildGradle).toContain(dependencyManagement); } - ); + }); it.each` skipFormat | expectedAction diff --git a/packages/nx-spring-boot/src/generators/project/lib/normalize-options.ts b/packages/nx-spring-boot/src/generators/project/lib/normalize-options.ts index b5e875e3..caa5576e 100644 --- a/packages/nx-spring-boot/src/generators/project/lib/normalize-options.ts +++ b/packages/nx-spring-boot/src/generators/project/lib/normalize-options.ts @@ -1,11 +1,19 @@ import { Tree } from '@nx/devkit'; import { ProjectGeneratorOptions, NormalizedSchema } from '../schema'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; export async function normalizeOptions( tree: Tree, options: ProjectGeneratorOptions ): Promise { + await ensureProjectName( + tree, + options as ProjectGeneratorOptions, + options.projectType + ); const { projectName, projectRoot } = await determineProjectNameAndRootOptions( tree, { diff --git a/packages/nx-spring-boot/src/generators/project/schema.json b/packages/nx-spring-boot/src/generators/project/schema.json index e61c6473..146c24b3 100644 --- a/packages/nx-spring-boot/src/generators/project/schema.json +++ b/packages/nx-spring-boot/src/generators/project/schema.json @@ -16,14 +16,6 @@ }, "x-prompt": "Which directory do you want to create the project in?" }, - "name": { - "type": "string", - "description": "Name of the project to generate.", - "alias": "projectName", - "x-prompt": "What name would you like to use?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "projectType": { "description": "Type of project.", "default": "application", @@ -163,6 +155,13 @@ "x-prompt": "What artifactId would you like to use?", "x-priority": "important" }, + "name": { + "description": "Name of the project.", + "type": "string", + "default": "demo", + "alias": "projectName", + "x-priority": "important" + }, "packageName": { "description": "Name of the main package of the project.", "type": "string", @@ -173,6 +172,7 @@ "description": { "description": "Description of the project.", "type": "string", + "default": "Demo project for Spring Boot", "x-priority": "internal" }, "skipFormat": {