@fredlackey/devutils 0.0.1 → 0.0.3
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 +5 -5
- package/package.json +1 -1
- package/src/commands/install.js +374 -36
- package/src/installs/adobe-creative-cloud.js +527 -25
- package/src/installs/adobe-creative-cloud.md +605 -0
- package/src/installs/appcleaner.js +303 -26
- package/src/installs/appcleaner.md +699 -0
- package/src/installs/apt-transport-https.js +390 -0
- package/src/installs/apt-transport-https.md +678 -0
- package/src/installs/atomicparsley.js +624 -26
- package/src/installs/atomicparsley.md +795 -0
- package/src/installs/aws-cli.js +779 -26
- package/src/installs/aws-cli.md +727 -0
- package/src/installs/balena-etcher.js +688 -26
- package/src/installs/balena-etcher.md +761 -0
- package/src/installs/bambu-studio.js +912 -26
- package/src/installs/bambu-studio.md +780 -0
- package/src/installs/bash-completion.js +554 -23
- package/src/installs/bash-completion.md +833 -0
- package/src/installs/bash.js +399 -26
- package/src/installs/bash.md +993 -0
- package/src/installs/beyond-compare.js +585 -26
- package/src/installs/beyond-compare.md +813 -0
- package/src/installs/build-essential.js +511 -26
- package/src/installs/build-essential.md +977 -0
- package/src/installs/ca-certificates.js +618 -0
- package/src/installs/ca-certificates.md +937 -0
- package/src/installs/caffeine.js +490 -26
- package/src/installs/caffeine.md +839 -0
- package/src/installs/camtasia.js +577 -25
- package/src/installs/camtasia.md +762 -0
- package/src/installs/chatgpt.js +458 -26
- package/src/installs/chatgpt.md +814 -0
- package/src/installs/chocolatey.js +447 -0
- package/src/installs/chocolatey.md +661 -0
- package/src/installs/chrome-canary.js +472 -26
- package/src/installs/chrome-canary.md +641 -0
- package/src/installs/chromium.js +645 -26
- package/src/installs/chromium.md +838 -0
- package/src/installs/claude-code.js +558 -26
- package/src/installs/claude-code.md +1173 -0
- package/src/installs/curl.js +361 -26
- package/src/installs/curl.md +714 -0
- package/src/installs/cursor.js +561 -26
- package/src/installs/cursor.md +970 -0
- package/src/installs/dbschema.js +674 -26
- package/src/installs/dbschema.md +925 -0
- package/src/installs/dependencies.md +435 -0
- package/src/installs/development-tools.js +600 -0
- package/src/installs/development-tools.md +977 -0
- package/src/installs/docker.js +1010 -25
- package/src/installs/docker.md +1109 -0
- package/src/installs/drawio.js +1001 -26
- package/src/installs/drawio.md +795 -0
- package/src/installs/elmedia-player.js +328 -25
- package/src/installs/elmedia-player.md +556 -0
- package/src/installs/ffmpeg.js +870 -25
- package/src/installs/ffmpeg.md +852 -0
- package/src/installs/file.js +464 -0
- package/src/installs/file.md +987 -0
- package/src/installs/gemini-cli.js +793 -26
- package/src/installs/gemini-cli.md +1153 -0
- package/src/installs/git.js +382 -26
- package/src/installs/git.md +907 -0
- package/src/installs/gitego.js +931 -26
- package/src/installs/gitego.md +1172 -0
- package/src/installs/go.js +913 -26
- package/src/installs/go.md +958 -0
- package/src/installs/google-chrome.js +801 -25
- package/src/installs/google-chrome.md +862 -0
- package/src/installs/gpg.js +412 -73
- package/src/installs/gpg.md +1056 -0
- package/src/installs/homebrew.js +1015 -26
- package/src/installs/homebrew.md +988 -0
- package/src/installs/imageoptim.js +950 -26
- package/src/installs/imageoptim.md +1119 -0
- package/src/installs/installers.json +2297 -0
- package/src/installs/jq.js +382 -26
- package/src/installs/jq.md +809 -0
- package/src/installs/keyboard-maestro.js +701 -26
- package/src/installs/keyboard-maestro.md +825 -0
- package/src/installs/latex.js +771 -26
- package/src/installs/latex.md +1095 -0
- package/src/installs/lftp.js +338 -26
- package/src/installs/lftp.md +907 -0
- package/src/installs/lsb-release.js +346 -0
- package/src/installs/lsb-release.md +814 -0
- package/src/installs/messenger.js +829 -26
- package/src/installs/messenger.md +900 -0
- package/src/installs/microsoft-office.js +550 -26
- package/src/installs/microsoft-office.md +760 -0
- package/src/installs/microsoft-teams.js +782 -25
- package/src/installs/microsoft-teams.md +886 -0
- package/src/installs/node.js +886 -26
- package/src/installs/node.md +1153 -0
- package/src/installs/nordpass.js +698 -26
- package/src/installs/nordpass.md +921 -0
- package/src/installs/nvm.js +977 -26
- package/src/installs/nvm.md +1057 -0
- package/src/installs/openssh.js +734 -64
- package/src/installs/openssh.md +1056 -0
- package/src/installs/pandoc.js +644 -26
- package/src/installs/pandoc.md +1036 -0
- package/src/installs/pinentry.js +492 -26
- package/src/installs/pinentry.md +1142 -0
- package/src/installs/pngyu.js +851 -26
- package/src/installs/pngyu.md +896 -0
- package/src/installs/postman.js +781 -26
- package/src/installs/postman.md +940 -0
- package/src/installs/procps.js +425 -0
- package/src/installs/procps.md +851 -0
- package/src/installs/safari-tech-preview.js +355 -25
- package/src/installs/safari-tech-preview.md +533 -0
- package/src/installs/sfnt2woff.js +640 -26
- package/src/installs/sfnt2woff.md +795 -0
- package/src/installs/shellcheck.js +463 -26
- package/src/installs/shellcheck.md +1005 -0
- package/src/installs/slack.js +722 -25
- package/src/installs/slack.md +865 -0
- package/src/installs/snagit.js +566 -25
- package/src/installs/snagit.md +844 -0
- package/src/installs/software-properties-common.js +372 -0
- package/src/installs/software-properties-common.md +805 -0
- package/src/installs/spotify.js +858 -25
- package/src/installs/spotify.md +901 -0
- package/src/installs/studio-3t.js +803 -26
- package/src/installs/studio-3t.md +918 -0
- package/src/installs/sublime-text.js +780 -25
- package/src/installs/sublime-text.md +914 -0
- package/src/installs/superwhisper.js +687 -25
- package/src/installs/superwhisper.md +630 -0
- package/src/installs/tailscale.js +727 -26
- package/src/installs/tailscale.md +1100 -0
- package/src/installs/tar.js +389 -0
- package/src/installs/tar.md +946 -0
- package/src/installs/termius.js +780 -26
- package/src/installs/termius.md +844 -0
- package/src/installs/terraform.js +761 -26
- package/src/installs/terraform.md +899 -0
- package/src/installs/tidal.js +752 -25
- package/src/installs/tidal.md +864 -0
- package/src/installs/tmux.js +328 -26
- package/src/installs/tmux.md +1030 -0
- package/src/installs/tree.js +393 -26
- package/src/installs/tree.md +833 -0
- package/src/installs/unzip.js +460 -0
- package/src/installs/unzip.md +879 -0
- package/src/installs/vim.js +403 -26
- package/src/installs/vim.md +1040 -0
- package/src/installs/vlc.js +803 -26
- package/src/installs/vlc.md +927 -0
- package/src/installs/vscode.js +825 -26
- package/src/installs/vscode.md +1002 -0
- package/src/installs/wget.js +415 -0
- package/src/installs/wget.md +791 -0
- package/src/installs/whatsapp.js +710 -25
- package/src/installs/whatsapp.md +854 -0
- package/src/installs/winpty.js +352 -0
- package/src/installs/winpty.md +620 -0
- package/src/installs/woff2.js +535 -26
- package/src/installs/woff2.md +977 -0
- package/src/installs/wsl.js +572 -0
- package/src/installs/wsl.md +699 -0
- package/src/installs/xcode-clt.js +520 -0
- package/src/installs/xcode-clt.md +351 -0
- package/src/installs/xcode.js +542 -26
- package/src/installs/xcode.md +573 -0
- package/src/installs/yarn.js +806 -26
- package/src/installs/yarn.md +1074 -0
- package/src/installs/yq.js +636 -26
- package/src/installs/yq.md +944 -0
- package/src/installs/yt-dlp.js +683 -26
- package/src/installs/yt-dlp.md +946 -0
- package/src/installs/yum-utils.js +297 -0
- package/src/installs/yum-utils.md +648 -0
- package/src/installs/zoom.js +740 -25
- package/src/installs/zoom.md +884 -0
- package/src/scripts/README.md +567 -45
- package/src/scripts/STATUS.md +208 -0
- package/src/scripts/afk.js +395 -7
- package/src/scripts/backup-all.js +731 -9
- package/src/scripts/backup-source.js +711 -8
- package/src/scripts/brewd.js +373 -7
- package/src/scripts/brewi.js +505 -9
- package/src/scripts/brewr.js +512 -9
- package/src/scripts/brews.js +462 -9
- package/src/scripts/brewu.js +488 -7
- package/src/scripts/c.js +185 -7
- package/src/scripts/ccurl.js +325 -8
- package/src/scripts/certbot-crontab-init.js +488 -8
- package/src/scripts/certbot-init.js +641 -9
- package/src/scripts/ch.js +339 -7
- package/src/scripts/claude-danger.js +253 -8
- package/src/scripts/clean-dev.js +419 -8
- package/src/scripts/clear-dns-cache.js +525 -7
- package/src/scripts/clone.js +417 -7
- package/src/scripts/code-all.js +420 -7
- package/src/scripts/count-files.js +195 -8
- package/src/scripts/count-folders.js +195 -8
- package/src/scripts/count.js +248 -8
- package/src/scripts/d.js +203 -7
- package/src/scripts/datauri.js +373 -8
- package/src/scripts/delete-files.js +363 -7
- package/src/scripts/docker-clean.js +410 -8
- package/src/scripts/dp.js +426 -7
- package/src/scripts/e.js +375 -9
- package/src/scripts/empty-trash.js +497 -7
- package/src/scripts/evm.js +428 -9
- package/src/scripts/fetch-github-repos.js +441 -10
- package/src/scripts/get-channel.js +329 -8
- package/src/scripts/get-course.js +384 -11
- package/src/scripts/get-dependencies.js +290 -9
- package/src/scripts/get-folder.js +783 -10
- package/src/scripts/get-tunes.js +411 -10
- package/src/scripts/get-video.js +352 -9
- package/src/scripts/git-backup.js +561 -9
- package/src/scripts/git-clone.js +477 -9
- package/src/scripts/git-pup.js +303 -7
- package/src/scripts/git-push.js +380 -8
- package/src/scripts/h.js +607 -9
- package/src/scripts/hide-desktop-icons.js +483 -7
- package/src/scripts/hide-hidden-files.js +522 -7
- package/src/scripts/install-dependencies-from.js +440 -9
- package/src/scripts/ips.js +647 -10
- package/src/scripts/iso.js +354 -8
- package/src/scripts/killni.js +561 -7
- package/src/scripts/ll.js +451 -8
- package/src/scripts/local-ip.js +310 -8
- package/src/scripts/m.js +508 -8
- package/src/scripts/map.js +293 -8
- package/src/scripts/mkd.js +287 -7
- package/src/scripts/ncu-update-all.js +441 -8
- package/src/scripts/nginx-init.js +702 -12
- package/src/scripts/npmi.js +366 -7
- package/src/scripts/o.js +495 -8
- package/src/scripts/org-by-date.js +321 -7
- package/src/scripts/p.js +208 -7
- package/src/scripts/packages.js +313 -8
- package/src/scripts/path.js +209 -7
- package/src/scripts/ports.js +582 -8
- package/src/scripts/q.js +290 -8
- package/src/scripts/refresh-files.js +378 -10
- package/src/scripts/remove-smaller-files.js +500 -8
- package/src/scripts/rename-files-with-date.js +517 -9
- package/src/scripts/resize-image.js +523 -9
- package/src/scripts/rm-safe.js +653 -8
- package/src/scripts/s.js +525 -9
- package/src/scripts/set-git-public.js +349 -7
- package/src/scripts/show-desktop-icons.js +459 -7
- package/src/scripts/show-hidden-files.js +456 -7
- package/src/scripts/tpa.js +265 -8
- package/src/scripts/tpo.js +264 -7
- package/src/scripts/u.js +489 -7
- package/src/scripts/vpush.js +422 -8
- package/src/scripts/y.js +267 -7
- package/src/utils/common/os.js +94 -2
- package/src/utils/ubuntu/apt.js +13 -7
- package/src/utils/windows/choco.js +82 -26
- package/src/utils/windows/winget.js +89 -27
|
@@ -1,24 +1,426 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* docker-clean - Remove all Docker containers, images, and volumes
|
|
5
|
+
*
|
|
6
|
+
* Migrated from legacy dotfiles alias.
|
|
7
|
+
* Original:
|
|
8
|
+
* docker-clean(){
|
|
9
|
+
* echo "This will remove ALL Docker containers, images, and volumes."
|
|
10
|
+
* echo "This action cannot be undone!"
|
|
11
|
+
* echo ""
|
|
12
|
+
* read -p "Are you sure you want to continue? (y/N): " -n 1 -r
|
|
13
|
+
* echo ""
|
|
14
|
+
*
|
|
15
|
+
* if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
16
|
+
* echo "Operation cancelled."
|
|
17
|
+
* return 0
|
|
18
|
+
* fi
|
|
19
|
+
*
|
|
20
|
+
* echo "Proceeding with Docker cleanup..."
|
|
21
|
+
*
|
|
22
|
+
* # Delete all containers
|
|
23
|
+
* if docker ps -a -q >/dev/null 2>&1; then
|
|
24
|
+
* echo "Removing all containers..."
|
|
25
|
+
* docker rm -f $(docker ps -a -q)
|
|
26
|
+
* else
|
|
27
|
+
* echo "No containers to remove."
|
|
28
|
+
* fi
|
|
29
|
+
*
|
|
30
|
+
* # Delete all images
|
|
31
|
+
* if docker images -q >/dev/null 2>&1; then
|
|
32
|
+
* echo "Removing all images..."
|
|
33
|
+
* docker images -q | xargs docker rmi -f
|
|
34
|
+
* else
|
|
35
|
+
* echo "No images to remove."
|
|
36
|
+
* fi
|
|
37
|
+
*
|
|
38
|
+
* # Delete volumes
|
|
39
|
+
* if docker volume ls -q >/dev/null 2>&1; then
|
|
40
|
+
* echo "Removing all volumes..."
|
|
41
|
+
* docker volume rm $(docker volume ls -q)
|
|
42
|
+
* else
|
|
43
|
+
* echo "No volumes to remove."
|
|
44
|
+
* fi
|
|
45
|
+
*
|
|
46
|
+
* echo "Docker cleanup completed."
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* This script removes ALL Docker containers, images, and volumes after
|
|
50
|
+
* prompting for confirmation (unless --force is passed). This action cannot be undone.
|
|
51
|
+
*
|
|
52
|
+
* Usage:
|
|
53
|
+
* docker-clean # Interactive mode - prompts for confirmation
|
|
54
|
+
* docker-clean --force # Skip confirmation prompt
|
|
55
|
+
* docker-clean -f # Skip confirmation prompt (short form)
|
|
56
|
+
*
|
|
5
57
|
* @module scripts/docker-clean
|
|
6
58
|
*/
|
|
7
59
|
|
|
60
|
+
const os = require('../utils/common/os');
|
|
61
|
+
const { execSync, spawnSync } = require('child_process');
|
|
62
|
+
const readline = require('readline');
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Helper function to check if a command exists on the system.
|
|
66
|
+
* Used to verify Docker is installed before attempting cleanup.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} cmd - The command name to check
|
|
69
|
+
* @returns {boolean} True if the command exists, false otherwise
|
|
70
|
+
*/
|
|
71
|
+
function isCommandAvailable(cmd) {
|
|
72
|
+
try {
|
|
73
|
+
// Use 'which' on Unix-like systems, 'where' on Windows
|
|
74
|
+
const checkCmd = process.platform === 'win32' ? `where ${cmd}` : `which ${cmd}`;
|
|
75
|
+
execSync(checkCmd, { stdio: 'ignore' });
|
|
76
|
+
return true;
|
|
77
|
+
} catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Helper function to prompt the user for confirmation.
|
|
84
|
+
* Returns a promise that resolves to true if user confirms, false otherwise.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} message - The question to ask the user
|
|
87
|
+
* @returns {Promise<boolean>} True if user confirms (y/Y), false otherwise
|
|
88
|
+
*/
|
|
89
|
+
function askConfirmation(message) {
|
|
90
|
+
return new Promise((resolve) => {
|
|
91
|
+
const rl = readline.createInterface({
|
|
92
|
+
input: process.stdin,
|
|
93
|
+
output: process.stdout
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
rl.question(message, (answer) => {
|
|
97
|
+
rl.close();
|
|
98
|
+
// Accept 'y' or 'Y' as confirmation, anything else is decline
|
|
99
|
+
resolve(answer.toLowerCase() === 'y');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Helper function to run a Docker command and return its output.
|
|
106
|
+
* Uses spawnSync for better handling of command output and errors.
|
|
107
|
+
*
|
|
108
|
+
* @param {string[]} args - Array of arguments to pass to docker
|
|
109
|
+
* @returns {{ success: boolean, output: string }} Result object with success status and output
|
|
110
|
+
*/
|
|
111
|
+
function runDockerCommand(args) {
|
|
112
|
+
const result = spawnSync('docker', args, {
|
|
113
|
+
encoding: 'utf8',
|
|
114
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
success: result.status === 0,
|
|
119
|
+
output: (result.stdout || '').trim(),
|
|
120
|
+
error: (result.stderr || '').trim()
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Pure Node.js implementation for Docker cleanup.
|
|
126
|
+
*
|
|
127
|
+
* Docker is a cross-platform tool that works identically on all operating systems.
|
|
128
|
+
* The Docker CLI commands (docker ps, docker rm, docker rmi, docker volume) are
|
|
129
|
+
* the same regardless of the underlying platform. Therefore, we use a single
|
|
130
|
+
* Node.js implementation that works everywhere Docker is installed.
|
|
131
|
+
*
|
|
132
|
+
* This function:
|
|
133
|
+
* 1. Checks if Docker is installed
|
|
134
|
+
* 2. Prompts for confirmation (unless --force is passed)
|
|
135
|
+
* 3. Removes all containers (stopped and running)
|
|
136
|
+
* 4. Removes all images
|
|
137
|
+
* 5. Removes all volumes
|
|
138
|
+
*
|
|
139
|
+
* @param {string[]} args - Command line arguments
|
|
140
|
+
* @param {string} [args.0] - Pass "--force" or "-f" to skip confirmation
|
|
141
|
+
* @returns {Promise<void>}
|
|
142
|
+
*/
|
|
143
|
+
async function do_docker_clean_nodejs(args) {
|
|
144
|
+
// Check if Docker is installed
|
|
145
|
+
if (!isCommandAvailable('docker')) {
|
|
146
|
+
console.error('Error: Docker is not installed or not in PATH.');
|
|
147
|
+
console.error('');
|
|
148
|
+
console.error('Install Docker:');
|
|
149
|
+
console.error(' macOS: brew install --cask docker');
|
|
150
|
+
console.error(' Ubuntu: sudo apt install docker.io');
|
|
151
|
+
console.error(' Windows: winget install Docker.DockerDesktop');
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Check if Docker daemon is running
|
|
156
|
+
const dockerInfo = runDockerCommand(['info']);
|
|
157
|
+
if (!dockerInfo.success) {
|
|
158
|
+
console.error('Error: Docker daemon is not running.');
|
|
159
|
+
console.error('');
|
|
160
|
+
console.error('Please start Docker:');
|
|
161
|
+
console.error(' macOS: Open Docker Desktop application');
|
|
162
|
+
console.error(' Linux: sudo systemctl start docker');
|
|
163
|
+
console.error(' Windows: Start Docker Desktop from Start menu');
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Check for --force or -f flag to skip confirmation
|
|
168
|
+
const forceMode = args.includes('--force') || args.includes('-f');
|
|
169
|
+
|
|
170
|
+
// Display warning and ask for confirmation (unless force mode)
|
|
171
|
+
console.log('This will remove ALL Docker containers, images, and volumes.');
|
|
172
|
+
console.log('This action cannot be undone!');
|
|
173
|
+
console.log('');
|
|
174
|
+
|
|
175
|
+
if (!forceMode) {
|
|
176
|
+
const confirmed = await askConfirmation('Are you sure you want to continue? (y/N): ');
|
|
177
|
+
console.log('');
|
|
178
|
+
|
|
179
|
+
if (!confirmed) {
|
|
180
|
+
console.log('Operation cancelled.');
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
console.log('Running in force mode - skipping confirmation.');
|
|
185
|
+
console.log('');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
console.log('Proceeding with Docker cleanup...');
|
|
189
|
+
console.log('');
|
|
190
|
+
|
|
191
|
+
// --- Step 1: Remove all containers ---
|
|
192
|
+
const containers = runDockerCommand(['ps', '-a', '-q']);
|
|
193
|
+
|
|
194
|
+
if (containers.success && containers.output) {
|
|
195
|
+
// There are containers to remove
|
|
196
|
+
const containerIds = containers.output.split('\n').filter(id => id.length > 0);
|
|
197
|
+
console.log(`Removing ${containerIds.length} container(s)...`);
|
|
198
|
+
|
|
199
|
+
// Remove containers one by one to show progress and handle errors gracefully
|
|
200
|
+
for (const containerId of containerIds) {
|
|
201
|
+
const removeResult = runDockerCommand(['rm', '-f', containerId]);
|
|
202
|
+
if (removeResult.success) {
|
|
203
|
+
console.log(` Removed container: ${containerId.substring(0, 12)}`);
|
|
204
|
+
} else {
|
|
205
|
+
console.log(` Warning: Could not remove container ${containerId.substring(0, 12)}: ${removeResult.error}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
console.log('');
|
|
209
|
+
} else {
|
|
210
|
+
console.log('No containers to remove.');
|
|
211
|
+
console.log('');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// --- Step 2: Remove all images ---
|
|
215
|
+
const images = runDockerCommand(['images', '-q']);
|
|
216
|
+
|
|
217
|
+
if (images.success && images.output) {
|
|
218
|
+
// There are images to remove
|
|
219
|
+
// Note: images -q may return duplicate IDs, so we deduplicate
|
|
220
|
+
const imageIds = [...new Set(images.output.split('\n').filter(id => id.length > 0))];
|
|
221
|
+
console.log(`Removing ${imageIds.length} image(s)...`);
|
|
222
|
+
|
|
223
|
+
// Remove images one by one
|
|
224
|
+
for (const imageId of imageIds) {
|
|
225
|
+
const removeResult = runDockerCommand(['rmi', '-f', imageId]);
|
|
226
|
+
if (removeResult.success) {
|
|
227
|
+
console.log(` Removed image: ${imageId.substring(0, 12)}`);
|
|
228
|
+
} else {
|
|
229
|
+
// Images may fail to remove if they're parent images; this is expected
|
|
230
|
+
console.log(` Warning: Could not remove image ${imageId.substring(0, 12)}: ${removeResult.error}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
console.log('');
|
|
234
|
+
} else {
|
|
235
|
+
console.log('No images to remove.');
|
|
236
|
+
console.log('');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// --- Step 3: Remove all volumes ---
|
|
240
|
+
const volumes = runDockerCommand(['volume', 'ls', '-q']);
|
|
241
|
+
|
|
242
|
+
if (volumes.success && volumes.output) {
|
|
243
|
+
// There are volumes to remove
|
|
244
|
+
const volumeNames = volumes.output.split('\n').filter(name => name.length > 0);
|
|
245
|
+
console.log(`Removing ${volumeNames.length} volume(s)...`);
|
|
246
|
+
|
|
247
|
+
// Remove volumes one by one
|
|
248
|
+
for (const volumeName of volumeNames) {
|
|
249
|
+
const removeResult = runDockerCommand(['volume', 'rm', volumeName]);
|
|
250
|
+
if (removeResult.success) {
|
|
251
|
+
console.log(` Removed volume: ${volumeName}`);
|
|
252
|
+
} else {
|
|
253
|
+
console.log(` Warning: Could not remove volume ${volumeName}: ${removeResult.error}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
console.log('');
|
|
257
|
+
} else {
|
|
258
|
+
console.log('No volumes to remove.');
|
|
259
|
+
console.log('');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
console.log('Docker cleanup completed.');
|
|
263
|
+
}
|
|
264
|
+
|
|
8
265
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
266
|
+
* Remove all Docker containers, images, and volumes on macOS.
|
|
267
|
+
*
|
|
268
|
+
* Docker works identically on macOS as on other platforms, so this function
|
|
269
|
+
* delegates to the pure Node.js implementation.
|
|
11
270
|
*
|
|
12
271
|
* @param {string[]} args - Command line arguments
|
|
13
|
-
* @param {string} [args.0] - Pass "--force" to skip confirmation
|
|
14
272
|
* @returns {Promise<void>}
|
|
15
273
|
*/
|
|
16
|
-
async function
|
|
17
|
-
|
|
274
|
+
async function do_docker_clean_macos(args) {
|
|
275
|
+
return do_docker_clean_nodejs(args);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Remove all Docker containers, images, and volumes on Ubuntu.
|
|
280
|
+
*
|
|
281
|
+
* Docker works identically on Ubuntu as on other platforms, so this function
|
|
282
|
+
* delegates to the pure Node.js implementation.
|
|
283
|
+
*
|
|
284
|
+
* @param {string[]} args - Command line arguments
|
|
285
|
+
* @returns {Promise<void>}
|
|
286
|
+
*/
|
|
287
|
+
async function do_docker_clean_ubuntu(args) {
|
|
288
|
+
return do_docker_clean_nodejs(args);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Remove all Docker containers, images, and volumes on Raspberry Pi OS.
|
|
293
|
+
*
|
|
294
|
+
* Docker works identically on Raspberry Pi OS as on other platforms, so this
|
|
295
|
+
* function delegates to the pure Node.js implementation.
|
|
296
|
+
*
|
|
297
|
+
* @param {string[]} args - Command line arguments
|
|
298
|
+
* @returns {Promise<void>}
|
|
299
|
+
*/
|
|
300
|
+
async function do_docker_clean_raspbian(args) {
|
|
301
|
+
return do_docker_clean_nodejs(args);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Remove all Docker containers, images, and volumes on Amazon Linux.
|
|
306
|
+
*
|
|
307
|
+
* Docker works identically on Amazon Linux as on other platforms, so this
|
|
308
|
+
* function delegates to the pure Node.js implementation.
|
|
309
|
+
*
|
|
310
|
+
* @param {string[]} args - Command line arguments
|
|
311
|
+
* @returns {Promise<void>}
|
|
312
|
+
*/
|
|
313
|
+
async function do_docker_clean_amazon_linux(args) {
|
|
314
|
+
return do_docker_clean_nodejs(args);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Remove all Docker containers, images, and volumes on Windows Command Prompt.
|
|
319
|
+
*
|
|
320
|
+
* Docker works identically on Windows as on other platforms, so this function
|
|
321
|
+
* delegates to the pure Node.js implementation.
|
|
322
|
+
*
|
|
323
|
+
* @param {string[]} args - Command line arguments
|
|
324
|
+
* @returns {Promise<void>}
|
|
325
|
+
*/
|
|
326
|
+
async function do_docker_clean_cmd(args) {
|
|
327
|
+
return do_docker_clean_nodejs(args);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Remove all Docker containers, images, and volumes on Windows PowerShell.
|
|
332
|
+
*
|
|
333
|
+
* Docker works identically on Windows as on other platforms, so this function
|
|
334
|
+
* delegates to the pure Node.js implementation.
|
|
335
|
+
*
|
|
336
|
+
* @param {string[]} args - Command line arguments
|
|
337
|
+
* @returns {Promise<void>}
|
|
338
|
+
*/
|
|
339
|
+
async function do_docker_clean_powershell(args) {
|
|
340
|
+
return do_docker_clean_nodejs(args);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Remove all Docker containers, images, and volumes on Git Bash.
|
|
345
|
+
*
|
|
346
|
+
* Docker works identically in Git Bash as on other platforms, so this function
|
|
347
|
+
* delegates to the pure Node.js implementation.
|
|
348
|
+
*
|
|
349
|
+
* @param {string[]} args - Command line arguments
|
|
350
|
+
* @returns {Promise<void>}
|
|
351
|
+
*/
|
|
352
|
+
async function do_docker_clean_gitbash(args) {
|
|
353
|
+
return do_docker_clean_nodejs(args);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Main entry point - detects environment and executes appropriate implementation.
|
|
358
|
+
*
|
|
359
|
+
* The "docker-clean" command removes ALL Docker containers, images, and volumes
|
|
360
|
+
* from the system. This is useful for:
|
|
361
|
+
* - Freeing up disk space consumed by Docker
|
|
362
|
+
* - Starting fresh with a clean Docker environment
|
|
363
|
+
* - Debugging issues by removing all cached layers and containers
|
|
364
|
+
*
|
|
365
|
+
* WARNING: This operation cannot be undone. All data stored in Docker volumes
|
|
366
|
+
* will be permanently deleted.
|
|
367
|
+
*
|
|
368
|
+
* Usage:
|
|
369
|
+
* docker-clean # Interactive mode with confirmation prompt
|
|
370
|
+
* docker-clean --force # Skip confirmation (use with caution!)
|
|
371
|
+
* docker-clean -f # Same as --force
|
|
372
|
+
*
|
|
373
|
+
* @param {string[]} args - Command line arguments
|
|
374
|
+
* @returns {Promise<void>}
|
|
375
|
+
*/
|
|
376
|
+
async function do_docker_clean(args) {
|
|
377
|
+
const platform = os.detect();
|
|
378
|
+
|
|
379
|
+
const handlers = {
|
|
380
|
+
'macos': do_docker_clean_macos,
|
|
381
|
+
'ubuntu': do_docker_clean_ubuntu,
|
|
382
|
+
'debian': do_docker_clean_ubuntu,
|
|
383
|
+
'raspbian': do_docker_clean_raspbian,
|
|
384
|
+
'amazon_linux': do_docker_clean_amazon_linux,
|
|
385
|
+
'rhel': do_docker_clean_amazon_linux,
|
|
386
|
+
'fedora': do_docker_clean_ubuntu,
|
|
387
|
+
'linux': do_docker_clean_ubuntu,
|
|
388
|
+
'wsl': do_docker_clean_ubuntu,
|
|
389
|
+
'cmd': do_docker_clean_cmd,
|
|
390
|
+
'windows': do_docker_clean_cmd,
|
|
391
|
+
'powershell': do_docker_clean_powershell,
|
|
392
|
+
'gitbash': do_docker_clean_gitbash
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const handler = handlers[platform.type];
|
|
396
|
+
if (!handler) {
|
|
397
|
+
console.error(`Platform '${platform.type}' is not supported for this command.`);
|
|
398
|
+
console.error('');
|
|
399
|
+
console.error('Supported platforms:');
|
|
400
|
+
console.error(' - macOS');
|
|
401
|
+
console.error(' - Ubuntu, Debian, and other Linux distributions');
|
|
402
|
+
console.error(' - Raspberry Pi OS');
|
|
403
|
+
console.error(' - Amazon Linux, RHEL, Fedora');
|
|
404
|
+
console.error(' - Windows (CMD, PowerShell, Git Bash)');
|
|
405
|
+
process.exit(1);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
await handler(args);
|
|
18
409
|
}
|
|
19
410
|
|
|
20
|
-
module.exports = {
|
|
411
|
+
module.exports = {
|
|
412
|
+
main: do_docker_clean,
|
|
413
|
+
do_docker_clean,
|
|
414
|
+
do_docker_clean_nodejs,
|
|
415
|
+
do_docker_clean_macos,
|
|
416
|
+
do_docker_clean_ubuntu,
|
|
417
|
+
do_docker_clean_raspbian,
|
|
418
|
+
do_docker_clean_amazon_linux,
|
|
419
|
+
do_docker_clean_cmd,
|
|
420
|
+
do_docker_clean_powershell,
|
|
421
|
+
do_docker_clean_gitbash
|
|
422
|
+
};
|
|
21
423
|
|
|
22
424
|
if (require.main === module) {
|
|
23
|
-
|
|
425
|
+
do_docker_clean(process.argv.slice(2));
|
|
24
426
|
}
|