#!/bin/bash

node_modules/.bin/jsdoc -t node_modules/tsd-jsdoc/dist -d . -r src

cat types.d.ts > lib/index.d.ts
rm types.d.ts

# Mark exports
exported_literals=(
  'ShelfNetwork'
  'Token'
  'Wallet'
  'NetworkError'
  'ClientTimeoutError'
  'ServerErrorBase'
  'NotFoundError'
  'BadGatewayError'
  'ServiceUnavailableError'
  'GatewayTimeoutError'
  'JsonApiError'
  'JsonApiBadRequestError'
  'JsonApiNotAllowedError'
  'JsonApiForbiddenRequestError'
  'JsonApiNotFoundError'
  'JsonApiConflictError'
  'JsonApiInternalServerError'
)

for i in "${exported_literals[@]}"
do
  cat lib/index.d.ts | sed -e "s/declare \(.*\) ${i} /export declare \1 ${i} /g" > tmp.d.ts
  cat tmp.d.ts > lib/index.d.ts
done

rm tmp.d.ts
