Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run json2ts from maven #18900

Merged
merged 7 commits into from
Dec 4, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ openmetadata-ui/src/main/resources/ui/src/jsons/connectionSchemas
openmetadata-ui/src/main/resources/ui/src/jsons/ingestionSchemas
openmetadata-ui/src/main/resources/ui/src/jsons/governanceSchemas

#UI - Generated TS
openmetadata-ui/src/main/resources/ui/src/generated

#vscode
*/.vscode/*
Expand Down Expand Up @@ -132,4 +130,4 @@ ingestion/tests/cli_e2e/**/*test.yaml
/ingestion/tests/integration/great_expectations/gx/*

# Tests
**/metastore_db/
**/metastore_db/
8 changes: 8 additions & 0 deletions openmetadata-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@
<filtering>true</filtering>
</resource>
</resources>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>gz</nonFilteredFileExtension>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
<nonFilteredFileExtension>eot</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
<nonFilteredFileExtension>png</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</execution>
</executions>
Expand Down
15 changes: 14 additions & 1 deletion openmetadata-ui/src/main/resources/ui/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/usr/bin/env sh
# .husky/pre-commit
# ...

# this should run first before running the yarn pre-commit hook as we are changing the directory
changed_files=$(git diff --cached --name-only --diff-filter=ACM | grep 'openmetadata-spec/src/main/resources/json/schema/')

if [ -n "$changed_files" ]; then
echo "JSON schema files changed. Regenerating TypeScript files..."
./openmetadata-ui/src/main/resources/ui/json2ts.sh $changed_files
git add openmetadata-ui/src/main/resources/ui/src/generated
else
echo "No changes in JSON schema files. Skipping TypeScript generation."
fi


cd openmetadata-ui/src/main/resources/ui
yarn pre-commit
yarn pre-commit
2 changes: 1 addition & 1 deletion openmetadata-ui/src/main/resources/ui/babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"plugins": ["@babel/plugin-transform-runtime"]
}
}
}
}
97 changes: 52 additions & 45 deletions openmetadata-ui/src/main/resources/ui/json2ts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,76 +12,83 @@
# limitations under the License.
#

schema_directory='openmetadata-spec/src/main/resources/json/schema/'
#!/bin/bash

schema_directory='openmetadata-spec/src/main/resources/json/schema'
om_ui_directory='openmetadata-ui/src/main/resources/ui/src/generated'
tmp_dir=$(mktemp -d)

addLicensing(){
addLicensing() {
dir=$1
txt=`cat openmetadata-ui/src/main/resources/ui/types-licensing.txt; cat "$dir"`
txt=$(cat openmetadata-ui/src/main/resources/ui/types-licensing.txt; cat "$dir")
echo "$txt" > "$dir"
}

generateTmpSchemaFile() {
schema_file=$1
tmp_schema_file=$2
jq '(."$id" |= sub("https://open-metadata.org/schema";"";"i"))' $schema_file > $tmp_schema_file
jq '(."$id" |= sub("https://open-metadata.org/schema";"";"i"))' "$schema_file" > "$tmp_schema_file"
}

generateType(){
generateType() {
tmp_schema_file=$1
output_file=$2
#generate ts
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
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

if [ -s $output_file ]
then
if [ -s "$output_file" ]; then
addLicensing "$output_file"
else
echo "Error: Could not generate $output_file"
rm -f "$output_file"
fi
}

getTypes(){
if [ -d "$om_ui_directory" ]
then
rm -r $om_ui_directory
fi

for file_with_dir in $(find $schema_directory -name "*.json" | sed -e 's/openmetadata-spec\/src\/main\/resources\/json\/schema\///g')
do
local_tmp_dir="$tmp_dir/$(dirname $file_with_dir)"
mkdir -p $local_tmp_dir
tmp_schema_file="${local_tmp_dir}/$(basename -- $file_with_dir)"
#args schema file, tmp schema file, output ts file
generateTmpSchemaFile $PWD"/"$schema_directory$file_with_dir $tmp_schema_file
done
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

escaped_tmp_dir=$(echo $tmp_dir | sed -e 's/[]\/$*.^[]/\\&/g')
for file_with_dir in $(find $tmp_dir -name "*.json" | sed -e "s/${escaped_tmp_dir}//g")
do
joblist=$(jobs | wc -l)
while [ ${joblist} -ge 30 ]
do
sleep 1
joblist=$(jobs | wc -l)
done
mkdir -p "$(dirname "$om_ui_directory$file_with_dir")"
fileTS=$(echo $file_with_dir | sed "s/.json/.ts/g")
outputTS=$PWD"/"$om_ui_directory$fileTS
tmp_schema_file=$tmp_dir$file_with_dir
#args schema file, tmp schema file, output ts file
generateType $tmp_schema_file $outputTS &
tmp_schema_file="$tmp_dir/$(basename "$schema_file")"
output_file="$output_dir/$(basename "$schema_file" .json).ts"

# Generate temporary schema and TypeScript file
generateTmpSchemaFile "$schema_file" "$tmp_schema_file"
generateType "$tmp_schema_file" "$output_file"
}

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))
done

}

