import { FlightParser } from '../src/services/FlightParser' import path from 'path' import fs from 'fs' import Flight from '../src/entities/Flight' export default ( async () => { const igcFiles = fs.readdirSync(path.join(__dirname, '../examples')) await Promise.all(igcFiles.map(async (igcFile: string) => { if(!igcFile.endsWith('.igc')) return const API_URL = process?.argv?.slice(2)[0] ?? 'http://127.0.0.1:3333' try { console.log(`Starting to parse: `, igcFile) const igcFilePath = path.join(__dirname, '../examples', igcFile) const igcFileContent = fs.readFileSync(igcFilePath, 'utf8') const flightParsed = new FlightParser(igcFileContent, API_URL) await flightParsed.processFile() const flight = new Flight({ ...flightParsed, flightParsed }) fs.writeFileSync(path.join(__dirname, '../examples/results', igcFile + '-result.json'), JSON.stringify(flight, null, 2)) console.log(`Finished parse of the file: `, igcFile) } catch (error) { if(error.message === 'ERROR_TERRAIN_ELEVATION') { console.warn('Error expected: ' + error.message) } else { throw error } } })) })()