Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open srcbook in browser on launch #157

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 94 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions srcbook/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import './lib/db/index.mjs';
*
*/
import readline from 'node:readline';
import express from 'express';
import fs from 'node:fs';
import path from 'node:path';
import http from 'node:http';
import { fileURLToPath } from 'url';
import path from 'path';
import { fileURLToPath } from 'node:url';
import express from 'express';
import { WebSocketServer as WsWebSocketServer } from 'ws';
import { wss, app, posthog } from './lib/index.mjs';
import chalk from 'chalk';
import open from 'open';

function clearScreen() {
const repeatCount = process.stdout.rows - 2;
Expand Down Expand Up @@ -56,11 +58,18 @@ app.get('*', (_req, res) => res.sendFile(INDEX_HTML));
console.log(chalk.green('Initialization complete.'));

const port = process.env.PORT || 2150;
const url = `http://localhost:${port}`;

posthog.capture({ event: 'user started Srcbook application' });

const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = fs.readFileSync(packageJsonPath, 'utf-8');
const { name, version } = JSON.parse(packageJson);

server.listen(port, () => {
console.log(`Running at http://localhost:${port}`);
console.log(`${name}@${version} running at ${url}`);
const noop = () => {};
open(url).catch(noop);
});

process.on('SIGINT', async function () {
Expand Down
1 change: 1 addition & 0 deletions srcbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"drizzle-orm": "^0.31.2",
"express": "^4.19.2",
"marked": "catalog:",
"open": "^10.1.0",
"posthog-node": "^4.0.1",
"ws": "catalog:",
"zod": "catalog:"
Expand Down
Loading