# Checkout root directory to generate typescript from schema
cd ../../../../..
# Move to project root directory
cd "$(dirname "$0")/../../../../.." || exit

echo "Generating TypeScript from OpenMetadata specifications"
getTypes
wait $(jobs -p)
rm -rf $tmp_dir

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 "$@"

# Clean up temporary files
rm -rf "$tmp_dir"

echo "TypeScript generation completed."
9 changes: 6 additions & 3 deletions openmetadata-ui/src/main/resources/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
"lint": "eslint \"./**/*.{js,jsx,ts,tsx,json}\"",
"lint:fix": "eslint './**/*.{js,jsx,ts,tsx,json}' --fix",
"pretty": "prettier . --config './.prettierrc.yaml' --ignore-path './.prettierignore' --write",
"build-check": "yarn run json2ts && yarn run js-antlr && yarn run parse-schema",
"build-check": "yarn run js-antlr && yarn run parse-schema",
"commit-check": "yarn run pretty && yarn run build",
"license-header-check": "license-check-and-add check -f .licenseheaderrc.json",
"license-header-fix": "license-check-and-add add -f .licenseheaderrc.json -r $(date +%Y)",
"json2ts": "sh json2ts.sh",
"parse-schema": "node parseSchemas",
"js-antlr": "PWD=$(echo $PWD) antlr4 -Dlanguage=JavaScript -o src/generated/antlr \"$PWD\"/../../../../../openmetadata-spec/src/main/antlr4/org/openmetadata/schema/*.g4",
"i18n": "sync-i18n --files '**/locale/languages/*.json' --primary en-us --space 2 --fn",
Expand Down Expand Up @@ -187,6 +186,7 @@
"babel-jest": "^24.9.0",
"babel-loader": "8.3.0",
"clean-webpack-plugin": "^3.0.0",
"compression-webpack-plugin": "^11.1.0",
"copy-webpack-plugin": "^7.0.0",
"css-loader": "^6.7.2",
"dotenv": "^16.0.0",
Expand All @@ -206,6 +206,7 @@
"html-webpack-plugin": "^5.5.0",
"husky": "^8.0.1",
"i18next-json-sync": "^3.1.2",
"image-webpack-loader": "^8.1.0",
"jest": "^26.6.3",
"jest-sonar-reporter": "^2.0.0",
"less-loader": "^11.0.0",
Expand All @@ -218,12 +219,14 @@
"react-test-renderer": "^16.14.0",
"style-loader": "^3.3.1",
"sync-i18n": "^0.0.20",
"thread-loader": "^4.0.4",
"ts-jest": "^26.4.4",
"ts-loader": "^8.0.14",
"tslib": "^2.4.1",
"typescript": "^4.2.4",
"url-loader": "^4.1.1",
"webpack": "5.94.0",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "4.15.2"
},
Expand All @@ -248,4 +251,4 @@
"jsonpath-plus": "10.0.7",
"cross-spawn": "7.0.5"
}
}
}
Loading
Loading