From 0d17db7187e2822be93c89f571f7039604f129d7 Mon Sep 17 00:00:00 2001 From: missinglink Date: Tue, 10 Jan 2023 13:17:38 +0100 Subject: [PATCH] feat(batch): support importing geojson files --- lib/parameters.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/parameters.js b/lib/parameters.js index 18136d42d..232228190 100644 --- a/lib/parameters.js +++ b/lib/parameters.js @@ -7,6 +7,7 @@ var _ = require('lodash'); var minimist = require( 'minimist' ); var peliasConfig = require( 'pelias-config' ).generate(); +const logger = require('pelias-logger').get('openaddresses-import'); /** * Interprets the command-line arguments passed to the script. @@ -99,7 +100,23 @@ function getFullFileList(peliasConfig, args) { return glob.sync( args.dirPath + '/**/*.{csv,geojson}' ); } else { // otherwise return the requested files with full path - return files.map(function(file) { + return files.map(file => { + + // remove file extension from source + const source = file.replace(/\.[^\/.]+$/, ''); + + // source definitions previously required a file extension. + // please remove file extensions from your ~/pelias.json file + // to silence these warning messages. + if (source !== file) { + logger.warn(`source definitions no longer require a file extension '${file}'`); + } + + // search for files matching this source id, ending in either .geojson or .csv + const found = glob.sync(`${source}.{csv,geojson}`, { cwd: args.dirPath, absolute: true }); + if (!_.isEmpty(found)) { return _.last(found); } // results are sorted, prefer .geojson + + // no matching files were found, return a non-matching absolute path return path.join(args.dirPath, file); }); }