Skip to content

Commit 1ef0be1

Browse files
committed
Install the CDS toolkit in each relevant directory
npx can sometimes install the inappropriate version of the cds compiler, if one is specified by a grandparent directory. We therefore update the script to install the cds command in each relevant directory with a package.json before using the npx command.
1 parent 37997b3 commit 1ef0be1

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

extractors/cds/tools/index-files.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,36 @@ if [ ! -s "$response_file" ]; then
1717
exit 0
1818
fi
1919

20-
# Ensure that we have the `cds` command
20+
# Determine if we have the cds command available, and if not, install the cds development kit
21+
# in the appropriate directories
2122
if ! command -v cds &> /dev/null
2223
then
24+
# Find all the directories containing a package.json with a dependency on @sap/cds, where
25+
# the directory contains at least one of the files listed in the response file (e.g. the
26+
# cds files we want to extract).
27+
#
28+
# We then install the cds development kit (@sap/cds-dk) in each directory, which makes the
29+
# `cds` command usable from the npx command within that directory.
30+
#
31+
# Nested package.json files simply cause the package to be installed in the parent node_modules
32+
# directory.
33+
#
34+
# We also ensure we skip node_modules, as we can end up in a recursive loop
35+
find . -type d -name node_modules -prune -false -o -type f \( -iname 'package.json' \) -exec grep -l '@sap/cds' {} + -execdir grep -q "^{}\(/\|$\)" "$response_file" + -execdir bash -c "echo \"Installing @sap/cds-dk into \$(pwd) to enable CDS compilation.\"" \; -execdir npm install @sap/cds-dk \;
36+
2337
# Use the npx command to dynamically install the cds development kit (@sap/cds-dk) package if necessary,
24-
# which then provides the cds command line tool.
38+
# which then provides the cds command line tool in directories which are not covered by the package.json
39+
# install command approach above
2540
cds_command="npx -y --package @sap/cds-dk cds"
2641
else
2742
cds_command="cds"
2843
fi
2944

3045
echo "Processing CDS files to JSON"
3146

47+
# Run the cds compile command on each file in the response file, outputting the JSON to a file with the same name
3248
while IFS= read -r cds_file; do
49+
$cds_command --version
3350
$cds_command compile "$cds_file" \
3451
-2 json \
3552
-o "$cds_file.json" \

0 commit comments

Comments
 (0)