@vlandoss/localproxy 0.0.3 → 0.0.4
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/package.json
CHANGED
package/src/commands/clean.ts
CHANGED
|
@@ -14,15 +14,17 @@ export function createCleanCommand({ caddyfilePath }: Context) {
|
|
|
14
14
|
.description("clean up config files")
|
|
15
15
|
.option("--verbose", "verbose mode, show background output", false)
|
|
16
16
|
.action(async function cleanAction(options: CommandOptions) {
|
|
17
|
+
const { verbose } = options;
|
|
18
|
+
|
|
17
19
|
const caddyService = new CaddyService(caddyfilePath);
|
|
18
|
-
await caddyService.stop(
|
|
20
|
+
await caddyService.stop({ verbose });
|
|
19
21
|
|
|
20
22
|
const caddyfileService = new CaddyfileService(caddyfilePath);
|
|
21
23
|
const localDomains = await caddyfileService.getLocalDomains();
|
|
22
|
-
const
|
|
24
|
+
const hostnames = localDomains.map((d) => d.hostname);
|
|
23
25
|
|
|
24
|
-
const hostsService = new HostsService(
|
|
25
|
-
await hostsService.clean(
|
|
26
|
+
const hostsService = new HostsService();
|
|
27
|
+
await hostsService.clean({ verbose, hostnames });
|
|
26
28
|
|
|
27
29
|
logger.success("Clean completed!");
|
|
28
30
|
});
|
package/src/commands/setup.ts
CHANGED
|
@@ -47,7 +47,7 @@ export function createSetupCommand({ binDir, installDir, caddyfilePath }: Contex
|
|
|
47
47
|
.description("setup config files")
|
|
48
48
|
.option("--verbose", "verbose mode, show background output", false)
|
|
49
49
|
.action(async function setupAction(options: CommandOptions) {
|
|
50
|
-
|
|
50
|
+
const { verbose } = options;
|
|
51
51
|
|
|
52
52
|
await checkInternalTools();
|
|
53
53
|
|
|
@@ -71,15 +71,14 @@ export function createSetupCommand({ binDir, installDir, caddyfilePath }: Contex
|
|
|
71
71
|
await fileService.print();
|
|
72
72
|
|
|
73
73
|
const caddyService = new CaddyService(caddyfilePath);
|
|
74
|
-
await caddyService.reboot(
|
|
74
|
+
await caddyService.reboot({ verbose });
|
|
75
75
|
|
|
76
76
|
const caddyfileService = new CaddyfileService(caddyfilePath);
|
|
77
|
-
|
|
78
77
|
const localDomains = await caddyfileService.getLocalDomains();
|
|
79
|
-
const
|
|
78
|
+
const hostnames = localDomains.map((d) => d.hostname);
|
|
80
79
|
|
|
81
|
-
const hostsService = new HostsService(
|
|
82
|
-
await hostsService.setup(
|
|
80
|
+
const hostsService = new HostsService();
|
|
81
|
+
await hostsService.setup({ verbose, hostnames });
|
|
83
82
|
|
|
84
83
|
logger.success("Setup completed!");
|
|
85
84
|
});
|
package/src/commands/status.ts
CHANGED
|
@@ -23,21 +23,19 @@ export function createStatusCommand({ caddyfilePath }: Context) {
|
|
|
23
23
|
|
|
24
24
|
const caddyfileService = new CaddyfileService(caddyfilePath);
|
|
25
25
|
const localDomains = await caddyfileService.getLocalDomains();
|
|
26
|
-
const hosts = localDomains.map((d) => d.host);
|
|
27
26
|
|
|
28
|
-
const hostsService = new HostsService(
|
|
27
|
+
const hostsService = new HostsService();
|
|
28
|
+
const enabledHosts = await hostsService.getEnabledHosts();
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const found = await hostsService.findHost(host);
|
|
30
|
+
localDomains.forEach(({ hostname, ports }) => {
|
|
31
|
+
const enabled = enabledHosts.some((h) => h.hostname === hostname);
|
|
34
32
|
const formattedPorts = ports.map((p) => `:${p}`).join(", ");
|
|
35
33
|
|
|
36
|
-
if (
|
|
37
|
-
logger.success("`%s` is configured -> %s",
|
|
34
|
+
if (enabled) {
|
|
35
|
+
logger.success("`%s` is configured -> %s", hostname, formattedPorts);
|
|
38
36
|
} else {
|
|
39
|
-
logger.warn("`%s` is not configured -> %s",
|
|
37
|
+
logger.warn("`%s` is not configured -> %s", hostname, formattedPorts);
|
|
40
38
|
}
|
|
41
|
-
}
|
|
39
|
+
});
|
|
42
40
|
});
|
|
43
41
|
}
|
|
@@ -5,7 +5,7 @@ import { CaddyfileParser } from "./parser";
|
|
|
5
5
|
const debug = logger.subdebug("caddyfile-service");
|
|
6
6
|
|
|
7
7
|
export type LocalDomain = {
|
|
8
|
-
|
|
8
|
+
hostname: string;
|
|
9
9
|
ports: string[];
|
|
10
10
|
};
|
|
11
11
|
|
|
@@ -33,7 +33,7 @@ export class CaddyfileService {
|
|
|
33
33
|
.map((arg) => arg.split(":")[1] as string);
|
|
34
34
|
|
|
35
35
|
return block.sites.map((site) => {
|
|
36
|
-
return {
|
|
36
|
+
return { hostname: site, ports };
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
|
package/src/services/hosts.ts
CHANGED
|
@@ -4,16 +4,20 @@ import { SudoService } from "./sudo";
|
|
|
4
4
|
|
|
5
5
|
type SetupOptions = {
|
|
6
6
|
verbose: boolean;
|
|
7
|
+
hostnames: string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type Host = {
|
|
11
|
+
ip: string;
|
|
12
|
+
hostname: string;
|
|
7
13
|
};
|
|
8
14
|
|
|
9
15
|
const debug = logger.subdebug("hosts");
|
|
10
16
|
|
|
11
17
|
export class HostsService {
|
|
12
|
-
#hosts: string[];
|
|
13
18
|
#sudo: SudoService;
|
|
14
19
|
|
|
15
|
-
constructor(
|
|
16
|
-
this.#hosts = domains;
|
|
20
|
+
constructor() {
|
|
17
21
|
this.#sudo = new SudoService();
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -22,6 +26,8 @@ export class HostsService {
|
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
async setup(options: SetupOptions) {
|
|
29
|
+
const { hostnames } = options;
|
|
30
|
+
|
|
25
31
|
logger.start("Setting up hosts");
|
|
26
32
|
|
|
27
33
|
await this.#sudo.auth();
|
|
@@ -30,7 +36,7 @@ export class HostsService {
|
|
|
30
36
|
|
|
31
37
|
await $`sudo hosts backups create`;
|
|
32
38
|
|
|
33
|
-
for (const host of
|
|
39
|
+
for (const host of hostnames) {
|
|
34
40
|
await this.addHost(host, options);
|
|
35
41
|
}
|
|
36
42
|
|
|
@@ -38,9 +44,11 @@ export class HostsService {
|
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
async clean(options: SetupOptions) {
|
|
47
|
+
const { hostnames } = options;
|
|
48
|
+
|
|
41
49
|
await this.#sudo.auth();
|
|
42
50
|
|
|
43
|
-
for (const host of
|
|
51
|
+
for (const host of hostnames) {
|
|
44
52
|
await this.removeHost(host, options);
|
|
45
53
|
}
|
|
46
54
|
}
|
|
@@ -71,4 +79,23 @@ export class HostsService {
|
|
|
71
79
|
await $`sudo hosts remove ${host}`;
|
|
72
80
|
}
|
|
73
81
|
}
|
|
82
|
+
|
|
83
|
+
async getEnabledHosts(): Promise<Host[]> {
|
|
84
|
+
const output = await quietShell.$`hosts list enabled`.text();
|
|
85
|
+
|
|
86
|
+
const hosts = output
|
|
87
|
+
.split("\n")
|
|
88
|
+
.map((line) => {
|
|
89
|
+
const [ip, hostname] = line.split(/\s+/);
|
|
90
|
+
|
|
91
|
+
if (!ip || !hostname) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { ip, hostname };
|
|
96
|
+
})
|
|
97
|
+
.filter(Boolean);
|
|
98
|
+
|
|
99
|
+
return hosts as Host[];
|
|
100
|
+
}
|
|
74
101
|
}
|