Skip to content

Commit

Permalink
Merge pull request #89 from codeSafari10/ts-package
Browse files Browse the repository at this point in the history
Generate ts lib for schemas
  • Loading branch information
aabidsofi19 authored Jul 3, 2024
2 parents f571291 + 6ade120 commit 42356d8
Show file tree
Hide file tree
Showing 15 changed files with 2,981 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ api-validate:
schemas-join:
chmod +x scripts/merge-openapi-specs.sh
scripts/merge-openapi-specs.sh

## Building docs with redocly
docs-build:
redocly bundle --output openapi/bundled-schema.yml
redocly build-docs openapi/bundled-schema.yml --output=openapi/index.html
rm openapi/bundled-schema.yml

## Generate typescript library
generate-ts:
npm run generate:types

build-ts: generate-ts
npm run build

publish-ts: build-ts
npm publish

#-----------------------------------------------------------------------------
# Dependencies
#-----------------------------------------------------------------------------
Expand All @@ -60,4 +71,4 @@ endif



# redocly join openapi-schema/schemas/applications.yml openapi-schema/schemas/connections.yml yml openapi-schema/schemas/user_onboarding.yml openapi-schema/schemas/users.yml
# redocly join openapi-schema/schemas/applications.yml openapi-schema/schemas/connections.yml yml openapi-schema/schemas/user_onboarding.yml openapi-schema/schemas/users.yml
67 changes: 67 additions & 0 deletions compile-types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

# Check if both input and output directories are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <input_directory> <output_directory>"
exit 1
fi

INPUT_DIR=$(realpath "$1")
OUTPUT_DIR=$(realpath "$2")

# Check if input directory exists
if [ ! -d "$INPUT_DIR" ]; then
echo "Error: Input directory '$INPUT_DIR' does not exist."
exit 1
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

# Store the original directory
ORIGINAL_DIR=$(pwd)

# Function to process files
process_file() {
local file="$1"
local relative_path="${file#$INPUT_DIR/}" # Remove base directory from path
local dir=$(dirname "$relative_path")
local filename=$(basename "$file" .json)

# Create subdirectory in output folder if it doesn't exist
mkdir -p "$OUTPUT_DIR/$dir"

# Change to the directory containing the JSON file
cd "$(dirname "$file")"

# Run npx json2ts and capture both stdout and stderr
if output=$(npx json2ts --input "$(basename "$file")" --output "$OUTPUT_DIR/$dir/$filename.d.ts" 2>&1); then
echo "Processed: $file"
else
echo "Failed to process: $file"
echo "Error: $output"
fi

# Change back to the original directory
cd "$ORIGINAL_DIR"
}

# Function to traverse directory
traverse_directory() {
local dir="$1"

for item in "$dir"/*; do
if [ -d "$item" ]; then
# If it's a directory, recurse into it
traverse_directory "$item"
elif [ -f "$item" ] && [[ "$item" == *.json ]]; then
# If it's a JSON file, process it
process_file "$item"
fi
done
}

# Start traversing from the provided input directory
traverse_directory "$INPUT_DIR"

echo "Processing complete. Output files are in '$OUTPUT_DIR'."
Loading

0 comments on commit 42356d8

Please sign in to comment.