diff --git a/scripts/copyPackageJsonFiles.sh b/scripts/copyPackageJsonFiles.sh deleted file mode 100755 index 92b836445..000000000 --- a/scripts/copyPackageJsonFiles.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env bash - -# Copies all package.json files inside the source directory into the artifacts/npm-package-json directory. -# It retains the original folder structure where the package.json files were in. - -# This script "jq" ( https://stedolan.github.io/jq ). - -# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands) -set -o errexit -o pipefail - -# Overrideable Defaults -ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"} -SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"} -NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY=${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY:-"npm-package-json"} # Subdirectory of "artifacts" containing the npm package.json files to scan - -# Check if the repository is actually a git repository -if [ ! -d "${SOURCE_DIRECTORY}" ]; then - echo "copyPackageJsonFiles: No ${SOURCE_DIRECTORY} directory. Skipping copy of package.json files." - return 0 -fi - -# Returns all relevant package.json files for the source directory given as first and only parameter. -find_package_json_files() { - find -L "${1}" \ - -type d -name "node_modules" -prune -o \ - -type d -name "dist" -prune -o \ - -type d -name ".yalc" -prune -o \ - -type d -name "target" -prune -o \ - -type d -name "temp" -prune -o \ - -type d -name "lib" -prune -o \ - -type d -name "libs" -prune -o \ - -name 'package.json' \ - -print0 | \ - xargs -0 -r -I {} echo {} -} - -( - cd "./${SOURCE_DIRECTORY}" - - echo "copyPackageJsonFiles: Existing package.json files will be copied from from ${SOURCE_DIRECTORY} to ../${ARTIFACTS_DIRECTORY}/${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY}" - echo "copyPackageJsonFiles: Author will be removed as workaround for https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5" - - copied_package_json_files=0 - - for file in $( find_package_json_files . ); do - fileDirectory=$(dirname "${file}") - targetDirectory="../${ARTIFACTS_DIRECTORY}/${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY}/${fileDirectory}" - # echo "copyPackageJsonFiles: Debug: Copying ${file} to ${targetDirectory}" # debug logging - - mkdir -p "${targetDirectory}" - cp -rf "${file}" "${targetDirectory}" - - # Workaround until the following issue is resolved: - # https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5 - fileName=$(basename "${file}") - jq 'del(.author)' "${targetDirectory}/${fileName}" > "${targetDirectory}/${fileName}.edited" - jq 'del(.contributors)' "${targetDirectory}/${fileName}.edited" > "${targetDirectory}/${fileName}" - rm -f "${targetDirectory}/${fileName}.edited" - - copied_package_json_files=$((copied_package_json_files + 1)) - done - - echo "copyPackageJsonFiles: Successfully copied ${copied_package_json_files} files" -) \ No newline at end of file diff --git a/scripts/findPathsToScan.sh b/scripts/findPathsToScan.sh index ea60142e1..76c5e43a3 100755 --- a/scripts/findPathsToScan.sh +++ b/scripts/findPathsToScan.sh @@ -28,6 +28,21 @@ appendNonEmpty() { fi } +findPackageJsonFiles() { + find -L "${1}" \ + -type d -name "node_modules" -prune -o \ + -type d -name "dist" -prune -o \ + -type d -name ".yalc" -prune -o \ + -type d -name "target" -prune -o \ + -type d -name "temp" -prune -o \ + -type d -name "lib" -prune -o \ + -type d -name "libs" -prune -o \ + -type d -name ".git" -prune -o \ + -name 'package.json' \ + -print0 | \ + xargs -0 -r -I {} echo {} +} + # Collect all files and directories to scan directoriesAndFilesToScan="" @@ -45,6 +60,7 @@ if [ -d "./${SOURCE_DIRECTORY}" ] ; then -type d -name "dist" -prune -o \ -type d -name "target" -prune -o \ -type d -name ".yalc" -prune -o \ + -type d -name ".git" -prune -o \ -type d -name "temp" -prune -o \ -type f -path "*/.reports/jqa/ts-output.json" \ -exec echo typescript:project::{} \; | tr '\n' ',' | sed 's/,$/\n/')" @@ -54,12 +70,12 @@ if [ -d "./${SOURCE_DIRECTORY}" ] ; then fi # Scan package.json files for npm (nodes package manager) in the source directory - # # TODO The following lines can be reactivated when the following issue is resolved: + # Since the following issue had been resolved, the scan be done here again: # https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5 - #npmPackageJsonFiles="$(find -L "${SOURCE_DIRECTORY}" -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {} | tr '\n' ',' | sed 's/,$/\n/')" - #if [ -n "${npmPackageJsonFiles}" ]; then - # directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")${npmPackageJsonFiles}" - #fi + npmPackageJsonFiles="$(findPackageJsonFiles "./${SOURCE_DIRECTORY}")" + if [ -n "${npmPackageJsonFiles}" ]; then + directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")${npmPackageJsonFiles}" + fi # Scan git repositories in the artifacts directory if [ "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "" ] || [ "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "plugin" ] ; then diff --git a/scripts/resetAndScanChanged.sh b/scripts/resetAndScanChanged.sh index 5abd5d758..1808e8c48 100755 --- a/scripts/resetAndScanChanged.sh +++ b/scripts/resetAndScanChanged.sh @@ -4,7 +4,7 @@ # Note: "resetAndScan" expects jQAssistant to be installed in the "tools" directory. -# Requires resetAndScan.sh, copyPackageJsonFiles.sh, scanTypescript.sh, detectChangedFiles.sh, findPathsToScan.sh +# Requires resetAndScan.sh, scanTypescript.sh, detectChangedFiles.sh, findPathsToScan.sh # Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands) set -o errexit -o pipefail @@ -17,9 +17,6 @@ SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" echo "resetAndScanChanged SCRIPTS_DIR=${SCRIPTS_DIR}" # Prepare scan -# TODO "copyPackageJsonFiles.sh" can be deleted here when the following issue is resolved: -# https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5 -source "${SCRIPTS_DIR}/copyPackageJsonFiles.sh" source "${SCRIPTS_DIR}/scanTypescript.sh" filesAndDirectoriesToScan=$( source "${SCRIPTS_DIR}/findPathsToScan.sh" )