@my-life-buddies/cli 0.17.6 → 0.18.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 +19 -3
- package/dist/bin/buddy.js +52 -15
- package/dist/bin/buddy.js.map +3 -3
- package/dist/bin/core.js +477 -294
- package/dist/bin/core.js.map +4 -4
- package/dist/bin/preview.js +17 -3
- package/dist/bin/preview.js.map +2 -2
- package/dist/web/app.css +6 -3
- package/dist/web/app.js +47 -9
- package/package.json +3 -3
package/dist/bin/preview.js
CHANGED
|
@@ -251,7 +251,9 @@ var PreviewController = class {
|
|
|
251
251
|
simulatorSnapshot() {
|
|
252
252
|
return Object.freeze({ ...this.#simulatorState, conversationRevision: this.#conversationRevision, stateRevision: this.#simulatorRevision });
|
|
253
253
|
}
|
|
254
|
+
#closed = false;
|
|
254
255
|
start() {
|
|
256
|
+
if (this.#closed) return Promise.reject(Object.assign(new Error("\u672C\u5730\u8FDE\u63A5\u5DF2\u7ED3\u675F\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C\u8FDE\u63A5\u6307\u4EE4"), { code: "PREVIEW_CLOSED", status: 409 }));
|
|
255
257
|
if (this.#startPromise) return this.#startPromise;
|
|
256
258
|
if (this.#handle) return Promise.resolve(this.#state);
|
|
257
259
|
if (this.#state.phase === "stopping") {
|
|
@@ -351,6 +353,7 @@ var PreviewController = class {
|
|
|
351
353
|
}
|
|
352
354
|
}
|
|
353
355
|
async close() {
|
|
356
|
+
this.#closed = true;
|
|
354
357
|
await this.stop();
|
|
355
358
|
this.#listeners.clear();
|
|
356
359
|
this.#simulatorListeners.clear();
|
|
@@ -1984,6 +1987,7 @@ async function connectPreviewBridge(options) {
|
|
|
1984
1987
|
let lastContact = Date.now();
|
|
1985
1988
|
let stopping;
|
|
1986
1989
|
let interrupted = false;
|
|
1990
|
+
let disconnecting = false;
|
|
1987
1991
|
async function call(path, token, payload, requestSignal = signal) {
|
|
1988
1992
|
const response = await fetch(new URL(path, options.webUrl), {
|
|
1989
1993
|
method: "POST",
|
|
@@ -1999,6 +2003,7 @@ async function connectPreviewBridge(options) {
|
|
|
1999
2003
|
const attach = async () => {
|
|
2000
2004
|
const result = await call("api/preview/connect", await options.token(), {
|
|
2001
2005
|
connectionId,
|
|
2006
|
+
forceDisconnect: true,
|
|
2002
2007
|
buddyId: options.buddyId,
|
|
2003
2008
|
projectRoot: options.controller.projectRoot,
|
|
2004
2009
|
machineName: hostname(),
|
|
@@ -2059,12 +2064,21 @@ async function connectPreviewBridge(options) {
|
|
|
2059
2064
|
watchdog.unref();
|
|
2060
2065
|
async function execute(command) {
|
|
2061
2066
|
try {
|
|
2067
|
+
if (command.path === "/api/connection/disconnect" && command.method === "POST") {
|
|
2068
|
+
disconnecting = true;
|
|
2069
|
+
await options.controller.close();
|
|
2070
|
+
await options.stopLocalDev?.();
|
|
2071
|
+
replies.set(command.id, { id: command.id, status: 200, contentType: "application/json", body: Buffer.from(JSON.stringify({ localStopped: Boolean(options.stopLocalDev) })).toString("base64") });
|
|
2072
|
+
options.onStatus?.("\u540E\u53F0\u5DF2\u8BF7\u6C42\u5F3A\u5236\u65AD\u8FDE\uFF0C\u5F53\u524D\u5DE5\u7A0B DEV \u5DF2\u505C\u6B62\u3002\u9700\u8981\u8C03\u8BD5\u65F6\u91CD\u65B0\u6267\u884C\u8FDE\u63A5\u6307\u4EE4\u3002");
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
if (disconnecting) throw new Error("\u6B63\u5728\u65AD\u5F00\u8FDE\u63A5");
|
|
2062
2076
|
if (!command.path.startsWith("/api/") || command.path === "/api/events" || command.path.includes("..")) throw new Error("\u8C03\u8BD5\u8DEF\u5F84\u65E0\u6548");
|
|
2063
2077
|
const target = new URL(command.path, options.localServer.origin);
|
|
2064
2078
|
if (target.origin !== options.localServer.origin.origin) throw new Error("\u8C03\u8BD5\u8DEF\u5F84\u65E0\u6548");
|
|
2065
2079
|
if ((await options.controller.project()).buddyId !== options.buddyId) throw new Error("\u5DE5\u7A0B buddyId \u5DF2\u6539\u53D8\uFF0C\u8BF7\u9000\u51FA CLI \u540E\u91CD\u65B0\u8FDE\u63A5\u5BF9\u5E94\u642D\u5B50");
|
|
2066
2080
|
signal.throwIfAborted();
|
|
2067
|
-
if (interrupted) throw new Error("\u672C\u5730\u8FDE\u63A5\u5DF2\u4E2D\u65AD");
|
|
2081
|
+
if (interrupted || disconnecting) throw new Error("\u672C\u5730\u8FDE\u63A5\u5DF2\u4E2D\u65AD");
|
|
2068
2082
|
const response = await fetch(target, {
|
|
2069
2083
|
method: command.method,
|
|
2070
2084
|
redirect: "error",
|
|
@@ -2121,8 +2135,8 @@ async function connectPreviewBridge(options) {
|
|
|
2121
2135
|
const status = cause.status;
|
|
2122
2136
|
if (status === 410) {
|
|
2123
2137
|
await options.controller.stop();
|
|
2124
|
-
|
|
2125
|
-
|
|
2138
|
+
options.onStatus?.("\u540E\u53F0\u8FDE\u63A5\u5DF2\u7ED3\u675F\uFF1B\u8BF7\u91CD\u65B0\u6267\u884C\u8FDE\u63A5\u6307\u4EE4\u3002\u672A\u81EA\u52A8\u91CD\u65B0\u8FDE\u63A5\u6216\u542F\u52A8 DEV\u3002");
|
|
2139
|
+
break;
|
|
2126
2140
|
} else if (status && status >= 400 && status < 500 && status !== 429) throw cause;
|
|
2127
2141
|
}
|
|
2128
2142
|
await delay(replies.size ? 20 : 500, void 0, { signal }).catch(() => void 0);
|