Skip to content

Commit

Permalink
fix: fix mvnw or gradlew no longer generated when creating simple…
Browse files Browse the repository at this point in the history
… projects
  • Loading branch information
tinesoft committed Jun 22, 2024
1 parent 4874959 commit 481c19d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export async function generateKtorProject(
mode: execPermission,
});
}
if (options.keepProjectLevelWrapper) {
if (
(options.transformIntoMultiModule ||
options.addToExistingParentModule) &&
options.keepProjectLevelWrapper
) {
tree.write(`${options.projectRoot}/${entryPath}`, entryContent, {
mode: execPermission,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export async function generateMicronautProject(
mode: execPermission,
});
}
if (options.keepProjectLevelWrapper) {
if (
(options.transformIntoMultiModule ||
options.addToExistingParentModule) &&
options.keepProjectLevelWrapper
) {
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
mode: execPermission,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export async function generateQuarkusProject(
mode: execPermission,
});
}
if (options.keepProjectLevelWrapper) {
if (
(options.transformIntoMultiModule ||
options.addToExistingParentModule) &&
options.keepProjectLevelWrapper
) {
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
mode: execPermission,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Tree, joinPathFragments, logger, names, stripIndents, workspaceRoot } from '@nx/devkit';
import {
Tree,
joinPathFragments,
logger,
names,
stripIndents,
workspaceRoot,
} from '@nx/devkit';

import fetch from 'node-fetch';
import { NormalizedSchema } from '../schema';
Expand Down Expand Up @@ -27,37 +34,51 @@ export async function generateBootProject(
);

logger.info(
`📦 Extracting Spring Boot project zip to '${joinPathFragments(workspaceRoot, options.projectRoot)}'...`
`📦 Extracting Spring Boot project zip to '${joinPathFragments(
workspaceRoot,
options.projectRoot
)}'...`
);

if (response.ok) {
await extractFromZipStream(response.body, (entryPath, entryContent) => {
await extractFromZipStream(response.body, (entryPath, entryContent) => {
const execPermission =
entryPath.endsWith('mvnw') || entryPath.endsWith('gradlew') ? '755' : undefined;
entryPath.endsWith('mvnw') || entryPath.endsWith('gradlew')
? '755'
: undefined;

if (getMavenWrapperFiles().includes(entryPath) || getGradleWrapperFiles().includes(entryPath)) {
if (
getMavenWrapperFiles().includes(entryPath) ||
getGradleWrapperFiles().includes(entryPath)
) {
if (options.transformIntoMultiModule) {
tree.write(`${options.moduleRoot}/${entryPath}`, entryContent, {
mode: execPermission,
});
}
if (options.keepProjectLevelWrapper) {
if (
(options.transformIntoMultiModule ||
options.addToExistingParentModule) &&
options.keepProjectLevelWrapper
) {
tree.write(`${options.projectRoot}/${entryPath}`, entryContent, {
mode: execPermission,
});
}

}
else if (options.projectType !== 'library' || !getBootApplicationOnlyFiles(options).includes(entryPath)) {
} else if (
options.projectType !== 'library' ||
!getBootApplicationOnlyFiles(options).includes(entryPath)
) {
tree.write(`${options.projectRoot}/${entryPath}`, entryContent, {
mode: execPermission,
});
}
});
} else {
throw new Error(stripIndents`
❌ Error downloading Spring Boot project zip from '${options.springInitializerUrl
}'
❌ Error downloading Spring Boot project zip from '${
options.springInitializerUrl
}'
If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information:
------------------------------------------------------
Download URL: ${downloadUrl}
Expand All @@ -68,14 +89,21 @@ export async function generateBootProject(
}
}


function getBootApplicationOnlyFiles(options: NormalizedSchema) {

const basePath = options.packageName?.replaceAll('.', '/');
const ext = options.language === 'kotlin' ? '.kt' : options.language === 'groovy' ? '.groovy' : '.java';
const ext =
options.language === 'kotlin'
? '.kt'
: options.language === 'groovy'
? '.groovy'
: '.java';
return [
`src/main/resources/application.properties`,
`src/main/${options.language}/${basePath}/${names(options.name).className}Application${ext}`,
`src/test/${options.language}/${basePath}/${names(options.name).className}ApplicationTests${ext}`];

}
`src/main/${options.language}/${basePath}/${
names(options.name).className
}Application${ext}`,
`src/test/${options.language}/${basePath}/${
names(options.name).className
}ApplicationTests${ext}`,
];
}

0 comments on commit 481c19d

Please sign in to comment.