diff --git a/index.ts b/index.ts index 9221911..318d1ac 100644 --- a/index.ts +++ b/index.ts @@ -195,6 +195,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 af9e7f1..f276ac5 100644 --- a/readme.md +++ b/readme.md @@ -89,6 +89,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"] }