Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
feat: rename "serverTarget" to "target" (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
domjtalbot authored Apr 16, 2023
1 parent 75af6f3 commit 45dad63
Show file tree
Hide file tree
Showing 20 changed files with 194 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-doors-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nx-ngrok': patch
---

Rename "serverTarget" to "target"
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Start a new Ngrok tunnel.
"dev": {
"executor": "nx-ngrok:tunnel",
"options": {
"serverTarget": "examples-nextjs:serve",
"target": "examples-nextjs:serve",
},
},
}
Expand All @@ -117,17 +117,17 @@ Start a new Ngrok tunnel.
<details>
<summary>tunnel executor options</summary>

| Name | Type | Required | Default | Description |
| -------------- | ---------------------------------------- | :------: | --------------- | -------------------------------------------------------------------------------------------------------- |
| `serverTarget` | `string` | - | - | Server target to run tunnel for. |
| `protocol` | `http`, `tcp`, `tls` | - | `http` | The tunnel protocol name. This defines the type of tunnel you would like to start. |
| `address` | `string`, `number` | - | - | Forward traffic to this local port number or network address. |
| `auth` | `string` | - | - | HTTP Basic authentication for tunnel. |
| `port` | `targetDefault`, `auto`, `number` | - | `targetDefault` | Override the serverTarget's port number — only supported if the serverTarget accepts a port setting. |
| `subdomain` | `string` | - | - | Subdomain name to request. If unspecified, ngrok provides a unique subdomain based on your account type. |
| `authToken` | `string` | - | - | Specifies the authentication token (authtoken) used to connect to the ngrok service. |
| `region` | `us`, `eu`, `au`, `ap`, `sa`, `jp`, `in` | - | `us` | Choose the region where the ngrok agent will connect to host its tunnels. |
| `ngrokConfig` | `string` | - | - | Custom path for ngrok config file. |
| Name | Type | Required | Default | Description |
| ------------- | ---------------------------------------- | :------: | --------------- | -------------------------------------------------------------------------------------------------------- |
| `target` | `string` | - | - | Server target to run tunnel for. |
| `protocol` | `http`, `tcp`, `tls` | - | `http` | The tunnel protocol name. This defines the type of tunnel you would like to start. |
| `address` | `string`, `number` | - | - | Forward traffic to this local port number or network address. |
| `auth` | `string` | - | - | HTTP Basic authentication for tunnel. |
| `port` | `targetDefault`, `auto`, `number` | - | `targetDefault` | Override the target's port number — only supported if the target accepts a port setting. |
| `subdomain` | `string` | - | - | Subdomain name to request. If unspecified, ngrok provides a unique subdomain based on your account type. |
| `authToken` | `string` | - | - | Specifies the authentication token (authtoken) used to connect to the ngrok service. |
| `region` | `us`, `eu`, `au`, `ap`, `sa`, `jp`, `in` | - | `us` | Choose the region where the ngrok agent will connect to host its tunnels. |
| `ngrokConfig` | `string` | - | - | Custom path for ngrok config file. |

</details>

Expand All @@ -140,7 +140,7 @@ Start a new Ngrok tunnel.
Generate a target to run a Ngrok tunnel for a local server.

```bash
nx generate nx-grok:tunnel dev --project=my-app --serverTarget=serve
nx generate nx-grok:tunnel dev --project=my-app --target=serve
```

<details>
Expand All @@ -157,17 +157,17 @@ UPDATE apps/my-app/project.json
<details>
<summary>tunnel generator options</summary>

