Skip to content
Open
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
69 changes: 59 additions & 10 deletions scripts/generate-nestjs-sdk.bash
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
#!/bin/bash
#
#

# Note: This script is meant to be run from the project root, e.g.
# ./scripts/generate-nestjs-sdk.bash
if [ ! -d "node_modules" ]; then
echo "Error: No node_modules folder found. This script is meant to be run from the project root."
exit 1
fi

# This default is for when developing with a backend running directly on localhost
SWAGGER_API_URL=${SWAGGER_API_URL:-"http://localhost:3000/explorer-json"}
while [[ "$#" -gt 0 ]]; do
case "$1" in
--swagger-url)
shift
SWAGGER_API_URL=$1
shift
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done

USER=`who am i | cut -d\ -f1`
echo -e "\nUser running the script: ${USER}"

echo -e "\nCleanup old files..."
rm -rf node_modules/@scicatproject/scicat-sdk-ts-angular
echo -e "\nCleaning up from any previous run..."
rm -rf @scicatproject/scicat-sdk-ts-angular
mkdir -p @scicatproject/scicat-sdk-ts-angular
rm local-api-for-generator.json

echo -e "\nFetching the Swagger API from the back end..."
curl ${SWAGGER_API_URL} > local-api-for-generator.json

echo -e "\nGenerating the new sdk..."

Expand All @@ -17,13 +43,26 @@ echo -e "\nGenerating the new sdk..."
##
docker run \
--rm \
--add-host host.docker.internal:host-gateway \
-v "`pwd`:/local" \
openapitools/openapi-generator-cli:v7.13.0 generate \
-i http://host.docker.internal:3000/explorer-json \
-i /local/local-api-for-generator.json \
-c /local/scripts/typescript-angular-config.json \
-g typescript-angular \
-o local/@scicatproject/scicat-sdk-ts-angular \
--additional-properties=ngVersion=19.0.0,npmName=@scicatproject/scicat-sdk-ts-angular,supportsES6=true,withInterfaces=true --skip-validate-spec
--additional-properties=supportsES6=true --skip-validate-spec

# Clean this up immediately after use, in case subsequent steps fail.
rm local-api-for-generator.json

# Check if the docker command resulted in any output.
# If we don't do this, we'll try to cd into a missing folder,
# and then we'd be invoking 'npm run build' as root in the main project folder,
# which would create a bunch of stuff in ./dist belonging to root,
# causing problems for things like SciCat Live.
if [ ! -d "@scicatproject/scicat-sdk-ts-angular/api" ]; then
echo "Error: OpenApi output not found."
exit 1
fi

REMOVE_NPM_LINK=0
if ! command -v npm 2>&1 1>/dev/null
Expand All @@ -44,19 +83,28 @@ fi

echo -e "\nInstalling dependencies and building the sdk..."
cd @scicatproject/scicat-sdk-ts-angular
# If this fails mysteriously you may need to run 'npm cache verify'.
npm install
npm run build

echo -e "\nCopying the build files in node_modules..."
cd ../..
cp -rv @scicatproject/scicat-sdk-ts-angular/dist node_modules/@scicatproject/scicat-sdk-ts-angular

if [ ! -d "@scicatproject/scicat-sdk-ts-angular/dist" ]; then
echo "Error: Build ouput not found."
exit 1
fi

echo -e "\nRemoving existing version from node_modules..."
rm -rf node_modules/@scicatproject/scicat-sdk-ts-angular
echo -e "\nCopying the build files into node_modules..."
mkdir -p node_modules/@scicatproject/scicat-sdk-ts-angular
cp -rv @scicatproject/scicat-sdk-ts-angular/dist/ node_modules/@scicatproject/scicat-sdk-ts-angular/

echo -e "\nAdjusting ownership to user ${USER}"
chown -Rv ${USER} node_modules/@scicatproject/scicat-sdk-ts-angular

echo -e "\nFinal cleanup..."
echo -e "Removing sdk folder"
rm -rfv @scicatproject
rm -rf @scicatproject

if [ $REMOVE_NPM_LINK -eq 1 ];
then
Expand All @@ -65,3 +113,4 @@ then
rm -fv "/usr/local/bin/node"
fi

echo -e "\nDone."
9 changes: 9 additions & 0 deletions scripts/typescript-angular-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"generatorName": "typescript-angular",
"npmName": "@scicatproject/scicat-sdk-ts-angular",
"ngVersion": "19.0.0",
"withInterfaces": true,
"paramNaming": "original",
"modelPropertyNaming": "original",
"enumPropertyNaming": "original"
}
Loading