2021-08-23 21:00:06 +05:30
|
|
|
#!/bin/bash
|
2022-12-27 12:37:58 +05:30
|
|
|
#
|
|
|
|
# Copyright 2022 Collate.
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2021-08-23 21:00:06 +05:30
|
|
|
|
2024-12-03 23:16:07 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
schema_directory='openmetadata-spec/src/main/resources/json/schema'
|
2023-07-09 21:12:46 -07:00
|
|
|
om_ui_directory='openmetadata-ui/src/main/resources/ui/src/generated'
|
|
|
|
|
|
|
|
|
2024-12-03 23:16:07 -08:00
|
|
|
generateType() {
|
2023-07-09 21:12:46 -07:00
|
|
|
tmp_schema_file=$1
|
|
|
|
output_file=$2
|
2024-12-03 23:16:07 -08:00
|
|
|
echo "Generating $output_file from specification at $tmp_schema_file"
|
|
|
|
./node_modules/.bin/quicktype -s schema "$tmp_schema_file" -o "$output_file" --just-types > /dev/null 2>&1
|
2022-05-19 21:23:39 +05:30
|
|
|
}
|
2023-07-09 21:12:46 -07:00
|
|
|
|
2024-12-03 23:16:07 -08:00
|
|
|
processFile() {
|
|
|
|
schema_file=$1
|
|
|
|
relative_path=${schema_file#"$schema_directory/"} # Extract relative path
|
|
|
|
output_dir="$om_ui_directory/$(dirname "$relative_path")"
|
|
|
|
|
|
|
|
# Debugging output
|
|
|
|
echo "Processing schema: $schema_file"
|
|
|
|
echo "Relative path: $relative_path"
|
|
|
|
echo "Output directory: $output_dir"
|
|
|
|
|
|
|
|
mkdir -p "$output_dir" # Ensure output directory exists
|
2023-07-09 21:12:46 -07:00
|
|
|
|
2024-12-03 23:16:07 -08:00
|
|
|
tmp_schema_file="$tmp_dir/$(basename "$schema_file")"
|
|
|
|
output_file="$output_dir/$(basename "$schema_file" .json).ts"
|
|
|
|
|
|
|
|
# Generate temporary schema and TypeScript file
|
2024-12-06 15:36:32 +05:30
|
|
|
generateType "$schema_file" "$output_file"
|
2024-12-03 23:16:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
getTypes() {
|
|
|
|
total_files=$#
|
|
|
|
current_file=1
|
|
|
|
|
|
|
|
for schema_file in "$@"; do
|
|
|
|
echo "Processing file $current_file of $total_files: $schema_file"
|
|
|
|
processFile "$schema_file"
|
|
|
|
current_file=$((current_file + 1))
|
2021-08-23 21:00:06 +05:30
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-12-03 23:16:07 -08:00
|
|
|
# Move to project root directory
|
|
|
|
cd "$(dirname "$0")/../../../../.." || exit
|
|
|
|
|
2023-07-09 21:12:46 -07:00
|
|
|
echo "Generating TypeScript from OpenMetadata specifications"
|
|
|
|
|
2024-12-03 23:16:07 -08:00
|
|
|
if [ "$#" -eq 0 ]; then
|
|
|
|
echo "No schema files specified. Please provide schema file paths."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Process the schema files passed as arguments
|
|
|
|
getTypes "$@"
|
|
|
|
|
|
|
|
echo "TypeScript generation completed."
|