Skip to content

Commit

Permalink
feat(nx-quarkus): add proxy support for project generation
Browse files Browse the repository at this point in the history
This means generating a project while connected behind a (corporate) proxy now works out-of-the-box.
  • Loading branch information
tinesoft committed Aug 17, 2022
1 parent bd3ac7e commit eaefe9a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/nx-quarkus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Here is a list of some of the coolest features of the plugin:
- ✅ Generation of Quarkus applications/libraries based on **Quarkus app generator** API
- ✅ Building, packaging, testing, etc your Quarkus projects
- ✅ Code formatting using the excellent [**Spotless**](https://github.com/diffplug/spotless) plugin for Maven or Gradle
- ✅ Support for corporate proxies (either via `--proxyUrl` or by defining environment variable `http_proxy`, `HTTP_PROXY`, `https_proxy` or `HTTPS_PROXY`)
- ✅ Integration with Nx's **dependency graph** (through `nx dep-graph` or `nx affected:dep-graph`): this allows you to **visualize** the dependencies of any Quarkus's `Maven`/`Gradle` applications or libraries inside your workspace, just like Nx natively does it for JS/TS-based projects!

![Nx Quarkus dependency graph](https://raw.githubusercontent.com/tinesoft/nxrocks/develop/images/nx-quarkus-dep-graph.png)
Expand Down Expand Up @@ -90,10 +91,15 @@ Option | Value | Description
`skipFormat` | `boolean` | Do not add the ability to format code (using Spotless plugin)
`extensions` | `string` | List of extensions to use (comma-separated). Go to https://code.quarkus.io/api/extensions to get the ids needed here
`quarkusInitializerUrl` | `https://code.quarkus.io` | URL to the Quarkus Initializer instance to use
`proxyUrl` | | The URL of the (corporate) proxy server to use to access Quarkus Initializer
`skipeCodeSamples` | `string` | Whether or not to include code samples from extensions (when available)
`tags` | `string` | Tags to use for linting (comma-separated)
`directory` | `string` | Directory where the project is placed

> **Note:** If you are working behind a corporate proxy, you can use the `proxyUrl` option to specify the URL of that corporate proxy server.
> Otherwise, you'll get a [ETIMEDOUT error](https://github.com/tinesoft/nxrocks/issues/125) when trying to access official Spring Initializer to generate the project.
> Even simpler, you can just define environment variable `http_proxy`, `HTTP_PROXY`, `https_proxy` or `HTTPS_PROXY` globally.
### Linking Projects (`link` generator)

This generator is used to link a Quarkus project inside the workspace (the *source* project) with another project (the _*target* project), by adding the source project as an **implicit dependency** of the later.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { workspaceRoot } from '@nrwl/workspace/src/utils/app-root';

import fetch from 'node-fetch';
import { NormalizedSchema } from '../schema';
import { buildQuarkusDownloadUrl } from '../../../utils/quarkus-utils';
import { extractFromZipStream, getPackageLatestNpmVersion, NX_QUARKUS_PKG } from '@nxrocks/common';
import { buildQuarkusDownloadUrl } from '../../../utils/quarkus-utils';
import { extractFromZipStream, getHttpProxyAgent, getPackageLatestNpmVersion, NX_QUARKUS_PKG } from '@nxrocks/common';

export async function generateQuarkusProject(tree: Tree, options: NormalizedSchema): Promise<void> {
const downloadUrl = buildQuarkusDownloadUrl(options);
Expand All @@ -13,11 +13,13 @@ export async function generateQuarkusProject(tree: Tree, options: NormalizedSche

const pkgVersion = getPackageLatestNpmVersion(NX_QUARKUS_PKG);
const userAgent = `@nxrocks_nx-quarkus/${pkgVersion}`;
const proxyAgent = getHttpProxyAgent(options.proxyUrl);
const opts = {
headers: {
'User-Agent': userAgent
}
}
},
...(proxyAgent ? {agent: proxyAgent} : {})
};
const response = await fetch(downloadUrl, opts);

logger.info(`📦 Extracting Quarkus project zip to '${workspaceRoot}/${options.projectRoot}'...`);
Expand Down
1 change: 1 addition & 0 deletions packages/nx-quarkus/src/generators/project/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ProjectGeneratorOptions {
directory?: string;

quarkusInitializerUrl?: string;
proxyUrl?: string;

buildSystem: 'MAVEN' | 'GRADLE' | 'GRADLE_KOTLIN_DSL';
groupId?: string;
Expand Down
4 changes: 4 additions & 0 deletions packages/nx-quarkus/src/generators/project/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
"default": "https://code.quarkus.io",
"description": "The URL to the Quarkus Initializer instance to use to generate the project"
},
"proxyUrl": {
"type": "string",
"description": "The URL of the (corporate) proxy server to use to access Quarkus Initializer"
},
"skipCodeSamples": {
"type": "boolean",
"description": "Would you like to include code samples from extensions (when available)?"
Expand Down

0 comments on commit eaefe9a

Please sign in to comment.