Repository navigation
Expand file tree
/
Copy pathIgnore node_modules.command
More file actions
executable file
·66 lines (60 loc) · 2.21 KB
/
Copy pathIgnore node_modules.command
File metadata and controls
executable file
·66 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
set -euo pipefail
finish() {
local status=$?
trap - EXIT
if [ "$status" -ne 0 ]; then
printf '\nCould not mark all generated folders as ignored. See the error above.\n' >&2
fi
if [ -t 0 ]; then
printf '\nPress Return to close this window.'
read -r _ || true
fi
exit "$status"
}
trap finish EXIT
# Resolve the folder containing this command each time, including Finder launches.
project_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
attribute='com.apple.fileprovider.ignore#P'
generated_folders=(
'node_modules'
'apps/web/dist'
'apps/api/dist'
'.qa'
'test-results'
'playwright-report'
)
# npm can install workspace-specific dependencies alongside the shared root ones.
# Vite and Vitest caches inside node_modules are covered by the same attribute.
for workspace in "$project_dir"/apps/* "$project_dir"/packages/*; do
if [ -f "$workspace/package.json" ]; then
generated_folders+=("${workspace#"$project_dir"/}/node_modules")
fi
done
# Check every path before changing any attributes.
# Check parents too, so nested workspace paths cannot follow symbolic links.
for folder in "${generated_folders[@]}"; do
directory="$project_dir/$folder"
while [ "$directory" != "$project_dir" ]; do
if [ -L "$directory" ] || { [ -e "$directory" ] && [ ! -d "$directory" ]; }; then
printf '%s is not a local directory.\n' "${directory#"$project_dir"/}" >&2
exit 1
fi
directory="${directory%/*}"
done
done
printf 'Setting Dropbox ignore attributes for LessonLab in:\n%s\n' "$project_dir"
for folder in "${generated_folders[@]}"; do
directory="$project_dir/$folder"
# Create missing folders so Dropbox can ignore them before tools populate them.
mkdir -p "$directory"
/usr/bin/xattr -w "$attribute" 1 "$directory"
value="$(/usr/bin/xattr -p "$attribute" "$directory")"
if [ "$value" != '1' ]; then
printf 'The Dropbox ignore attribute could not be verified for %s.\n' "$folder" >&2
exit 1
fi
printf ' Verified: %s\n' "$directory"
done
printf '\nLocal files are kept. Dropbox removes the synced copy from the cloud and other devices.\n'
printf 'Run this again if any of these folders are deleted and recreated (for example, by npm ci or a clean build).\n'