hytopia 0.10.39 → 0.10.41
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 +50 -1
- package/package.json +1 -1
- package/server.mjs +270 -203
package/bin/scripts.js
CHANGED
|
@@ -41,10 +41,14 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
41
41
|
'init-mcp': initMcp,
|
|
42
42
|
'package': packageProject,
|
|
43
43
|
'start': start,
|
|
44
|
+
'update-hosts': checkHostsConfiguration,
|
|
44
45
|
'upgrade-cli': () => upgradeCli(process.argv[3] || 'latest'),
|
|
45
46
|
'upgrade-project': () => upgradeProject(process.argv[3] || 'latest'),
|
|
46
47
|
'version': displayVersion,
|
|
47
48
|
};
|
|
49
|
+
|
|
50
|
+
// Check that hosts is properly configured
|
|
51
|
+
checkHostsConfiguration();
|
|
48
52
|
|
|
49
53
|
const handler = commandHandlers[command];
|
|
50
54
|
|
|
@@ -470,7 +474,6 @@ async function packageProject() {
|
|
|
470
474
|
// UTILITY FUNCTIONS
|
|
471
475
|
// ================================================================================
|
|
472
476
|
|
|
473
|
-
// set priority level for takahiro tickets
|
|
474
477
|
|
|
475
478
|
async function build(devMode = false) {
|
|
476
479
|
let envFlags = devMode ? '' : '--minify --sourcemap=inline';
|
|
@@ -478,6 +481,51 @@ async function build(devMode = false) {
|
|
|
478
481
|
execSync(`npx --yes bun build --target=node --env=disable --format=esm ${envFlags} --outfile=index.mjs index.ts`, { stdio: 'inherit' });
|
|
479
482
|
}
|
|
480
483
|
|
|
484
|
+
/**
|
|
485
|
+
* Checks the hosts files and makes sure that dev-local.hytopia.com points to localhost.
|
|
486
|
+
*/
|
|
487
|
+
function checkHostsConfiguration() {
|
|
488
|
+
const DOMAIN = 'dev-local.hytopia.com';
|
|
489
|
+
const isWindows = process.platform === 'win32';
|
|
490
|
+
const hostsPath = isWindows
|
|
491
|
+
? path.join(process.env.SystemRoot || 'C://Windows', 'System32', 'drivers', 'etc', 'hosts')
|
|
492
|
+
: '/etc/hosts';
|
|
493
|
+
|
|
494
|
+
let content = '';
|
|
495
|
+
try {
|
|
496
|
+
content = fs.existsSync(hostsPath) ? fs.readFileSync(hostsPath, 'utf8') : '';
|
|
497
|
+
} catch {
|
|
498
|
+
console.warn(`⚠️ Unable to check hosts configuration, if you're unable to connect and test your game, you may need to run this command using 'sudo hytopia'`);
|
|
499
|
+
return; // no read access; skip silently
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const managedBegin = '# HYTOPIA DEV-LOCAL BEGIN';
|
|
503
|
+
const managedEnd = '# HYTOPIA DEV-LOCAL END';
|
|
504
|
+
|
|
505
|
+
if (content.includes(managedBegin) && content.includes(managedEnd)) {
|
|
506
|
+
console.log(`✅ Hosts already configured: ${DOMAIN} -> 127.0.0.1, ::1`);
|
|
507
|
+
return; // already configured by us, skip
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const EOL = content.includes('\r\n') ? '\r\n' : '\n';
|
|
511
|
+
const block = [
|
|
512
|
+
managedBegin,
|
|
513
|
+
`127.0.0.1 ${DOMAIN}`,
|
|
514
|
+
`::1 ${DOMAIN}`,
|
|
515
|
+
managedEnd,
|
|
516
|
+
''
|
|
517
|
+
].join(EOL);
|
|
518
|
+
|
|
519
|
+
const newContent = block + content;
|
|
520
|
+
|
|
521
|
+
try {
|
|
522
|
+
fs.writeFileSync(hostsPath, newContent, { encoding: 'utf8' });
|
|
523
|
+
console.log(`✅ Hosts updated: ${DOMAIN} -> 127.0.0.1, ::1`);
|
|
524
|
+
} catch {
|
|
525
|
+
console.warn(`⚠️ Could not modify hosts file (${hostsPath}) to add the dev-local.hytopia.com. Please run this command using 'sudo hytopia', otherwise you may not be able to connect and test your game.`);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
481
529
|
/**
|
|
482
530
|
* Parses command-line flags in the format --flag value
|
|
483
531
|
*/
|
|
@@ -614,6 +662,7 @@ function displayHelp() {
|
|
|
614
662
|
console.log(' init [--template NAME] Initialize a new project');
|
|
615
663
|
console.log(' init-mcp Setup MCP integrations');
|
|
616
664
|
console.log(' package Create a zip of the project for uploading to the HYTOPIA create portal.');
|
|
665
|
+
console.log(' update-hosts Update the hosts file to add the dev-local.hytopia.com domain');
|
|
617
666
|
console.log(' upgrade-cli Upgrade the HYTOPIA CLI');
|
|
618
667
|
console.log(' upgrade-project [VERSION] Upgrade project SDK dep (default: latest)');
|
|
619
668
|
console.log('');
|
package/package.json
CHANGED