Skip to content

Commit 61ac659

Browse files
committed
Scan each Typescript package on failing repo scan
1 parent 2554c2b commit 61ac659

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

scripts/scanTypescript.sh

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
2424
echo "scanTypescript: SCRIPTS_DIR=${SCRIPTS_DIR}" >&2
2525

2626
# Dry run for internal testing (not intended to be accessible from the outside)
27-
TYPESCRIPT_SCAN_DRY_RUN=false
27+
TYPESCRIPT_SCAN_DRY_RUN=true # !!!!!!!! TODO !!!!!!! set back to false
2828
if [ "${TYPESCRIPT_SCAN_DRY_RUN}" = true ] ; then
2929
echo "scanTypescript: -> DRY RUN <- Scanning will only be logged, not executed." >&2
3030
fi
@@ -39,6 +39,48 @@ if ! command -v "npx" &> /dev/null ; then
3939
exit 1
4040
fi
4141

42+
# Takes one parameter containing the directory to search.
43+
# Returns all directories (multi-line) that contain a "package.json" file within the given base directory.
44+
find_directories_with_package_json_file() {
45+
find -L "${1}" \
46+
-type d -name "node_modules" -prune -o \
47+
-type d -name "dist" -prune -o \
48+
-type d -name ".yalc" -prune -o \
49+
-type d -name "lib" -prune -o \
50+
-type d -name "libs" -prune -o \
51+
-type d -name "*test" -prune -o \
52+
-type d -name "*tests" -prune -o \
53+
-name "package.json" \
54+
-print0 \
55+
| xargs -0 -r -I {} dirname {}
56+
}
57+
58+
# Takes one parameter containing the directory to scan for Typescript projects.
59+
# Executes the Typescript scan for the given base directory including subdirectories.
60+
# Skips the scan in case of a dry run
61+
scan_directory() {
62+
echo "" >&2
63+
echo "scanTypescript: $(date +'%Y-%m-%dT%H:%M:%S%z') Scanning ${directory_name} (${processed_directories}/${total_directories}) -----------------" >&2
64+
65+
if [ "${TYPESCRIPT_SCAN_DRY_RUN}" = false ] ; then
66+
# Note: For later troubleshooting, the output is also copied to a dedicated log file using "tee".
67+
# Note: Don't worry about the hardcoded version number. It will be updated by Renovate using a custom Manager.
68+
# Note: NODE_OPTIONS --max-old-space-size=4096 increases the memory for scanning larger projects
69+
NODE_OPTIONS="${NODE_OPTIONS} --max-old-space-size=${TYPESCRIPT_SCAN_HEAP_MEMORY}" npx --yes @jqassistant/[email protected] "${1}" --extension React 2>&1 | tee "${LOG_DIRECTORY}/jqassistant-typescript-scan-${directory_name}.log" >&2
70+
fi
71+
}
72+
73+
# Takes one parameter containing the directory to scan for Typescript projects.
74+
# TODO under construction
75+
is_empty_scan_result() {
76+
scan_file_size=$(wc -c "${1}/.reports/jqa/ts-output.json" | awk '{print $1}')
77+
if [[ "${scan_file_size}" -le 600 ]]; then
78+
true;
79+
else
80+
false;
81+
fi
82+
}
83+
4284
# Scan and analyze Artifacts when they were changed
4385
changeDetectionHashFilePath="./${SOURCE_DIRECTORY}/typescriptFileChangeDetectionHashFile.txt"
4486
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --readonly --hashfile "${changeDetectionHashFilePath}" --paths "./${SOURCE_DIRECTORY}")
@@ -54,23 +96,18 @@ if [ "${changeDetectionReturnCode}" != "0" ] || [ "${TYPESCRIPT_SCAN_DRY_RUN}" =
5496
LOG_DIRECTORY="$(pwd)/runtime/logs"
5597
echo "scanTypescript: LOG_DIRECTORY=${LOG_DIRECTORY}" >&2
5698

57-
source_directories=$( find -L "./${SOURCE_DIRECTORY}" -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -r -I {} echo {} )
99+
# source_directories=$( find -L "./${SOURCE_DIRECTORY}" -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -r -I {} echo {} )
100+
# TODO Idea: Leave source directories and get sub package.json projects for each of them. Ideally merge results with jq per source directory?
101+
# Another idea would be to switch between package.json granular scans versus current source level scans
102+
source_directories=$( find_directories_with_package_json_file "./${SOURCE_DIRECTORY}" )
58103

59104
total_directories=$(echo "${source_directories}" | wc -l | awk '{print $1}')
60105
processed_directories=0
61106

62107
for directory in ${source_directories}; do
63108
directory_name=$(basename "${directory}");
64109
processed_directories=$((processed_directories + 1))
65-
echo "" >&2
66-
echo "scanTypescript: $(date +'%Y-%m-%dT%H:%M:%S%z') Scanning ${directory_name} (${processed_directories}/${total_directories}) -----------------" >&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
110+
scan_directory "${directory}"
74111
done
75112

76113
if [ "${TYPESCRIPT_SCAN_DRY_RUN}" = false ] ; then

0 commit comments

Comments
 (0)