Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds version() function #108

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}
Loading