nixamp 0.5.7 → 0.5.8
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/dist/daemon.d.ts +3 -3
- package/dist/daemon.js +22 -3
- package/dist/main.js +5 -5
- package/package.json +1 -1
- package/src/daemon.ts +19 -3
- package/src/main.ts +4 -5
- package/web/dist/sw.js +1 -1
package/dist/daemon.d.ts
CHANGED
|
@@ -49,8 +49,8 @@ export declare function status(): {
|
|
|
49
49
|
/** The URL an admin client should talk to. */
|
|
50
50
|
export declare function daemonUrl(state: DaemonState): string;
|
|
51
51
|
/**
|
|
52
|
-
* What `nixamp daemon start`
|
|
53
|
-
* starting a daemon.
|
|
52
|
+
* What `nixamp daemon start` and `nixamp daemon status` print, as lines, so it
|
|
53
|
+
* can be tested without starting a daemon.
|
|
54
54
|
*
|
|
55
55
|
* Every address the server found, not one loopback link: the point of a daemon
|
|
56
56
|
* is the phone in the other room, and 127.0.0.1 is the single address that
|
|
@@ -58,7 +58,7 @@ export declare function daemonUrl(state: DaemonState): string;
|
|
|
58
58
|
* server writes that into a log file nobody reads, not to the person who just
|
|
59
59
|
* typed the command.
|
|
60
60
|
*/
|
|
61
|
-
export declare function daemonLines(state: DaemonState): string[];
|
|
61
|
+
export declare function daemonLines(state: DaemonState, uptimeMs?: number): string[];
|
|
62
62
|
/**
|
|
63
63
|
* Start one, detached, and wait until it is actually answering before saying
|
|
64
64
|
* it started. Reporting success and leaving the user to discover a crash in a
|
package/dist/daemon.js
CHANGED
|
@@ -65,8 +65,25 @@ export function daemonUrl(state) {
|
|
|
65
65
|
return `http://${host.includes(":") ? `[${host}]` : host}:${state.port}`;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
68
|
+
* How long it has been up, as a person would say it. Written here rather than
|
|
69
|
+
* borrowed from admin.ts, which would drag the whole terminal UI into a code
|
|
70
|
+
* path that only prints four lines.
|
|
71
|
+
*/
|
|
72
|
+
function spell(ms) {
|
|
73
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
74
|
+
if (seconds < 60)
|
|
75
|
+
return `${seconds}s`;
|
|
76
|
+
const minutes = Math.floor(seconds / 60);
|
|
77
|
+
if (minutes < 60)
|
|
78
|
+
return `${minutes}m ${seconds % 60}s`;
|
|
79
|
+
const hours = Math.floor(minutes / 60);
|
|
80
|
+
if (hours < 24)
|
|
81
|
+
return `${hours}h ${minutes % 60}m`;
|
|
82
|
+
return `${Math.floor(hours / 24)}d ${hours % 24}h`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* What `nixamp daemon start` and `nixamp daemon status` print, as lines, so it
|
|
86
|
+
* can be tested without starting a daemon.
|
|
70
87
|
*
|
|
71
88
|
* Every address the server found, not one loopback link: the point of a daemon
|
|
72
89
|
* is the phone in the other room, and 127.0.0.1 is the single address that
|
|
@@ -74,7 +91,7 @@ export function daemonUrl(state) {
|
|
|
74
91
|
* server writes that into a log file nobody reads, not to the person who just
|
|
75
92
|
* typed the command.
|
|
76
93
|
*/
|
|
77
|
-
export function daemonLines(state) {
|
|
94
|
+
export function daemonLines(state, uptimeMs) {
|
|
78
95
|
const link = (url) => (state.key ? `${url}/s/${state.key}` : url);
|
|
79
96
|
// A state file written by an older nixamp has no list, so host and port
|
|
80
97
|
// still stand in rather than printing nothing at all.
|
|
@@ -84,6 +101,8 @@ export function daemonLines(state) {
|
|
|
84
101
|
for (const { label, url } of addresses)
|
|
85
102
|
lines.push(` ${label.padEnd(width)} ${link(url)}`);
|
|
86
103
|
lines.push(` ${"source".padEnd(width)} ${state.source}`);
|
|
104
|
+
if (uptimeMs !== undefined)
|
|
105
|
+
lines.push(` ${"up".padEnd(width)} ${spell(uptimeMs)}`);
|
|
87
106
|
if (state.guessedPublic) {
|
|
88
107
|
lines.push("", " That internet address is this machine's router, not this port.", ` Nothing outside reaches it until ${state.port} is forwarded here.`);
|
|
89
108
|
}
|
package/dist/main.js
CHANGED
|
@@ -223,11 +223,11 @@ async function runDaemon(argv) {
|
|
|
223
223
|
console.log(`nixamp: the daemon (pid ${state.pid}) is gone. See ${state.log}`);
|
|
224
224
|
return 1;
|
|
225
225
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
226
|
+
// The same lines start prints, because the question "where is it" has the
|
|
227
|
+
// same answer however you ask it -- and printing loopback alone was the
|
|
228
|
+
// one address that cannot be handed to anybody.
|
|
229
|
+
for (const line of d.daemonLines(state, Date.now() - state.startedAt))
|
|
230
|
+
console.log(line);
|
|
231
231
|
return 0;
|
|
232
232
|
}
|
|
233
233
|
// `nixamp daemon attach` is what people try before `nixamp attach`, so it is
|
package/package.json
CHANGED
package/src/daemon.ts
CHANGED
|
@@ -100,8 +100,23 @@ export function daemonUrl(state: DaemonState): string {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
103
|
+
* How long it has been up, as a person would say it. Written here rather than
|
|
104
|
+
* borrowed from admin.ts, which would drag the whole terminal UI into a code
|
|
105
|
+
* path that only prints four lines.
|
|
106
|
+
*/
|
|
107
|
+
function spell(ms: number): string {
|
|
108
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
109
|
+
if (seconds < 60) return `${seconds}s`;
|
|
110
|
+
const minutes = Math.floor(seconds / 60);
|
|
111
|
+
if (minutes < 60) return `${minutes}m ${seconds % 60}s`;
|
|
112
|
+
const hours = Math.floor(minutes / 60);
|
|
113
|
+
if (hours < 24) return `${hours}h ${minutes % 60}m`;
|
|
114
|
+
return `${Math.floor(hours / 24)}d ${hours % 24}h`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* What `nixamp daemon start` and `nixamp daemon status` print, as lines, so it
|
|
119
|
+
* can be tested without starting a daemon.
|
|
105
120
|
*
|
|
106
121
|
* Every address the server found, not one loopback link: the point of a daemon
|
|
107
122
|
* is the phone in the other room, and 127.0.0.1 is the single address that
|
|
@@ -109,7 +124,7 @@ export function daemonUrl(state: DaemonState): string {
|
|
|
109
124
|
* server writes that into a log file nobody reads, not to the person who just
|
|
110
125
|
* typed the command.
|
|
111
126
|
*/
|
|
112
|
-
export function daemonLines(state: DaemonState): string[] {
|
|
127
|
+
export function daemonLines(state: DaemonState, uptimeMs?: number): string[] {
|
|
113
128
|
const link = (url: string): string => (state.key ? `${url}/s/${state.key}` : url);
|
|
114
129
|
// A state file written by an older nixamp has no list, so host and port
|
|
115
130
|
// still stand in rather than printing nothing at all.
|
|
@@ -119,6 +134,7 @@ export function daemonLines(state: DaemonState): string[] {
|
|
|
119
134
|
const lines = [`nixamp daemon running (pid ${state.pid})`];
|
|
120
135
|
for (const { label, url } of addresses) lines.push(` ${label.padEnd(width)} ${link(url)}`);
|
|
121
136
|
lines.push(` ${"source".padEnd(width)} ${state.source}`);
|
|
137
|
+
if (uptimeMs !== undefined) lines.push(` ${"up".padEnd(width)} ${spell(uptimeMs)}`);
|
|
122
138
|
|
|
123
139
|
if (state.guessedPublic) {
|
|
124
140
|
lines.push(
|
package/src/main.ts
CHANGED
|
@@ -252,11 +252,10 @@ async function runDaemon(argv: string[]): Promise<number> {
|
|
|
252
252
|
console.log(`nixamp: the daemon (pid ${state.pid}) is gone. See ${state.log}`);
|
|
253
253
|
return 1;
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
console.log(` up ${Math.round((Date.now() - state.startedAt) / 1000)}s`);
|
|
255
|
+
// The same lines start prints, because the question "where is it" has the
|
|
256
|
+
// same answer however you ask it -- and printing loopback alone was the
|
|
257
|
+
// one address that cannot be handed to anybody.
|
|
258
|
+
for (const line of d.daemonLines(state, Date.now() - state.startedAt)) console.log(line);
|
|
260
259
|
return 0;
|
|
261
260
|
}
|
|
262
261
|
|
package/web/dist/sw.js
CHANGED