hytopia 0.10.27-prerelease-4 → 0.10.27-prerelease-6

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 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
 
@@ -33,7 +34,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
33
34
 
34
35
  // Execute the appropriate command
35
36
  const commandHandlers = {
36
- 'build': build,
37
+ 'build': () => build(false),
38
+ 'build-dev': () => build(true),
37
39
  'help': displayHelp,
38
40
  'init': init,
39
41
  'init-mcp': initMcp,
@@ -64,78 +66,29 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
64
66
  *
65
67
  * @example
66
68
  */
67
- async function build() {
68
- console.log('🔧 Building project (bun)...');
69
- execSync('npx --yes bun build --target=node --format=esm --outfile=index.mjs index.ts', { stdio: 'inherit' });
70
- }
71
69
 
72
70
  /**
73
71
  * Runs a hytopia project's index file using node.js
74
72
  * and watches for changes.
75
73
  */
76
- function start() {
77
- (async () => {
78
- let child = null;
79
- let restartTimer = null;
80
- let bunProc = null;
81
- let watcher = null;
82
-
83
- const stopNode = () => {
84
- if (child && !child.killed) {
85
- try { child.kill(); } catch {}
86
- }
87
- };
88
-
89
- const restartNode = () => {
90
- stopNode();
91
- child = spawn(process.execPath, ['--enable-source-maps', 'index.mjs'], { stdio: 'inherit', shell: false });
92
- };
93
-
94
- // Start bun build in watch mode. Externalize mediasoup similar to previous dev behavior.
95
- const bunArgs = [
96
- '--yes', 'bun', 'build',
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
- })();
74
+ async function start() {
75
+ const projectRoot = process.cwd();
76
+ const entryFile = path.join(projectRoot, 'index.mjs');
77
+ const buildCmd = 'hytopia build-dev';
78
+ const runCmd = `"${process.execPath}" --enable-source-maps "${entryFile}"`;
79
+
80
+ // Start nodemon to watch for changes, rebuild, then run the server
81
+ nodemon({
82
+ watch: ['.'],
83
+ ext: 'js,ts,html',
84
+ ignore: ['node_modules/**', '.git/**', '*.zip', 'index.mjs'],
85
+ exec: `${buildCmd} && ${runCmd}`,
86
+ delay: 100,
87
+ })
88
+ .on('quit', () => {
89
+ console.log('👋 Shutting down...');
90
+ process.exit();
91
+ });
139
92
  }
140
93
 
141
94
  /**
@@ -519,6 +472,12 @@ async function packageProject() {
519
472
 
520
473
  // set priority level for takahiro tickets
521
474
 
475
+ async function build(devMode = false) {
476
+ let devFlags = devMode ? '--external=mediasoup' : '';
477
+
478
+ execSync(`npx --yes bun build --target=node --format=esm ${devFlags} --outfile=index.mjs index.ts`, { stdio: 'inherit' });
479
+ }
480
+
522
481
  /**
523
482
  * Parses command-line flags in the format --flag value
524
483
  */
@@ -650,6 +609,7 @@ function displayHelp() {
650
609
  console.log(' help, -h, --help Show this help');
651
610
  console.log(' version, -v, --version Show CLI version');
652
611
  console.log(' build Build the project (Generates ESM index.mjs)');
612
+ console.log(' build-dev Build the project in development mode (Generates ESM index.mjs with local dependencies externalized)');
653
613
  console.log(' start Start a HYTOPIA project server (Node.js & watch)');
654
614
  console.log(' init [--template NAME] Initialize a new project');
655
615
  console.log(' init-mcp Setup MCP integrations');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hytopia",
3
- "version": "0.10.27-prerelease-4",
3
+ "version": "0.10.27-prerelease-6",
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": {