-
Notifications
You must be signed in to change notification settings - Fork 196
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
🐛 Fixes #368
🐛 Fixes #368
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,102 @@ | ||||||||
#!/bin/bash | ||||||||
|
||||||||
# Make the script executable | ||||||||
# chmod +x connectorUpdate.sh | ||||||||
|
||||||||
# Run the script with (vertical) and (provider) | ||||||||
# ./connectorUpdate.sh crm contact | ||||||||
|
||||||||
# Calculate the directory where the script resides | ||||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||
BASE_DIR="$(cd "$SCRIPT_DIR" && cd ../../.. && pwd)" # Adjust the path as necessary based on your directory structure | ||||||||
|
||||||||
# Function to scan directories for new services | ||||||||
scanDirectory() { | ||||||||
local dir=$1 | ||||||||
find "$dir" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | ||||||||
} | ||||||||
|
||||||||
# Function to replace relative paths | ||||||||
replaceRelativePaths() { | ||||||||
local path=$1 | ||||||||
echo "${path//..\/src\//@}" | ||||||||
} | ||||||||
|
||||||||
# Function to generate import statements for new services | ||||||||
generateImportStatements() { | ||||||||
local basePath=$1 | ||||||||
local objectType=$2 | ||||||||
local serviceNames=("$@") | ||||||||
shift 2 | ||||||||
local importStatements=() | ||||||||
for serviceName in "${serviceNames[@]}"; do | ||||||||
local importPath="${basePath}/${serviceName}/types" | ||||||||
local replacedPath=$(replaceRelativePaths "$importPath") | ||||||||
local name="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$objectType" | ||||||||
importStatements+=("import { ${name}Input, ${name}Output } from '${replacedPath}';") | ||||||||
done | ||||||||
printf "%s\n" "${importStatements[@]}" | ||||||||
} | ||||||||
|
||||||||
# Function to append import statements and update type definitions | ||||||||
updateTargetFile() { | ||||||||
local file=$1 | ||||||||
local imports=$2 | ||||||||
local serviceNames=("$@") | ||||||||
shift 2 | ||||||||
|
||||||||
# Append import statements to the file | ||||||||
printf "%s\n\n" "$imports" >> "$file" | ||||||||
|
||||||||
# Update type definitions | ||||||||
for serviceName in "${serviceNames[@]}"; do | ||||||||
local typeName="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$OBJECT_TYPE" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider separating declaration and assignment. Similar to previous comments, separating the declaration and assignment can improve clarity and prevent potential issues in script behavior. - local typeName="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$OBJECT_TYPE"
+ local typeName
+ typeName="$(tr '[:lower:]' '[:upper:]' <<< "${serviceName:0:1}")${serviceName:1}$OBJECT_TYPE" Committable suggestion
Suggested change
|
||||||||
sed -i "/export type Original${OBJECT_TYPE}Input =/a \ | ${typeName}Input" "$file" | ||||||||
sed -i "/export type Original${OBJECT_TYPE}Output =/a \ | ${typeName}Output" "$file" | ||||||||
done | ||||||||
} | ||||||||
|
||||||||
# Function to update mappings and module files | ||||||||
updateMappingsAndModules() { | ||||||||
local vertical=$1 | ||||||||
local objectType=$2 | ||||||||
local serviceDirs=("$@") | ||||||||
shift 2 | ||||||||
local mappingsPath="${MAPPINGS_FILE}/${vertical}/${objectType}/types/mappingsTypes.ts" | ||||||||
local modulePath="${BASE_DIR}/src/${vertical}/${objectType}/${objectType}.module.ts" | ||||||||
|
||||||||
# Update module and mapping files | ||||||||
for service in "${serviceDirs[@]}"; do | ||||||||
local serviceClass="${service^}Service" | ||||||||
if ! grep -q "$serviceClass" "$modulePath"; then | ||||||||
echo "import { $serviceClass } from './services/${service}';" >> "$modulePath" | ||||||||
fi | ||||||||
done | ||||||||
} | ||||||||
|
||||||||
# Main execution block | ||||||||
if [ "$#" -ne 2 ]; then | ||||||||
echo "Usage: $0 <vertical> <objectType>" | ||||||||
exit 1 | ||||||||
fi | ||||||||
|
||||||||
VERTICAL=$1 | ||||||||
OBJECT_TYPE=$2 | ||||||||
|
||||||||
# Define paths based on input | ||||||||
TARGET_FILE="${BASE_DIR}/src/@core/utils/types/original/original${VERTICAL}.ts" | ||||||||
SERVICES_DIR="${BASE_DIR}/src/${VERTICAL}/${OBJECT_TYPE}/services" | ||||||||
|
||||||||
# Scan for new services | ||||||||
newServices=($(scanDirectory "$SERVICES_DIR")) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Using - newServices=($(scanDirectory "$SERVICES_DIR"))
+ mapfile -t newServices < <(scanDirectory "$SERVICES_DIR") |
||||||||
|
||||||||
# Generate import statements | ||||||||
imports=$(generateImportStatements "$SERVICES_DIR" "$OBJECT_TYPE" "${newServices[@]}") | ||||||||
|
||||||||
# Update the target file | ||||||||
updateTargetFile "$TARGET_FILE" "$imports" "${newServices[@]}" | ||||||||
|
||||||||
# Update mappings and module files | ||||||||
updateMappingsAndModules "$VERTICAL" "$OBJECT_TYPE" "${newServices[@]}" | ||||||||
|
||||||||
echo "Update process completed for $VERTICAL $OBJECT_TYPE." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider separating declaration and assignment.
It's generally a good practice to separate the declaration of variables from their assignment when the assignment involves a function call. This can enhance readability and prevent issues where the return value might be masked by the assignment.
Committable suggestion