mikes-macos-developer-disk-cleanup 1.0.1 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,10 +31,8 @@ Currently it searches for (and cleans) the following items:
31
31
 
32
32
  ## How to Use the Script
33
33
 
34
- 1. Clone this repository: `git clone https://github.com/cunneen/mikes-macos-developer-disk-cleanup.git cleanup`
35
- 2. Navigate to the directory where the script is located using the `cd` command: `cd cleanup`
36
- 3. Run the script by typing `./mikes-macos-disk-cleanup.sh`.
37
- 4. Panic because all your files are now gone and are never coming back.
34
+ 1. `npx mikes-macos-developer-disk-cleanup`
35
+ 2. Panic because all your files are now gone and are never coming back.
38
36
 
39
37
  ## Important Notes
40
38
 
@@ -26,6 +26,7 @@
26
26
  # - Android SDK packages
27
27
  # - Android AVDs
28
28
  # - Homebrew caches
29
+ # - CocoaPods
29
30
 
30
31
  # ==== CONFIGURATION DEFAULTS - change as needed ====
31
32
  CONFIGFILE="${HOME}/.config/mikes-macos-disk-cleanup.env" # you'll be prompted to create this if it doesn't exist
@@ -68,9 +69,16 @@ if [ ${INITIALISED:-0} -ne 1 ]; then
68
69
  fi
69
70
  printf "DEVELOPMENT_BASE_DIR=${DEVELOPMENT_BASE_DIR}\n" >${CONFIGFILE}
70
71
  echo "Configuration saved to ${CONFIGFILE}"
72
+ echo "NOTE: subsequent invocations will immediately commence deleting files!"
71
73
  else
72
74
  echo "Not saving configuration..."
73
75
  fi
76
+
77
+ read -p "Deleting is about to start! Proceed? [y/n]" SHOULD_PROCEED
78
+ if [ "${SHOULD_PROCEED}" != "y" ]; then
79
+ echo "Exiting..."
80
+ exit 1
81
+ fi
74
82
  fi
75
83
 
76
84
  echo "Using development base directory: ${DEVELOPMENT_BASE_DIR}"
@@ -84,7 +92,12 @@ INITIALISED=1 # set to 1 so that the script will not prompt again (only really m
84
92
 
85
93
  # ==== END OF CONFIGURATION ====
86
94
  # get the full path for the current dir
87
- DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
95
+ # - if this is being run via "npx" then "${BASH_SOURCE[0]}" will be a symlink,
96
+ # so we need to get the full path to the script (and not just the symlink) so
97
+ # we can load the modules from the correct location
98
+
99
+ RESOLVED_SOURCE="$(node -e "const path = require('path');fs = require('fs');console.log(fs.realpathSync('${BASH_SOURCE[0]}'));")"
100
+ DIR=$(dirname "${RESOLVED_SOURCE}")
88
101
 
89
102
  # ===== Error handling =======
90
103
  # set -e: exit on error
@@ -115,29 +128,36 @@ INITIALSPACE=$(
115
128
  )
116
129
  echo "DISK USAGE BEFORE CLEANUP: ${INITIALSPACE}"
117
130
 
118
- # # remove everything in ~/Library/Caches
119
- # source "${DIR}/modules/library-caches.sh"
120
- # libraryCaches
131
+ # addHint function
132
+ source "${DIR}/modules/hints.sh"
133
+
134
+ # CocoaPods
135
+ source "${DIR}/modules/cocoapods.sh"
136
+ cocoapods
121
137
 
122
- # # remove everything from Trash - this sometimes prompts for confirmation
123
- # source "${DIR}/modules/trash.sh"
124
- # trash
138
+ # remove everything in ~/Library/Caches
139
+ source "${DIR}/modules/library-caches.sh"
140
+ libraryCaches
125
141
 
126
- # # meteor
127
- # source "${DIR}/modules/meteor-builds-and-packages.sh"
128
- # meteorBuildsAndPackages
142
+ # remove everything from Trash - this sometimes prompts for confirmation
143
+ source "${DIR}/modules/trash.sh"
144
+ trash
129
145
 
