Skip to content

Commit 49f9c67

Browse files
committed
fix: fix mvnw or gradlew no longer generated when creating simple projects
1 parent 4874959 commit 49f9c67

File tree

4 files changed

+118
-45
lines changed

4 files changed

+118
-45
lines changed

packages/nx-ktor/src/generators/project/lib/generate-ktor-project.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit';
1+
import {
2+
Tree,
3+
joinPathFragments,
4+
logger,
5+
stripIndents,
6+
workspaceRoot,
7+
} from '@nx/devkit';
28

39
import fetch from 'node-fetch';
410
import { NormalizedSchema } from '../schema';
511
import { buildKtorDownloadUrl } from '../../../utils/ktor-utils';
612
import { NX_KTOR_PKG } from '../../../index';
713
import {
814
extractFromZipStream,
9-
getCommonHttpHeaders,
15+
getCommonHttpHeaders,
1016
getGradleWrapperFiles,
1117
getMavenWrapperFiles,
1218
} from '@nxrocks/common-jvm';
@@ -35,7 +41,10 @@ export async function generateKtorProject(
3541
const response = await fetch(downloadUrl, downloadOptions);
3642

3743
logger.info(
38-
`📦 Extracting Ktor project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...`
44+
`📦 Extracting Ktor project zip to '${joinPathFragments(
45+
workspaceRoot,
46+
options.projectRoot
47+
)}'...`
3948
);
4049

4150
if (response.ok) {
@@ -44,29 +53,35 @@ export async function generateKtorProject(
4453
entryPath.endsWith('mvnw') || entryPath.endsWith('gradlew')
4554
? '755'
4655
: undefined;
47-
if (getMavenWrapperFiles().includes(entryPath) || getGradleWrapperFiles().includes(entryPath)) {
56+
if (
57+
getMavenWrapperFiles().includes(entryPath) ||
58+
getGradleWrapperFiles().includes(entryPath)
59+
) {
4860
if (options.transformIntoMultiModule) {
4961
tree.write(`${options.moduleRoot}/${entryPath}`, entryContent, {
5062
mode: execPermission,
5163
});
5264
}
53-
if (options.keepProjectLevelWrapper) {
65+
if (
66+
(options.transformIntoMultiModule ||
67+
options.addToExistingParentModule) &&
68+
options.keepProjectLevelWrapper
69+
) {
5470
tree.write(`${options.projectRoot}/${entryPath}`, entryContent, {
5571
mode: execPermission,
5672
});
5773
}
58-
59-
}
60-
else {
74+
} else {
6175
tree.write(`${options.projectRoot}/${entryPath}`, entryContent, {
6276
mode: execPermission,
6377
});
6478
}
6579
});
6680
} else {
6781
throw new Error(stripIndents`
68-
❌ Error downloading Ktor project zip from '${options.ktorInitializrUrl
69-
}'
82+
❌ Error downloading Ktor project zip from '${
83+
options.ktorInitializrUrl
84+
}'
7085
If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information:
7186
------------------------------------------------------
7287
Download URL: ${downloadUrl}

packages/nx-micronaut/src/generators/project/lib/generate-micronaut-project.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit';
1+
import {
2+
Tree,
3+
joinPathFragments,
4+
logger,
5+
stripIndents,
6+
workspaceRoot,
7+
} from '@nx/devkit';
28

39
import fetch from 'node-fetch';
410
import { NormalizedSchema } from '../schema';
@@ -27,7 +33,10 @@ export async function generateMicronautProject(
2733
);
2834

2935
logger.info(
30-
`📦 Extracting Micronaut project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...`
36+
`📦 Extracting Micronaut project zip to '${joinPathFragments(
37+
workspaceRoot,
38+
options.projectRoot
39+
)}'...`
3140
);
3241

3342
if (response.ok) {
@@ -40,29 +49,35 @@ export async function generateMicronautProject(
4049
filePath.endsWith('mvnw') || filePath.endsWith('gradlew')
4150
? '755'
4251
: undefined;
43-
if (getMavenWrapperFiles().includes(filePath) || getGradleWrapperFiles().includes(filePath)) {
52+
if (
53+
getMavenWrapperFiles().includes(filePath) ||
54+
getGradleWrapperFiles().includes(filePath)
55+
) {
4456
if (options.transformIntoMultiModule) {
4557
tree.write(`${options.moduleRoot}/${filePath}`, entryContent, {
4658
mode: execPermission,
4759
});
4860
}
49-
if (options.keepProjectLevelWrapper) {
61+
if (
62+
(options.transformIntoMultiModule ||
63+
options.addToExistingParentModule) &&
64+
options.keepProjectLevelWrapper
65+
) {
5066
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
5167
mode: execPermission,
5268
});
5369
}
54-
55-
}
56-
else {
70+
} else {
5771
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
5872
mode: execPermission,
5973
});
6074
}
6175
});
6276
} else {
6377
throw new Error(stripIndents`
64-
❌ Error downloading Micronaut project zip from '${options.micronautLaunchUrl
65-
}'
78+
❌ Error downloading Micronaut project zip from '${
79+
options.micronautLaunchUrl
80+
}'
6681
If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information:
6782
------------------------------------------------------
6883
Download URL: ${downloadUrl}

packages/nx-quarkus/src/generators/project/lib/generate-quarkus-project.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit';
1+
import {
2+
Tree,
3+
joinPathFragments,
4+
logger,
5+
stripIndents,
6+
workspaceRoot,
7+
} from '@nx/devkit';
28

39
import fetch from 'node-fetch';
410
import { NormalizedSchema } from '../schema';
@@ -25,7 +31,10 @@ export async function generateQuarkusProject(
2531
);
2632

2733
logger.info(
28-
`📦 Extracting Quarkus project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...`
34+
`📦 Extracting Quarkus project zip to '${joinPathFragments(
35+
workspaceRoot,
36+
options.projectRoot
37+
)}'...`
2938
);
3039

