44
55# Uses: patchJQAssistantTypescriptPlugin.sh, detectChangedFiles.sh
66
7+ # Note: This script must not output anything except for the return code to stdout.
8+ # All output of the scanning needs to be redirected to stderr using ">&2".
9+
710# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
811set -o errexit -o pipefail
912
1013ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:- " artifacts" }
1114SOURCE_DIRECTORY=${SOURCE_DIRECTORY:- " source" }
1215
1316TYPESCRIPT_SCAN_HEAP_MEMORY=${TYPESCRIPT_SCAN_HEAP_MEMORY:- " 4096" } # Heap memory in megabytes for Typescript scanning with (Node.js process). Defaults to 4096 MB.
14- echo " scanTypescript TYPESCRIPT_SCAN_HEAP_MEMORY=${TYPESCRIPT_SCAN_HEAP_MEMORY} " >&2
17+ echo " scanTypescript: TYPESCRIPT_SCAN_HEAP_MEMORY=${TYPESCRIPT_SCAN_HEAP_MEMORY} " >&2
1518
1619# # Get this "scripts" directory if not already set
1720# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
1821# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
1922# This way non-standard tools like readlink aren't needed.
2023SCRIPTS_DIR=${SCRIPTS_DIR:- $( CDPATH=. cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " && pwd -P )} # Repository directory containing the shell scripts
21- echo " scanTypescript SCRIPTS_DIR=${SCRIPTS_DIR} " >&2
24+ echo " scanTypescript: SCRIPTS_DIR=${SCRIPTS_DIR} " >&2
25+
26+ # Dry run for internal testing (not intended to be accessible from the outside)
27+ TYPESCRIPT_SCAN_DRY_RUN=false
28+ if [ " ${TYPESCRIPT_SCAN_DRY_RUN} " = true ] ; then
29+ echo " scanTypescript: -> DRY RUN <- Scanning will only be logged, not executed." >&2
30+ fi
2231
2332if [ ! -d " ./${SOURCE_DIRECTORY} " ] ; then
2433 echo " scanTypescript: Source directory '${SOURCE_DIRECTORY} ' doesn't exist. The scan will therefore be skipped." >&2
3443changeDetectionHashFilePath=" ./${SOURCE_DIRECTORY} /typescriptFileChangeDetectionHashFile.txt"
3544changeDetectionReturnCode=$( source " ${SCRIPTS_DIR} /detectChangedFiles.sh" --readonly --hashfile " ${changeDetectionHashFilePath} " --paths " ./${SOURCE_DIRECTORY} " )
3645
37- if [ " ${changeDetectionReturnCode} " == " 0" ] ; then
46+ if [ " ${changeDetectionReturnCode} " == " 0" ]; then
3847 echo " scanTypescript: Files unchanged. Scan skipped."
39- else
48+ fi
49+
50+ if [ " ${changeDetectionReturnCode} " != " 0" ] || [ " ${TYPESCRIPT_SCAN_DRY_RUN} " = true ]; then
4051 echo " scanTypescript: Detected change (${changeDetectionReturnCode} ). Scanning Typescript source using @jqassistant/ts-lce."
4152
4253 mkdir -p " ./runtime/logs"
4354 LOG_DIRECTORY=" $( pwd) /runtime/logs"
4455 echo " scanTypescript: LOG_DIRECTORY=${LOG_DIRECTORY} " >&2
4556
4657 source_directories=$( find -L " ./${SOURCE_DIRECTORY} " -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -r -I {} echo {} )
58+
4759 total_directories=$( echo " ${source_directories} " | wc -l | awk ' {print $1}' )
4860 processed_directories=0
4961
5264 processed_directories=$(( processed_directories + 1 ))
5365 echo " " >&2
5466 echo " scanTypescript: $( date +' %Y-%m-%dT%H:%M:%S%z' ) Scanning ${directory_name} (${processed_directories} /${total_directories} ) -----------------" >&2
55- # Note: This script must not output anything except for the return code to stdout,
56- # all output of the scanning needs to be redirected to stderr using ">&2".
57- # For later troubleshooting, the output is also copied to a dedicated log file using "tee".
58- # Note: Don't worry about the hardcoded version number. It will be updated by Renovate using a custom Manager.
59- # Note: NODE_OPTIONS --max-old-space-size=4096 increases the memory for larger projects to scan
60- NODE_OPTIONS=
" ${NODE_OPTIONS} --max-old-space-size=${TYPESCRIPT_SCAN_HEAP_MEMORY} " npx --yes @jqassistant/
[email protected] " ${directory} " --extension React
2>&1 | tee
" ${LOG_DIRECTORY} /jqassistant-typescript-scan-${directory_name} .log" >&2 67+
68+ if [ " ${TYPESCRIPT_SCAN_DRY_RUN} " = false ] ; then
69+ # Note: For later troubleshooting, the output is also copied to a dedicated log file using "tee".
70+ # Note: Don't worry about the hardcoded version number. It will be updated by Renovate using a custom Manager.
71+ # Note: NODE_OPTIONS --max-old-space-size=4096 increases the memory for scanning larger projects
72+ NODE_OPTIONS=
" ${NODE_OPTIONS} --max-old-space-size=${TYPESCRIPT_SCAN_HEAP_MEMORY} " npx --yes @jqassistant/
[email protected] " ${directory} " --extension React
2>&1 | tee
" ${LOG_DIRECTORY} /jqassistant-typescript-scan-${directory_name} .log" >&2 73+ fi
6174 done
6275
63- changeDetectionReturnCode=$( source " ${SCRIPTS_DIR} /detectChangedFiles.sh" --hashfile " ${changeDetectionHashFilePath} " --paths " ./${SOURCE_DIRECTORY} " )
76+ if [ " ${TYPESCRIPT_SCAN_DRY_RUN} " = false ] ; then
77+ changeDetectionReturnCode=$( source " ${SCRIPTS_DIR} /detectChangedFiles.sh" --hashfile " ${changeDetectionHashFilePath} " --paths " ./${SOURCE_DIRECTORY} " )
78+ fi
6479fi
0 commit comments