Skip to content

Commit cf12276

Browse files
committed
Add bash script to find packages
1 parent e7635cb commit cf12276

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tools/scripts/find_packages

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Finds packages.
4+
5+
6+
# VARIABLES #
7+
8+
# Determine the host kernel:
9+
kernel=$(uname -s)
10+
11+
# Determine root directory:
12+
root_dir="$(git rev-parse --show-toplevel)"
13+
14+
# Define the path to the build directory:
15+
build_dir="${root_dir}/build"
16+
17+
# Define the path to the reports directory:
18+
reports_dir="${root_dir}/reports"
19+
20+
# Define the directory for top-level tools:
21+
tools_dir="${root_dir}/tools"
22+
23+
# Define the path to node modules:
24+
node_modules="${root_dir}/node_modules"
25+
26+
# Define a package filename identifier:
27+
packages_file='package.json'
28+
29+
# Define the pattern for filtering packages based on their file path:
30+
packages_filter='.*/.*'
31+
32+
33+
# FUNCTIONS #
34+
35+
# Finds packages.
36+
main() {
37+
local pkgs
38+
39+
# On Mac OSX, in order to use `|` and other regular expression operators, we need to use enhanced regular expression syntax (-E); see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man7/re_format.7.html#//apple_ref/doc/man/7/re_format.
40+
if [[ "${kernel}" == "Darwin" ]]; then
41+
pkgs=$(find -E "${root_dir}" -not -path "${root_dir}/.*" -not -path "${node_modules}/*" -not -path "${build_dir}/*" -not -path "${reports_dir}/*" -not -path "${tools_dir}/*" -regex "${packages_filter}" -name "${packages_file}" -exec dirname {} \;)
42+
else
43+
pkgs=$(find "${root_dir}" -regextype posix-extended -not -path "${root_dir}/.*" -not -path "${node_modules}/*" -not -path "${build_dir}/*" -not -path "${reports_dir}/*" -not -path "${tools_dir}/*" -regex "${packages_filter}" -name "${packages_file}" -exec dirname {} \;)
44+
fi
45+
echo "${pkgs}"
46+
}
47+
48+
# Run main:
49+
main

0 commit comments

Comments
 (0)