diff --git a/cli.js b/cli.js index ed0b0be..d98590a 100755 --- a/cli.js +++ b/cli.js @@ -76,6 +76,9 @@ const { }, 'import-metadata': { type: 'boolean', + }, + 'folder-mode': { + type: 'boolean', } }, allowPositionals: true, @@ -148,6 +151,10 @@ Options: - gtfs_data_imported_at (timestamp with time zone) - gtfs_via_postgres_version (text) - gtfs_via_postgres_options (jsonb) + --folder-mode Use folder name instead of file wildcard. Script automatically + parses file names in specified folder. + This mode works for Windows machines. + Example: gtfs-to-sql --folder-mode -- gtfs Examples: gtfs-to-sql some-gtfs/*.txt | sponge | psql -b # import into PostgreSQL gtfs-to-sql -u -- some-gtfs/*.txt | gzip >gtfs.sql.gz # generate a gzipped SQL dump @@ -167,11 +174,7 @@ const {basename, extname} = require('path') const {pipeline} = require('stream') const convertGtfsToSql = require('./index') const DataError = require('./lib/data-error') - -const files = args.map((file) => { - const name = basename(file, extname(file)) - return {name, file} -}) +const {readdirSync} = require('fs'); const opt = { silent: !!flags.silent, @@ -188,6 +191,7 @@ const opt = { postgraphile: !!flags.postgraphile, postgrest: !!flags.postgrest, importMetadata: !!flags['import-metadata'], + folderMode: !!flags['folder-mode'], } if ('stops-without-level-id' in flags) { opt.stopsWithoutLevelId = flags['stops-without-level-id'] @@ -210,6 +214,14 @@ if ('postgrest-query-cost-limit' in flags) { opt.lowerCaseLanguageCodes = limit } +const files = (opt.folderMode ? readdirSync(args[0]) : args).map((file) => { + const name = basename(file, extname(file)) + return { + name, + file: opt.folderMode ? `${args[0]}/${file}` : file + } +}); + pipeline( convertGtfsToSql(files, opt), process.stdout, diff --git a/readme.md b/readme.md index 44c87b2..8ff1390 100644 --- a/readme.md +++ b/readme.md @@ -313,6 +313,14 @@ With the `--postgrest` flag, `gtfs-via-postgres` will augment the schema with a [read more](docs/postgrest.md) +### Folder mode + +With the `--folder-mode` flag, a folder name can be used instead of a file wildcard. All files in the given directory will be read and used in the script. Unsupported files can be ignored using the `-u` flag. + +``` +npm exec -- gtfs-to-sql --folder-mode -- gtfs | sponge | psql -b +``` + ### more guides The [`docs` directory](docs) contains more instructions on how to use `gtfs-via-postgres`.