UNPKG

@gooin/fit2spatial

Version:

Convert Garmin FIT files to GeoJSON, SHP, KML, GPX

68 lines (67 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const path = require("node:path"); const utils_1 = require("../utils"); const file_1 = require("../utils/file"); class Shp extends core_1.Command { async run() { const { flags } = await this.parse(Shp); const input = flags.input; const output = flags.output; core_1.ux.action.start('starting a process'); if ((0, file_1.checkIsFitFile)(input)) { let outputPath = output; const fileName = (0, file_1.getFitFileName)(input); if (output) { if ((0, file_1.checkIsDirectory)(output)) { outputPath = path.join(output, fileName + '.zip'); } else if (output.endsWith('.shp')) { outputPath = path.join(path.dirname(input), path.basename(output, '.shp') + '.zip'); } } else { outputPath = path.join(path.dirname(input), fileName + '.zip'); } await (0, utils_1.fit2shp)(input, outputPath); } if ((0, file_1.checkIsDirectory)(input)) { const fitFiles = (0, file_1.listFitFiles)(input); // this.log('run - fitFiles:', fitFiles) // this.log('-> output path: ', output) if (output && !(0, file_1.checkIsDirectory)(output)) { this.log(`${output} is not a directory, creating...`); (0, file_1.createDirectory)(output); } // eslint-disable-next-line unicorn/no-for-loop for (let index = 0; index < fitFiles.length; index++) { const fitFile = fitFiles[index]; const fileName = (0, file_1.getFitFileName)(path.join(input, fitFile)); const outputPath = output ? path.join(output, fileName + '.zip') : path.join(input, fileName + '.zip'); const inputPath = path.join(input, fitFile); // eslint-disable-next-line no-await-in-loop await (0, utils_1.fit2shp)(inputPath, outputPath); } } core_1.ux.action.stop(); } } exports.default = Shp; Shp.description = 'describe the command here'; Shp.examples = [ '<%= config.bin %> <%= command.id %>', ]; Shp.flags = { // flag with no value (-i, --input=VALUE) input: core_1.Flags.string({ char: 'i', description: 'input file or directory', summary: 'input .fit file or directory', required: true, }), output: core_1.Flags.string({ char: 'o', description: 'output file or directory', }), };