pixifact-cli 0.5.0 → 0.6.1
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 +27 -2
- package/editor/assets/browserAll-DePxC4RK.js +1 -0
- package/editor/assets/{index-CVrKIfXK.css → index-D3t5XxiB.css} +1 -1
- package/editor/assets/index-DoPhYWF1.js +1130 -0
- package/editor/assets/init-CuKNsO_k.js +1 -0
- package/editor/assets/webworkerAll-DM9kdU0t.js +1 -0
- package/editor/index.html +2 -2
- package/package.json +2 -2
- package/src/automation.ts +2 -3
- package/src/editorSession.ts +211 -4
- package/src/pixifact-cli.ts +143 -1
- package/src/runtimeSession.ts +133 -0
- package/editor/assets/browserAll-CdyZj0BN.js +0 -1
- package/editor/assets/index-CAe9Mkmr.js +0 -1130
- package/editor/assets/init-C32NAhsC.js +0 -1
- package/editor/assets/webworkerAll-BEmxAAYf.js +0 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findActiveRuntimeSession,
|
|
3
|
+
type RuntimeSessionDescriptor,
|
|
4
|
+
} from 'pixifact/compiler-node';
|
|
5
|
+
import type { RuntimePageDescriptor, RuntimeRequest } from 'pixifact/runtime-dev';
|
|
6
|
+
|
|
7
|
+
interface RuntimeSessionLookupOptions {
|
|
8
|
+
projectRoot: string;
|
|
9
|
+
sessionsRoot?: string;
|
|
10
|
+
fetch?: typeof fetch;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface RuntimeQueryOptions extends RuntimeSessionLookupOptions {
|
|
14
|
+
runtimeId?: string;
|
|
15
|
+
request: RuntimeRequest;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type RuntimeListResult =
|
|
19
|
+
| { ok: true; runtimes: Array<RuntimePageDescriptor & { connectedAt: string }> }
|
|
20
|
+
| { ok: false; error: string; [key: string]: unknown };
|
|
21
|
+
|
|
22
|
+
async function activeDescriptor(options: RuntimeSessionLookupOptions) {
|
|
23
|
+
const descriptor = await findActiveRuntimeSession(options);
|
|
24
|
+
if (!descriptor) {
|
|
25
|
+
return {
|
|
26
|
+
ok: false as const,
|
|
27
|
+
error: 'No Pixifact Runtime Vite server is running for this project.',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return { ok: true as const, descriptor };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function runtimeHostFetch(
|
|
34
|
+
descriptor: RuntimeSessionDescriptor,
|
|
35
|
+
pathname: string,
|
|
36
|
+
fetcher: typeof fetch,
|
|
37
|
+
init: RequestInit = {},
|
|
38
|
+
) {
|
|
39
|
+
try {
|
|
40
|
+
const response = await fetcher(`${descriptor.origin}/__pixifact_runtime__/${pathname}`, {
|
|
41
|
+
...init,
|
|
42
|
+
headers: {
|
|
43
|
+
authorization: `Bearer ${descriptor.token}`,
|
|
44
|
+
...init.headers,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
return await response.json() as Record<string, unknown>;
|
|
48
|
+
} catch {
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
error: 'Pixifact Runtime Vite server is not reachable for this project.',
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function queryRuntimeList(
|
|
57
|
+
options: RuntimeSessionLookupOptions,
|
|
58
|
+
): Promise<RuntimeListResult> {
|
|
59
|
+
const active = await activeDescriptor(options);
|
|
60
|
+
if (!active.ok) return active;
|
|
61
|
+
const result = await runtimeHostFetch(active.descriptor, 'list', options.fetch ?? fetch);
|
|
62
|
+
if (
|
|
63
|
+
result.ok !== true
|
|
64
|
+
|| !Array.isArray(result.runtimes)
|
|
65
|
+
|| !result.runtimes.every((runtime) => (
|
|
66
|
+
typeof runtime === 'object'
|
|
67
|
+
&& runtime !== null
|
|
68
|
+
&& typeof runtime.runtimeId === 'string'
|
|
69
|
+
&& typeof runtime.url === 'string'
|
|
70
|
+
&& typeof runtime.title === 'string'
|
|
71
|
+
&& typeof runtime.ready === 'boolean'
|
|
72
|
+
&& typeof runtime.connectedAt === 'string'
|
|
73
|
+
))
|
|
74
|
+
) {
|
|
75
|
+
return result.ok === false && typeof result.error === 'string'
|
|
76
|
+
? result as RuntimeListResult
|
|
77
|
+
: {
|
|
78
|
+
ok: false,
|
|
79
|
+
error: 'Pixifact Runtime Vite server returned an invalid runtime list.',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return result as RuntimeListResult;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function selectRuntime(
|
|
86
|
+
runtimes: Array<RuntimePageDescriptor & { connectedAt: string }>,
|
|
87
|
+
runtimeId: string | undefined,
|
|
88
|
+
) {
|
|
89
|
+
if (runtimeId) {
|
|
90
|
+
const selected = runtimes.find((runtime) => runtime.runtimeId === runtimeId);
|
|
91
|
+
return selected
|
|
92
|
+
? { ok: true as const, runtime: selected }
|
|
93
|
+
: {
|
|
94
|
+
ok: false as const,
|
|
95
|
+
error: `Pixifact Runtime "${runtimeId}" is not connected.`,
|
|
96
|
+
runtimes,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (runtimes.length === 0) {
|
|
100
|
+
return {
|
|
101
|
+
ok: false as const,
|
|
102
|
+
error: 'No Pixifact Runtime game page is connected for this project.',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (runtimes.length > 1) {
|
|
106
|
+
return {
|
|
107
|
+
ok: false as const,
|
|
108
|
+
error: 'Multiple Pixifact Runtime game pages are connected. Use --runtime <runtime-id>.',
|
|
109
|
+
runtimes,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return { ok: true as const, runtime: runtimes[0] };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function queryRuntime(options: RuntimeQueryOptions) {
|
|
116
|
+
const active = await activeDescriptor(options);
|
|
117
|
+
if (!active.ok) return active;
|
|
118
|
+
const listed = await runtimeHostFetch(active.descriptor, 'list', options.fetch ?? fetch);
|
|
119
|
+
if (listed.ok !== true || !Array.isArray(listed.runtimes)) return listed;
|
|
120
|
+
const selected = selectRuntime(
|
|
121
|
+
listed.runtimes as Array<RuntimePageDescriptor & { connectedAt: string }>,
|
|
122
|
+
options.runtimeId,
|
|
123
|
+
);
|
|
124
|
+
if (!selected.ok) return selected;
|
|
125
|
+
return runtimeHostFetch(active.descriptor, 'request', options.fetch ?? fetch, {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
headers: { 'content-type': 'application/json' },
|
|
128
|
+
body: JSON.stringify({
|
|
129
|
+
runtimeId: selected.runtime.runtimeId,
|
|
130
|
+
request: options.request,
|
|
131
|
+
}),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,c as t,i as n,l as r,o as i,s as a,u as o}from"./index-CAe9Mkmr.js";import"./init-C32NAhsC.js";o.add(t),o.mixin(r,a),o.add(i),o.add(e),o.mixin(r,n);
|