|
| 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