130
- # # npm cache
131
- # source "${DIR}/modules/npm-cache.sh"
132
- # npmCache
146
+ # meteor
147
+ source "${DIR}/modules/meteor-builds-and-packages.sh"
148
+ meteorBuildsAndPackages
133
149
 
134
- # # yarn cache
135
- # source "${DIR}/modules/yarn-cache.sh"
136
- # yarnCache
150
+ # npm cache
151
+ source "${DIR}/modules/npm-cache.sh"
152
+ npmCache
137
153
 
138
- # # bun cache
139
- # source "${DIR}/modules/bun-cache.sh"
140
- # bunCache
154
+ # yarn cache
155
+ source "${DIR}/modules/yarn-cache.sh"
156
+ yarnCache
157
+
158
+ # bun cache
159
+ source "${DIR}/modules/bun-cache.sh"
160
+ bunCache
141
161
 
142
162
  # ### XCode ###
143
163
  source "${DIR}/modules/xcode-artifacts.sh"
@@ -165,7 +185,20 @@ androidBuildFolders
165
185
 
166
186
  # Android SDKs
167
187
  source "${DIR}/modules/android-sdk.sh"
188
+ set +e ; # don't exit on error
168
189
  androidSDK
190
+ RETCODE=$?
191
+ set -e; # exit on error
192
+
193
+ if [ ${RETCODE} -ne 0 ]; then
194
+ if [ ${RETCODE} -eq 100 ]; then
195
+ echo "Android SDK packages already only have one version installed. Proceeding."
196
+ else
197
+ echo "!!! Failed to clean up Android SDKs !!!"
198
+ echo " check the output above for more info"
199
+ exit ${RETCODE}
200
+ fi
201
+ fi
169
202
 
170
203
  # Android AVDs
171
204
  source "${DIR}/modules/android-avd.sh"
@@ -185,8 +218,8 @@ FINALSPACE=$(
185
218
  }'
186
219
  )
187
220
 
188
- echo "=== FINISHED! ==="
221
+ echo "============================== FINISHED! ================================="
189
222
 
190
- echo "DISK USAGE BEFORE CLEANUP: ${INITIALSPACE}"
191
- echo "DISK USAGE AFTER CLEANUP: ${FINALSPACE}"
223
+ echo "BEFORE CLEANUP: ${INITIALSPACE}"
224
+ echo "NOW: ${FINALSPACE}"
192
225
  echo "${HINTS_UPON_FINISH}"
