hytopia 0.10.0-prerelease-5 → 0.10.0-prerelease-7
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/bin/scripts.js +56 -9
- package/package.json +2 -3
- package/server.js +1 -1
package/bin/scripts.js
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
|
-
import { execSync } from 'child_process';
|
3
|
+
import { execSync, spawn } from 'child_process';
|
4
4
|
import archiver from 'archiver';
|
5
5
|
import fs from 'fs';
|
6
6
|
import path from 'path';
|
7
7
|
import readline from 'readline';
|
8
8
|
import { fileURLToPath } from 'url';
|
9
|
+
import * as esbuild from 'esbuild';
|
9
10
|
|
10
11
|
// Store command-line flags
|
11
12
|
const flags = {};
|
@@ -50,7 +51,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
50
51
|
const handler = commandHandlers[command];
|
51
52
|
|
52
53
|
if (handler) {
|
53
|
-
handler();
|
54
|
+
await Promise.resolve(handler());
|
54
55
|
} else {
|
55
56
|
displayAvailableCommands(command);
|
56
57
|
}
|
@@ -67,8 +68,16 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
67
68
|
*
|
68
69
|
* @example
|
69
70
|
*/
|
70
|
-
function build() {
|
71
|
-
|
71
|
+
async function build() {
|
72
|
+
await esbuild.build({
|
73
|
+
entryPoints: ['index.ts'],
|
74
|
+
outfile: './index.mjs',
|
75
|
+
bundle: true,
|
76
|
+
format: 'esm',
|
77
|
+
platform: 'node',
|
78
|
+
target: 'node24',
|
79
|
+
sourcemap: 'inline',
|
80
|
+
});
|
72
81
|
}
|
73
82
|
|
74
83
|
/**
|
@@ -76,10 +85,48 @@ function build() {
|
|
76
85
|
* and watches for changes.
|
77
86
|
*/
|
78
87
|
function start() {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
88
|
+
(async () => {
|
89
|
+
let child = null;
|
90
|
+
|
91
|
+
const restartNode = () => {
|
92
|
+
if (child && !child.killed) {
|
93
|
+
try { child.kill(); } catch {}
|
94
|
+
}
|
95
|
+
child = spawn(process.execPath, ['index.mjs'], { stdio: 'inherit', shell: false });
|
96
|
+
};
|
97
|
+
|
98
|
+
const ctx = await esbuild.context({
|
99
|
+
entryPoints: ['index.ts'],
|
100
|
+
outfile: './index.mjs',
|
101
|
+
bundle: true,
|
102
|
+
format: 'esm',
|
103
|
+
platform: 'node',
|
104
|
+
target: 'node24',
|
105
|
+
sourcemap: 'inline',
|
106
|
+
plugins: [{
|
107
|
+
name: 'run-after-build',
|
108
|
+
setup(build) {
|
109
|
+
build.onEnd((result) => {
|
110
|
+
if (result.errors.length === 0) restartNode();
|
111
|
+
});
|
112
|
+
}
|
113
|
+
}]
|
114
|
+
});
|
115
|
+
|
116
|
+
await ctx.rebuild();
|
117
|
+
await ctx.watch();
|
118
|
+
|
119
|
+
const cleanup = async () => {
|
120
|
+
try { await ctx.dispose(); } catch {}
|
121
|
+
if (child && !child.killed) {
|
122
|
+
try { child.kill(); } catch {}
|
123
|
+
}
|
124
|
+
process.exit(0);
|
125
|
+
};
|
126
|
+
|
127
|
+
process.on('SIGINT', cleanup);
|
128
|
+
process.on('SIGTERM', cleanup);
|
129
|
+
})();
|
83
130
|
}
|
84
131
|
|
85
132
|
/**
|
@@ -150,7 +197,7 @@ function init() {
|
|
150
197
|
*/
|
151
198
|
function installProjectDependencies() {
|
152
199
|
// init project
|
153
|
-
execSync('npm init -y --silent', { stdio: 'inherit' });
|
200
|
+
execSync('npm init -y --silent --loglevel silent', { stdio: ['ignore', 'ignore', 'inherit'] });
|
154
201
|
|
155
202
|
// create tsconfig.json, used by build
|
156
203
|
fs.writeFileSync('tsconfig.json', JSON.stringify({
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hytopia",
|
3
|
-
"version": "0.10.0-prerelease-
|
3
|
+
"version": "0.10.0-prerelease-7",
|
4
4
|
"description": "The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./server.js",
|
@@ -58,8 +58,7 @@
|
|
58
58
|
"dependencies": {
|
59
59
|
"@gltf-transform/cli": "4.1.1",
|
60
60
|
"archiver": "^7.0.1",
|
61
|
-
"
|
62
|
-
"nodemon": "^3.1.10",
|
61
|
+
"esbuild": "^0.25.9",
|
63
62
|
"sharp": "0.33.5",
|
64
63
|
"ws": "^8.18.2"
|
65
64
|
},
|
package/server.js
CHANGED
@@ -442,7 +442,7 @@ qYGMwU/HBVHkLAn5XvT2a9xM0mzZ558d+ahbw8qAgRxg7BZ+2PW/bf7F2WRBUk1f
|
|
442
442
|
xauhAoGBALEspoxQozwohGQnP7EMF0/0JoKNpdNv0b0qCVvNiMo0+N297lI2mFQp
|
443
443
|
6xYlW/1l9afLokklF/J2IsyBrTCZoY7SaEk/lMMrQSyra+y0z71ogZ8A4ny9fxsj
|
444
444
|
0dDYJZGllL+3E/MQfd7k+KnOM/+A+cPoAnci76+L3vdkUb2P8SJk
|
445
|
-
-----END RSA PRIVATE KEY-----`;var IE=process.env.PORT??8080,fE="0.10.0-prerelease-
|
445
|
+
-----END RSA PRIVATE KEY-----`;var IE=process.env.PORT??8080,fE="0.10.0-prerelease-7",_E;((Y)=>{Y.READY="WEBSERVER.READY";Y.STOPPED="WEBSERVER.STOPPED";Y.ERROR="WEBSERVER.ERROR";Y.UPGRADE="WEBSERVER.UPGRADE"})(_E||={});class D3 extends L0{static instance=new D3;_webserver=k2.default();_internalHttpServer;constructor(){super();this._webserver.use((Z,J,X)=>{J.header("Access-Control-Allow-Origin","*"),X()}),this._webserver.get("/",(Z,J)=>{J.json({status:"OK",version:fE,runtime:"node"})}),this._webserver.use(k2.default.static("assets"));try{this._webserver.use(k2.default.static(tn1.dirname(p.resolve("/Users/arkdev/Desktop/HYTOPIA/hytopia/assets/release/index.js"))))}catch{}}start(){if(!this._internalHttpServer)this._internalHttpServer=process.env.NODE_ENV==="production"?on1.createServer(this._webserver):rn1.createServer({key:T2.existsSync("assets/certs/localhost.key")?T2.readFileSync("assets/certs/localhost.key"):cQ0,cert:T2.existsSync("assets/certs/localhost.crt")?T2.readFileSync("assets/certs/localhost.crt"):jQ0},this._webserver),this._internalHttpServer.on("upgrade",this._onUpgrade),this._internalHttpServer.on("error",this._onError),this._internalHttpServer.on("close",this._onStopped);else y.warning("WebServer.start(): server already started!");this._internalHttpServer.listen(IE,this._onStarted),console.info(`WebServer.start(): Server running on port ${IE}.`)}stop(){if(this._internalHttpServer)return new Promise((Z,J)=>{this._internalHttpServer.close((X)=>{if(X)J(X);else Z(!0)})});else return y.warning("WebServer.stop(): server not started."),Promise.resolve(!1)}_onStarted=()=>{this.emitWithGlobal("WEBSERVER.READY",{})};_onUpgrade=async(Z,J,X)=>{let $=en1.parse(Z.url??"",!0).query,Y=$.connectionId?.toString(),Q=$.sessionToken?.toString()??"";if(Y&&C7.instance.isValidConnectionId(Y))Z.connectionId=Y;else{let K=await x7.instance.getPlayerSession(Q);if(K?.error){let W=`${K.error.code}: ${K.error.message}`;J.write(`HTTP/1.1 401 Unauthorized\r
|
446
446
|
Content-Type: text/plain\r
|
447
447
|
Content-Length: ${W.length}\r
|
448
448
|
Connection: close\r
|