highest-endpoint-version helper tool

[ci skip]
This commit is contained in:
Jannis R 2020-03-09 13:16:37 +01:00
parent 225a7c15c1
commit b61c2584b2
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,71 @@
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const argv = mri(process.argv.slice(2), {
boolean: [
'help', 'h',
'silent', 's',
]
})
if (argv.help || argv.h) {
process.stdout.write(`
Usage:
highest-endpoint-version <profile>
Options:
--silent -s Output just the version instead of a pretty
represenation.
Examples:
highest-endpoint-version oebb
\n`)
process.exit(0)
}
const {join} = require('path')
const createClient = require('../..')
const profile = require(join(__dirname, '..', '..', 'p', argv._[0]))
const id = (ctx, val) => val
const origTransformReqBody = profile.transformReqBody || id
const checkWithVersion = async (version) => {
const transformReqBody = (ctx, body) => {
body = origTransformReqBody(ctx, body)
return {...body, ver: version}
}
const client = createClient({
...profile, transformReqBody
}, 'hafas-client-highest-endpoint-version')
try {
await client.locations('foo', {results: 1})
} catch (err) {
if (err && err.code === 'VERSION') return false
const wrapped = new Error(`check for ${version} support failed with an unknown error`)
wrapped.originalError = err
throw wrapped
}
return true
}
const silent = argv.silent || argv.s
;(async () => {
for (let minor = 16; minor <= 35; minor++) {
const v = '1.' + minor
if (await checkWithVersion(v)) {
if (!silent) console.log(v + ' is supported ✔︎')
} else {
if (silent) console.log(v)
else console.log(v + ' is not supported ✘')
process.exit(0)
}
}
process.exit(1)
})()
.catch((err) => {
console.error(err)
process.exit(1)
})

View file

@ -0,0 +1,13 @@
{
"private": true,
"name": "find-highest-endpoint-version",
"version": "1.0.0",
"bin": {
"hafas-client-find-highest-endpoint-version": "./cli.js"
},
"author": "Jannis R <mail@jannisr.de>",
"license": "ISC",
"dependencies": {
"mri": "^1.1.4"
}
}