@@ -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
+ cd "$target_dir"
113
+ git add "$target_file" # This stages the deletion
114
+ cd - > /dev/null
115
+ fi
116
+ fi
117
+ done
118
+
119
+ # Step 2: Sync source files to target
120
+ echo "Syncing source files..."
86
121
find "$source_dir" -name "README.mdx" | while read -r source_file; do
87
122
# Get the component path (e.g., anthropic/v0/README.mdx from pkg/component/ai/anthropic/v0/README.mdx)
88
123
component_path="${source_file#$source_dir/}"
@@ -97,10 +132,6 @@ jobs:
97
132
# Create flattened filename using component ID (e.g., anthropic.mdx)
98
133
target_file="$target_dir/${COMPONENT_ID}.mdx"
99
134
100
- # Create target directory if it doesn't exist
101
- target_file_dir=$(dirname "$target_file")
102
- mkdir -p "$target_file_dir"
103
-
104
135
# Compare files and copy if different
105
136
if [ ! -f "$target_file" ] || ! cmp -s "$source_file" "$target_file"; then
106
137
echo "Updating: $component_path -> ${COMPONENT_ID}.mdx"
@@ -119,9 +150,9 @@ jobs:
119
150
local target_dir="$2"
120
151
local component_type="$3"
121
152
local index_file="readme/docs/Component/${component_type}.mdx"
122
-
153
+
123
154
echo "Updating component index for $component_type..."
124
-
155
+
125
156
# Remove existing table if it exists
126
157
if [[ "${OSTYPE}" == "darwin"* ]]; then
127
158
# macOS
@@ -131,17 +162,17 @@ jobs:
131
162
sed -i '/^ *|.*| *$/d; /^[[:space:]]*:-+[[:space:]]*|[[:space:]]*-+.*$/d' "$index_file"
132
163
sed -i '/^$/N;/^\n$/D' "$index_file"
133
164
fi
134
-
165
+
135
166
# Add new table header
136
167
echo "" >> "$index_file"
137
168
echo "| Name | Description |" >> "$index_file"
138
169
echo "|:--|:--|" >> "$index_file"
139
-
170
+
140
171
# Add components to table
141
172
for component_file in "$target_dir"/*.mdx; do
142
173
if [[ -f "$component_file" ]]; then
143
174
component_id=$(basename "$component_file" .mdx)
144
-
175
+
145
176
# Find the corresponding source directory by matching component_id in definition.yaml files
146
177
component_source_dir=""
147
178
for dir in "$source_dir"/*; do
@@ -153,7 +184,7 @@ jobs:
153
184
fi
154
185
fi
155
186
done
156
-
187
+
157
188
# Use the metadata we found
158
189
if [[ -n "$component_source_dir" ]]; then
159
190
component_title="$COMPONENT_TITLE"
@@ -162,12 +193,12 @@ jobs:
162
193
component_title="$component_id"
163
194
component_description="Component definition is missing"
164
195
fi
165
-
196
+
166
197
# Create table row
167
198
echo "| [$component_title](/docs/$component_id) | $component_description |" >> "$index_file"
168
199
fi
169
200
done
170
-
201
+
171
202
# Stage the updated index file
172
203
cd "readme/docs/Component"
173
204
git add "${component_type}.mdx"
0 commit comments