Skip to content

Commit 7136981

Browse files
committed
Scan Typescript sources only on changes.
1 parent da98d15 commit 7136981

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

scripts/findPathsToScan.sh

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,6 @@ else
3939
fi
4040

4141
if [ -d "./${SOURCE_DIRECTORY}" ] ; then
42-
if command -v "npx" &> /dev/null ; then
43-
# TODO: Remove patchJQAssistantTypescriptPlugin when issue is resolved: https://github.com/jqassistant-plugin/jqassistant-typescript-plugin/issues/125
44-
source "${SCRIPTS_DIR}/patchJQAssistantTypescriptPlugin.sh" >&2
45-
echo "findPathsToScan: Scanning Typescript source using @jqassistant/ts-lce..." >&2
46-
# Note: The npx command will be executed in the source directory using a subshell by putting parentheses around it.
47-
# The subshell is the reason why it isn't needed to change back to the main directory after execution.
48-
# Note: This script must not output anything except for the return code to stdout,
49-
# all output of the scanning needs to be redirected to stderr using ">&2".
50-
# For later troubleshooting, the output is also copied to a dedicated log file using "tee".
51-
# Note: Don't worry about the hardcoded version number. It will be updated by Renovate using a custom Manager.
52-
( cd "./${SOURCE_DIRECTORY}" && npx --yes @jqassistant/[email protected] --extension React 2>&1 | tee "./../runtime/logs/jqassistant-typescript-scan.log" >&2 || exit )
53-
else
54-
echo "findPathToScan Error: Command npx not found. It's needed to execute @jqassistant/ts-lce to scan Typescript projects." >&2
55-
fi
56-
5742
# Scan Typescript analysis json data files in the source directory
5843
typescriptAnalysisFiles="$(find "./${SOURCE_DIRECTORY}" \
5944
-type d -name "node_modules" -prune -o \

scripts/resetAndScanChanged.sh

Lines changed: 4 additions & 3 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, detectChangedFiles.sh, findPathsToScan.sh
7+
# Requires resetAndScan.sh, copyPackageJsonFiles.sh, scanTypescript.sh, detectChangedFiles.sh, findPathsToScan.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,12 +16,13 @@ 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-
filesAndDirectoriesToScan=$( source "${SCRIPTS_DIR}/findPathsToScan.sh" )
20-
2119
# Prepare scan
2220
# TODO "copyPackageJsonFiles.sh" can be deleted here when the following issue is resolved:
2321
# https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5
2422
source "${SCRIPTS_DIR}/copyPackageJsonFiles.sh"
23+
source "${SCRIPTS_DIR}/scanTypescript.sh"
24+
25+
filesAndDirectoriesToScan=$( source "${SCRIPTS_DIR}/findPathsToScan.sh" )
2526

2627
# Scan and analyze Artifacts when they were changed
2728
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --readonly --paths "${filesAndDirectoriesToScan}")

scripts/scanTypescript.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
# Executes the npm package @jqassistant/ts-lc using npx to scan the Typescript projects in the source directory and create an intermediate json data file for the jQAssistant Typescript plugin.
4+
5+
# Uses: patchJQAssistantTypescriptPlugin.sh, detectChangedFiles.sh
6+
7+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
8+
set -o errexit -o pipefail
9+
10+
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"}
11+
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"}
12+
13+
## Get this "scripts" directory if not already set
14+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
15+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
16+
# This way non-standard tools like readlink aren't needed.
17+
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the shell scripts
18+
echo "scanTypescript SCRIPTS_DIR=${SCRIPTS_DIR}" >&2
19+
20+
if [ ! -d "./${SOURCE_DIRECTORY}" ] ; then
21+
echo "scanTypescript: Source directory '${SOURCE_DIRECTORY}' doesn't exist. The scan will therefore be skipped." >&2
22+
return 0
23+
fi
24+
25+
if ! command -v "npx" &> /dev/null ; then
26+
echo "scanTypescript Error: Command npx not found. It's needed to execute @jqassistant/ts-lce to scan Typescript projects." >&2
27+
exit 1
28+
fi
29+
30+
31+
32+
# Note: The npx command will be executed in the source directory using a subshell by putting parentheses around it.
33+
# The subshell is the reason why it isn't needed to change back to the main directory after execution.
34+
# Note: This script must not output anything except for the return code to stdout,
35+
# all output of the scanning needs to be redirected to stderr using ">&2".
36+
# For later troubleshooting, the output is also copied to a dedicated log file using "tee".
37+
# Note: Don't worry about the hardcoded version number. It will be updated by Renovate using a custom Manager.
38+
39+
40+
# Scan and analyze Artifacts when they were changed
41+
changeDetectionHashFilePath="./${SOURCE_DIRECTORY}/typescriptFileChangeDetectionHashFile.txt"
42+
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --readonly --hashfile "${changeDetectionHashFilePath}" --paths "./${SOURCE_DIRECTORY}")
43+
44+
if [ "${changeDetectionReturnCode}" == "0" ] ; then
45+
echo "scanTypescript: Files unchanged. Scan skipped."
46+
else
47+
echo "scanTypescript: Detected change (${changeDetectionReturnCode}). Scanning Typescript source using @jqassistant/ts-lce."
48+
49+
# TODO: Remove patchJQAssistantTypescriptPlugin when issue is resolved: https://github.com/jqassistant-plugin/jqassistant-typescript-plugin/issues/125
50+
source "${SCRIPTS_DIR}/patchJQAssistantTypescriptPlugin.sh" >&2
51+
52+
( cd "./${SOURCE_DIRECTORY}" && npx --yes @jqassistant/[email protected] --extension React 2>&1 | tee "./../runtime/logs/jqassistant-typescript-scan.log" >&2 || exit )
53+
54+
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${changeDetectionHashFilePath}" --paths "./${SOURCE_DIRECTORY}")
55+
fi
56+
57+

0 commit comments

Comments
 (0)