Skip to content

Commit ca3ec21

Browse files
committed
Support scanning npm package.json files
1 parent f4aef01 commit ca3ec21

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

scripts/copyPackageJsonFiles.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
# Deletes all data in the Neo4j graph database and rescans the downloaded artifacts to create a new graph.
4+
5+
# CAUTION: This script deletes all relationships and nodes in the Neo4j Graph Database.
6+
# Note: The environment variable NEO4J_INITIAL_PASSWORD is required to login to Neo4j.
7+
8+
# Requires findTypescriptDataFiles.sh, importGit.sh
9+
10+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
11+
set -o errexit -o pipefail
12+
13+
# Overrideable Defaults
14+
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"}
15+
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"}
16+
NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY=${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY:-"npm-package-json"} # Subdirectory of "artifacts" containing the npm package.json files to scan
17+
18+
## Get this "scripts" directory if not already set
19+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
20+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
21+
# This way non-standard tools like readlink aren't needed.
22+
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the shell scripts
23+
echo "test: SCRIPTS_DIR=${SCRIPTS_DIR}"
24+
25+
#Explanation of the command changes:
26+
# -path ./node_modules -prune: This part of the command tells find to skip the node_modules directory.
27+
# -o: This is the logical OR operator. It allows you to combine conditions. The -prune action will prevent find from descending into node_modules directories.
28+
# -name 'package.json': This part of the command looks for files named package.json.
29+
# -exec sh -c 'for f; do ... done' sh {} +: Executes the given shell command for each found package.json file.
30+
31+
(
32+
cd "./${SOURCE_DIRECTORY}"
33+
34+
for file in $( find . -path ./node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {}); do
35+
fileDirectory=$(dirname "${file}")
36+
targetDirectory="../${ARTIFACTS_DIRECTORY}/${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY}/${fileDirectory}"
37+
echo "test: Copying ${file} to ${targetDirectory}"
38+
39+
mkdir -p "${targetDirectory}"
40+
cp "${file}" "${targetDirectory}"
41+
42+
# Workaround until the following issue is resolved:
43+
# https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5
44+
fileName=$(basename "${file}")
45+
sed -i.backup '/"author":.*".*"/d' "${targetDirectory}/${fileName}"
46+
rm -f "${targetDirectory}/${fileName}.backup"
47+
done
48+
)

0 commit comments

Comments
 (0)