@air-jam/server 0.1.4 → 0.9.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/LICENSE +21 -0
- package/bin/air-jam-server.mjs +49 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/chunk-5ZVGSYXC.js +252 -0
- package/dist/chunk-5ZVGSYXC.js.map +1 -0
- package/dist/chunk-RM7AMBDY.js +831 -0
- package/dist/chunk-RM7AMBDY.js.map +1 -0
- package/dist/cli.js +513 -5
- package/dist/cli.js.map +1 -1
- package/dist/game-dev-D3TEAHOD.js +422 -0
- package/dist/game-dev-D3TEAHOD.js.map +1 -0
- package/dist/index.js +5978 -1
- package/dist/index.js.map +1 -1
- package/dist/local-dev-state-QT7H5GUA.js +270 -0
- package/dist/local-dev-state-QT7H5GUA.js.map +1 -0
- package/dist/secure-dev-HMOGLYVC.js +39 -0
- package/dist/secure-dev-HMOGLYVC.js.map +1 -0
- package/dist/topology-PM3PI753.js +140 -0
- package/dist/topology-PM3PI753.js.map +1 -0
- package/package.json +33 -12
- package/src/project-cli/vite-config.d.mts +17 -0
- package/src/project-cli/vite-config.mjs +121 -0
- package/src/project-cli/vite-https.d.mts +14 -0
- package/src/project-cli/vite-https.mjs +39 -0
- package/dist/chunk-CGONPUNG.js +0 -1141
- package/dist/chunk-CGONPUNG.js.map +0 -1
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// src/project-cli/local-dev-state.mjs
|
|
2
|
+
import { spawnSync } from "child_process";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
var DEVTOOLS_SCHEMA_VERSION = 1;
|
|
7
|
+
var KNOWN_LOCAL_DEV_PORTS = [4e3, 5173];
|
|
8
|
+
var KNOWN_PORTS_ENV = "AIRJAM_DEVTOOLS_KNOWN_PORTS";
|
|
9
|
+
var isProcessAlive = (pid) => {
|
|
10
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
process.kill(pid, 0);
|
|
15
|
+
return true;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var runCommandResult = ({ command, args, cwd }) => {
|
|
21
|
+
const result = spawnSync(command, args, {
|
|
22
|
+
cwd,
|
|
23
|
+
encoding: "utf8",
|
|
24
|
+
env: {
|
|
25
|
+
...process.env,
|
|
26
|
+
CI: process.env.CI ?? "1",
|
|
27
|
+
NO_UPDATE_NOTIFIER: "1"
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const exitCode = result.status ?? null;
|
|
31
|
+
return {
|
|
32
|
+
exitCode,
|
|
33
|
+
ok: exitCode === 0 && !result.error,
|
|
34
|
+
stdout: result.stdout ?? "",
|
|
35
|
+
stderr: result.stderr ?? (result.error instanceof Error ? result.error.message : "")
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
var readCommandOutput = (command, args, cwd) => {
|
|
39
|
+
try {
|
|
40
|
+
return runCommandResult({ command, args, cwd }).stdout.trim();
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var readListeningPidsForPort = (port, cwd) => {
|
|
46
|
+
const output = readCommandOutput(
|
|
47
|
+
"lsof",
|
|
48
|
+
["-nP", `-tiTCP:${port}`, "-sTCP:LISTEN"],
|
|
49
|
+
cwd
|
|
50
|
+
);
|
|
51
|
+
if (!output) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
return output.split(/\r?\n/).map((value) => Number.parseInt(value.trim(), 10)).filter((value) => Number.isInteger(value) && value > 0);
|
|
55
|
+
};
|
|
56
|
+
var readProcessCommand = (pid, cwd) => {
|
|
57
|
+
const output = readCommandOutput(
|
|
58
|
+
"ps",
|
|
59
|
+
["-p", String(pid), "-o", "command="],
|
|
60
|
+
cwd
|
|
61
|
+
);
|
|
62
|
+
return output && output.length > 0 ? output : null;
|
|
63
|
+
};
|
|
64
|
+
var readProcessAgeMs = (pid, cwd) => {
|
|
65
|
+
const output = readCommandOutput(
|
|
66
|
+
"ps",
|
|
67
|
+
["-p", String(pid), "-o", "etimes="],
|
|
68
|
+
cwd
|
|
69
|
+
);
|
|
70
|
+
const seconds = output ? Number.parseInt(output.trim(), 10) : Number.NaN;
|
|
71
|
+
return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : null;
|
|
72
|
+
};
|
|
73
|
+
var getKnownLocalDevPorts = () => {
|
|
74
|
+
const rawPorts = process.env[KNOWN_PORTS_ENV];
|
|
75
|
+
if (!rawPorts) {
|
|
76
|
+
return [...KNOWN_LOCAL_DEV_PORTS];
|
|
77
|
+
}
|
|
78
|
+
const ports = rawPorts.split(",").map((value) => Number.parseInt(value.trim(), 10)).filter((value) => Number.isInteger(value) && value > 0);
|
|
79
|
+
return ports.length > 0 ? Array.from(new Set(ports)) : [...KNOWN_LOCAL_DEV_PORTS];
|
|
80
|
+
};
|
|
81
|
+
var isLikelyAirJamLocalDevCommand = (command) => {
|
|
82
|
+
if (!command) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return /(^|\W)(@air-jam\/server|air-jam-server|airjam|vite|create-airjam|workspace-runtime-cli)(\W|$)/.test(
|
|
86
|
+
command
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
var listKnownPortListeners = (cwd) => {
|
|
90
|
+
const byPid = /* @__PURE__ */ new Map();
|
|
91
|
+
for (const port of getKnownLocalDevPorts()) {
|
|
92
|
+
for (const pid of readListeningPidsForPort(port, cwd)) {
|
|
93
|
+
const ports = byPid.get(pid) ?? /* @__PURE__ */ new Set();
|
|
94
|
+
ports.add(port);
|
|
95
|
+
byPid.set(pid, ports);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return Array.from(byPid.entries()).map(([pid, ports]) => {
|
|
99
|
+
const ageMs = readProcessAgeMs(pid, cwd);
|
|
100
|
+
return {
|
|
101
|
+
pid,
|
|
102
|
+
ports: Array.from(ports).sort((left, right) => left - right),
|
|
103
|
+
command: readProcessCommand(pid, cwd),
|
|
104
|
+
startedAt: ageMs !== null ? new Date(Date.now() - ageMs).toISOString() : null,
|
|
105
|
+
ageMs,
|
|
106
|
+
managed: false
|
|
107
|
+
};
|
|
108
|
+
}).sort((left, right) => left.pid - right.pid);
|
|
109
|
+
};
|
|
110
|
+
var killManagedProcess = (pid) => {
|
|
111
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
if (process.platform !== "win32") {
|
|
116
|
+
process.kill(-pid, "SIGTERM");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
} catch {
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
process.kill(pid, "SIGTERM");
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var pathExists = async (targetPath) => existsSync(targetPath);
|
|
127
|
+
var readPackageJson = async (rootDir) => {
|
|
128
|
+
const packageJsonPath = path.join(rootDir, "package.json");
|
|
129
|
+
if (!await pathExists(packageJsonPath)) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
133
|
+
};
|
|
134
|
+
var isMonorepoRoot = async (rootDir, packageJson) => {
|
|
135
|
+
if (packageJson?.name !== "air-jam") {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return await pathExists(path.join(rootDir, "scripts", "repo", "cli.mjs")) && await pathExists(path.join(rootDir, "packages", "sdk")) && await pathExists(path.join(rootDir, "packages", "create-airjam"));
|
|
139
|
+
};
|
|
140
|
+
var findProjectRoot = async (cwd) => {
|
|
141
|
+
let currentDir = path.resolve(cwd);
|
|
142
|
+
while (true) {
|
|
143
|
+
const packageJson = await readPackageJson(currentDir);
|
|
144
|
+
if (await isMonorepoRoot(currentDir, packageJson)) {
|
|
145
|
+
return currentDir;
|
|
146
|
+
}
|
|
147
|
+
if (packageJson) {
|
|
148
|
+
return currentDir;
|
|
149
|
+
}
|
|
150
|
+
const parentDir = path.dirname(currentDir);
|
|
151
|
+
if (parentDir === currentDir) {
|
|
152
|
+
return path.resolve(cwd);
|
|
153
|
+
}
|
|
154
|
+
currentDir = parentDir;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var getDevtoolsRoot = (rootDir) => path.join(rootDir, ".airjam", "devtools");
|
|
158
|
+
var getManagedRegistryPath = (rootDir) => path.join(getDevtoolsRoot(rootDir), "managed-processes.json");
|
|
159
|
+
var readRegistry = async (rootDir) => {
|
|
160
|
+
const registryPath = getManagedRegistryPath(rootDir);
|
|
161
|
+
if (!await pathExists(registryPath)) {
|
|
162
|
+
return {
|
|
163
|
+
schemaVersion: DEVTOOLS_SCHEMA_VERSION,
|
|
164
|
+
processes: []
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const parsed = JSON.parse(await readFile(registryPath, "utf8"));
|
|
168
|
+
return {
|
|
169
|
+
schemaVersion: DEVTOOLS_SCHEMA_VERSION,
|
|
170
|
+
processes: Array.isArray(parsed.processes) ? parsed.processes : []
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
var writeRegistry = async (rootDir, registry) => {
|
|
174
|
+
const registryPath = getManagedRegistryPath(rootDir);
|
|
175
|
+
await mkdir(path.dirname(registryPath), { recursive: true });
|
|
176
|
+
await writeFile(registryPath, `${JSON.stringify(registry, null, 2)}
|
|
177
|
+
`, "utf8");
|
|
178
|
+
};
|
|
179
|
+
var listManagedProcessesForRoot = async (rootDir) => {
|
|
180
|
+
const registry = await readRegistry(rootDir);
|
|
181
|
+
const aliveProcesses = registry.processes.filter(
|
|
182
|
+
(processInfo) => isProcessAlive(processInfo.pid)
|
|
183
|
+
);
|
|
184
|
+
if (aliveProcesses.length !== registry.processes.length) {
|
|
185
|
+
await writeRegistry(rootDir, {
|
|
186
|
+
schemaVersion: DEVTOOLS_SCHEMA_VERSION,
|
|
187
|
+
processes: aliveProcesses
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return aliveProcesses.sort(
|
|
191
|
+
(left, right) => left.startedAt.localeCompare(right.startedAt)
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
var stopDev = async ({ cwd, processId, mode } = {}) => {
|
|
195
|
+
const rootDir = await findProjectRoot(cwd ?? process.cwd());
|
|
196
|
+
const processes = await listManagedProcessesForRoot(rootDir);
|
|
197
|
+
const selected = processes.filter((processInfo) => {
|
|
198
|
+
if (processId) {
|
|
199
|
+
return processInfo.id === processId;
|
|
200
|
+
}
|
|
201
|
+
if (mode) {
|
|
202
|
+
return processInfo.mode === mode;
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
});
|
|
206
|
+
for (const processInfo of selected) {
|
|
207
|
+
killManagedProcess(processInfo.pid);
|
|
208
|
+
}
|
|
209
|
+
const remaining = processes.filter(
|
|
210
|
+
(processInfo) => !selected.some(
|
|
211
|
+
(selectedProcess) => selectedProcess.id === processInfo.id
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
await writeRegistry(rootDir, {
|
|
215
|
+
schemaVersion: DEVTOOLS_SCHEMA_VERSION,
|
|
216
|
+
processes: remaining
|
|
217
|
+
});
|
|
218
|
+
return {
|
|
219
|
+
rootDir,
|
|
220
|
+
stopped: selected
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
var getDevStatus = async ({ cwd = process.cwd() } = {}) => {
|
|
224
|
+
const rootDir = await findProjectRoot(cwd);
|
|
225
|
+
const managedProcesses = await listManagedProcessesForRoot(rootDir);
|
|
226
|
+
const managedPids = new Set(managedProcesses.map((entry) => entry.pid));
|
|
227
|
+
return {
|
|
228
|
+
processes: managedProcesses,
|
|
229
|
+
unmanagedProcesses: listKnownPortListeners(rootDir).filter(
|
|
230
|
+
(entry) => !managedPids.has(entry.pid)
|
|
231
|
+
),
|
|
232
|
+
knownPorts: getKnownLocalDevPorts()
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
var resetLocalDev = async ({ cwd = process.cwd() } = {}) => {
|
|
236
|
+
const { rootDir, stopped: stoppedManaged } = await stopDev({ cwd });
|
|
237
|
+
const managedPids = new Set(stoppedManaged.map((entry) => entry.pid));
|
|
238
|
+
const unmanaged = listKnownPortListeners(rootDir).filter(
|
|
239
|
+
(entry) => !managedPids.has(entry.pid)
|
|
240
|
+
);
|
|
241
|
+
const stoppedUnmanaged = [];
|
|
242
|
+
for (const processInfo of unmanaged) {
|
|
243
|
+
if (!isLikelyAirJamLocalDevCommand(processInfo.command)) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
killManagedProcess(processInfo.pid);
|
|
247
|
+
stoppedUnmanaged.push(processInfo);
|
|
248
|
+
}
|
|
249
|
+
await rm(path.join(rootDir, ".airjam", "preview-managed-server.json"), {
|
|
250
|
+
force: true
|
|
251
|
+
}).catch(() => void 0);
|
|
252
|
+
const stoppedPids = /* @__PURE__ */ new Set([
|
|
253
|
+
...stoppedManaged.map((entry) => entry.pid),
|
|
254
|
+
...stoppedUnmanaged.map((entry) => entry.pid)
|
|
255
|
+
]);
|
|
256
|
+
const remainingUnmanaged = listKnownPortListeners(rootDir).filter(
|
|
257
|
+
(entry) => !stoppedPids.has(entry.pid)
|
|
258
|
+
);
|
|
259
|
+
return {
|
|
260
|
+
stoppedManaged,
|
|
261
|
+
stoppedUnmanaged,
|
|
262
|
+
remainingUnmanaged,
|
|
263
|
+
knownPorts: getKnownLocalDevPorts()
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
export {
|
|
267
|
+
getDevStatus,
|
|
268
|
+
resetLocalDev
|
|
269
|
+
};
|
|
270
|
+
//# sourceMappingURL=local-dev-state-QT7H5GUA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/project-cli/local-dev-state.mjs"],"sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\n\nconst DEVTOOLS_SCHEMA_VERSION = 1;\nconst KNOWN_LOCAL_DEV_PORTS = [4000, 5173];\nconst KNOWN_PORTS_ENV = \"AIRJAM_DEVTOOLS_KNOWN_PORTS\";\n\nconst isProcessAlive = (pid) => {\n if (!Number.isInteger(pid) || pid <= 0) {\n return false;\n }\n\n try {\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n};\n\nconst runCommandResult = ({ command, args, cwd }) => {\n const result = spawnSync(command, args, {\n cwd,\n encoding: \"utf8\",\n env: {\n ...process.env,\n CI: process.env.CI ?? \"1\",\n NO_UPDATE_NOTIFIER: \"1\",\n },\n });\n\n const exitCode = result.status ?? null;\n return {\n exitCode,\n ok: exitCode === 0 && !result.error,\n stdout: result.stdout ?? \"\",\n stderr:\n result.stderr ??\n (result.error instanceof Error ? result.error.message : \"\"),\n };\n};\n\nconst readCommandOutput = (command, args, cwd) => {\n try {\n return runCommandResult({ command, args, cwd }).stdout.trim();\n } catch {\n return null;\n }\n};\n\nconst readListeningPidsForPort = (port, cwd) => {\n const output = readCommandOutput(\n \"lsof\",\n [\"-nP\", `-tiTCP:${port}`, \"-sTCP:LISTEN\"],\n cwd,\n );\n if (!output) {\n return [];\n }\n\n return output\n .split(/\\r?\\n/)\n .map((value) => Number.parseInt(value.trim(), 10))\n .filter((value) => Number.isInteger(value) && value > 0);\n};\n\nconst readProcessCommand = (pid, cwd) => {\n const output = readCommandOutput(\n \"ps\",\n [\"-p\", String(pid), \"-o\", \"command=\"],\n cwd,\n );\n return output && output.length > 0 ? output : null;\n};\n\nconst readProcessAgeMs = (pid, cwd) => {\n const output = readCommandOutput(\n \"ps\",\n [\"-p\", String(pid), \"-o\", \"etimes=\"],\n cwd,\n );\n const seconds = output ? Number.parseInt(output.trim(), 10) : Number.NaN;\n return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1000 : null;\n};\n\nconst getKnownLocalDevPorts = () => {\n const rawPorts = process.env[KNOWN_PORTS_ENV];\n if (!rawPorts) {\n return [...KNOWN_LOCAL_DEV_PORTS];\n }\n\n const ports = rawPorts\n .split(\",\")\n .map((value) => Number.parseInt(value.trim(), 10))\n .filter((value) => Number.isInteger(value) && value > 0);\n\n return ports.length > 0 ? Array.from(new Set(ports)) : [...KNOWN_LOCAL_DEV_PORTS];\n};\n\nconst isLikelyAirJamLocalDevCommand = (command) => {\n if (!command) {\n return false;\n }\n\n return /(^|\\W)(@air-jam\\/server|air-jam-server|airjam|vite|create-airjam|workspace-runtime-cli)(\\W|$)/.test(\n command,\n );\n};\n\nconst listKnownPortListeners = (cwd) => {\n const byPid = new Map();\n\n for (const port of getKnownLocalDevPorts()) {\n for (const pid of readListeningPidsForPort(port, cwd)) {\n const ports = byPid.get(pid) ?? new Set();\n ports.add(port);\n byPid.set(pid, ports);\n }\n }\n\n return Array.from(byPid.entries())\n .map(([pid, ports]) => {\n const ageMs = readProcessAgeMs(pid, cwd);\n return {\n pid,\n ports: Array.from(ports).sort((left, right) => left - right),\n command: readProcessCommand(pid, cwd),\n startedAt:\n ageMs !== null ? new Date(Date.now() - ageMs).toISOString() : null,\n ageMs,\n managed: false,\n };\n })\n .sort((left, right) => left.pid - right.pid);\n};\n\nconst killManagedProcess = (pid) => {\n if (!Number.isInteger(pid) || pid <= 0) {\n return;\n }\n\n try {\n if (process.platform !== \"win32\") {\n process.kill(-pid, \"SIGTERM\");\n return;\n }\n } catch {\n // Fall through to direct kill below.\n }\n\n try {\n process.kill(pid, \"SIGTERM\");\n } catch {\n // Best effort only.\n }\n};\n\nconst pathExists = async (targetPath) => existsSync(targetPath);\n\nconst readPackageJson = async (rootDir) => {\n const packageJsonPath = path.join(rootDir, \"package.json\");\n if (!(await pathExists(packageJsonPath))) {\n return null;\n }\n\n return JSON.parse(await readFile(packageJsonPath, \"utf8\"));\n};\n\nconst isMonorepoRoot = async (rootDir, packageJson) => {\n if (packageJson?.name !== \"air-jam\") {\n return false;\n }\n\n return (\n (await pathExists(path.join(rootDir, \"scripts\", \"repo\", \"cli.mjs\"))) &&\n (await pathExists(path.join(rootDir, \"packages\", \"sdk\"))) &&\n (await pathExists(path.join(rootDir, \"packages\", \"create-airjam\")))\n );\n};\n\nconst findProjectRoot = async (cwd) => {\n let currentDir = path.resolve(cwd);\n\n while (true) {\n const packageJson = await readPackageJson(currentDir);\n if (await isMonorepoRoot(currentDir, packageJson)) {\n return currentDir;\n }\n\n if (packageJson) {\n return currentDir;\n }\n\n const parentDir = path.dirname(currentDir);\n if (parentDir === currentDir) {\n return path.resolve(cwd);\n }\n currentDir = parentDir;\n }\n};\n\nconst getDevtoolsRoot = (rootDir) => path.join(rootDir, \".airjam\", \"devtools\");\n\nconst getManagedRegistryPath = (rootDir) =>\n path.join(getDevtoolsRoot(rootDir), \"managed-processes.json\");\n\nconst readRegistry = async (rootDir) => {\n const registryPath = getManagedRegistryPath(rootDir);\n if (!(await pathExists(registryPath))) {\n return {\n schemaVersion: DEVTOOLS_SCHEMA_VERSION,\n processes: [],\n };\n }\n\n const parsed = JSON.parse(await readFile(registryPath, \"utf8\"));\n return {\n schemaVersion: DEVTOOLS_SCHEMA_VERSION,\n processes: Array.isArray(parsed.processes) ? parsed.processes : [],\n };\n};\n\nconst writeRegistry = async (rootDir, registry) => {\n const registryPath = getManagedRegistryPath(rootDir);\n await mkdir(path.dirname(registryPath), { recursive: true });\n await writeFile(registryPath, `${JSON.stringify(registry, null, 2)}\\n`, \"utf8\");\n};\n\nconst listManagedProcessesForRoot = async (rootDir) => {\n const registry = await readRegistry(rootDir);\n const aliveProcesses = registry.processes.filter((processInfo) =>\n isProcessAlive(processInfo.pid),\n );\n\n if (aliveProcesses.length !== registry.processes.length) {\n await writeRegistry(rootDir, {\n schemaVersion: DEVTOOLS_SCHEMA_VERSION,\n processes: aliveProcesses,\n });\n }\n\n return aliveProcesses.sort((left, right) =>\n left.startedAt.localeCompare(right.startedAt),\n );\n};\n\nconst stopDev = async ({ cwd, processId, mode } = {}) => {\n const rootDir = await findProjectRoot(cwd ?? process.cwd());\n const processes = await listManagedProcessesForRoot(rootDir);\n const selected = processes.filter((processInfo) => {\n if (processId) {\n return processInfo.id === processId;\n }\n if (mode) {\n return processInfo.mode === mode;\n }\n return true;\n });\n\n for (const processInfo of selected) {\n killManagedProcess(processInfo.pid);\n }\n\n const remaining = processes.filter(\n (processInfo) =>\n !selected.some(\n (selectedProcess) => selectedProcess.id === processInfo.id,\n ),\n );\n await writeRegistry(rootDir, {\n schemaVersion: DEVTOOLS_SCHEMA_VERSION,\n processes: remaining,\n });\n\n return {\n rootDir,\n stopped: selected,\n };\n};\n\nexport const getDevStatus = async ({ cwd = process.cwd() } = {}) => {\n const rootDir = await findProjectRoot(cwd);\n const managedProcesses = await listManagedProcessesForRoot(rootDir);\n const managedPids = new Set(managedProcesses.map((entry) => entry.pid));\n return {\n processes: managedProcesses,\n unmanagedProcesses: listKnownPortListeners(rootDir).filter(\n (entry) => !managedPids.has(entry.pid),\n ),\n knownPorts: getKnownLocalDevPorts(),\n };\n};\n\nexport const resetLocalDev = async ({ cwd = process.cwd() } = {}) => {\n const { rootDir, stopped: stoppedManaged } = await stopDev({ cwd });\n const managedPids = new Set(stoppedManaged.map((entry) => entry.pid));\n const unmanaged = listKnownPortListeners(rootDir).filter(\n (entry) => !managedPids.has(entry.pid),\n );\n const stoppedUnmanaged = [];\n\n for (const processInfo of unmanaged) {\n if (!isLikelyAirJamLocalDevCommand(processInfo.command)) {\n continue;\n }\n killManagedProcess(processInfo.pid);\n stoppedUnmanaged.push(processInfo);\n }\n\n await rm(path.join(rootDir, \".airjam\", \"preview-managed-server.json\"), {\n force: true,\n }).catch(() => undefined);\n\n const stoppedPids = new Set([\n ...stoppedManaged.map((entry) => entry.pid),\n ...stoppedUnmanaged.map((entry) => entry.pid),\n ]);\n const remainingUnmanaged = listKnownPortListeners(rootDir).filter(\n (entry) => !stoppedPids.has(entry.pid),\n );\n\n return {\n stoppedManaged,\n stoppedUnmanaged,\n remainingUnmanaged,\n knownPorts: getKnownLocalDevPorts(),\n };\n};\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,OAAO,UAAU;AACjB,SAAS,OAAO,UAAU,IAAI,iBAAiB;AAC/C,SAAS,kBAAkB;AAE3B,IAAM,0BAA0B;AAChC,IAAM,wBAAwB,CAAC,KAAM,IAAI;AACzC,IAAM,kBAAkB;AAExB,IAAM,iBAAiB,CAAC,QAAQ;AAC9B,MAAI,CAAC,OAAO,UAAU,GAAG,KAAK,OAAO,GAAG;AACtC,WAAO;AAAA,EACT;AAEA,MAAI;AACF,YAAQ,KAAK,KAAK,CAAC;AACnB,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,IAAM,mBAAmB,CAAC,EAAE,SAAS,MAAM,IAAI,MAAM;AACnD,QAAM,SAAS,UAAU,SAAS,MAAM;AAAA,IACtC;AAAA,IACA,UAAU;AAAA,IACV,KAAK;AAAA,MACH,GAAG,QAAQ;AAAA,MACX,IAAI,QAAQ,IAAI,MAAM;AAAA,MACtB,oBAAoB;AAAA,IACtB;AAAA,EACF,CAAC;AAED,QAAM,WAAW,OAAO,UAAU;AAClC,SAAO;AAAA,IACL;AAAA,IACA,IAAI,aAAa,KAAK,CAAC,OAAO;AAAA,IAC9B,QAAQ,OAAO,UAAU;AAAA,IACzB,QACE,OAAO,WACN,OAAO,iBAAiB,QAAQ,OAAO,MAAM,UAAU;AAAA,EAC5D;AACF;AAEA,IAAM,oBAAoB,CAAC,SAAS,MAAM,QAAQ;AAChD,MAAI;AACF,WAAO,iBAAiB,EAAE,SAAS,MAAM,IAAI,CAAC,EAAE,OAAO,KAAK;AAAA,EAC9D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,IAAM,2BAA2B,CAAC,MAAM,Q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iBAAiB,IAAI,CAAC,UAAU,MAAM,GAAG;AAAA,EAC9C,CAAC;AACD,QAAM,qBAAqB,uBAAuB,OAAO,EAAE;AAAA,IACzD,CAAC,UAAU,CAAC,YAAY,IAAI,MAAM,GAAG;AAAA,EACvC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,sBAAsB;AAAA,EACpC;AACF;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_GAME_PORT,
|
|
3
|
+
DEFAULT_PLATFORM_PORT,
|
|
4
|
+
SECURE_MODE_LOCAL,
|
|
5
|
+
SECURE_MODE_TUNNEL,
|
|
6
|
+
appendNextHttpsArgs,
|
|
7
|
+
buildLocalCertificateHosts,
|
|
8
|
+
buildSecureGameEnv,
|
|
9
|
+
getSecurePaths,
|
|
10
|
+
initializeSecureDev,
|
|
11
|
+
loadSecureDevState,
|
|
12
|
+
parseGameDevArgs,
|
|
13
|
+
parseSecureInitArgs,
|
|
14
|
+
resolveRequestedSecureMode,
|
|
15
|
+
resolveSecureLoopbackHost,
|
|
16
|
+
resolveSecurePlatformHost,
|
|
17
|
+
resolveSecurePublicHost,
|
|
18
|
+
runSecureInitCli
|
|
19
|
+
} from "./chunk-RM7AMBDY.js";
|
|
20
|
+
export {
|
|
21
|
+
DEFAULT_GAME_PORT,
|
|
22
|
+
DEFAULT_PLATFORM_PORT,
|
|
23
|
+
SECURE_MODE_LOCAL,
|
|
24
|
+
SECURE_MODE_TUNNEL,
|
|
25
|
+
appendNextHttpsArgs,
|
|
26
|
+
buildLocalCertificateHosts,
|
|
27
|
+
buildSecureGameEnv,
|
|
28
|
+
getSecurePaths,
|
|
29
|
+
initializeSecureDev,
|
|
30
|
+
loadSecureDevState,
|
|
31
|
+
parseGameDevArgs,
|
|
32
|
+
parseSecureInitArgs,
|
|
33
|
+
resolveRequestedSecureMode,
|
|
34
|
+
resolveSecureLoopbackHost,
|
|
35
|
+
resolveSecurePlatformHost,
|
|
36
|
+
resolveSecurePublicHost,
|
|
37
|
+
runSecureInitCli
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=secure-dev-HMOGLYVC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_AIR_JAM_DEV_BACKEND_URL,
|
|
3
|
+
DEFAULT_GAME_PORT,
|
|
4
|
+
SECURE_MODE_LOCAL,
|
|
5
|
+
detectLocalIpv4,
|
|
6
|
+
getFlagValue,
|
|
7
|
+
hasFlag,
|
|
8
|
+
loadCreateAirJamRuntimeEnv,
|
|
9
|
+
loadEnvFile,
|
|
10
|
+
loadSecureDevState
|
|
11
|
+
} from "./chunk-RM7AMBDY.js";
|
|
12
|
+
|
|
13
|
+
// src/project-cli/topology.mjs
|
|
14
|
+
import { resolveProjectRuntimeTopology } from "@air-jam/sdk/runtime-topology";
|
|
15
|
+
import path from "path";
|
|
16
|
+
var SUPPORTED_MODES = /* @__PURE__ */ new Set([
|
|
17
|
+
"standalone-dev",
|
|
18
|
+
"self-hosted-production",
|
|
19
|
+
"hosted-release"
|
|
20
|
+
]);
|
|
21
|
+
var getDefaultStandalonePublicHost = (env) => {
|
|
22
|
+
const explicitPublicHost = env.VITE_AIR_JAM_PUBLIC_HOST?.trim();
|
|
23
|
+
if (explicitPublicHost) {
|
|
24
|
+
return explicitPublicHost;
|
|
25
|
+
}
|
|
26
|
+
const detectedIp = detectLocalIpv4();
|
|
27
|
+
if (!detectedIp) {
|
|
28
|
+
return `http://localhost:${DEFAULT_GAME_PORT}`;
|
|
29
|
+
}
|
|
30
|
+
return `http://${detectedIp}:${DEFAULT_GAME_PORT}`;
|
|
31
|
+
};
|
|
32
|
+
var requireConfiguredAppOrigin = (env, mode) => {
|
|
33
|
+
const appOrigin = env.VITE_AIR_JAM_PUBLIC_HOST?.trim() || env.NEXT_PUBLIC_APP_URL?.trim();
|
|
34
|
+
if (appOrigin) {
|
|
35
|
+
return appOrigin;
|
|
36
|
+
}
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Mode "${mode}" requires VITE_AIR_JAM_PUBLIC_HOST (or NEXT_PUBLIC_APP_URL) to be set.`
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
var createProjectSurfaceTopology = ({
|
|
42
|
+
runtimeMode,
|
|
43
|
+
secure,
|
|
44
|
+
env,
|
|
45
|
+
surfaceRole,
|
|
46
|
+
cwd
|
|
47
|
+
}) => {
|
|
48
|
+
if (runtimeMode === "standalone-dev") {
|
|
49
|
+
const secureState = secure ? loadSecureDevState({
|
|
50
|
+
cwd,
|
|
51
|
+
mode: SECURE_MODE_LOCAL,
|
|
52
|
+
env,
|
|
53
|
+
gamePort: DEFAULT_GAME_PORT
|
|
54
|
+
}) : null;
|
|
55
|
+
const publicHost = secure ? secureState.publicHost : getDefaultStandalonePublicHost(env);
|
|
56
|
+
return resolveProjectRuntimeTopology({
|
|
57
|
+
runtimeMode: secure ? "standalone-secure" : "standalone-dev",
|
|
58
|
+
surfaceRole,
|
|
59
|
+
appOrigin: publicHost,
|
|
60
|
+
backendOrigin: env.VITE_AIR_JAM_SERVER_URL?.trim() || DEFAULT_AIR_JAM_DEV_BACKEND_URL,
|
|
61
|
+
publicHost,
|
|
62
|
+
secureTransport: secure
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const appOrigin = requireConfiguredAppOrigin(env, runtimeMode);
|
|
66
|
+
return resolveProjectRuntimeTopology({
|
|
67
|
+
runtimeMode,
|
|
68
|
+
surfaceRole,
|
|
69
|
+
appOrigin,
|
|
70
|
+
backendOrigin: env.VITE_AIR_JAM_SERVER_URL?.trim() || appOrigin,
|
|
71
|
+
publicHost: env.VITE_AIR_JAM_PUBLIC_HOST?.trim() || appOrigin
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
var runProjectTopologyCli = async ({
|
|
75
|
+
cwd = process.cwd(),
|
|
76
|
+
argv = process.argv.slice(2),
|
|
77
|
+
env = process.env
|
|
78
|
+
} = {}) => {
|
|
79
|
+
if (hasFlag(argv, "--help") || hasFlag(argv, "-h")) {
|
|
80
|
+
console.log("Usage: air-jam-server topology --mode=<mode> [--secure]");
|
|
81
|
+
console.log("");
|
|
82
|
+
console.log("Modes:");
|
|
83
|
+
console.log(
|
|
84
|
+
" standalone-dev Resolve standalone local game topology"
|
|
85
|
+
);
|
|
86
|
+
console.log(
|
|
87
|
+
" self-hosted-production Resolve self-hosted production topology"
|
|
88
|
+
);
|
|
89
|
+
console.log(
|
|
90
|
+
" hosted-release Resolve hosted Air Jam release topology"
|
|
91
|
+
);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
loadEnvFile(path.join(cwd, ".env"), env);
|
|
95
|
+
loadEnvFile(path.join(cwd, ".env.local"), env);
|
|
96
|
+
const runtimeEnv = loadCreateAirJamRuntimeEnv({
|
|
97
|
+
env,
|
|
98
|
+
boundary: "air-jam-server.topology"
|
|
99
|
+
});
|
|
100
|
+
const mode = getFlagValue(argv, "--mode")?.trim();
|
|
101
|
+
if (!mode || !SUPPORTED_MODES.has(mode)) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
"Missing or unsupported --mode. Use standalone-dev, self-hosted-production, or hosted-release."
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
const secure = hasFlag(argv, "--secure");
|
|
107
|
+
if (secure && mode !== "standalone-dev") {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`--secure is only supported with --mode=standalone-dev. ${mode} should express transport through its configured URL values.`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const surfaces = Object.fromEntries(
|
|
113
|
+
["host", "controller"].map((surfaceRole) => [
|
|
114
|
+
surfaceRole,
|
|
115
|
+
createProjectSurfaceTopology({
|
|
116
|
+
runtimeMode: mode,
|
|
117
|
+
secure,
|
|
118
|
+
env: runtimeEnv,
|
|
119
|
+
surfaceRole,
|
|
120
|
+
cwd
|
|
121
|
+
})
|
|
122
|
+
])
|
|
123
|
+
);
|
|
124
|
+
process.stdout.write(
|
|
125
|
+
`${JSON.stringify(
|
|
126
|
+
{
|
|
127
|
+
mode,
|
|
128
|
+
secure,
|
|
129
|
+
surfaces
|
|
130
|
+
},
|
|
131
|
+
null,
|
|
132
|
+
2
|
|
133
|
+
)}
|
|
134
|
+
`
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
export {
|
|
138
|
+
runProjectTopologyCli
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=topology-PM3PI753.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/project-cli/topology.mjs"],"sourcesContent":["import { resolveProjectRuntimeTopology } from \"@air-jam/sdk/runtime-topology\";\nimport path from \"node:path\";\nimport {\n detectLocalIpv4,\n getFlagValue,\n hasFlag,\n loadEnvFile,\n} from \"./dev-utils.mjs\";\nimport { loadCreateAirJamRuntimeEnv } from \"./runtime-env.mjs\";\nimport {\n DEFAULT_GAME_PORT,\n loadSecureDevState,\n SECURE_MODE_LOCAL,\n} from \"./secure-dev.mjs\";\nimport { DEFAULT_AIR_JAM_DEV_BACKEND_URL } from \"./vite-https.mjs\";\n\nconst SUPPORTED_MODES = new Set([\n \"standalone-dev\",\n \"self-hosted-production\",\n \"hosted-release\",\n]);\n\nconst getDefaultStandalonePublicHost = (env) => {\n const explicitPublicHost = env.VITE_AIR_JAM_PUBLIC_HOST?.trim();\n if (explicitPublicHost) {\n return explicitPublicHost;\n }\n\n const detectedIp = detectLocalIpv4();\n if (!detectedIp) {\n return `http://localhost:${DEFAULT_GAME_PORT}`;\n }\n\n return `http://${detectedIp}:${DEFAULT_GAME_PORT}`;\n};\n\nconst requireConfiguredAppOrigin = (env, mode) => {\n const appOrigin =\n env.VITE_AIR_JAM_PUBLIC_HOST?.trim() || env.NEXT_PUBLIC_APP_URL?.trim();\n if (appOrigin) {\n return appOrigin;\n }\n\n throw new Error(\n `Mode \"${mode}\" requires VITE_AIR_JAM_PUBLIC_HOST (or NEXT_PUBLIC_APP_URL) to be set.`,\n );\n};\n\nconst createProjectSurfaceTopology = ({\n runtimeMode,\n secure,\n env,\n surfaceRole,\n cwd,\n}) => {\n if (runtimeMode === \"standalone-dev\") {\n const secureState = secure\n ? loadSecureDevState({\n cwd,\n mode: SECURE_MODE_LOCAL,\n env,\n gamePort: DEFAULT_GAME_PORT,\n })\n : null;\n const publicHost = secure\n ? secureState.publicHost\n : getDefaultStandalonePublicHost(env);\n\n return resolveProjectRuntimeTopology({\n runtimeMode: secure ? \"standalone-secure\" : \"standalone-dev\",\n surfaceRole,\n appOrigin: publicHost,\n backendOrigin:\n env.VITE_AIR_JAM_SERVER_URL?.trim() || DEFAULT_AIR_JAM_DEV_BACKEND_URL,\n publicHost,\n secureTransport: secure,\n });\n }\n\n const appOrigin = requireConfiguredAppOrigin(env, runtimeMode);\n\n return resolveProjectRuntimeTopology({\n runtimeMode,\n surfaceRole,\n appOrigin,\n backendOrigin: env.VITE_AIR_JAM_SERVER_URL?.trim() || appOrigin,\n publicHost: env.VITE_AIR_JAM_PUBLIC_HOST?.trim() || appOrigin,\n });\n};\n\nexport const runProjectTopologyCli = async ({\n cwd = process.cwd(),\n argv = process.argv.slice(2),\n env = process.env,\n} = {}) => {\n if (hasFlag(argv, \"--help\") || hasFlag(argv, \"-h\")) {\n console.log(\"Usage: air-jam-server topology --mode=<mode> [--secure]\");\n console.log(\"\");\n console.log(\"Modes:\");\n console.log(\n \" standalone-dev Resolve standalone local game topology\",\n );\n console.log(\n \" self-hosted-production Resolve self-hosted production topology\",\n );\n console.log(\n \" hosted-release Resolve hosted Air Jam release topology\",\n );\n return;\n }\n\n loadEnvFile(path.join(cwd, \".env\"), env);\n loadEnvFile(path.join(cwd, \".env.local\"), env);\n const runtimeEnv = loadCreateAirJamRuntimeEnv({\n env,\n boundary: \"air-jam-server.topology\",\n });\n\n const mode = getFlagValue(argv, \"--mode\")?.trim();\n if (!mode || !SUPPORTED_MODES.has(mode)) {\n throw new Error(\n \"Missing or unsupported --mode. Use standalone-dev, self-hosted-production, or hosted-release.\",\n );\n }\n\n const secure = hasFlag(argv, \"--secure\");\n if (secure && mode !== \"standalone-dev\") {\n throw new Error(\n `--secure is only supported with --mode=standalone-dev. ${mode} should express transport through its configured URL values.`,\n );\n }\n\n const surfaces = Object.fromEntries(\n [\"host\", \"controller\"].map((surfaceRole) => [\n surfaceRole,\n createProjectSurfaceTopology({\n runtimeMode: mode,\n secure,\n env: runtimeEnv,\n surfaceRole,\n cwd,\n }),\n ]),\n );\n\n process.stdout.write(\n `${JSON.stringify(\n {\n mode,\n secure,\n surfaces,\n },\n null,\n 2,\n )}\\n`,\n );\n};\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,qCAAqC;AAC9C,OAAO,UAAU;AAejB,IAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,iCAAiC,CAAC,QAAQ;AAC9C,QAAM,qBAAqB,IAAI,0BAA0B,KAAK;AAC9D,MAAI,oBAAoB;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,gBAAgB;AACnC,MAAI,CAAC,YAAY;AACf,WAAO,oBAAoB,iBAAiB;AAAA,EAC9C;AAEA,SAAO,UAAU,UAAU,IAAI,iBAAiB;AAClD;AAEA,IAAM,6BAA6B,CAAC,KAAK,SAAS;AAChD,QAAM,YACJ,IAAI,0BAA0B,KAAK,KAAK,IAAI,qBAAqB,KAAK;AACxE,MAAI,WAAW;AACb,WAAO;AAAA,EACT;AAEA,QAAM,IAAI;AAAA,IACR,SAAS,IAAI;AAAA,EACf;AACF;AAEA,IAAM,+BAA+B,CAAC;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,MAAI,gBAAgB,kBAAkB;AACpC,UAAM,cAAc,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AM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,QAAQ,MAAM,UAAU;AACvC,MAAI,UAAU,SAAS,kBAAkB;AACvC,UAAM,IAAI;AAAA,MACR,0DAA0D,IAAI;AAAA,IAChE;AAAA,EACF;AAEA,QAAM,WAAW,OAAO;AAAA,IACtB,CAAC,QAAQ,YAAY,EAAE,IAAI,CAAC,gBAAgB;AAAA,MAC1C;AAAA,MACA,6BAA6B;AAAA,QAC3B,aAAa;AAAA,QACb;AAAA,QACA,KAAK;AAAA,QACL;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAEA,UAAQ,OAAO;AAAA,IACb,GAAG,KAAK;AAAA,MACN;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA;AAAA,EACH;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,36 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@air-jam/server",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Air Jam game server for local development and production",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/vucinatim/
|
|
10
|
+
"url": "git+https://github.com/vucinatim/airjam.git",
|
|
11
11
|
"directory": "packages/server"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://github.com/vucinatim/
|
|
13
|
+
"homepage": "https://github.com/vucinatim/airjam#readme",
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/vucinatim/
|
|
15
|
+
"url": "https://github.com/vucinatim/airjam/issues"
|
|
16
16
|
},
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"bin": {
|
|
21
|
-
"air-jam-server": "./
|
|
21
|
+
"air-jam-server": "./bin/air-jam-server.mjs"
|
|
22
22
|
},
|
|
23
23
|
"main": "dist/index.js",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./dist/index.js",
|
|
26
|
+
"./vite-config": {
|
|
27
|
+
"types": "./src/project-cli/vite-config.d.mts",
|
|
28
|
+
"import": "./src/project-cli/vite-config.mjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
24
31
|
"files": [
|
|
25
|
-
"
|
|
32
|
+
"bin",
|
|
33
|
+
"dist",
|
|
34
|
+
"src/project-cli/vite-config.mjs",
|
|
35
|
+
"src/project-cli/vite-config.d.mts",
|
|
36
|
+
"src/project-cli/vite-https.mjs",
|
|
37
|
+
"src/project-cli/vite-https.d.mts"
|
|
26
38
|
],
|
|
27
39
|
"dependencies": {
|
|
28
|
-
"@air-jam/sdk": "
|
|
40
|
+
"@air-jam/sdk": "0.9.1",
|
|
29
41
|
"color": "^5.0.3",
|
|
42
|
+
"commander": "^14.0.0",
|
|
30
43
|
"cors": "^2.8.5",
|
|
31
44
|
"dotenv": "^17.2.3",
|
|
32
45
|
"drizzle-orm": "^0.45.0",
|
|
33
46
|
"express": "^4.21.2",
|
|
47
|
+
"pino": "^10.3.1",
|
|
34
48
|
"postgres": "^3.4.7",
|
|
35
49
|
"socket.io": "^4.8.1",
|
|
36
50
|
"uuid": "^13.0.0",
|
|
@@ -41,14 +55,21 @@
|
|
|
41
55
|
"@types/express": "^4.17.21",
|
|
42
56
|
"@types/node": "^24.10.1",
|
|
43
57
|
"@types/uuid": "^11.0.0",
|
|
58
|
+
"socket.io-client": "^4.8.1",
|
|
44
59
|
"tsup": "^8.5.1",
|
|
45
60
|
"tsx": "^4.19.2",
|
|
46
|
-
"typescript": "~5.9.3"
|
|
61
|
+
"typescript": "~5.9.3",
|
|
62
|
+
"vitest": "^3.2.4"
|
|
47
63
|
},
|
|
48
64
|
"scripts": {
|
|
49
|
-
"dev": "tsx src/
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
65
|
+
"dev": "tsx src/main.ts",
|
|
66
|
+
"logs:dev": "tsx scripts/dev-logs.ts",
|
|
67
|
+
"analytics:rebuild": "tsx scripts/runtime-usage-rebuild.ts",
|
|
68
|
+
"start": "node ./bin/air-jam-server.mjs",
|
|
69
|
+
"build": "node ../../scripts/ensure-workspace-package-build.mjs @air-jam/devtools-core && node ../../scripts/ensure-workspace-package-build.mjs @air-jam/harness && tsup",
|
|
70
|
+
"test": "node ../../scripts/ensure-workspace-package-build.mjs @air-jam/devtools-core && node ../../scripts/ensure-workspace-package-build.mjs @air-jam/harness && vitest run --config vitest.config.ts",
|
|
71
|
+
"test:watch": "vitest --config vitest.config.ts",
|
|
72
|
+
"perf:sanity": "tsx scripts/perf-sanity.ts",
|
|
73
|
+
"typecheck": "node ../../scripts/ensure-workspace-package-build.mjs @air-jam/devtools-core && node ../../scripts/ensure-workspace-package-build.mjs @air-jam/harness && tsc --noEmit && tsc -p tests/tsconfig.json --noEmit"
|
|
53
74
|
}
|
|
54
75
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { UserConfig } from "vite";
|
|
2
|
+
|
|
3
|
+
export type AirJamViteProfile = "default" | "three";
|
|
4
|
+
|
|
5
|
+
export interface CreateAirJamViteConfigOptions {
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
port?: number;
|
|
8
|
+
profile?: AirJamViteProfile;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare const AIR_JAM_IFRAME_HEADERS: {
|
|
12
|
+
"Content-Security-Policy": string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export declare function createAirJamViteConfig(
|
|
16
|
+
options?: CreateAirJamViteConfigOptions,
|
|
17
|
+
): Pick<UserConfig, "build" | "server" | "preview">;
|