dbdesk-studio 0.1.0
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/dist/cli.d.ts +1 -0
- package/dist/cli.js +211 -0
- package/package.json +38 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
backendPort: 6789,
|
|
11
|
+
frontendPort: 9876,
|
|
12
|
+
backendUrl: 'http://localhost:6789'
|
|
13
|
+
};
|
|
14
|
+
function parseArgs() {
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
const config = { ...DEFAULT_CONFIG };
|
|
17
|
+
for (let i = 0; i < args.length; i++) {
|
|
18
|
+
if (args[i] === '--backend-port') {
|
|
19
|
+
const port = args[i + 1];
|
|
20
|
+
if (port)
|
|
21
|
+
config.backendPort = parseInt(port, 10);
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
else if (args[i] === '--frontend-port') {
|
|
25
|
+
const port = args[i + 1];
|
|
26
|
+
if (port)
|
|
27
|
+
config.frontendPort = parseInt(port, 10);
|
|
28
|
+
i++;
|
|
29
|
+
}
|
|
30
|
+
else if (args[i] === '--backend-url') {
|
|
31
|
+
const url = args[i + 1];
|
|
32
|
+
if (url)
|
|
33
|
+
config.backendUrl = url;
|
|
34
|
+
i++;
|
|
35
|
+
}
|
|
36
|
+
else if (args[i] === '--help' || args[i] === '-h') {
|
|
37
|
+
printHelp();
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return config;
|
|
42
|
+
}
|
|
43
|
+
function printHelp() {
|
|
44
|
+
console.log(`
|
|
45
|
+
Usage: dbdesk-studio [options]
|
|
46
|
+
|
|
47
|
+
Options:
|
|
48
|
+
--backend-port <port> Backend server port (default: 6789)
|
|
49
|
+
--frontend-port <port> Frontend server port (default: 9876)
|
|
50
|
+
--backend-url <url> Backend URL for frontend (default: http://localhost:6789)
|
|
51
|
+
--help, -h Show this help message
|
|
52
|
+
|
|
53
|
+
Examples:
|
|
54
|
+
dbdesk-studio
|
|
55
|
+
dbdesk-studio --backend-port 4000 --frontend-port 8080
|
|
56
|
+
dbdesk-studio --backend-url http://api.example.com
|
|
57
|
+
`);
|
|
58
|
+
}
|
|
59
|
+
function getServerPath() {
|
|
60
|
+
// Try to find the server in different possible locations
|
|
61
|
+
const possiblePaths = [
|
|
62
|
+
path.join(__dirname, '../../..', 'apps/server/dist/index.js'),
|
|
63
|
+
path.join(__dirname, '../../../apps/server/dist/index.js'),
|
|
64
|
+
path.join(__dirname, '../../server/dist/index.js'),
|
|
65
|
+
];
|
|
66
|
+
for (const p of possiblePaths) {
|
|
67
|
+
if (fs.existsSync(p)) {
|
|
68
|
+
return p;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Fallback - try using tsx to run the TS directly
|
|
72
|
+
const tsPath = path.join(__dirname, '../../..', 'apps/server/src/index.ts');
|
|
73
|
+
if (fs.existsSync(tsPath)) {
|
|
74
|
+
return tsPath;
|
|
75
|
+
}
|
|
76
|
+
throw new Error('Could not find server app. Make sure to run: pnpm build');
|
|
77
|
+
}
|
|
78
|
+
function getWebDistPath() {
|
|
79
|
+
const possiblePaths = [
|
|
80
|
+
path.join(__dirname, '../../..', 'apps/web/dist'),
|
|
81
|
+
path.join(__dirname, '../../../apps/web/dist'),
|
|
82
|
+
path.join(__dirname, '../../web/dist'),
|
|
83
|
+
];
|
|
84
|
+
for (const p of possiblePaths) {
|
|
85
|
+
if (fs.existsSync(p)) {
|
|
86
|
+
return p;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
throw new Error('Could not find web app dist. Make sure to run: pnpm build');
|
|
90
|
+
}
|
|
91
|
+
function startBackend(config) {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const serverPath = getServerPath();
|
|
94
|
+
const useTs = serverPath.endsWith('.ts');
|
|
95
|
+
const args = useTs ? [serverPath] : [];
|
|
96
|
+
const cmd = useTs ? 'tsx' : 'node';
|
|
97
|
+
console.log(`🚀 Starting backend on port ${config.backendPort}...`);
|
|
98
|
+
const env = {
|
|
99
|
+
...process.env,
|
|
100
|
+
PORT: String(config.backendPort),
|
|
101
|
+
NODE_ENV: process.env.NODE_ENV || 'production'
|
|
102
|
+
};
|
|
103
|
+
const backend = spawn(cmd, args, {
|
|
104
|
+
env,
|
|
105
|
+
stdio: 'inherit'
|
|
106
|
+
});
|
|
107
|
+
backend.on('error', (err) => {
|
|
108
|
+
console.error('❌ Failed to start backend:', err.message);
|
|
109
|
+
reject(err);
|
|
110
|
+
});
|
|
111
|
+
// Give backend time to start
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
console.log(`✅ Backend started on port ${config.backendPort}`);
|
|
114
|
+
resolve();
|
|
115
|
+
}, 2000);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function startFrontend(config) {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
const webDistPath = getWebDistPath();
|
|
121
|
+
console.log(`🚀 Starting frontend on port ${config.frontendPort}...`);
|
|
122
|
+
// Create a simple HTTP server to serve static files
|
|
123
|
+
const serverScript = `
|
|
124
|
+
const http = require('http');
|
|
125
|
+
const fs = require('fs');
|
|
126
|
+
const path = require('path');
|
|
127
|
+
|
|
128
|
+
const distPath = '${webDistPath}';
|
|
129
|
+
const port = ${config.frontendPort};
|
|
130
|
+
|
|
131
|
+
const server = http.createServer((req, res) => {
|
|
132
|
+
let filePath = path.join(distPath, req.url === '/' ? 'index.html' : req.url);
|
|
133
|
+
const extname = path.extname(filePath);
|
|
134
|
+
|
|
135
|
+
let contentType = 'text/html';
|
|
136
|
+
if (extname === '.js') contentType = 'text/javascript';
|
|
137
|
+
if (extname === '.css') contentType = 'text/css';
|
|
138
|
+
if (extname === '.json') contentType = 'application/json';
|
|
139
|
+
if (extname === '.png') contentType = 'image/png';
|
|
140
|
+
if (extname === '.jpg') contentType = 'image/jpeg';
|
|
141
|
+
if (extname === '.svg') contentType = 'image/svg+xml';
|
|
142
|
+
if (extname === '.woff') contentType = 'font/woff';
|
|
143
|
+
if (extname === '.woff2') contentType = 'font/woff2';
|
|
144
|
+
|
|
145
|
+
fs.readFile(filePath, (err, content) => {
|
|
146
|
+
if (err) {
|
|
147
|
+
if (fs.existsSync(path.join(distPath, 'index.html'))) {
|
|
148
|
+
fs.readFile(path.join(distPath, 'index.html'), (err, content) => {
|
|
149
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
150
|
+
res.end(content, 'utf-8');
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
res.writeHead(404);
|
|
154
|
+
res.end('Not found');
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
res.writeHead(200, { 'Content-Type': contentType });
|
|
158
|
+
res.end(content, 'utf-8');
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
server.listen(port, () => {
|
|
164
|
+
console.log('✅ Frontend started on port ' + port);
|
|
165
|
+
});
|
|
166
|
+
`;
|
|
167
|
+
const frontendServer = spawn('node', ['-e', serverScript], {
|
|
168
|
+
stdio: 'inherit'
|
|
169
|
+
});
|
|
170
|
+
frontendServer.on('error', (err) => {
|
|
171
|
+
console.error('❌ Failed to start frontend:', err.message);
|
|
172
|
+
reject(err);
|
|
173
|
+
});
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
console.log(`🌐 Open http://localhost:${config.frontendPort} in your browser`);
|
|
176
|
+
resolve();
|
|
177
|
+
}, 1000);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async function main() {
|
|
181
|
+
const config = parseArgs();
|
|
182
|
+
console.log(`
|
|
183
|
+
╔═══════════════════════════════════════════╗
|
|
184
|
+
║ dbdesk-studio v0.0.1 ║
|
|
185
|
+
║ Database Management Studio ║
|
|
186
|
+
╚═══════════════════════════════════════════╝
|
|
187
|
+
`);
|
|
188
|
+
console.log('Configuration:');
|
|
189
|
+
console.log(` Backend Port: ${config.backendPort}`);
|
|
190
|
+
console.log(` Frontend Port: ${config.frontendPort}`);
|
|
191
|
+
console.log(` Backend URL: ${config.backendUrl}`);
|
|
192
|
+
console.log('');
|
|
193
|
+
try {
|
|
194
|
+
// Start both services
|
|
195
|
+
await Promise.all([
|
|
196
|
+
startBackend(config),
|
|
197
|
+
startFrontend(config)
|
|
198
|
+
]);
|
|
199
|
+
console.log('');
|
|
200
|
+
console.log('🎉 All services started successfully!');
|
|
201
|
+
console.log(`📖 Frontend: http://localhost:${config.frontendPort}`);
|
|
202
|
+
console.log(`🔌 Backend: http://localhost:${config.backendPort}`);
|
|
203
|
+
console.log('');
|
|
204
|
+
console.log('Press Ctrl+C to stop all services');
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
console.error('❌ Failed to start services:', err);
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dbdesk-studio",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Database management studio with a web interface",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"dbdesk-studio": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/cli.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc && echo '#!/usr/bin/env node' | cat - dist/cli.js > dist/cli.tmp && mv dist/cli.tmp dist/cli.js && chmod +x dist/cli.js",
|
|
15
|
+
"dev": "tsx src/cli.ts",
|
|
16
|
+
"check-types": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"express": "^5.1.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "catalog:",
|
|
23
|
+
"typescript": "catalog:",
|
|
24
|
+
"tsx": "^4.19.2"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"database",
|
|
28
|
+
"studio",
|
|
29
|
+
"web-ui",
|
|
30
|
+
"sql"
|
|
31
|
+
],
|
|
32
|
+
"author": "",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/zexahq/dbdesk-studio.git"
|
|
37
|
+
}
|
|
38
|
+
}
|