Skip to content

Commit

Permalink
feat(generators): add language option to parent-project generator (#623)
Browse files Browse the repository at this point in the history
* test: fix failing tests

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

* build: work in progress

---------

Co-authored-by: khalilou88 <[email protected]>
  • Loading branch information
khalilou88 and khalilou88 authored Nov 16, 2023
1 parent e706958 commit e6cf9ca
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 53 deletions.
43 changes: 1 addition & 42 deletions packages/internal/testing/src/lib/testing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CustomCli, springBootVersion } from '@jnxplus/common';
import { readXml, xmlToString } from '@jnxplus/xml';
import { CustomCli } from '@jnxplus/common';
import { getPackageManagerCommand } from '@nx/devkit';
import { exists, tmpProjPath } from '@nx/plugin/testing';
import axios from 'axios';
Expand All @@ -10,7 +9,6 @@ import * as path from 'path';
import { check as portCheck } from 'tcp-port-used';
import * as treeKill from 'tree-kill';
import { promisify } from 'util';
import { XmlDocument } from 'xmldoc';
import kill = require('kill-port');

/**
Expand Down Expand Up @@ -296,42 +294,3 @@ export function addJVMMemory() {
);
fs.writeFileSync(gradlePropertiesPath, updatedFileContent);
}

export function addSpringBootVersion() {
let xmldoc;
let pomXmlPath = path.join(tmpProjPath(), 'pom.xml');

if (fs.existsSync(pomXmlPath)) {
xmldoc = readXml(pomXmlPath);
} else {
pomXmlPath = path.join(tmpProjPath(), 'nx-maven', 'pom.xml');
xmldoc = readXml(pomXmlPath);
}

//properties
let properties = xmldoc.childNamed('properties');

if (properties === undefined) {
xmldoc.children.push(
new XmlDocument(`
<properties>
</properties>
`),
);
properties = xmldoc.childNamed('properties');
}

if (properties === undefined) {
throw new Error('Properties tag undefined');
}
const springBootVersionTag = properties.childNamed('spring.boot.version');
if (springBootVersionTag === undefined) {
properties.children.push(
new XmlDocument(`
<spring.boot.version>${springBootVersion}</spring.boot.version>
`),
);

fs.writeFileSync(pomXmlPath, xmlToString(xmldoc));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<% if(language === 'kotlin') { -%>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
</plugin>
<% } -%>
</plugins>
</pluginManagement>
</build>
Expand Down
3 changes: 2 additions & 1 deletion packages/nx-maven/src/generators/parent-project/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProjectType } from '@jnxplus/common';
import { LanguageType, ProjectType } from '@jnxplus/common';

export interface NxMavenParentProjectGeneratorSchema {
name: string;
Expand All @@ -11,4 +11,5 @@ export interface NxMavenParentProjectGeneratorSchema {
parentProject?: string;
aggregatorProject?: string;
framework?: 'spring-boot' | 'quarkus' | 'micronaut' | 'none';
language: LanguageType;
}
19 changes: 19 additions & 0 deletions packages/nx-maven/src/generators/parent-project/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@
]
}
},
"language": {
"description": "Language for sub-projects",
"type": "string",
"default": "java",
"x-prompt": {
"message": "Which language for sub-projects would you like to use?",
"type": "list",
"items": [
{
"value": "java",
"label": "Java"
},
{
"value": "kotlin",
"label": "Kotlin"
}
]
}
},
"parentProject": {
"type": "string",
"description": "ArtifactId of the parent project, or leave it blank for the root project"
Expand Down
7 changes: 2 additions & 5 deletions testing-projects/jnxplus-e2e/tests/nx-maven/all-bom.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { normalizeName } from '@jnxplus/common';
import {
addSpringBootVersion,
addTmpToGitignore,
createTestWorkspace,
getData,
Expand Down Expand Up @@ -45,8 +44,6 @@ describe('nx-maven all bom e2e', () => {
`generate @jnxplus/nx-maven:init --parentProjectName ${parentProjectName}`,
);

addSpringBootVersion();

if (isCI) {
removeTmpFromGitignore();
}
Expand Down Expand Up @@ -535,11 +532,11 @@ describe('nx-maven all bom e2e', () => {
});
}, 120000);

xit('should add a kotlin lib to a kotlin app dependencies', async () => {
it('should add a kotlin lib to a kotlin app dependencies', async () => {
const libsParentProject = uniq('libs-parent-project-');

await runNxCommandAsync(
`generate @jnxplus/nx-maven:parent-project ${libsParentProject} --projectType library`,
`generate @jnxplus/nx-maven:parent-project ${libsParentProject} --projectType library --language kotlin`,
);

const appsParentProject = uniq('apps-parent-project-');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { normalizeName } from '@jnxplus/common';
import {
addSpringBootVersion,
addTmpToGitignore,
checkFilesDoNotExist,
createTestWorkspace,
Expand Down Expand Up @@ -60,8 +59,6 @@ describe('nx-maven maven-root-directory e2e', () => {

await runNxCommandAsync('generate @jnxplus/nx-checkstyle:init');

addSpringBootVersion();

if (isCI) {
removeTmpFromGitignore();
}
Expand Down Expand Up @@ -588,11 +585,11 @@ describe('nx-maven maven-root-directory e2e', () => {
});
}, 120000);

xit('should add a kotlin lib to a kotlin app dependencies', async () => {
it('should add a kotlin lib to a kotlin app dependencies', async () => {
const libsParentProject = uniq('libs-parent-project-');

await runNxCommandAsync(
`generate @jnxplus/nx-maven:parent-project ${libsParentProject} --projectType library`,
`generate @jnxplus/nx-maven:parent-project ${libsParentProject} --projectType library --language kotlin`,
);

const appsParentProject = uniq('apps-parent-project-');
Expand Down

0 comments on commit e6cf9ca

Please sign in to comment.