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 49f9c67
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit';
import {
Tree,
joinPathFragments,
logger,
stripIndents,
workspaceRoot,
} from '@nx/devkit';

import fetch from 'node-fetch';
import { NormalizedSchema } from '../schema';
import { buildKtorDownloadUrl } from '../../../utils/ktor-utils';
import { NX_KTOR_PKG } from '../../../index';
import {
extractFromZipStream,
getCommonHttpHeaders,
getCommonHttpHeaders,
getGradleWrapperFiles,
getMavenWrapperFiles,
} from '@nxrocks/common-jvm';
Expand Down Expand Up @@ -35,7 +41,10 @@ export async function generateKtorProject(
const response = await fetch(downloadUrl, downloadOptions);

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

if (response.ok) {
Expand All @@ -44,29 +53,35 @@ export async function generateKtorProject(
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 {
} else {
tree.write(`${options.projectRoot}/${entryPath}`, entryContent, {
mode: execPermission,
});
}
});
} else {
throw new Error(stripIndents`
❌ Error downloading Ktor project zip from '${options.ktorInitializrUrl
}'
❌ Error downloading Ktor project zip from '${
options.ktorInitializrUrl
}'
If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information:
------------------------------------------------------
Download URL: ${downloadUrl}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit';
import {
Tree,
joinPathFragments,
logger,
stripIndents,
workspaceRoot,
} from '@nx/devkit';

import fetch from 'node-fetch';
import { NormalizedSchema } from '../schema';
Expand Down Expand Up @@ -27,7 +33,10 @@ export async function generateMicronautProject(
);

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

if (response.ok) {
Expand All @@ -40,29 +49,35 @@ export async function generateMicronautProject(
filePath.endsWith('mvnw') || filePath.endsWith('gradlew')
? '755'
: undefined;
if (getMavenWrapperFiles().includes(filePath) || getGradleWrapperFiles().includes(filePath)) {
if (
getMavenWrapperFiles().includes(filePath) ||
getGradleWrapperFiles().includes(filePath)
) {
if (options.transformIntoMultiModule) {
tree.write(`${options.moduleRoot}/${filePath}`, entryContent, {
mode: execPermission,
});
}
if (options.keepProjectLevelWrapper) {
if (
(options.transformIntoMultiModule ||
options.addToExistingParentModule) &&
options.keepProjectLevelWrapper
) {
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
mode: execPermission,
});
}

}
else {
} else {
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
mode: execPermission,
});
}
});
} else {
throw new Error(stripIndents`
❌ Error downloading Micronaut project zip from '${options.micronautLaunchUrl
}'
❌ Error downloading Micronaut project zip from '${
options.micronautLaunchUrl
}'
If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information:
------------------------------------------------------
Download URL: ${downloadUrl}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Tree, joinPathFragments, logger, stripIndents, workspaceRoot } from '@nx/devkit';
import {
Tree,
joinPathFragments,
logger,
stripIndents,
workspaceRoot,
} from '@nx/devkit';

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

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

if (response.ok) {
Expand All @@ -35,29 +44,35 @@ export async function generateQuarkusProject(
filePath.endsWith('mvnw') || filePath.endsWith('gradlew')
? '755'
: undefined;
if (getMavenWrapperFiles().includes(filePath) || getGradleWrapperFiles().includes(filePath)) {
if (
getMavenWrapperFiles().includes(filePath) ||
getGradleWrapperFiles().includes(filePath)
) {
if (options.transformIntoMultiModule) {
tree.write(`${options.moduleRoot}/${filePath}`, entryContent, {
mode: execPermission,
});
}
if (options.keepProjectLevelWrapper) {
if (
(options.transformIntoMultiModule ||
options.addToExistingParentModule) &&
options.keepProjectLevelWrapper
) {
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
mode: execPermission,
});
}

}
else {
} else {
tree.write(`${options.projectRoot}/${filePath}`, entryContent, {
mode: execPermission,
});
}
});
} else {
throw new Error(stripIndents`
❌ Error downloading Quarkus project zip from '${options.quarkusInitializerUrl
}'
❌ Error downloading Quarkus project zip from '${
options.quarkusInitializerUrl
}'
If the problem persists, please open an issue at https://github.com/tinesoft/nxrocks/issues, with the following information:
------------------------------------------------------
Download URL: ${downloadUrl}
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) => {
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 49f9c67

Please sign in to comment.