Skip to content

Commit e2a3583

Browse files
authored
fix: made studio start on different port if one is already in use (#1815)
Co-authored-by: Tushar Anand <tusharannand@gmail.com> Co-authored-by: asyncapi-bot <info@asyncapi.io> Co-authored-by: Shurtu-gal <ashishpadhy1729@gmail.com>
1 parent 4af0469 commit e2a3583

10 files changed

Lines changed: 139 additions & 146 deletions

File tree

.changeset/1815.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@asyncapi/cli': patch
3+
---
4+
5+
fix: made studio start on different port if one is already in use
6+
7+
- 43a8cb8: fix: made studio start on differnt port if one is already in use
8+
9+
Signed-off-by: Tushar Anand <tusharannand@gmail.com>
10+
- ce4b061: Merge remote-tracking branch 'remote/master' into fix-studio-multiple-instance
11+
- 122812a: chore: new approach for port allocation done
12+
13+
Signed-off-by: Tushar Anand <tusharannand@gmail.com>
14+
- 5946001: fix: removed comment and fix linting errors
15+
16+
Signed-off-by: Tushar Anand <tusharannand@gmail.com>
17+
18+

src/apps/cli/commands/generate/fromTemplate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default class Template extends Command {
5151

5252
parser = new Parser();
5353

54+
// eslint-disable-next-line sonarjs/cognitive-complexity
5455
async run() {
5556
const { args, flags } = await this.parse(Template); // NOSONAR
5657
const interactive = !flags['no-interactive'];

src/apps/cli/commands/generate/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class Models extends Command {
2626
...proxyFlags(),
2727
};
2828

29+
// eslint-disable-next-line sonarjs/cognitive-complexity
2930
async run() {
3031
const { args, flags } = await this.parse(Models);
3132
let { language, file } = args;

src/apps/cli/commands/start/preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class PreviewStudio extends Command {
2323

2424
let filePath: string | undefined = args['spec-file'] ?? flags.file;
2525

26-
const previewPort = flags.port;
26+
const previewPort = parseInt(flags.port ?? '0',10);
2727

2828
if (!filePath) {
2929
filePath = (await load()).getFilePath();
@@ -37,7 +37,7 @@ export default class PreviewStudio extends Command {
3737
}
3838
}
3939
this.metricsMetadata.port = previewPort;
40-
startPreview(
40+
await startPreview(
4141
filePath as string,
4242
flags.base,
4343
flags.baseDir,

src/apps/cli/commands/start/studio.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class StartStudio extends Command {
2222

2323
let filePath = args['spec-file'] ?? flags.file;
2424

25-
let port = flags.port;
25+
let port = parseInt(flags.port ?? '0',10);
2626

2727
if (flags.file) {
2828
this.warn(
@@ -55,7 +55,7 @@ export default class StartStudio extends Command {
5555
}
5656
}
5757
this.metricsMetadata.port = port;
58-
startStudio(filePath as string, port);
58+
await startStudio(filePath as string, port);
5959
}
6060

6161
private async parseArgs(args: Record<string, any>, port?: string) {

src/apps/cli/internal/flags/start/preview.flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Flags } from '@oclif/core';
33
export const previewFlags = () => {
44
return {
55
help: Flags.help({ char: 'h' }),
6-
port: Flags.integer({
6+
port: Flags.string({
77
char: 'p',
88
description: 'port in which to start Studio in the preview mode',
99
}),

src/apps/cli/internal/flags/start/studio.flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const studioFlags = () => {
88
description: 'path to the AsyncAPI file to link with Studio',
99
deprecated: true,
1010
}),
11-
port: Flags.integer({
11+
port: Flags.string({
1212
char: 'p',
1313
description: 'port in which to start Studio',
1414
}),

0 commit comments

Comments
 (0)