Skip to content

Commit 2534f3f

Browse files
committed
Revert "Scan npm package.json files directly from the source directory"
This reverts commit 74f5043.
1 parent 4475a29 commit 2534f3f

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

scripts/copyPackageJsonFiles.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Copies all package.json files inside the source directory into the artifacts/npm-package-json directory.
4+
# It retains the original folder structure where the package.json files were in.
5+
6+
# This script "jq" ( https://stedolan.github.io/jq ).
7+
8+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
9+
set -o errexit -o pipefail
10+
11+
# Overrideable Defaults
12+
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"}
13+
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"}
14+
NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY=${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY:-"npm-package-json"} # Subdirectory of "artifacts" containing the npm package.json files to scan
15+
16+
# Check if the repository is actually a git repository
17+
if [ ! -d "${SOURCE_DIRECTORY}" ]; then
18+
echo "copyPackageJsonFiles: No ${SOURCE_DIRECTORY} directory. Skipping copy of package.json files."
19+
return 0
20+
fi
21+
22+
(
23+
cd "./${SOURCE_DIRECTORY}"
24+
25+
echo "copyPackageJsonFiles: Existing package.json files will be copied from from ${SOURCE_DIRECTORY} to ../${ARTIFACTS_DIRECTORY}/${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY}"
26+
echo "copyPackageJsonFiles: Author will be removed as workaround for https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5"
27+
28+
for file in $( find . -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {}); do
29+
fileDirectory=$(dirname "${file}")
30+
targetDirectory="../${ARTIFACTS_DIRECTORY}/${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY}/${fileDirectory}"
31+
# echo "copyPackageJsonFiles: Copying ${file} to ${targetDirectory}"
32+
33+
mkdir -p "${targetDirectory}"
34+
cp -rf "${file}" "${targetDirectory}"
35+
36+
# Workaround until the following issue is resolved:
37+
# https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5
38+
fileName=$(basename "${file}")
39+
jq 'del(.author)' "${targetDirectory}/${fileName}" > "${targetDirectory}/${fileName}.edited"
40+
jq 'del(.contributors)' "${targetDirectory}/${fileName}.edited" > "${targetDirectory}/${fileName}"
41+
rm -f "${targetDirectory}/${fileName}.edited"
42+
done
43+
)

scripts/findPathsToScan.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ if [ -d "${SOURCE_DIRECTORY}" ] ; then
3636
fi
3737

3838
# Scan package.json files for npm (nodes package manager) in the source directory
39-
npmPackageJsonFiles="$(find "${SOURCE_DIRECTORY}" -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {} | tr '\n' ',' | sed 's/,$/\n/')"
40-
if [ -n "${npmPackageJsonFiles}" ]; then
41-
directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")${npmPackageJsonFiles}"
42-
fi
39+
# # TODO The following lines can be reactivated when the following issue is resolved:
40+
# https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5
41+
#npmPackageJsonFiles="$(find "${SOURCE_DIRECTORY}" -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {} | tr '\n' ',' | sed 's/,$/\n/')"
42+
#if [ -n "${npmPackageJsonFiles}" ]; then
43+
# directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")${npmPackageJsonFiles}"
44+
#fi
4345

4446
# Scan git repositories in the artifacts directory
4547
if [ "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "" ] || [ "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "plugin" ] ; then

scripts/resetAndScanChanged.sh

Lines changed: 6 additions & 1 deletion
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, detectChangedArtifacts.sh, findPathsToScan.sh
7+
# Requires resetAndScan.sh, copyPackageJsonFiles.sh, detectChangedArtifacts.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
@@ -18,6 +18,11 @@ echo "resetAndScanChanged SCRIPTS_DIR=${SCRIPTS_DIR}"
1818

1919
filesAndDirectoriesToScan=$( source "${SCRIPTS_DIR}/findPathsToScan.sh" )
2020

21+
# Prepare scan
22+
# TODO "copyPackageJsonFiles.sh" can be deleted here when the following issue is resolved:
23+
# https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5
24+
source "${SCRIPTS_DIR}/copyPackageJsonFiles.sh"
25+
2126
# Scan and analyze Artifacts when they were changed
2227
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedArtifacts.sh" --readonly --paths "${filesAndDirectoriesToScan}")
2328
if [[ "${changeDetectionReturnCode}" == "0" ]] ; then

0 commit comments

Comments
 (0)