Initial commit

This commit is contained in:
JB
2026-01-14 20:21:44 -05:00
commit e9865d3ee8
237 changed files with 15121 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import fs from 'fs';
import path from 'path';
import { Readable } from 'stream';
import { exec } from 'child_process';
export async function downloadAndExtract(url: string, outputDir: string): Promise<void> {
const response = await fetch(url);
if (!response.ok || !response.body) throw new Error(`Failed to download ${url}`);
const nodeStream = Readable.fromWeb(response.body as any);
const compressedFilePath = path.join(outputDir, 'archive.tar.xz');
const fileStream = fs.createWriteStream(compressedFilePath);
nodeStream.pipe(fileStream);
return new Promise((resolve, reject) => {
fileStream.on('finish', () => {
// Use native tar command to extract files
exec(`tar -xJf ${compressedFilePath} -C ${outputDir}`, (error, stdout, stderr) => {
if (error) {
console.error(`Extraction error: ${stderr}`);
reject(error);
} else {
console.log('Extraction complete');
// Clean up the archive file
fs.unlink(compressedFilePath, (err) => {
if (err) {
console.error(`Error removing archive: ${err.message}`);
reject(err);
} else {
console.log('Archive cleaned up');
resolve();
}
});
}
});
});
fileStream.on('error', (err) => {
console.error('File stream error', err);
reject(err);
});
});
}
// CLI execution (only runs when file is executed directly)
if (import.meta.main) {
const args = process.argv.slice(2);
if (args.length !== 2) {
console.error('Usage: bun run downloadAndExtract.ts <url> <outputDir>');
process.exit(1);
}
const [url, outputDir] = args;
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
downloadAndExtract(url, outputDir).catch((err) => console.error('Download failed', err));
}

View File

@@ -0,0 +1,19 @@
import { Database } from "bun:sqlite";
import { join } from "node:path";
const db = new Database(join(process.cwd(), 'data/evestatic.db'));
const query = db.query("SELECT * FROM mapSolarSystems");
const results = query.all();
const output = results.reduce((acc: any, system: any) => {
acc[system.solarSystemID] = system;
return acc;
}, {});
const jsonData = JSON.stringify(output, null, 2);
const fs = await import('fs/promises');
await fs.writeFile(join(process.cwd(), 'data/reference-data/solar_systems.json'), jsonData);
db.close();