hytopia 0.10.27-prerelease-4 → 0.10.27-prerelease-5
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 +22 -63
- package/package.json +2 -1
- package/server.mjs +2 -2
package/bin/scripts.js
CHANGED
|
@@ -4,6 +4,7 @@ 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
|
+
import nodemon from 'nodemon';
|
|
7
8
|
import readline from 'readline';
|
|
8
9
|
import { fileURLToPath } from 'url';
|
|
9
10
|
|
|
@@ -73,69 +74,27 @@ async function build() {
|
|
|
73
74
|
* Runs a hytopia project's index file using node.js
|
|
74
75
|
* and watches for changes.
|
|
75
76
|
*/
|
|
76
|
-
function start() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
'--target=node',
|
|
98
|
-
'--format=esm',
|
|
99
|
-
'--outfile=index.mjs',
|
|
100
|
-
'--external=mediasoup',
|
|
101
|
-
'--watch',
|
|
102
|
-
'index.ts'
|
|
103
|
-
];
|
|
104
|
-
bunProc = spawn('npx', bunArgs, { stdio: 'inherit', shell: false });
|
|
105
|
-
|
|
106
|
-
const outputFile = path.join(process.cwd(), 'index.mjs');
|
|
107
|
-
// If output exists, start the node process; otherwise wait for first build
|
|
108
|
-
if (fs.existsSync(outputFile)) {
|
|
109
|
-
restartNode();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Watch for changes to the output file and restart the node process
|
|
113
|
-
try {
|
|
114
|
-
watcher = fs.watch(outputFile, { persistent: true }, () => {
|
|
115
|
-
if (restartTimer) { clearTimeout(restartTimer); restartTimer = null; }
|
|
116
|
-
restartTimer = setTimeout(restartNode, 150);
|
|
117
|
-
});
|
|
118
|
-
} catch {
|
|
119
|
-
// Fallback: watch the current directory for changes to index.mjs
|
|
120
|
-
watcher = fs.watch(process.cwd(), { persistent: true }, (eventType, filename) => {
|
|
121
|
-
if (filename === 'index.mjs') {
|
|
122
|
-
if (restartTimer) { clearTimeout(restartTimer); restartTimer = null; }
|
|
123
|
-
restartTimer = setTimeout(restartNode, 150);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const cleanup = async () => {
|
|
129
|
-
if (restartTimer) clearTimeout(restartTimer);
|
|
130
|
-
stopNode();
|
|
131
|
-
try { if (watcher) watcher.close(); } catch {}
|
|
132
|
-
try { if (bunProc && !bunProc.killed) bunProc.kill(); } catch {}
|
|
133
|
-
process.exit(0);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
process.on('SIGINT', cleanup);
|
|
137
|
-
process.on('SIGTERM', cleanup);
|
|
138
|
-
})();
|
|
77
|
+
async function start() {
|
|
78
|
+
// Initial build via CLI to ensure consistency
|
|
79
|
+
execSync('hytopia build', { stdio: 'inherit' });
|
|
80
|
+
|
|
81
|
+
const projectRoot = process.cwd();
|
|
82
|
+
const entryFile = path.join(projectRoot, 'index.mjs');
|
|
83
|
+
const buildCmd = 'hytopia build';
|
|
84
|
+
const runCmd = `"${process.execPath}" --enable-source-maps "${entryFile}"`;
|
|
85
|
+
|
|
86
|
+
// Start nodemon to watch for changes, rebuild, then run the server
|
|
87
|
+
nodemon({
|
|
88
|
+
watch: ['.'],
|
|
89
|
+
ext: 'js,ts,html',
|
|
90
|
+
ignore: ['node_modules/**', '.git/**', '*.zip', 'index.mjs'],
|
|
91
|
+
exec: `${buildCmd} && ${runCmd}`,
|
|
92
|
+
delay: 100,
|
|
93
|
+
})
|
|
94
|
+
.on('quit', () => {
|
|
95
|
+
console.log('👋 Shutting down...');
|
|
96
|
+
process.exit();
|
|
97
|
+
});
|
|
139
98
|
}
|
|
140
99
|
|
|
141
100
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hytopia",
|
|
3
|
-
"version": "0.10.27-prerelease-
|
|
3
|
+
"version": "0.10.27-prerelease-5",
|
|
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.mjs",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"@gltf-transform/cli": "^4.2.1",
|
|
60
60
|
"archiver": "^7.0.1",
|
|
61
61
|
"bun": "^1.3.0",
|
|
62
|
+
"nodemon": "^3.1.10",
|
|
62
63
|
"ws": "^8.18.2"
|
|
63
64
|
},
|
|
64
65
|
"optionalDependencies": {
|