3140
if (response.ok) {
@@ -35,29 +44,35 @@ export async function generateQuarkusProject(
3544
filePath.endsWith('mvnw') || filePath.endsWith('gradlew')
3645
? '755'
3746
: undefined;
38-
if (getMavenWrapperFiles().includes(filePath) || getGradleWrapperFiles().includes(filePath)) {
47+
if (
48+
getMavenWrapperFiles().includes(filePath) ||
49+
getGradleWrapperFiles().includes(filePath)
50+
) {
3951
if (options.transformIntoMultiModule) {
4052
tree.write(`${options.moduleRoot}/${filePath}`, entryContent, {
4153
mode: execPermission,
4254
});
4355
}
44-
if (options.keepProjectLevelWrapper) {
56+
if (
57+
(options.transformIntoMultiModule ||
58+
options.addToExistingParentModule) &&
59+
options.keepProjectLevelWrapper
60+
) {
4561
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
4662
mode: execPermission,
4763
});
4864
}
49-
50-
}
51-
else {
65+
} else {
5266
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
5367
mode: execPermission,
5468
});
5569
}
5670
});
5771
} else {
5872
throw new Error(stripIndents`
59-
❌ Error downloading Quarkus project zip from '${options.quarkusInitializerUrl
60-
}'
73+
❌ Error downloading Quarkus project zip from '${
74+
options.quarkusInitializerUrl
75+
}'
6176
If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information:
6277
------------------------------------------------------
6378
Download URL: ${downloadUrl}

packages/nx-spring-boot/src/generators/project/lib/generate-boot-project.ts

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Tree, joinPathFragments, logger, names, stripIndents, workspaceRoot } from '@nx/devkit';
1+
import {
2+
Tree,
3+
joinPathFragments,
4+
logger,
5+
names,
6+
stripIndents,
7+
workspaceRoot,
8+
} from '@nx/devkit';
29

310
import fetch from 'node-fetch';
411
import { NormalizedSchema } from '../schema';
@@ -27,37 +34,51 @@ export async function generateBootProject(
2734
);
2835

2936
logger.info(
30-
`📦 Extracting Spring Boot project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...`
37+
`📦 Extracting Spring Boot project zip to '${joinPathFragments(
38+
workspaceRoot,
39+
options.projectRoot
40+
)}'...`
3141
);
3242

3343
if (response.ok) {
3444
await extractFromZipStream(response.body, (entryPath, entryContent) => {
3545
const execPermission =
36-
entryPath.endsWith('mvnw') || entryPath.endsWith('gradlew') ? '755' : undefined;
46+
entryPath.endsWith('mvnw') || entryPath.endsWith('gradlew')
47+
? '755'
48+
: undefined;
3749

38-
if (getMavenWrapperFiles().includes(entryPath) || getGradleWrapperFiles().includes(entryPath)) {
50+
if (
51+
getMavenWrapperFiles().includes(entryPath) ||
52+
getGradleWrapperFiles().includes(entryPath)
53+
) {
3954
if (options.transformIntoMultiModule) {
4055
tree.write(`${options.moduleRoot}/${entryPath}`, entryContent, {
4156
mode: execPermission,
4257
});
4358
}
44-
if (options.keepProjectLevelWrapper) {
59+
if (
60+
(options.transformIntoMultiModule ||
61+
options.addToExistingParentModule) &&
62+
options.keepProjectLevelWrapper
63+
) {
4564
tree.write(`${options.projectRoot}/${entryPath}`, entryContent, {
4665
mode: execPermission,
4766
});
4867
}
49-
50-
}
51-
else if (options.projectType !== 'library' || !getBootApplicationOnlyFiles(options).includes(entryPath)) {
68+
} else if (
69+
options.projectType !== 'library' ||
70+
!getBootApplicationOnlyFiles(options).includes(entryPath)
71+
) {
5272
tree.write(`${options.projectRoot}/${entryPath}`, entryContent, {
5373
mode: execPermission,
5474
});
5575
}
5676
});
5777
} else {
5878
throw new Error(stripIndents`
59-
❌ Error downloading Spring Boot project zip from '${options.springInitializerUrl
60-
}'
79+
❌ Error downloading Spring Boot project zip from '${
80+
options.springInitializerUrl
81+
}'
6182
If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information:
6283
------------------------------------------------------
6384
Download URL: ${downloadUrl}
@@ -68,14 +89,21 @@ export async function generateBootProject(
6889
}
6990
}
7091

71-
7292
function getBootApplicationOnlyFiles(options: NormalizedSchema) {
73-
7493
const basePath = options.packageName?.replaceAll('.', '/');
75-
const ext = options.language === 'kotlin' ? '.kt' : options.language === 'groovy' ? '.groovy' : '.java';
94+
const ext =
95+
options.language === 'kotlin'
96+
? '.kt'
97+
: options.language === 'groovy'
98+
? '.groovy'
99+
: '.java';
76100
return [
77101
`src/main/resources/application.properties`,
78-
`src/main/${options.language}/${basePath}/${names(options.name).className}Application${ext}`,
79-
`src/test/${options.language}/${basePath}/${names(options.name).className}ApplicationTests${ext}`];
80-
81-
}
102+
`src/main/${options.language}/${basePath}/${
103+
names(options.name).className
104+
}Application${ext}`,
105+
`src/test/${options.language}/${basePath}/${
106+
names(options.name).className
107+
}ApplicationTests${ext}`,
108+
];
109+
}

0 commit comments

Comments
 (0)