@@ -1,6 +1,6 @@
1
1
  androidAVD() {
2
2
  # Android Virtual Device Cleanup
3
- command -v avdmanager >/dev/null 2>&1 && {
3
+ command -v ${ANDROID_HOME}/tools/bin/avdmanager >/dev/null 2>&1 && {
4
4
  # get the full path from one of the AVDs
5
5
  local FIRST_AVD_PATH=$(avdmanager list avd | grep "Path:" | head -1 | tr -s " "| cut -f3 -d" ")
6
6
 
@@ -21,7 +21,7 @@ androidAVD() {
21
21
  local AVDFOLDERSIZEAFTER=$(du -hs "${FIRST_AVD_PARENTPATH}" | cut -f1)
22
22
  echo " AVD folder size before: ${AVDFOLDERSIZEBEFORE}; after: ${AVDFOLDERSIZEAFTER}"
23
23
  } || {
24
- echo "'avdmanager' command not found"
24
+ echo "'${ANDROID_HOME}/tools/bin/avdmanager' command not found"
25
25
  return 1
26
26
  }
27
27
  }
@@ -2,23 +2,29 @@ androidSDK() {
2
2
  local THISMODULEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3
3
 
4
4
  # Android SDK Manager Cleanup
5
- command -v sdkmanager >/dev/null 2>&1 && {
5
+ command -v ${ANDROID_HOME}/tools/bin/sdkmanager >/dev/null 2>&1 && {
6
6
 
7
7
  local ANDROIDHOME_BEFORE=$(du -hs $ANDROID_HOME | cut -f1)
8
8
 
9
9
  echo "=== android sdkmanager cleanup ==="
10
10
  echo " - BEFORE CLEANUP: ${ANDROIDHOME_BEFORE} (${ANDROID_HOME})"
11
11
 
12
+ # remove .downloadIntermediates folder if it exists
13
+ if [ -d "${ANDROID_HOME}/.downloadIntermediates" ]; then
14
+ echo " - removing ${ANDROID_HOME}/.downloadIntermediates"
15
+ rm -rf "${ANDROID_HOME}/.downloadIntermediates"
16
+ fi
12
17
  # create temporary output file
13
18
  local OUTFILENAME=$(mktemp)
14
19
 
15
- sdkmanager --list_installed --include_obsolete |
20
+ local SDKMANAGER_OUTPUT=$(sdkmanager --list_installed --include_obsolete)
21
+ echo "${SDKMANAGER_OUTPUT}" |
16
22
  awk -f "${THISMODULEDIR}/android-sdk.awk" -v outputFile="${OUTFILENAME}"
17
23
 
18
24
  if [ $? -ne 0 ]; then
19
25
  echo " WARNING: we couldn't parse the output of 'sdkmanager --list_installed --include_obsolete'"
20
- echo " (maybe there's just nothing to remove?)"
21
- return 1
26
+ echo " (very likely there's just nothing to remove)"
27
+ return 100
22
28
  fi
23
29
 
24
30
  echo " - packages to remove: "
@@ -28,10 +34,11 @@ androidSDK() {
28
34
  sdkmanager --uninstall --package_file="${OUTFILENAME}"
29
35
  local ANDROIDHOME_AFTER=$(du -hs $ANDROID_HOME | cut -f1)
30
36
 
31
- echo " - BEFORE CLEANUP: ${ANDROIDHOME_BEFORE} (${ANDROID_HOME})"
32
- echo " - AFTER CLEANUP: ${ANDROIDHOME_AFTER}"
37
+ echo " - BEFORE ANDROID SDKMANAGER CLEANUP: ${ANDROIDHOME_BEFORE} (${ANDROID_HOME})"
38
+ echo " - AFTER ANDROID SDKMANAGER CLEANUP: ${ANDROIDHOME_AFTER}"
39
+ addHint "- You may need to run android's SDK manager to restore the Android SDK versions you were using"
33
40
  } || {
34
- echo "'sdkmanager' command not found"
41
+ echo "'${ANDROID_HOME}/tools/bin/sdkmanager' command not found"
35
42
  return 1
36
43
  }
37
44
  }
@@ -0,0 +1,32 @@
1
+ cocoapods() {
2
+ if [ -d ${HOME}/.cocoapods ]; then
3
+ # Pods folders
4
+ echo "=== clearing Pods folders ==="
5
+ pod cache clean --all
6
+ echo " - looking for Pods folders in ${DEVELOPMENT_BASE_DIR}... "
7
+ local PODS_FOLDERS=$(
8
+ find -E "${DEVELOPMENT_BASE_DIR}" -type d \
9
+ -regex '^.*Pods$' \
10
+ -not -regex "${HOME}/\..*" \
11
+ -not -regex "^.*Pods.+"
12
+ )
13
+ echo " - found Pods folders:"
14
+ IFS=$'\n' # make newlines the only separator
15
+ for PODS_FOLDER in ${PODS_FOLDERS}; do
16
+ echo " - ${PODS_FOLDER}"
17
+ done
18
+ echo " - running 'rm -rf ' in each of the above"
19
+ local PODS_WERE_REMOVED=0
20
+ for PODS_FOLDER in ${PODS_FOLDERS}; do
21
+ PODS_WERE_REMOVED=1
22
+ local PODS_FOLDER_SIZE=$(du -hs "${PODS_FOLDER}" | cut -f1)
23
+ printf " - removing '${PODS_FOLDER}' (${PODS_FOLDER_SIZE}) ... "
24
+ rm -rf "${PODS_FOLDER}"
25
+ echo "done"
26
+ done
27
+ unset IFS
28
+ if [ ${PODS_WERE_REMOVED} -eq 1 ]; then
29
+ addHint "- You'll need to perform a 'pod install' (or npx pod-install) in each of your projects"
30
+ fi
31
+ fi
32
+ }
@@ -0,0 +1,9 @@
1
+ addHint(){
2
+ local HINTLENGTH=${#HINTS_UPON_FINISH}
3
+ if [ ${HINTLENGTH} -gt 0 ]; then
4
+ # add a newline if there was a previous hint
5
+ HINTS_UPON_FINISH=$(printf "%s\n%s", "${HINTS_UPON_FINISH}", "${1}")
6
+ else
7
+ HINTS_UPON_FINISH="${1}"
8
+ fi
9
+ }
@@ -13,13 +13,18 @@ nodeModules() {
13
13
  for NODE_MODULE_FOLDER in ${NODE_MODULE_FOLDERS}; do
14
14
  echo " - ${NODE_MODULE_FOLDER}"
15
15
  done
16
+ local MODULESWERE_REMOVED=0
16
17
  echo " - running 'rm -rf ' in each of the above"
17
18
  for NODE_MODULE_FOLDER in ${NODE_MODULE_FOLDERS}; do
19
+ MODULESWERE_REMOVED=1
18
20
  local NODE_MODULE_SIZE=$(du -hs "${NODE_MODULE_FOLDER}" | cut -f1)
19
21
  printf " - removing '${NODE_MODULE_FOLDER}' (${NODE_MODULE_SIZE}) ... "
20
22
  rm -rf "${NODE_MODULE_FOLDER}"
21
23
  echo "done"
22
24
  done
23
25
  unset IFS
26
+ if [ ${MODULESWERE_REMOVED} -eq 1 ]; then
27
+ addHint "- You will need to reinstall node modules in each of your projects"
28
+ fi
24
29
 
25
30
  }
@@ -40,5 +40,9 @@ rubyGems() {
40
40
  done
41
41
 
42
42
  unset IFS
43
+ rvm use
43
44
  }
45
+
46
+ addHint "- You might need to reinstall your ruby gems"
47
+ addHint " - e.g. gem install cocoapods"
44
48
  }
@@ -20,7 +20,7 @@ xcodeArtifacts() {
20
20
  # Xcode DeviceLogs
21
21
  if [ -d ${HOME}/Library/Developer/CoreSimulator/Caches ]; then
22
22
  local XCCACHESIZE=$(du -hs ${HOME}/Library/Developer/CoreSimulator/Caches | cut -f1)
23
- echo " removing Xcode Caches (${XCCACHESIZE})..."
23
+ echo " removing Xcode CoreSimulator Caches (${XCCACHESIZE})..."
24
24
  rm -rf ${HOME}/Library/Developer/CoreSimulator/Caches
25
25
  fi
26
26
 
@@ -35,11 +35,11 @@ xcodeArtifacts() {
35
35
  awk '{\
36
36
  r=$0;\
37
37
  gsub(/^[^[:space:]]+[[:space:]]+/,"",r);\
38
- printf("- This command would recover %s:\n rm -rf \"%s\"\n",$1, r);\
38
+ printf("- This command would recover an additional %s:\n rm -rf \"%s\"\n",$1, r);\
39
39
  }'
40
40
  )
41
41
  echo "${DEVICESUPPORTCOMMAND}"
42
- HINTS_UPON_FINISH=$(printf "${HINTS_UPON_FINISH}\n${DEVICESUPPORTCOMMAND}")
42
+ addHint "${DEVICESUPPORTCOMMAND}"
43
43
  fi
44
44
  fi # xcode
45
45
  }
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "mikes-macos-developer-disk-cleanup",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "Cleans up a developer's mac disk space. Aggressively.",
5
5
  "bin": {
6
- "mikes-macos-disk-cleanup": "mikes-macos-disk-cleanup.sh",
7
- "modules": "modules"
6
+ "mikes-macos-disk-cleanup": "mikes-macos-disk-cleanup.sh"
8
7
  },
9
8
  "scripts": {
10
9
  "test": "echo \"Error: no test specified\" && exit 1"