@@ -51,10 +51,10 @@ jobs:
51
51
local component_id=""
52
52
local component_title=""
53
53
local component_description=""
54
-
54
+
55
55
# Find the latest version directory (v0, v1, v2, etc.)
56
56
latest_version=$(find "$component_source_dir" -maxdepth 1 -type d -name "v*" | sort -V | tail -n 1)
57
-
57
+
58
58
# Extract metadata from definition.yaml in the latest version
59
59
if [[ -n "$latest_version" && -f "$latest_version/config/definition.yaml" ]]; then
60
60
component_id=$(yq -r '.id' "$latest_version/config/definition.yaml")
67
67
component_title="$component_name"
68
68
component_description="Component definition is missing"
69
69
fi
70
-
70
+
71
71
# Return values (bash doesn't have return values, so we use global variables)
72
72
COMPONENT_ID="$component_id"
73
73
COMPONENT_TITLE="$component_title"
82
82
83
83
echo "Comparing $component_type components..."
84
84
85
- # Find all README.mdx files in source directory
85
+ # Create target directory if it doesn't exist
86
+ mkdir -p "$target_dir"
87
+
88
+ # Step 1: Remove target files that don't exist in source
89
+ echo "Cleaning up orphaned files..."
90
+ for target_file in "$target_dir"/*.mdx; do
91
+ if [[ -f "$target_file" ]]; then
92
+ component_id=$(basename "$target_file" .mdx)
93
+
94
+ # Check if this component exists in source
95
+ component_exists=false
96
+ for source_component_dir in "$source_dir"/*; do
97
+ if [[ -d "$source_component_dir" ]]; then
98
+ latest_version=$(find "$source_component_dir" -maxdepth 1 -type d -name "v*" | sort -V | tail -n 1)
99
+ if [[ -n "$latest_version" && -f "$latest_version/config/definition.yaml" ]]; then
100
+ source_component_id=$(yq -r '.id' "$latest_version/config/definition.yaml")
101
+ if [[ "$source_component_id" == "$component_id" ]]; then
102
+ component_exists=true
103
+ break
104
+ fi
105
+ fi
106
+ fi
107
+ done
108
+
109
+ if [[ "$component_exists" == "false" ]]; then
110
+ echo "Removing orphaned file: $component_id.mdx"
111
+ rm "$target_file"
112
+ # Stage the deletion properly
113
+ cd "$target_dir"
114
+ git rm "$component_id.mdx"
115
+ cd - > /dev/null
116
+ fi
117
+ fi
118
+ done
119
+
120
+ # Step 2: Sync source files to target
121
+ echo "Syncing source files..."
86
122
find "$source_dir" -name "README.mdx" | while read -r source_file; do
87
123
# Get the component path (e.g., anthropic/v0/README.mdx from pkg/component/ai/anthropic/v0/README.mdx)
88
124
component_path="${source_file#$source_dir/}"
@@ -94,13 +130,15 @@ jobs:
94
130
component_source_dir="$source_dir/$component_name"
95
131
get_component_metadata "$component_source_dir"
96
132
133
+ # Skip if component ID is null or empty
134
+ if [[ "$COMPONENT_ID" == "null" || -z "$COMPONENT_ID" ]]; then
135
+ echo "Skipping component with invalid ID: $component_name"
136
+ continue
137
+ fi
138
+
97
139
# Create flattened filename using component ID (e.g., anthropic.mdx)
98
140
target_file="$target_dir/${COMPONENT_ID}.mdx"
99
141
100
- # Create target directory if it doesn't exist
101
- target_file_dir=$(dirname "$target_file")
102
- mkdir -p "$target_file_dir"
103
-
104
142
# Compare files and copy if different
105
143
if [ ! -f "$target_file" ] || ! cmp -s "$source_file" "$target_file"; then
106
144
echo "Updating: $component_path -> ${COMPONENT_ID}.mdx"
@@ -119,9 +157,9 @@ jobs:
119
157
local target_dir="$2"
120
158
local component_type="$3"
121
159
local index_file="readme/docs/Component/${component_type}.mdx"
122
-
160
+
123
161
echo "Updating component index for $component_type..."
124
-
162
+
125
163
# Remove existing table if it exists
126
164
if [[ "${OSTYPE}" == "darwin"* ]]; then
127
165
# macOS
@@ -131,17 +169,17 @@ jobs:
131
169
sed -i '/^ *|.*| *$/d; /^[[:space:]]*:-+[[:space:]]*|[[:space:]]*-+.*$/d' "$index_file"
132
170
sed -i '/^$/N;/^\n$/D' "$index_file"
133
171
fi
134
-
172
+
135
173
# Add new table header
136
174
echo "" >> "$index_file"
137
175
echo "| Name | Description |" >> "$index_file"
138
176
echo "|:--|:--|" >> "$index_file"
139
-
177
+
140
178
# Add components to table
141
179
for component_file in "$target_dir"/*.mdx; do
142
180
if [[ -f "$component_file" ]]; then
143
181
component_id=$(basename "$component_file" .mdx)
144
-
182
+
145
183
# Find the corresponding source directory by matching component_id in definition.yaml files
146
184
component_source_dir=""
147
185
for dir in "$source_dir"/*; do
@@ -153,7 +191,7 @@ jobs:
153
191
fi
154
192
fi
155
193
done
156
-
194
+
157
195
# Use the metadata we found
158
196
if [[ -n "$component_source_dir" ]]; then
159
197
component_title="$COMPONENT_TITLE"
@@ -162,12 +200,12 @@ jobs:
162
200
component_title="$component_id"
163
201
component_description="Component definition is missing"
164
202
fi
165
-
203
+
166
204
# Create table row
167
205
echo "| [$component_title](/docs/$component_id) | $component_description |" >> "$index_file"
168
206
fi
169
207
done
170
-
208
+
171
209
# Stage the updated index file
172
210
cd "readme/docs/Component"
173
211
git add "${component_type}.mdx"
0 commit comments