Skip to content

Commit

Permalink
Adds version() function (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
molynerd authored Sep 3, 2024
1 parent 4d8ec6b commit 7eca1c3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
14 changes: 13 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ class Ogr2ogr implements PromiseLike<Result> {
}
}

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<string>((res, rej) => {
execFile("ogr2ogr", ["--version"], {}, (err, stdout) => {
if (err) rej(err)
res(stdout)
})
})
return vers.trim()
}

export default ogr2ogr
3 changes: 3 additions & 0 deletions index_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ogr2ogr",
"version": "5.0.0",
"version": "5.1.0",
"description": "ogr2ogr wrapper w/ multiple format support",
"keywords": [
"ogr2ogr",
Expand Down
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\<string\>

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]:
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"declaration": true,
"outDir": "./dist/cjs",
"esModuleInterop": true,
"resolveJsonModule": true,
"resolveJsonModule": true
},
"exclude": ["node_modules", "dist"],
"exclude": ["node_modules", "dist"]
}

0 comments on commit 7eca1c3

Please sign in to comment.