From 7eca1c3815d9c8f04b969bfdff1b35e83352a1b0 Mon Sep 17 00:00:00 2001 From: Nick Molyneux Date: Tue, 3 Sep 2024 09:40:11 -0700 Subject: [PATCH] Adds version() function (#108) --- index.ts | 14 +++++++++++++- index_test.ts | 3 +++ package.json | 2 +- readme.md | 11 +++++++++++ tsconfig.json | 4 ++-- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index f5db4f5..2f04464 100644 --- a/index.ts +++ b/index.ts @@ -196,6 +196,18 @@ class Ogr2ogr implements PromiseLike { } } -export default function ogr2ogr(input: Input, opts?: Options): Ogr2ogr { +function ogr2ogr(input: Input, opts?: Options): Ogr2ogr { return new Ogr2ogr(input, opts) } + +ogr2ogr.version = async () => { + let vers = await new Promise((res, rej) => { + execFile("ogr2ogr", ["--version"], {}, (err, stdout) => { + if (err) rej(err) + res(stdout) + }) + }) + return vers.trim() +} + +export default ogr2ogr diff --git a/index_test.ts b/index_test.ts index 8467fb5..5c0b843 100644 --- a/index_test.ts +++ b/index_test.ts @@ -11,6 +11,9 @@ import ogr2ogr from "./" let dir = __dirname + "/testdata/" test(async (t) => { + const vers = await ogr2ogr.version() + t.match(vers, /^GDAL /) + interface TT { file?: string url?: string diff --git a/package.json b/package.json index 7414581..45bc58a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ogr2ogr", - "version": "5.0.0", + "version": "5.1.0", "description": "ogr2ogr wrapper w/ multiple format support", "keywords": [ "ogr2ogr", diff --git a/readme.md b/readme.md index edeed48..e7b867b 100644 --- a/readme.md +++ b/readme.md @@ -88,6 +88,17 @@ The **`output`** object has the following properties: The callback API supports the same options as above but in a NodeJS style callback format. +### ogr2ogr.version() -> Promise\ + +Retrieve the version of `ogr2ogr` that will be called by default by this library (same as calling `ogr2ogr --version` from command line). + +```javascript +const version = await ogr2ogr.version() +console.log(version) + +// GDAL X.X.X, released XXXX/XX/XX +``` + ## Tips and tricks Running `ogr2ogr` in a [Docker container][6]: diff --git a/tsconfig.json b/tsconfig.json index 525d29b..da1c546 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "declaration": true, "outDir": "./dist/cjs", "esModuleInterop": true, - "resolveJsonModule": true, + "resolveJsonModule": true }, - "exclude": ["node_modules", "dist"], + "exclude": ["node_modules", "dist"] }