Skip to content

Commit 064d92b

Browse files
committed
Scan npm package.json files directly from the source directory
1 parent 51a4f42 commit 064d92b

File tree

3 files changed

+17
-52
lines changed

3 files changed

+17
-52
lines changed

scripts/copyPackageJsonFiles.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.

scripts/resetAndScan.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ JQASSISTANT_CONFIG_TEMPLATE=${JQASSISTANT_CONFIG_TEMPLATE:-"template-neo4jv5-jqa
1717
NEO4J_INITIAL_PASSWORD=${NEO4J_INITIAL_PASSWORD:-""} # Neo4j login password that was set to replace the temporary initial password
1818
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"} # Directory with the Java artifacts to scan and analyze
1919
TOOLS_DIRECTORY=${TOOLS_DIRECTORY:-"tools"} # Get the tools directory (defaults to "tools")
20+
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"} # Get the source repository directory (defaults to "source")
2021

2122
## Get this "scripts" directory if not already set
2223
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
@@ -68,16 +69,26 @@ if [ -d "${ARTIFACTS_DIRECTORY}" ] ; then
6869
directoriesAndFilesToScan="${directoriesAndFilesToScan},./${ARTIFACTS_DIRECTORY}"
6970
fi
7071

71-
# Scan Typescript analysis json data files in the artifacts/typescript directory
72-
typescriptAnalysisFiles="$(find . -type f -path "*/.reports/jqa/ts-output.json" -exec echo typescript:project::{} \; | tr '\n' ',' | sed 's/,$/\n/')"
73-
if [ -n "${typescriptAnalysisFiles}" ]; then
74-
directoriesAndFilesToScan="${directoriesAndFilesToScan},${typescriptAnalysisFiles}"
72+
if [ -d "${SOURCE_DIRECTORY}" ] ; then
73+
# Scan Typescript analysis json data files in the source directory
74+
typescriptAnalysisFiles="$(find "${SOURCE_DIRECTORY}" -type f -path "*/.reports/jqa/ts-output.json" -exec echo typescript:project::{} \; | tr '\n' ',' | sed 's/,$/\n/')"
75+
if [ -n "${typescriptAnalysisFiles}" ]; then
76+
directoriesAndFilesToScan="${directoriesAndFilesToScan},${typescriptAnalysisFiles}"
77+
fi
78+
# Scan package.json files for npm (nodes package manager) in the source directory
79+
npmPackageJsonFiles="$(find "${SOURCE_DIRECTORY}" -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {} | tr '\n' ',' | sed 's/,$/\n/')"
80+
if [ -n "${npmPackageJsonFiles}" ]; then
81+
directoriesAndFilesToScan="${directoriesAndFilesToScan},${npmPackageJsonFiles}"
82+
fi
7583
fi
7684

7785
# ------------------------------------------------------------------
7886

7987
# Use jQAssistant to scan the downloaded artifacts and write the results into the separate, local Neo4j Graph Database
80-
echo "resetAndScan: Using jQAssistant CLI version ${JQASSISTANT_CLI_VERSION} to scan: ${directoriesAndFilesToScan}"
88+
echo "resetAndScan: Using jQAssistant CLI version ${JQASSISTANT_CLI_VERSION} to scan the following files and directories:"
89+
for directoryOrFileToScan in ${directoriesAndFilesToScan//,/ }; do
90+
echo " - ${directoryOrFileToScan}"
91+
done
8192

8293
"${JQASSISTANT_BIN}"/jqassistant.sh scan -f "${directoriesAndFilesToScan}"
8394

scripts/resetAndScanChanged.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Note: "resetAndScan" expects jQAssistant to be installed in the "tools" directory.
66

7-
# Requires resetAndScan.sh, copyPackageJsonFiles.sh
7+
# Requires resetAndScan.sh
88

99
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
1010
set -o errexit -o pipefail
@@ -16,9 +16,6 @@ set -o errexit -o pipefail
1616
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the shell scripts
1717
echo "resetAndScanChanged SCRIPTS_DIR=${SCRIPTS_DIR}"
1818

19-
# Prepare scan
20-
source "${SCRIPTS_DIR}/copyPackageJsonFiles.sh"
21-
2219
# Scan and analyze Artifacts when they were changed
2320
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedArtifacts.sh" --readonly)
2421
if [[ "${changeDetectionReturnCode}" == "0" ]] ; then

0 commit comments

Comments
 (0)