@hubspot/local-dev-lib 5.4.0 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/constants/ports.js
CHANGED
package/constants/projects.d.ts
CHANGED
package/constants/projects.js
CHANGED
package/lib/portManager.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { RequestPortsData, ServerPortMap } from '../types/PortManager.js';
|
|
2
|
-
export declare const BASE_URL = "http://localhost:8080";
|
|
3
2
|
export declare function isPortManagerPortAvailable(): Promise<boolean>;
|
|
4
3
|
export declare function isPortManagerServerRunning(): Promise<boolean>;
|
|
5
|
-
export declare function startPortManagerServer(): Promise<void>;
|
|
4
|
+
export declare function startPortManagerServer(port?: number): Promise<void>;
|
|
6
5
|
export declare function stopPortManagerServer(): Promise<void>;
|
|
7
6
|
export declare function requestPorts(portData: Array<RequestPortsData>): Promise<{
|
|
8
7
|
[instanceId: string]: number;
|
package/lib/portManager.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { HEALTH_CHECK_PATH, PortManagerServer, SERVICE_HEALTHY, } from '../utils/PortManagerServer.js';
|
|
3
|
-
import { PORT_MANAGER_SERVER_PORT } from '../constants/ports.js';
|
|
4
3
|
import { logger } from './logger.js';
|
|
5
|
-
export const BASE_URL = `http://localhost:${PORT_MANAGER_SERVER_PORT}`;
|
|
6
4
|
export async function isPortManagerPortAvailable() {
|
|
7
5
|
return PortManagerServer.portAvailable();
|
|
8
6
|
}
|
|
9
7
|
export async function isPortManagerServerRunning() {
|
|
10
8
|
try {
|
|
11
|
-
const { data } = await axios.get(`${
|
|
9
|
+
const { data } = await axios.get(`${PortManagerServer.baseUrl}${HEALTH_CHECK_PATH}`);
|
|
12
10
|
return data.status === SERVICE_HEALTHY;
|
|
13
11
|
}
|
|
14
12
|
catch (e) {
|
|
@@ -16,36 +14,36 @@ export async function isPortManagerServerRunning() {
|
|
|
16
14
|
return false;
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
|
-
export async function startPortManagerServer() {
|
|
17
|
+
export async function startPortManagerServer(port) {
|
|
20
18
|
const isRunning = await isPortManagerServerRunning();
|
|
21
19
|
if (!isRunning) {
|
|
22
|
-
await PortManagerServer.init();
|
|
20
|
+
await PortManagerServer.init(port);
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
export async function stopPortManagerServer() {
|
|
26
24
|
const isRunning = await isPortManagerServerRunning();
|
|
27
25
|
if (isRunning) {
|
|
28
|
-
await axios.post(`${
|
|
26
|
+
await axios.post(`${PortManagerServer.baseUrl}/close`);
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
export async function requestPorts(portData) {
|
|
32
|
-
const { data } = await axios.post(`${
|
|
30
|
+
const { data } = await axios.post(`${PortManagerServer.baseUrl}/servers`, {
|
|
33
31
|
portData: portData,
|
|
34
32
|
});
|
|
35
33
|
return data.ports;
|
|
36
34
|
}
|
|
37
35
|
export async function getActiveServers() {
|
|
38
|
-
const { data } = await axios.get(`${
|
|
36
|
+
const { data } = await axios.get(`${PortManagerServer.baseUrl}/servers`);
|
|
39
37
|
return data.servers;
|
|
40
38
|
}
|
|
41
39
|
export async function getServerPortByInstanceId(serverInstanceId) {
|
|
42
|
-
const { data } = await axios.get(`${
|
|
40
|
+
const { data } = await axios.get(`${PortManagerServer.baseUrl}/servers/${serverInstanceId}`);
|
|
43
41
|
return data.port;
|
|
44
42
|
}
|
|
45
43
|
export async function deleteServerInstance(serverInstanceId) {
|
|
46
|
-
await axios.delete(`${
|
|
44
|
+
await axios.delete(`${PortManagerServer.baseUrl}/servers/${serverInstanceId}`);
|
|
47
45
|
}
|
|
48
46
|
export async function portManagerHasActiveServers() {
|
|
49
|
-
const { data } = await axios.get(`${
|
|
47
|
+
const { data } = await axios.get(`${PortManagerServer.baseUrl}/servers`);
|
|
50
48
|
return data.count > 0;
|
|
51
49
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { Express } from 'express';
|
|
2
|
-
import { Server } from 'http';
|
|
3
|
-
import { ServerPortMap } from '../types/PortManager.js';
|
|
4
1
|
export declare const HEALTH_CHECK_PATH = "/port-manager-health-check";
|
|
5
2
|
export declare const SERVICE_HEALTHY = "OK";
|
|
6
3
|
declare class _PortManagerServer {
|
|
7
|
-
app
|
|
8
|
-
server
|
|
9
|
-
serverPortMap
|
|
4
|
+
private app?;
|
|
5
|
+
private server?;
|
|
6
|
+
private serverPortMap;
|
|
7
|
+
private port;
|
|
10
8
|
constructor();
|
|
11
|
-
|
|
9
|
+
get baseUrl(): string;
|
|
10
|
+
init(port?: number): Promise<void>;
|
|
12
11
|
private reset;
|
|
13
12
|
portAvailable(): Promise<boolean>;
|
|
14
13
|
private listen;
|
|
@@ -11,13 +11,21 @@ class _PortManagerServer {
|
|
|
11
11
|
app;
|
|
12
12
|
server;
|
|
13
13
|
serverPortMap;
|
|
14
|
+
port;
|
|
14
15
|
constructor() {
|
|
15
16
|
this.serverPortMap = {};
|
|
17
|
+
this.port = PORT_MANAGER_SERVER_PORT;
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
get baseUrl() {
|
|
20
|
+
return `http://localhost:${this.port}`;
|
|
21
|
+
}
|
|
22
|
+
async init(port) {
|
|
23
|
+
if (port) {
|
|
24
|
+
this.port = port;
|
|
25
|
+
}
|
|
18
26
|
if (!(await this.portAvailable())) {
|
|
19
27
|
throw new Error(i18n(`${i18nKey}.errors.portInUse`, {
|
|
20
|
-
port:
|
|
28
|
+
port: this.port,
|
|
21
29
|
}));
|
|
22
30
|
}
|
|
23
31
|
if (this.app) {
|
|
@@ -34,15 +42,16 @@ class _PortManagerServer {
|
|
|
34
42
|
this.app = undefined;
|
|
35
43
|
this.server = undefined;
|
|
36
44
|
this.serverPortMap = {};
|
|
45
|
+
this.port = PORT_MANAGER_SERVER_PORT;
|
|
37
46
|
}
|
|
38
47
|
async portAvailable() {
|
|
39
|
-
return (
|
|
48
|
+
return (await detectPort(this.port)) === this.port;
|
|
40
49
|
}
|
|
41
50
|
listen() {
|
|
42
51
|
return new Promise((resolve, reject) => {
|
|
43
|
-
const server = this.app.listen(
|
|
52
|
+
const server = this.app.listen(this.port, () => {
|
|
44
53
|
logger.debug(i18n(`${i18nKey}.started`, {
|
|
45
|
-
port:
|
|
54
|
+
port: this.port,
|
|
46
55
|
}));
|
|
47
56
|
resolve(server);
|
|
48
57
|
}).on('error', (err) => {
|