| Name | Alias | Type | Required | Default | Description |
| -------------- | --------------------------------- | ---------------------------------------- | :-------------: | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| `name` | - | `string` || - | Target name. |
| `project` | - | `string` || - | What project does the target belong to? |
| `serverTarget` | - | `string` | - | - | Server target to run tunnel for. |
| `port` | `targetDefault`, `auto`, `number` | - | `targetDefault` | Override the serverTarget's port number — only supported if the serverTarget accepts a port setting. |
| `protocol` | - | `http`, `tcp`, `tls` | - | `http` | The tunnel protocol name. This defines the type of tunnel you would like to start. |
| `address` | - | `string`, `number` | - | - | Forward traffic to this local port number or network address. |
| `auth` | - | `string` | - | - | HTTP Basic authentication for tunnel. |
| `subdomain` | - | `string` | - | - | Subdomain name to request. If unspecified, ngrok provides a unique subdomain based on your account type. |
| `region` | - | `us`, `eu`, `au`, `ap`, `sa`, `jp`, `in` | - | `us` | Choose the region where the ngrok agent will connect to host its tunnels. |
| Name | Alias | Type | Required | Default | Description |
| ----------- | --------------------------------- | ---------------------------------------- | :-------------: | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| `name` | - | `string` || - | Target name. |
| `project` | - | `string` || - | What project does the target belong to? |
| `target` | - | `string` | - | - | Server target to run tunnel for. |
| `port` | `targetDefault`, `auto`, `number` | - | `targetDefault` | Override the target's port number — only supported if the target accepts a port setting. |
| `protocol` | - | `http`, `tcp`, `tls` | - | `http` | The tunnel protocol name. This defines the type of tunnel you would like to start. |
| `address` | - | `string`, `number` | - | - | Forward traffic to this local port number or network address. |
| `auth` | - | `string` | - | - | HTTP Basic authentication for tunnel. |
| `subdomain` | - | `string` | - | - | Subdomain name to request. If unspecified, ngrok provides a unique subdomain based on your account type. |
| `region` | - | `us`, `eu`, `au`, `ap`, `sa`, `jp`, `in` | - | `us` | Choose the region where the ngrok agent will connect to host its tunnels. |

</details>

Expand Down
10 changes: 5 additions & 5 deletions e2e/nx-ngrok-e2e/tests/nx-ngrok.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ describe('test e2e', () => {
);

await runCli(
`pnpm nx generate nx-ngrok:tunnel dev --project=${appName} --serverTarget=${appName}:serve`,
`pnpm nx generate nx-ngrok:tunnel dev --project=${appName} --target=${appName}:serve`,
{ cwd: workspacePath }
);

const project = readJson(`apps/${appName}/project.json`);

expect(project?.targets?.dev?.options).toEqual({
serverTarget: `${appName}:serve`,
target: `${appName}:serve`,
});
}, 120000);

