localgate 0.4.0 → 0.6.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/README.md +91 -19
- package/logic/cli/localgateBanner.ts +9 -8
- package/logic/cli/localgateCli.ts +158 -23
- package/logic/client/localgateProxyClient.ts +9 -1
- package/logic/config/localgateAliasStore.ts +187 -0
- package/logic/config/localgateConfigReport.ts +45 -0
- package/logic/config/localgateMachineConfig.ts +7 -0
- package/logic/config/localgateNames.ts +19 -0
- package/logic/proxy/localgateAliasRoute.ts +46 -0
- package/logic/proxy/localgateControlApi.ts +18 -0
- package/logic/proxy/localgateHealth.ts +53 -15
- package/logic/proxy/localgatePortProbe.ts +42 -0
- package/logic/proxy/localgateProxy.ts +34 -1
- package/logic/proxy/localgateProxyHost.ts +52 -6
- package/logic/proxy/localgateRegistry.ts +20 -8
- package/logic/proxy/localgateStartPage.ts +491 -0
- package/logic/proxy/localgateUrl.ts +43 -0
- package/logic/run/localgateEnvRewrite.ts +28 -6
- package/logic/run/localgateNodeBootstrap.mjs +29 -0
- package/logic/run/localgateNodeOptions.ts +15 -0
- package/logic/run/localgateProcessTree.ts +122 -31
- package/logic/run/localgateRunner.ts +215 -124
- package/logic/run/localgateRunnerControl.ts +151 -0
- package/logic/run/localgateShellCommand.ts +51 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
// Runs one line from the machine's own alias file and waits for it to finish.
|
|
4
|
+
//
|
|
5
|
+
// It is a shell line on purpose - `docker stop wagtail`, `systemctl --user stop thing` - because what
|
|
6
|
+
// stops a service localgate did not start is the service owner's business, not something localgate can
|
|
7
|
+
// derive. Only the owner of `~/.localgate/aliases.json` can put a line here, and nothing that arrives
|
|
8
|
+
// over a socket ever reaches this.
|
|
9
|
+
export class LocalgateShellCommand
|
|
10
|
+
{
|
|
11
|
+
private static readonly timeoutMsConst = 25_000;
|
|
12
|
+
private static readonly outputKeptConst = 400;
|
|
13
|
+
|
|
14
|
+
// Waited on rather than fired off, so the page can say what happened. `docker stop` takes seconds,
|
|
15
|
+
// which is the wait the reader is expecting after clicking; a command that hangs past the timeout is
|
|
16
|
+
// killed and reported rather than holding the request open.
|
|
17
|
+
static run(command: string, timeoutMs: number = LocalgateShellCommand.timeoutMsConst): Promise<void>
|
|
18
|
+
{
|
|
19
|
+
return new Promise<void>((resolve, reject) =>
|
|
20
|
+
{
|
|
21
|
+
const child = spawn(command, { shell: true, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
22
|
+
let output = "";
|
|
23
|
+
const collect = (chunk: Buffer) =>
|
|
24
|
+
{
|
|
25
|
+
output = `${output}${String(chunk)}`.slice(-LocalgateShellCommand.outputKeptConst);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
child.stdout?.on("data", collect);
|
|
29
|
+
child.stderr?.on("data", collect);
|
|
30
|
+
|
|
31
|
+
const timer = setTimeout(() =>
|
|
32
|
+
{
|
|
33
|
+
child.kill();
|
|
34
|
+
reject(new Error(`${command} did not finish within ${timeoutMs / 1000} s`));
|
|
35
|
+
}, timeoutMs);
|
|
36
|
+
|
|
37
|
+
child.once("error", (error: Error) =>
|
|
38
|
+
{
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
reject(new Error(`${command} could not be started: ${error.message}`));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
child.once("close", code =>
|
|
44
|
+
{
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
if (code == 0) return resolve();
|
|
47
|
+
reject(new Error(`${command} exited with ${code}${output.trim() ? `: ${output.trim()}` : ""}`));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "localgate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Stable names for local dev servers: one port 80 multiplexed by Host, plus an API that can restart a dev server owned by your editor.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|