6
6
set -e
7
7
8
8
# Base directory to scan (relative to project root)
9
- BASE_DIR=" javascript/frameworks/cap/test/queries "
9
+ BASE_DIR=" javascript/frameworks/cap/test"
10
10
11
11
# Navigate to project root directory (4 levels up from extractors/cds/tools/test/)
12
12
SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
@@ -32,26 +32,26 @@ echo ""
32
32
resolve_cds_dk_version () {
33
33
local package_json_path=" $1 "
34
34
local minimum_version=8
35
-
35
+
36
36
if [ ! -f " $package_json_path " ]; then
37
37
echo " ^$minimum_version "
38
38
return
39
39
fi
40
-
40
+
41
41
# Extract @sap/cds and @sap/cds-dk versions from package.json using grep and sed
42
42
local cds_version=" "
43
43
local cds_dk_version=" "
44
-
44
+
45
45
if grep -q ' "@sap/cds"' " $package_json_path " ; then
46
46
cds_version=$( grep ' "@sap/cds"' " $package_json_path " | sed -E ' s/.*"@sap\/cds": "([^"]+)".*/\1/' )
47
47
fi
48
-
48
+
49
49
if grep -q ' "@sap/cds-dk"' " $package_json_path " ; then
50
50
cds_dk_version=$( grep ' "@sap/cds-dk"' " $package_json_path " | sed -E ' s/.*"@sap\/cds-dk": "([^"]+)".*/\1/' )
51
51
fi
52
-
52
+
53
53
local preferred_dk_version=" "
54
-
54
+
55
55
if [ -n " $cds_dk_version " ]; then
56
56
# Use explicit @sap/cds-dk version if available, but enforce minimum
57
57
preferred_dk_version=$( enforce_minimum_version " $cds_dk_version " " $minimum_version " )
@@ -62,18 +62,18 @@ resolve_cds_dk_version() {
62
62
# No version information found, use minimum
63
63
preferred_dk_version=" ^$minimum_version "
64
64
fi
65
-
65
+
66
66
echo " $preferred_dk_version "
67
67
}
68
68
69
69
# Function to enforce minimum version requirement
70
70
enforce_minimum_version () {
71
71
local version=" $1 "
72
72
local minimum_version=" $2 "
73
-
73
+
74
74
# Extract major version number (handle ^, ~, and plain numbers)
75
75
local major_version=$( echo " $version " | sed -E ' s/^[\^~]?([0-9]+).*/\1/' )
76
-
76
+
77
77
if [[ " $major_version " =~ ^[0-9]+$ ]]; then
78
78
if [ " $major_version " -lt " $minimum_version " ]; then
79
79
echo " ^$minimum_version "
@@ -89,10 +89,10 @@ enforce_minimum_version() {
89
89
derive_compatible_version () {
90
90
local cds_version=" $1 "
91
91
local minimum_version=" $2 "
92
-
92
+
93
93
# Extract major version and use same range
94
94
local major_version=$( echo " $cds_version " | sed -E ' s/^[\^~]?([0-9]+).*/\1/' )
95
-
95
+
96
96
if [[ " $major_version " =~ ^[0-9]+$ ]]; then
97
97
local derived_version=" ^$major_version "
98
98
# Apply minimum version enforcement
@@ -107,7 +107,7 @@ derive_compatible_version() {
107
107
get_relative_path () {
108
108
local target=" $1 "
109
109
local base=" $2 "
110
-
110
+
111
111
# Use Python to calculate relative path (works on both macOS and Linux)
112
112
python3 -c " import os.path; print(os.path.relpath('$target ', '$base '))" 2> /dev/null || echo " $target "
113
113
}
@@ -121,27 +121,64 @@ echo ""
121
121
# Array to collect generated model.cds.json files
122
122
GENERATED_FILES=()
123
123
124
- # Find test directories (those containing .expected files)
124
+ # Array to track processed directories to avoid duplicates
125
+ PROCESSED_DIRS=()
126
+
127
+ # Find test directories (those containing .expected files) and deduplicate
125
128
echo " Scanning for test directories..."
126
- for test_dir in $( find " $BASE_DIR " -type f -name ' *.expected' -exec dirname {} \; ) ;
129
+ TEST_DIRS=($( find " $BASE_DIR " -type f -name ' *.expected' -exec dirname {} \; | sort -u) )
130
+
131
+ for test_dir in " ${TEST_DIRS[@]} " ;
127
132
do
133
+ # Skip if this directory has already been processed
134
+ if [[ " ${PROCESSED_DIRS[@]} " =~ " ${test_dir} " ]]; then
135
+ echo " Skipping already processed directory: $test_dir "
136
+ continue
137
+ fi
138
+
128
139
echo " Processing test directory: $test_dir "
129
-
140
+
130
141
# Change to test directory
131
142
pushd " $test_dir " > /dev/null
132
-
143
+
144
+ # Check if this directory contains any .cds files in supported locations
145
+ echo " Checking for CDS files in project directory: $( pwd) "
146
+ CDS_FILES_FOUND=false
147
+
148
+ # Check for .cds files in the base directory
149
+ if find . -maxdepth 1 -type f -name ' *.cds' | grep -q . ; then
150
+ CDS_FILES_FOUND=true
151
+ fi
152
+
153
+ # Check for .cds files in app/, db/, or srv/ subdirectories (including nested)
154
+ if [ " $CDS_FILES_FOUND " = false ]; then
155
+ for subdir in app db srv; do
156
+ if [ -d " $subdir " ] && find " $subdir " -type f -name ' *.cds' | grep -q . ; then
157
+ CDS_FILES_FOUND=true
158
+ break
159
+ fi
160
+ done
161
+ fi
162
+
163
+ if [ " $CDS_FILES_FOUND " = false ]; then
164
+ echo " ⚠️ No .cds files found in base directory or app/db/srv subdirectories - skipping compilation"
165
+ popd > /dev/null
166
+ echo " "
167
+ continue
168
+ fi
169
+
133
170
# Generate a single model.cds.json file per project directory,
134
171
# aligning with the CDS extractor's standardized compilation behavior.
135
172
echo " Compiling CDS project in directory: $( pwd) "
136
-
173
+
137
174
# Resolve the appropriate @sap/cds-dk version for this project
138
175
local_package_json=" $( pwd) /package.json"
139
176
preferred_dk_version=$( resolve_cds_dk_version " $local_package_json " )
140
177
echo " Resolved @sap/cds-dk version: $preferred_dk_version "
141
-
178
+
142
179
# Determine compilation targets using simplified logic from CDS extractor
143
180
COMPILE_TARGETS=" "
144
-
181
+
145
182
# Rule 1. index.cds if the test_dir directly contains an index.cds file (highest priority)
146
183
if [ -f " index.cds" ]; then
147
184
COMPILE_TARGETS=" index.cds"
160
197
echo " Using CAP directories and root CDS files as compilation targets: app db srv $ROOT_FILES "
161
198
fi
162
199
fi
163
-
200
+
164
201
# Use npx with project-specific version to ensure compatibility
165
202
cds_dk_package=" @sap/cds-dk@$preferred_dk_version "
166
203
echo " Running: npx --yes --package $cds_dk_package cds compile $COMPILE_TARGETS --locations --to json --dest model.cds.json"
167
-
204
+
168
205
# Disable exit-on-error for this compilation attempt
169
206
set +e
170
207
npx --yes --package " $cds_dk_package " cds compile \
175
212
--log-level warn
176
213
COMPILE_EXIT_CODE=$?
177
214
set -e
178
-
215
+
179
216
# Log compilation result
180
217
if [ -f " model.cds.json" ]; then
181
218
echo " ✓ Successfully generated model.cds.json in $( pwd) "
182
219
# Add to list of generated files (convert to relative path)
183
220
RELATIVE_PATH=$( get_relative_path " $( pwd) /model.cds.json" " $PROJECT_ROOT " )
184
221
GENERATED_FILES+=(" $RELATIVE_PATH " )
222
+ # Mark this directory as processed
223
+ PROCESSED_DIRS+=(" $test_dir " )
185
224
else
186
225
echo " ✗ Warning: model.cds.json was not generated in $( pwd) (exit code: $COMPILE_EXIT_CODE )"
187
226
if [ -s " compilation.err" ]; then
188
227
echo " Compilation errors:"
189
228
cat " compilation.err" | sed ' s/^/ /'
190
229
fi
191
230
fi
192
-
231
+
193
232
popd > /dev/null
194
233
echo " "
195
234
done
0 commit comments