Expand All @@ -53,7 +53,7 @@ describe('test e2e', () => {
);

await runCli(
`pnpm nx generate nx-ngrok:tunnel dev --project=${appName} --serverTarget=${appName}:serve`,
`pnpm nx generate nx-ngrok:tunnel dev --project=${appName} --target=${appName}:serve`,
{ cwd: workspacePath }
);

Expand All @@ -79,7 +79,7 @@ describe('test e2e', () => {
);

await runCli(
`pnpm nx generate nx-ngrok:tunnel dev --project=${appName} --serverTarget=${appName}:serve --port=${port}`,
`pnpm nx generate nx-ngrok:tunnel dev --project=${appName} --target=${appName}:serve --port=${port}`,
{ cwd: workspacePath }
);

Expand All @@ -104,7 +104,7 @@ describe('test e2e', () => {
);

await runCli(
`pnpm nx generate nx-ngrok:tunnel dev --project=${appName} --serverTarget=${appName}:serve --port=auto`,
`pnpm nx generate nx-ngrok:tunnel dev --project=${appName} --target=${appName}:serve --port=auto`,
{ cwd: workspacePath }
);

Expand Down
4 changes: 2 additions & 2 deletions examples/nest/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"dev": {
"executor": "nx-ngrok:tunnel",
"options": {
"serverTarget": "examples-nest:serve:development",
"target": "examples-nest:serve:development",
"address": 3333
},
"configurations": {
"production": {
"serverTarget": "examples-nest:serve:production"
"target": "examples-nest:serve:production"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"dev": {
"executor": "nx-ngrok:tunnel",
"options": {
"serverTarget": "examples-nextjs:serve:development",
"target": "examples-nextjs:serve:development",
"port": 8000
},
"configurations": {
"production": {
"serverTarget": "examples-nextjs:serve:development"
"target": "examples-nextjs:serve:development"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions examples/nx-mesh-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"dev": {
"executor": "nx-ngrok:tunnel",
"options": {
"serverTarget": "examples-nx-mesh-app:serve:development"
"target": "examples-nx-mesh-app:serve:development"
},
"configurations": {
"production": {
"serverTarget": "examples-nx-mesh-app:serve:production"
"target": "examples-nx-mesh-app:serve:production"
}
}
},
Expand Down
7 changes: 6 additions & 1 deletion packages/nx-ngrok/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
"rules": {}
},
{
"files": ["./package.json", "./generators.json", "./executors.json"],
"files": [
"./package.json",
"./generators.json",
"./executors.json",
"./migrations.json"
],
"parser": "jsonc-eslint-parser",
"rules": {
"@nrwl/nx/nx-plugin-checks": "error"
Expand Down
10 changes: 10 additions & 0 deletions packages/nx-ngrok/migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"generators": {
"rename-servertarget-to-target": {
"version": "1.2.0",
"description": "Rename 'serverTarget' setting to 'target'",
"cli": "nx",
"implementation": "./src/migrations/1.2.0/rename-servertarget-to-target"
}
}
}
10 changes: 7 additions & 3 deletions packages/nx-ngrok/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
"format": ["cjs"],
"minify": true,
"esbuildOptions": {
"outExtension": { ".js": ".js" }
"outExtension": {
".js": ".js"
}
},
"sourcemap": true,
"additionalEntryPoints": [
"packages/nx-ngrok/src/executors/tunnel/executor.ts"
"packages/nx-ngrok/src/executors/tunnel/executor.ts",
"packages/nx-ngrok/src/migrations/1.2.0/rename-servertarget-to-target"
],
"external": ["@nrwl/devkit", "ngrok"],
"assets": [
Expand Down Expand Up @@ -87,7 +90,8 @@
"packages/nx-ngrok/**/*.ts",
"packages/nx-ngrok/generators.json",
"packages/nx-ngrok/executors.json",
"packages/nx-ngrok/package.json"
"packages/nx-ngrok/package.json",
"packages/nx-ngrok/migrations.json"
]
},
"configurations": {
Expand Down
4 changes: 2 additions & 2 deletions packages/nx-ngrok/src/executors/tunnel/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ describe('tunnel Executor', () => {
);
});

it('should get baseUrl from the serverTarget', async () => {
it('should get baseUrl from the target', async () => {
const tunnel = await tunnelExecutor(
{ serverTarget: 'myapp:serve' },
{ target: 'myapp:serve' },
mockContext
).next();

Expand Down
2 changes: 1 addition & 1 deletion packages/nx-ngrok/src/executors/tunnel/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export interface TunnelExecutorSchema {
port?: 'targetDefault' | 'auto' | number;
protocol?: Ngrok.Options['proto'];
region?: Ngrok.Options['region'];
serverTarget?: string;
target?: string;
subdomain?: string;
}
4 changes: 2 additions & 2 deletions packages/nx-ngrok/src/executors/tunnel/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"description": "",
"type": "object",
"properties": {
"serverTarget": {
"target": {
"type": "string",
"description": "Server target to run tunnel for."
},
"port": {
"type": "string",
"description": "Override the serverTarget's port number — only supported if the serverTarget accepts a port setting.",
"description": "Override the target's port number — only supported if the target accepts a port setting.",
"oneOf": [
{
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions packages/nx-ngrok/src/executors/tunnel/utils/start-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export async function* startTarget(
port = options.port;
}

if (!options.serverTarget) {
if (!options.target) {
yield { baseUrl: options.address ?? undefined };

return;
}

const parsedDevServerTarget = parseTargetString(
options.serverTarget,
const parsedDevtarget = parseTargetString(
options.target,
context.projectGraph
);

Expand All @@ -35,7 +35,7 @@ export async function* startTarget(
baseUrl?: string;
info?: { port: number; baseUrl?: string };
}>(
parsedDevServerTarget,
parsedDevtarget,
{
port,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-ngrok/src/generators/tunnel/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export interface TunnelGeneratorSchema {
port?: 'targetDefault' | 'auto' | number;
protocol?: Ngrok.Options['proto'];
region?: Ngrok.Options['region'];
serverTarget?: string;
target?: string;
subdomain?: string;
}
6 changes: 3 additions & 3 deletions packages/nx-ngrok/src/generators/tunnel/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "object",
"examples": [
{
"command": "nx g nx-ngrok:tunnel dev --project my-app --serverTarget 'my-app:serve'",
"command": "nx g nx-ngrok:tunnel dev --project my-app --target 'my-app:serve'",
"description": "Add the `dev` target to `my-app`"
}
],
Expand All @@ -23,7 +23,7 @@
},
"port": {
"type": "string",
"description": "Override the serverTarget's port number — only supported if the serverTarget accepts a port setting.",
"description": "Override the target's port number — only supported if the target accepts a port setting.",
"oneOf": [
{
"type": "string",
Expand All @@ -42,7 +42,7 @@
"x-prompt": "What project does the target belong to?",
"x-dropdown": "projects"
},
"serverTarget": {
"target": {
"type": "string",
"description": "Server target to run tunnel for.",
"x-priority": "important"
Expand Down
Loading

0 comments on commit 45dad63

Please sign in to comment.