Skip to content

Commit dae7277

Browse files
committed
Changed connect commands to use rootCommand that way it updates with the current project and doesn't rely on global codify. Added error if port is already in use.
1 parent 421e152 commit dae7277

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/commands/connect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { BaseCommand } from '../common/base-command.js';
2-
import { LoginOrchestrator } from '../orchestrators/login.js';
32
import { ConnectOrchestrator } from '../orchestrators/connect.js';
43

54
export default class Connect extends BaseCommand {
@@ -18,7 +17,8 @@ For more information, visit: https://docs.codifycli.com/commands/validate
1817

1918
public async run(): Promise<void> {
2019
const { flags } = await this.parse(Connect)
20+
const config = this.config;
2121

22-
await ConnectOrchestrator.run();
22+
await ConnectOrchestrator.run(config);
2323
}
2424
}

src/commands/edit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ For more information, visit: https://docs.codifycli.com/commands/validate
1818
public async run(): Promise<void> {
1919
const { flags } = await this.parse(Edit)
2020

21-
await ConnectOrchestrator.run();
21+
// await ConnectOrchestrator.run();
2222
}
2323
}

src/connect/http-routes/handlers/create-command.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { spawn } from '@homebridge/node-pty-prebuilt-multiarch';
22
import chalk from 'chalk';
33
import { Router } from 'express';
44

5+
import { ConnectOrchestrator } from '../../../orchestrators/connect.js';
56
import { SocketServer } from '../../socket-server.js';
67

78
export enum ConnectCommand {
@@ -17,15 +18,15 @@ const CommandInfo = {
1718
requiresDocumentId: false,
1819
},
1920
[ConnectCommand.APPLY]: {
20-
command: (args) => ['-c', `codify apply ${args}`],
21+
command: (args) => ['-c', `${ConnectOrchestrator.rootCommand} apply ${args}`],
2122
requiresDocumentId: true,
2223
},
2324
[ConnectCommand.PLAN]: {
24-
command: (args) => ['-c', `codify plan ${args}`],
25+
command: (args) => ['-c', `${ConnectOrchestrator.rootCommand} plan ${args}`],
2526
requiresDocumentId: true,
2627
},
2728
[ConnectCommand.IMPORT]: {
28-
command: (args) => ['-c', `codify import -p ${args}`],
29+
command: (args) => ['-c', `${ConnectOrchestrator.rootCommand} import -p ${args}`],
2930
requiresDocumentId: true,
3031
}
3132
}

src/orchestrators/connect.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Config } from '@oclif/core';
12
import cors from 'cors';
23
import express, { json } from 'express';
34
import { randomBytes } from 'node:crypto';
@@ -8,15 +9,28 @@ import router from '../connect/http-routes/router.js';
89
import { SocketServer } from '../connect/socket-server.js';
910

1011
export class ConnectOrchestrator {
11-
static async run() {
12+
static rootCommand: string;
13+
14+
static async run(oclifConfig: Config) {
15+
this.rootCommand = oclifConfig.options.root;
16+
1217
const connectionSecret = ConnectOrchestrator.tokenGenerate()
1318
const app = express();
1419

1520
app.use(cors({ origin: config.corsAllowedOrigins }))
1621
app.use(json())
1722
app.use(router);
1823

19-
const server = app.listen(config.connectServerPort, () => {
24+
const server = app.listen(config.connectServerPort, (error) => {
25+
if (error) {
26+
if (error.message.includes('EADDRINUSE')) {
27+
console.error('An instance of \'codify connect\' is already running.\n\nExiting...')
28+
return;
29+
}
30+
31+
throw error;
32+
}
33+
2034
open(`http://localhost:3000/connection/success?code=${connectionSecret}`)
2135
console.log(`Open browser window to store code.
2236

0 commit comments

Comments
 (0)