-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
31 lines (26 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import initializeDatabase from './src/db.js';
import { generateDatabase } from './src/tablegen.js';
import schemas from 'spacedatastandards.org/lib/json/index.json' assert { type: 'json' };
import packageJSON from 'spacedatastandards.org/package.json' assert { type: 'json' };
import fs from 'fs';
import path from 'path';
const { STANDARDS } = schemas;
async function startServer() {
const sqlFilePath = path.resolve(`./sql/${packageJSON.version}.sql`);
if (!fs.existsSync(sqlFilePath)) {
try {
await generateDatabase(Object.values(STANDARDS), sqlFilePath);
console.log('Database schema generated successfully.');
} catch (err) {
console.error('Error generating database schema:', err);
process.exit(1);
}
} else {
console.log('SQL file already exists, skipping generation.');
}
// Initialize the database
const db = await initializeDatabase();
console.log(db);
// Your server logic here, e.g., setting up routes, etc.
}
startServer();