-
Notifications
You must be signed in to change notification settings - Fork 10
/
rebuild.sh
executable file
·72 lines (57 loc) · 2.28 KB
/
rebuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
set -euxo pipefail
VERSION=0.3.0 # Target version of FalconJS
ORIGINAL_SWAGGER=./specs/swagger.json
FINAL_SWAGGER=./specs/final.json
CONTAINER_TOOL=
if command -v docker >/dev/null 2>&1; then
CONTAINER_TOOL="docker"
elif command -v podman >/dev/null 2>&1; then
CONTAINER_TOOL="podman"
else
echo "No container runtime tool found. Please install either Docker or Podman."
exit 1
fi
if [ ! -f $ORIGINAL_SWAGGER ]; then
echo "couldn't find $ORIGINAL_SWAGGER (you need to download it manually)"
exit 1
fi
SPEC_VERSION=$(jq -r .info.version specs/swagger.json)
jq -f ./specs/transformation.jq $ORIGINAL_SWAGGER > $FINAL_SWAGGER
sed -f ./specs/transformation.sed -i '' $FINAL_SWAGGER
typ=typescript-fetch
build_dir="specs/out/$typ"
rm -rf "./$build_dir"
BUILD_CONTAINER="openapitools/openapi-generator-cli:v7.7.0"
$CONTAINER_TOOL pull "$BUILD_CONTAINER"
$CONTAINER_TOOL run --rm \
-v "$PWD":/falcon-js "$BUILD_CONTAINER" generate \
-i /falcon-js/$FINAL_SWAGGER \
-g "${typ}" \
-o "/falcon-js/$build_dir" \
--additional-properties=httpUserAgent=falconjs/$VERSION \
--additional-properties=packageName=falconjs \
--additional-properties=packageVersion=$VERSION \
--additional-properties=npmVersion=$VERSION \
--additional-properties=disallowAdditionalPropertiesIfNotPresent=false \
--additional-properties=useSingleRequestParameter=false \
--additional-properties=prefixParameterInterfaces=true \
--additional-properties=npmName=crowdstrike-falcon \
--additional-properties=npmRepository=https://github.com/crowdstrike/falcon-js \
--additional-properties=supportsES6=true \
--additional-properties=typescriptThreePlus=true \
--skip-validate-spec
grep -lr ./src -e 'This class is auto generated by OpenAPI Generator' | xargs rm --
# use the index.ts with all exports that we maintain, not just generated classes
rm ./${build_dir}/src/index.ts
cp -a ./${build_dir}/src/* ./src/
#TODO: populate client.ts with all API imports, class defs, and constructors
npm run format:fix
npm run lint:fix
npm run lint
npm run build
cat << EOF
✅ Rebuild complete. If everything looks good and you're ready to commit:
git add src/
git commit -m "Re-generate the codebase using swagger $SPEC_VERSION"
EOF