Skip to content

Commit 386ecf2

Browse files
committed
Provide generic download script for Typescript projects
1 parent 775a218 commit 386ecf2

File tree

3 files changed

+192
-83
lines changed

3 files changed

+192
-83
lines changed

scripts/downloader/downloadAntDesign.sh

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,26 @@
44
# The source files are written into the "source" directory of the current analysis directory.
55
# After scanning it with jQAssistant Typescript Plugin the resulting JSON will be moved into the "artifacts" directory.
66

7-
# Note: The #-framed blocks are those that are specific to this download.
8-
# The other parts of the script can be reused/copied as a reference to write other download scripts.
9-
107
# Note: This script is meant to be started within the temporary analysis directory (e.g. "temp/AnalysisName/")
118

129
# Fail on any error (errexit = exit on first error, errtrace = error inherited from sub-shell ,pipefail exist on errors within piped commands)
1310
set -o errexit -o errtrace -o pipefail
1411

15-
# Get the analysis name from the middle part of the current file name (without prefix "download" and without extension)
16-
SCRIPT_FILE_NAME="$(basename -- "${BASH_SOURCE[0]}")"
17-
SCRIPT_FILE_NAME_WITHOUT_EXTENSION="${SCRIPT_FILE_NAME%%.*}"
18-
SCRIPT_FILE_NAME_WITHOUT_PREFIX_AND_EXTENSION="${SCRIPT_FILE_NAME_WITHOUT_EXTENSION##download}"
19-
ANALYSIS_NAME="${SCRIPT_FILE_NAME_WITHOUT_PREFIX_AND_EXTENSION}"
20-
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"} # Get the source repository directory (defaults to "source")
21-
22-
echo "download${ANALYSIS_NAME}: SCRIPT_FILE_NAME=${SCRIPT_FILE_NAME}"
23-
echo "download${ANALYSIS_NAME}: SCRIPT_FILE_NAME_WITHOUT_EXTENSION=${SCRIPT_FILE_NAME_WITHOUT_EXTENSION}"
24-
echo "download${ANALYSIS_NAME}: ANALYSIS_NAME=${ANALYSIS_NAME}"
25-
2612
# Read the first input argument containing the version(s) of the artifact(s)
2713
if [ "$#" -ne 1 ]; then
28-
echo "Error (download${ANALYSIS_NAME}): Usage: $0 <version>" >&2
14+
echo "downloadAntDesign: Error: Usage: $0 <version>" >&2
2915
exit 1
3016
fi
31-
PROJECT_VERSION=$1
32-
echo "download${ANALYSIS_NAME}: PROJECT_VERSION=${PROJECT_VERSION}"
33-
34-
# Create runtime logs directory if it hasn't existed yet
35-
mkdir -p ./runtime/logs
36-
37-
################################################################
38-
# Download ant-design source files to be analyzed
39-
################################################################
40-
PROJECT_NAME="ant-design"
41-
FULL_PROJECT_NAME="${PROJECT_NAME}-${PROJECT_VERSION}"
42-
FULL_SOURCE_DIRECTORY="${SOURCE_DIRECTORY}/${FULL_PROJECT_NAME}"
43-
44-
if [ ! -d "${FULL_SOURCE_DIRECTORY}" ] ; then # only clone if source doesn't exist
45-
git clone --branch "${PROJECT_VERSION}" "https://github.com/ant-design/${PROJECT_NAME}.git" "${FULL_SOURCE_DIRECTORY}"
46-
fi
47-
(
48-
cd "${FULL_SOURCE_DIRECTORY}" || exit
49-
echo "download${ANALYSIS_NAME}: Installing dependencies..."
50-
npm install --verbose || exit
51-
echo "download${ANALYSIS_NAME}: Analyzing source..."
52-
npx --yes @jqassistant/ts-lce >"./../../runtime/logs/jqassistant-typescript-scan-${PROJECT_NAME}.log" 2>&1 || exit
53-
)
54-
mkdir -p artifacts/typescript
55-
mv -nv "${FULL_SOURCE_DIRECTORY}/.reports/jqa/ts-output.json" "artifacts/typescript/${FULL_PROJECT_NAME}.json"
56-
################################################################
17+
projectVersion="${1}"
18+
echo "downloadAntDesign: projectVersion=${projectVersion}"
19+
20+
## Get the directory of this script if not already set
21+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
22+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
23+
# This way non-standard tools like readlink aren't needed.
24+
DOWNLOADER_SCRIPTS_DIR=${DOWNLOADER_SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
25+
echo "downloadReactRouter: DOWNLOADER_SCRIPTS_DIR=${DOWNLOADER_SCRIPTS_DIR}"
26+
27+
source "${DOWNLOADER_SCRIPTS_DIR}/downloadTypescriptProject.sh" \
28+
--url https://github.com/ant-design/ant-design.git \
29+
--version "${projectVersion}"

scripts/downloader/downloadReactRouter.sh

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,31 @@
44
# The source files are written into the "source" directory of the current analysis directory.
55
# After scanning it with jQAssistant Typescript Plugin the resulting JSON will be moved into the "artifacts" directory.
66

7-
# Note: The #-framed blocks are those that are specific to this download.
8-
# The other parts of the script can be reused/copied as a reference to write other download scripts.
9-
107
# Note: This script is meant to be started within the temporary analysis directory (e.g. "temp/AnalysisName/")
8+
# Note: react-router uses pnpm as package manager which needs to be installed first
119

12-
# Note: react-router uses pnpm as package manager which needs to be installed
10+
# Requires downloadTypescriptProject.sh
1311

1412
# Fail on any error (errexit = exit on first error, errtrace = error inherited from sub-shell ,pipefail exist on errors within piped commands)
1513
set -o errexit -o errtrace -o pipefail
1614

17-
# Get the analysis name from the middle part of the current file name (without prefix "download" and without extension)
18-
SCRIPT_FILE_NAME="$(basename -- "${BASH_SOURCE[0]}")"
19-
SCRIPT_FILE_NAME_WITHOUT_EXTENSION="${SCRIPT_FILE_NAME%%.*}"
20-
SCRIPT_FILE_NAME_WITHOUT_PREFIX_AND_EXTENSION="${SCRIPT_FILE_NAME_WITHOUT_EXTENSION##download}"
21-
ANALYSIS_NAME="${SCRIPT_FILE_NAME_WITHOUT_PREFIX_AND_EXTENSION}"
22-
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"} # Get the source repository directory (defaults to "source")
23-
24-
echo "download${ANALYSIS_NAME}: SCRIPT_FILE_NAME=${SCRIPT_FILE_NAME}"
25-
echo "download${ANALYSIS_NAME}: SCRIPT_FILE_NAME_WITHOUT_EXTENSION=${SCRIPT_FILE_NAME_WITHOUT_EXTENSION}"
26-
echo "download${ANALYSIS_NAME}: ANALYSIS_NAME=${ANALYSIS_NAME}"
27-
2815
# Read the first input argument containing the version(s) of the artifact(s)
2916
if [ "$#" -ne 1 ]; then
30-
echo "Error (download${ANALYSIS_NAME}): Usage: $0 <version>" >&2
17+
echo "downloadAntDesign: Error: Usage: $0 <version>" >&2
3118
exit 1
3219
fi
33-
PROJECT_VERSION=$1
34-
echo "download${ANALYSIS_NAME}: PROJECT_VERSION=${PROJECT_VERSION}"
35-
36-
# Create runtime logs directory if it hasn't existed yet
37-
mkdir -p ./runtime/logs
38-
39-
################################################################
40-
# Download react-router source files to be analyzed
41-
################################################################
42-
PROJECT_NAME="react-router"
43-
FULL_PROJECT_NAME="${PROJECT_NAME}-${PROJECT_VERSION}"
44-
FULL_SOURCE_DIRECTORY="${SOURCE_DIRECTORY}/${FULL_PROJECT_NAME}"
45-
46-
if [ ! -d "${FULL_SOURCE_DIRECTORY}" ] ; then # only clone if source doesn't exist
47-
git clone --branch "react-router@${PROJECT_VERSION}" "https://github.com/remix-run/${PROJECT_NAME}.git" "${FULL_SOURCE_DIRECTORY}"
48-
fi
49-
(
50-
cd "${FULL_SOURCE_DIRECTORY}" || exit
51-
echo "download${ANALYSIS_NAME}: Installing dependencies..."
52-
pnpm install --frozen-lockfile || exit
53-
echo "download${ANALYSIS_NAME}: Analyzing source..."
54-
npx --yes @jqassistant/ts-lce >"./../../runtime/logs/jqassistant-typescript-scan-${FULL_PROJECT_NAME}.log" 2>&1 || exit
55-
)
56-
mkdir -p artifacts/typescript
57-
mv -nv "${FULL_SOURCE_DIRECTORY}/.reports/jqa/ts-output.json" "artifacts/typescript/${FULL_PROJECT_NAME}.json"
58-
################################################################
20+
projectVersion="${1}"
21+
echo "downloadAntDesign: projectVersion=${projectVersion}"
22+
23+
## Get the directory of this script if not already set
24+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
25+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
26+
# This way non-standard tools like readlink aren't needed.
27+
DOWNLOADER_SCRIPTS_DIR=${DOWNLOADER_SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
28+
echo "downloadReactRouter: DOWNLOADER_SCRIPTS_DIR=${DOWNLOADER_SCRIPTS_DIR}"
29+
30+
source "${DOWNLOADER_SCRIPTS_DIR}/downloadTypescriptProject.sh" \
31+
--url https://github.com/remix-run/react-router.git \
32+
--version "${projectVersion}" \
33+
--tag "react-router@${projectVersion}" \
34+
--packageManager pnpm
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/usr/bin/env bash
2+
3+
# Downloads a Typescript project from a git repository using git clone.
4+
# The cloned project is then moved into the "source" directory of the current analysis directory.
5+
# After scanning it with jQAssistant's Typescript Plugin, the resulting JSON will be moved into the "artifacts/typescript" directory.
6+
7+
# Note: This script is meant to be started within the temporary analysis directory (e.g. "temp/AnalysisName/")
8+
9+
# Fail on any error (errexit = exit on first error, errtrace = error inherited from sub-shell ,pipefail exist on errors within piped commands)
10+
set -o errexit -o errtrace -o pipefail
11+
12+
# Overrideable Defaults
13+
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"}
14+
echo "downloadTypescriptProject: SOURCE_DIRECTORY=${SOURCE_DIRECTORY}"
15+
16+
# Display how this command is intended to be used including an example when wrong input parameters were detected
17+
usage() {
18+
echo ""
19+
echo "Usage: $0 \\"
20+
echo " --url <git-clone-url> \\"
21+
echo " --version <project version \\"
22+
echo " [ --tag <git-tag-for-that-version> (default=version) \\]"
23+
echo " [ --project <name-of-the-project> (default=url file name) \\]"
24+
echo " [ --packageManager <npm/pnpm/yarn> (default=npm) ]"
25+
echo "Example: $0 \\"
26+
echo " --url https://github.com/ant-design/ant-design.git \\"
27+
echo " --version 5.19.3"
28+
exit 1
29+
}
30+
31+
# Default command line option values
32+
cloneUrl=""
33+
projectName=""
34+
projectVersion=""
35+
projectTag=""
36+
packageManager="npm"
37+
38+
# Parse command line options
39+
while [[ $# -gt 0 ]]; do
40+
key="${1}"
41+
value="${2}"
42+
43+
case "${key}" in
44+
--url)
45+
cloneUrl="${value}"
46+
shift
47+
;;
48+
--project)
49+
projectName="${value}"
50+
shift
51+
;;
52+
--version)
53+
projectVersion="${value}"
54+
shift
55+
;;
56+
--tag)
57+
projectTag="${value}"
58+
shift
59+
;;
60+
--packageManager)
61+
packageManager="${value}"
62+
shift
63+
;;
64+
*)
65+
echo "downloadTypescriptProject Error: Unknown option: ${key}"
66+
usage
67+
;;
68+
esac
69+
shift
70+
done
71+
72+
if [[ -z ${cloneUrl} ]]; then
73+
echo "downloadTypescriptProject Error: Please specify an URL for git clone."
74+
usage
75+
fi
76+
77+
if ! curl --head --fail "${cloneUrl}" >/dev/null 2>&1; then
78+
echo "downloadTypescriptProject Error: Invalid URL: ${cloneUrl}"
79+
exit 1
80+
fi
81+
82+
if [[ -z ${projectName} ]]; then
83+
# When empty, infer the project name from the file name / last part of the clone url excluding the extension .git
84+
projectName=$(basename -s .git "${cloneUrl}")
85+
fi
86+
87+
if [[ -z ${projectVersion} ]]; then
88+
echo "downloadTypescriptProject Error: Please specify a project version."
89+
usage
90+
fi
91+
92+
if [[ -z ${projectTag} ]]; then
93+
# When empty, use the value of the option "version" as tag
94+
projectTag="${projectVersion}"
95+
fi
96+
97+
case "${packageManager}" in
98+
npm|pnpm|yarn)
99+
echo "downloadTypescriptProject Using package manager ${packageManager}"
100+
;;
101+
*)
102+
echo "downloadTypescriptProject Error: Unknown package manager: ${packageManager}"
103+
usage
104+
;;
105+
esac
106+
107+
if ! command -v "${packageManager}" &> /dev/null ; then
108+
echo "downloadTypescriptProject Error: Package manager ${packageManager} could not be found"
109+
exit 1
110+
fi
111+
112+
if ! command -v "npx" &> /dev/null ; then
113+
echo "downloadTypescriptProject Error: Command npx not found. It's needed to execute npm packages."
114+
exit 1
115+
fi
116+
117+
echo "downloadTypescriptProject: cloneUrl: ${cloneUrl}"
118+
echo "downloadTypescriptProject: projectName: ${projectName}"
119+
echo "downloadTypescriptProject: projectVersion: ${projectVersion}"
120+
echo "downloadTypescriptProject: projectTag: ${projectTag}"
121+
echo "downloadTypescriptProject: packageManager: ${packageManager}"
122+
123+
usePackageManagerToInstallDependencies() {
124+
echo "downloadTypescriptProject: Installing dependencies using ${packageManager}..."
125+
case "${packageManager}" in
126+
npm)
127+
# npm ci is not sufficient for projects like "ant-design" that rely on generating the package-lock
128+
# Even if this is not standard, this is an acceptable solution for standard and edge cases.
129+
npm install --ignore-scripts --verbose || exit
130+
;;
131+
pnpm)
132+
pnpm install --frozen-lockfile || exit
133+
;;
134+
yarn)
135+
yarn install --frozen-lockfile --ignore-scripts --non-interactive --verbose || exit
136+
;;
137+
esac
138+
}
139+
140+
# Create runtime logs directory if it hasn't existed yet
141+
mkdir -p ./runtime/logs
142+
143+
# Download the project to be analyzed
144+
fullProjectName="${projectName}-${projectVersion}"
145+
fullSourceDirectory="${SOURCE_DIRECTORY}/${fullProjectName}"
146+
147+
if [ ! -d "${fullSourceDirectory}" ] ; then # only clone if source doesn't exist
148+
echo "downloadTypescriptProject: Cloning ${cloneUrl} with version ${projectVersion}..."
149+
# A full clone is done since not only the source is scanned, but also the git log history.
150+
git clone --branch "${projectTag}" "${cloneUrl}" "${fullSourceDirectory}"
151+
fi
152+
(
153+
cd "${fullSourceDirectory}" || exit
154+
usePackageManagerToInstallDependencies
155+
echo "downloadTypescriptProject: Scanning Typescript source using @jqassistant/ts-lce..."
156+
npx --yes @jqassistant/ts-lce >"./../../runtime/logs/jqassistant-typescript-scan-${projectName}.log" 2>&1 || exit
157+
)
158+
echo "downloadTypescriptProject: Moving scanned results into the artifacts/typescript directory..."
159+
mkdir -p artifacts/typescript
160+
mv -nv "${fullSourceDirectory}/.reports/jqa/ts-output.json" "artifacts/typescript/${fullProjectName}.json"

0 commit comments

Comments
 (0)