@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.
Files changed (259) hide show
  1. package/README.md +5 -5
  2. package/package.json +1 -1
  3. package/src/commands/install.js +374 -36
  4. package/src/installs/adobe-creative-cloud.js +527 -25
  5. package/src/installs/adobe-creative-cloud.md +605 -0
  6. package/src/installs/appcleaner.js +303 -26
  7. package/src/installs/appcleaner.md +699 -0
  8. package/src/installs/apt-transport-https.js +390 -0
  9. package/src/installs/apt-transport-https.md +678 -0
  10. package/src/installs/atomicparsley.js +624 -26
  11. package/src/installs/atomicparsley.md +795 -0
  12. package/src/installs/aws-cli.js +779 -26
  13. package/src/installs/aws-cli.md +727 -0
  14. package/src/installs/balena-etcher.js +688 -26
  15. package/src/installs/balena-etcher.md +761 -0
  16. package/src/installs/bambu-studio.js +912 -26
  17. package/src/installs/bambu-studio.md +780 -0
  18. package/src/installs/bash-completion.js +554 -23
  19. package/src/installs/bash-completion.md +833 -0
  20. package/src/installs/bash.js +399 -26
  21. package/src/installs/bash.md +993 -0
  22. package/src/installs/beyond-compare.js +585 -26
  23. package/src/installs/beyond-compare.md +813 -0
  24. package/src/installs/build-essential.js +511 -26
  25. package/src/installs/build-essential.md +977 -0
  26. package/src/installs/ca-certificates.js +618 -0
  27. package/src/installs/ca-certificates.md +937 -0
  28. package/src/installs/caffeine.js +490 -26
  29. package/src/installs/caffeine.md +839 -0
  30. package/src/installs/camtasia.js +577 -25
  31. package/src/installs/camtasia.md +762 -0
  32. package/src/installs/chatgpt.js +458 -26
  33. package/src/installs/chatgpt.md +814 -0
  34. package/src/installs/chocolatey.js +447 -0
  35. package/src/installs/chocolatey.md +661 -0
  36. package/src/installs/chrome-canary.js +472 -26
  37. package/src/installs/chrome-canary.md +641 -0
  38. package/src/installs/chromium.js +645 -26
  39. package/src/installs/chromium.md +838 -0
  40. package/src/installs/claude-code.js +558 -26
  41. package/src/installs/claude-code.md +1173 -0
  42. package/src/installs/curl.js +361 -26
  43. package/src/installs/curl.md +714 -0
  44. package/src/installs/cursor.js +561 -26
  45. package/src/installs/cursor.md +970 -0
  46. package/src/installs/dbschema.js +674 -26
  47. package/src/installs/dbschema.md +925 -0
  48. package/src/installs/dependencies.md +435 -0
  49. package/src/installs/development-tools.js +600 -0
  50. package/src/installs/development-tools.md +977 -0
  51. package/src/installs/docker.js +1010 -25
  52. package/src/installs/docker.md +1109 -0
  53. package/src/installs/drawio.js +1001 -26
  54. package/src/installs/drawio.md +795 -0
  55. package/src/installs/elmedia-player.js +328 -25
  56. package/src/installs/elmedia-player.md +556 -0
  57. package/src/installs/ffmpeg.js +870 -25
  58. package/src/installs/ffmpeg.md +852 -0
  59. package/src/installs/file.js +464 -0
  60. package/src/installs/file.md +987 -0
  61. package/src/installs/gemini-cli.js +793 -26
  62. package/src/installs/gemini-cli.md +1153 -0
  63. package/src/installs/git.js +382 -26
  64. package/src/installs/git.md +907 -0
  65. package/src/installs/gitego.js +931 -26
  66. package/src/installs/gitego.md +1172 -0
  67. package/src/installs/go.js +913 -26
  68. package/src/installs/go.md +958 -0
  69. package/src/installs/google-chrome.js +801 -25
  70. package/src/installs/google-chrome.md +862 -0
  71. package/src/installs/gpg.js +412 -73
  72. package/src/installs/gpg.md +1056 -0
  73. package/src/installs/homebrew.js +1015 -26
  74. package/src/installs/homebrew.md +988 -0
  75. package/src/installs/imageoptim.js +950 -26
  76. package/src/installs/imageoptim.md +1119 -0
  77. package/src/installs/installers.json +2297 -0
  78. package/src/installs/jq.js +382 -26
  79. package/src/installs/jq.md +809 -0
  80. package/src/installs/keyboard-maestro.js +701 -26
  81. package/src/installs/keyboard-maestro.md +825 -0
  82. package/src/installs/latex.js +771 -26
  83. package/src/installs/latex.md +1095 -0
  84. package/src/installs/lftp.js +338 -26
  85. package/src/installs/lftp.md +907 -0
  86. package/src/installs/lsb-release.js +346 -0
  87. package/src/installs/lsb-release.md +814 -0
  88. package/src/installs/messenger.js +829 -26
  89. package/src/installs/messenger.md +900 -0
  90. package/src/installs/microsoft-office.js +550 -26
  91. package/src/installs/microsoft-office.md +760 -0
  92. package/src/installs/microsoft-teams.js +782 -25
  93. package/src/installs/microsoft-teams.md +886 -0
  94. package/src/installs/node.js +886 -26
  95. package/src/installs/node.md +1153 -0
  96. package/src/installs/nordpass.js +698 -26
  97. package/src/installs/nordpass.md +921 -0
  98. package/src/installs/nvm.js +977 -26
  99. package/src/installs/nvm.md +1057 -0
  100. package/src/installs/openssh.js +734 -64
  101. package/src/installs/openssh.md +1056 -0
  102. package/src/installs/pandoc.js +644 -26
  103. package/src/installs/pandoc.md +1036 -0
  104. package/src/installs/pinentry.js +492 -26
  105. package/src/installs/pinentry.md +1142 -0
  106. package/src/installs/pngyu.js +851 -26
  107. package/src/installs/pngyu.md +896 -0
  108. package/src/installs/postman.js +781 -26
  109. package/src/installs/postman.md +940 -0
  110. package/src/installs/procps.js +425 -0
  111. package/src/installs/procps.md +851 -0
  112. package/src/installs/safari-tech-preview.js +355 -25
  113. package/src/installs/safari-tech-preview.md +533 -0
  114. package/src/installs/sfnt2woff.js +640 -26
  115. package/src/installs/sfnt2woff.md +795 -0
  116. package/src/installs/shellcheck.js +463 -26
  117. package/src/installs/shellcheck.md +1005 -0
  118. package/src/installs/slack.js +722 -25
  119. package/src/installs/slack.md +865 -0
  120. package/src/installs/snagit.js +566 -25
  121. package/src/installs/snagit.md +844 -0
  122. package/src/installs/software-properties-common.js +372 -0
  123. package/src/installs/software-properties-common.md +805 -0
  124. package/src/installs/spotify.js +858 -25
  125. package/src/installs/spotify.md +901 -0
  126. package/src/installs/studio-3t.js +803 -26
  127. package/src/installs/studio-3t.md +918 -0
  128. package/src/installs/sublime-text.js +780 -25
  129. package/src/installs/sublime-text.md +914 -0
  130. package/src/installs/superwhisper.js +687 -25
  131. package/src/installs/superwhisper.md +630 -0
  132. package/src/installs/tailscale.js +727 -26
  133. package/src/installs/tailscale.md +1100 -0
  134. package/src/installs/tar.js +389 -0
  135. package/src/installs/tar.md +946 -0
  136. package/src/installs/termius.js +780 -26
  137. package/src/installs/termius.md +844 -0
  138. package/src/installs/terraform.js +761 -26
  139. package/src/installs/terraform.md +899 -0
  140. package/src/installs/tidal.js +752 -25
  141. package/src/installs/tidal.md +864 -0
  142. package/src/installs/tmux.js +328 -26
  143. package/src/installs/tmux.md +1030 -0
  144. package/src/installs/tree.js +393 -26
  145. package/src/installs/tree.md +833 -0
  146. package/src/installs/unzip.js +460 -0
  147. package/src/installs/unzip.md +879 -0
  148. package/src/installs/vim.js +403 -26
  149. package/src/installs/vim.md +1040 -0
  150. package/src/installs/vlc.js +803 -26
  151. package/src/installs/vlc.md +927 -0
  152. package/src/installs/vscode.js +825 -26
  153. package/src/installs/vscode.md +1002 -0
  154. package/src/installs/wget.js +415 -0
  155. package/src/installs/wget.md +791 -0
  156. package/src/installs/whatsapp.js +710 -25
  157. package/src/installs/whatsapp.md +854 -0
  158. package/src/installs/winpty.js +352 -0
  159. package/src/installs/winpty.md +620 -0
  160. package/src/installs/woff2.js +535 -26
  161. package/src/installs/woff2.md +977 -0
  162. package/src/installs/wsl.js +572 -0
  163. package/src/installs/wsl.md +699 -0
  164. package/src/installs/xcode-clt.js +520 -0
  165. package/src/installs/xcode-clt.md +351 -0
  166. package/src/installs/xcode.js +542 -26
  167. package/src/installs/xcode.md +573 -0
  168. package/src/installs/yarn.js +806 -26
  169. package/src/installs/yarn.md +1074 -0
  170. package/src/installs/yq.js +636 -26
  171. package/src/installs/yq.md +944 -0
  172. package/src/installs/yt-dlp.js +683 -26
  173. package/src/installs/yt-dlp.md +946 -0
  174. package/src/installs/yum-utils.js +297 -0
  175. package/src/installs/yum-utils.md +648 -0
  176. package/src/installs/zoom.js +740 -25
  177. package/src/installs/zoom.md +884 -0
  178. package/src/scripts/README.md +567 -45
  179. package/src/scripts/STATUS.md +208 -0
  180. package/src/scripts/afk.js +395 -7
  181. package/src/scripts/backup-all.js +731 -9
  182. package/src/scripts/backup-source.js +711 -8
  183. package/src/scripts/brewd.js +373 -7
  184. package/src/scripts/brewi.js +505 -9
  185. package/src/scripts/brewr.js +512 -9
  186. package/src/scripts/brews.js +462 -9
  187. package/src/scripts/brewu.js +488 -7
  188. package/src/scripts/c.js +185 -7
  189. package/src/scripts/ccurl.js +325 -8
  190. package/src/scripts/certbot-crontab-init.js +488 -8
  191. package/src/scripts/certbot-init.js +641 -9
  192. package/src/scripts/ch.js +339 -7
  193. package/src/scripts/claude-danger.js +253 -8
  194. package/src/scripts/clean-dev.js +419 -8
  195. package/src/scripts/clear-dns-cache.js +525 -7
  196. package/src/scripts/clone.js +417 -7
  197. package/src/scripts/code-all.js +420 -7
  198. package/src/scripts/count-files.js +195 -8
  199. package/src/scripts/count-folders.js +195 -8
  200. package/src/scripts/count.js +248 -8
  201. package/src/scripts/d.js +203 -7
  202. package/src/scripts/datauri.js +373 -8
  203. package/src/scripts/delete-files.js +363 -7
  204. package/src/scripts/docker-clean.js +410 -8
  205. package/src/scripts/dp.js +426 -7
  206. package/src/scripts/e.js +375 -9
  207. package/src/scripts/empty-trash.js +497 -7
  208. package/src/scripts/evm.js +428 -9
  209. package/src/scripts/fetch-github-repos.js +441 -10
  210. package/src/scripts/get-channel.js +329 -8
  211. package/src/scripts/get-course.js +384 -11
  212. package/src/scripts/get-dependencies.js +290 -9
  213. package/src/scripts/get-folder.js +783 -10
  214. package/src/scripts/get-tunes.js +411 -10
  215. package/src/scripts/get-video.js +352 -9
  216. package/src/scripts/git-backup.js +561 -9
  217. package/src/scripts/git-clone.js +477 -9
  218. package/src/scripts/git-pup.js +303 -7
  219. package/src/scripts/git-push.js +380 -8
  220. package/src/scripts/h.js +607 -9
  221. package/src/scripts/hide-desktop-icons.js +483 -7
  222. package/src/scripts/hide-hidden-files.js +522 -7
  223. package/src/scripts/install-dependencies-from.js +440 -9
  224. package/src/scripts/ips.js +647 -10
  225. package/src/scripts/iso.js +354 -8
  226. package/src/scripts/killni.js +561 -7
  227. package/src/scripts/ll.js +451 -8
  228. package/src/scripts/local-ip.js +310 -8
  229. package/src/scripts/m.js +508 -8
  230. package/src/scripts/map.js +293 -8
  231. package/src/scripts/mkd.js +287 -7
  232. package/src/scripts/ncu-update-all.js +441 -8
  233. package/src/scripts/nginx-init.js +702 -12
  234. package/src/scripts/npmi.js +366 -7
  235. package/src/scripts/o.js +495 -8
  236. package/src/scripts/org-by-date.js +321 -7
  237. package/src/scripts/p.js +208 -7
  238. package/src/scripts/packages.js +313 -8
  239. package/src/scripts/path.js +209 -7
  240. package/src/scripts/ports.js +582 -8
  241. package/src/scripts/q.js +290 -8
  242. package/src/scripts/refresh-files.js +378 -10
  243. package/src/scripts/remove-smaller-files.js +500 -8
  244. package/src/scripts/rename-files-with-date.js +517 -9
  245. package/src/scripts/resize-image.js +523 -9
  246. package/src/scripts/rm-safe.js +653 -8
  247. package/src/scripts/s.js +525 -9
  248. package/src/scripts/set-git-public.js +349 -7
  249. package/src/scripts/show-desktop-icons.js +459 -7
  250. package/src/scripts/show-hidden-files.js +456 -7
  251. package/src/scripts/tpa.js +265 -8
  252. package/src/scripts/tpo.js +264 -7
  253. package/src/scripts/u.js +489 -7
  254. package/src/scripts/vpush.js +422 -8
  255. package/src/scripts/y.js +267 -7
  256. package/src/utils/common/os.js +94 -2
  257. package/src/utils/ubuntu/apt.js +13 -7
  258. package/src/utils/windows/choco.js +82 -26
  259. package/src/utils/windows/winget.js +89 -27
package/src/scripts/d.js CHANGED
@@ -1,23 +1,219 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * @fileoverview Navigate to the Desktop directory.
4
+ * d - Navigate to the Desktop directory
5
+ *
6
+ * Migrated from legacy dotfiles alias.
7
+ * Original: alias d="cd ~/Desktop"
8
+ *
9
+ * This script outputs the path to the user's Desktop folder, which can be used
10
+ * with shell integration (e.g., `cd $(d)`). The Desktop folder location varies
11
+ * by operating system:
12
+ * - macOS: ~/Desktop
13
+ * - Linux: ~/Desktop (XDG standard)
14
+ * - Windows: %USERPROFILE%\Desktop
15
+ *
5
16
  * @module scripts/d
6
17
  */
7
18
 
19
+ const os = require('../utils/common/os');
20
+ const path = require('path');
21
+ const fs = require('fs');
22
+
23
+ /**
24
+ * Pure Node.js implementation that works on any platform.
25
+ *
26
+ * This function determines the Desktop folder path using Node.js APIs.
27
+ * The Desktop folder is typically in the user's home directory, but the
28
+ * exact location can vary. We check for the folder's existence and provide
29
+ * helpful feedback if it doesn't exist.
30
+ *
31
+ * @param {string[]} args - Command line arguments (unused)
32
+ * @returns {Promise<void>}
33
+ */
34
+ async function do_d_nodejs(args) {
35
+ // Get the user's home directory using Node.js built-in os module
36
+ const homeDir = os.getHomeDir();
37
+
38
+ // Construct the path to the Desktop folder
39
+ // On all major platforms, the Desktop folder is named "Desktop" in the home directory
40
+ const desktopPath = path.join(homeDir, 'Desktop');
41
+
42
+ // Check if the Desktop folder exists
43
+ if (!fs.existsSync(desktopPath)) {
44
+ // The Desktop folder doesn't exist - this is unusual but can happen
45
+ // on headless servers or minimal installations
46
+ console.error(`Error: Desktop folder not found at ${desktopPath}`);
47
+ console.error('');
48
+ console.error('This might happen if:');
49
+ console.error(' - You are on a headless server without a desktop environment');
50
+ console.error(' - The Desktop folder was deleted or renamed');
51
+ console.error(' - Your system uses a non-standard Desktop location');
52
+ console.error('');
53
+ console.error(`You can create it with: mkdir -p "${desktopPath}"`);
54
+ process.exit(1);
55
+ }
56
+
57
+ // Output the path so it can be used with shell integration
58
+ // Example usage: cd $(d)
59
+ console.log(desktopPath);
60
+ }
61
+
8
62
  /**
9
- * Changes the current working directory to the user's Desktop folder.
10
- * Outputs the path for use with shell integration (e.g., cd $(d)).
63
+ * Navigate to the Desktop folder on macOS.
64
+ *
65
+ * On macOS, the Desktop folder is always at ~/Desktop.
66
+ * This function delegates to the pure Node.js implementation since
67
+ * the logic is identical across platforms.
11
68
  *
12
69
  * @param {string[]} args - Command line arguments (unused)
13
70
  * @returns {Promise<void>}
14
71
  */
15
- async function main(args) {
16
- // TODO: Implement Desktop navigation
72
+ async function do_d_macos(args) {
73
+ return do_d_nodejs(args);
74
+ }
75
+
76
+ /**
77
+ * Navigate to the Desktop folder on Ubuntu.
78
+ *
79
+ * On Ubuntu and other Linux distributions following the XDG Base Directory
80
+ * Specification, the Desktop folder is typically at ~/Desktop.
81
+ * This function delegates to the pure Node.js implementation.
82
+ *
83
+ * @param {string[]} args - Command line arguments (unused)
84
+ * @returns {Promise<void>}
85
+ */
86
+ async function do_d_ubuntu(args) {
87
+ return do_d_nodejs(args);
88
+ }
89
+
90
+ /**
91
+ * Navigate to the Desktop folder on Raspberry Pi OS.
92
+ *
93
+ * Raspberry Pi OS follows the same convention as other Debian-based systems.
94
+ * The Desktop folder is at ~/Desktop.
95
+ * This function delegates to the pure Node.js implementation.
96
+ *
97
+ * @param {string[]} args - Command line arguments (unused)
98
+ * @returns {Promise<void>}
99
+ */
100
+ async function do_d_raspbian(args) {
101
+ return do_d_nodejs(args);
102
+ }
103
+
104
+ /**
105
+ * Navigate to the Desktop folder on Amazon Linux.
106
+ *
107
+ * On Amazon Linux (typically used in server environments), a Desktop folder
108
+ * may not exist. This function delegates to the pure Node.js implementation,
109
+ * which will provide helpful feedback if the folder doesn't exist.
110
+ *
111
+ * @param {string[]} args - Command line arguments (unused)
112
+ * @returns {Promise<void>}
113
+ */
114
+ async function do_d_amazon_linux(args) {
115
+ return do_d_nodejs(args);
116
+ }
117
+
118
+ /**
119
+ * Navigate to the Desktop folder on Windows Command Prompt.
120
+ *
121
+ * On Windows, the Desktop folder is at %USERPROFILE%\Desktop.
122
+ * Node.js's os.homedir() correctly returns the USERPROFILE path on Windows,
123
+ * so the pure Node.js implementation works correctly.
124
+ * This function delegates to the pure Node.js implementation.
125
+ *
126
+ * @param {string[]} args - Command line arguments (unused)
127
+ * @returns {Promise<void>}
128
+ */
129
+ async function do_d_cmd(args) {
130
+ return do_d_nodejs(args);
131
+ }
132
+
133
+ /**
134
+ * Navigate to the Desktop folder on Windows PowerShell.
135
+ *
136
+ * On Windows, the Desktop folder is at %USERPROFILE%\Desktop.
137
+ * This function delegates to the pure Node.js implementation.
138
+ *
139
+ * @param {string[]} args - Command line arguments (unused)
140
+ * @returns {Promise<void>}
141
+ */
142
+ async function do_d_powershell(args) {
143
+ return do_d_nodejs(args);
144
+ }
145
+
146
+ /**
147
+ * Navigate to the Desktop folder on Git Bash (Windows).
148
+ *
149
+ * Git Bash runs on Windows, so the Desktop folder is at %USERPROFILE%\Desktop.
150
+ * This function delegates to the pure Node.js implementation.
151
+ *
152
+ * @param {string[]} args - Command line arguments (unused)
153
+ * @returns {Promise<void>}
154
+ */
155
+ async function do_d_gitbash(args) {
156
+ return do_d_nodejs(args);
157
+ }
158
+
159
+ /**
160
+ * Main entry point - detects environment and executes appropriate implementation.
161
+ *
162
+ * The "d" command outputs the path to the user's Desktop folder.
163
+ * This is designed to be used with shell integration:
164
+ *
165
+ * cd $(d) # Change to Desktop folder
166
+ * ls $(d) # List Desktop contents
167
+ * cp file $(d) # Copy file to Desktop
168
+ *
169
+ * The original alias "cd ~/Desktop" directly changed directories, but since
170
+ * Node.js scripts run in a subprocess, they cannot change the parent shell's
171
+ * working directory. Instead, this script outputs the path for the shell to use.
172
+ *
173
+ * @param {string[]} args - Command line arguments (unused)
174
+ * @returns {Promise<void>}
175
+ */
176
+ async function do_d(args) {
177
+ const platform = os.detect();
178
+
179
+ const handlers = {
180
+ 'macos': do_d_macos,
181
+ 'ubuntu': do_d_ubuntu,
182
+ 'debian': do_d_ubuntu,
183
+ 'raspbian': do_d_raspbian,
184
+ 'amazon_linux': do_d_amazon_linux,
185
+ 'rhel': do_d_amazon_linux,
186
+ 'fedora': do_d_ubuntu,
187
+ 'linux': do_d_ubuntu,
188
+ 'wsl': do_d_ubuntu,
189
+ 'cmd': do_d_cmd,
190
+ 'windows': do_d_cmd,
191
+ 'powershell': do_d_powershell,
192
+ 'gitbash': do_d_gitbash
193
+ };
194
+
195
+ const handler = handlers[platform.type];
196
+ if (!handler) {
197
+ console.error(`Platform '${platform.type}' is not supported for this command.`);
198
+ process.exit(1);
199
+ }
200
+
201
+ await handler(args);
17
202
  }
18
203
 
19
- module.exports = { main };
204
+ module.exports = {
205
+ main: do_d,
206
+ do_d,
207
+ do_d_nodejs,
208
+ do_d_macos,
209
+ do_d_ubuntu,
210
+ do_d_raspbian,
211
+ do_d_amazon_linux,
212
+ do_d_cmd,
213
+ do_d_powershell,
214
+ do_d_gitbash
215
+ };
20
216
 
21
217
  if (require.main === module) {
22
- main(process.argv.slice(2));
218
+ do_d(process.argv.slice(2));
23
219
  }
@@ -1,24 +1,389 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * @fileoverview Convert file to base64 data URI.
4
+ * datauri - Convert a file to a base64-encoded data URI string
5
+ *
6
+ * Migrated from legacy dotfiles function.
7
+ * Original:
8
+ * datauri() {
9
+ * local mimeType=""
10
+ * if [ ! -f "$1" ]; then
11
+ * printf "%s is not a file.\n" "$1"
12
+ * return
13
+ * fi
14
+ * mimeType=$(file --brief --mime-type "$1")
15
+ * if [[ $mimeType == text/* ]]; then
16
+ * mimeType="$mimeType;charset=utf-8"
17
+ * fi
18
+ * printf "data:%s;base64,%s" \
19
+ * "$mimeType" \
20
+ * "$(openssl base64 -in "$1" | tr -d "\n")"
21
+ * }
22
+ *
23
+ * This script converts any file to a data URI format that can be embedded
24
+ * directly in HTML, CSS, or other documents. Data URIs are useful for:
25
+ * - Embedding small images directly in HTML/CSS
26
+ * - Avoiding additional HTTP requests
27
+ * - Creating self-contained HTML files
28
+ *
5
29
  * @module scripts/datauri
6
30
  */
7
31
 
32
+ const fs = require('fs');
33
+ const path = require('path');
34
+ const os = require('../utils/common/os');
35
+
36
+ /**
37
+ * A mapping of common file extensions to their MIME types.
38
+ * This allows pure Node.js MIME type detection without external dependencies.
39
+ *
40
+ * The mapping covers the most common file types used in web development,
41
+ * images, documents, and media files.
42
+ */
43
+ const MIME_TYPES = {
44
+ // Images
45
+ '.png': 'image/png',
46
+ '.jpg': 'image/jpeg',
47
+ '.jpeg': 'image/jpeg',
48
+ '.gif': 'image/gif',
49
+ '.webp': 'image/webp',
50
+ '.svg': 'image/svg+xml',
51
+ '.ico': 'image/x-icon',
52
+ '.bmp': 'image/bmp',
53
+ '.tiff': 'image/tiff',
54
+ '.tif': 'image/tiff',
55
+ '.avif': 'image/avif',
56
+
57
+ // Audio
58
+ '.mp3': 'audio/mpeg',
59
+ '.wav': 'audio/wav',
60
+ '.ogg': 'audio/ogg',
61
+ '.m4a': 'audio/mp4',
62
+ '.flac': 'audio/flac',
63
+ '.aac': 'audio/aac',
64
+ '.weba': 'audio/webm',
65
+
66
+ // Video
67
+ '.mp4': 'video/mp4',
68
+ '.webm': 'video/webm',
69
+ '.ogv': 'video/ogg',
70
+ '.avi': 'video/x-msvideo',
71
+ '.mov': 'video/quicktime',
72
+ '.mkv': 'video/x-matroska',
73
+
74
+ // Fonts
75
+ '.woff': 'font/woff',
76
+ '.woff2': 'font/woff2',
77
+ '.ttf': 'font/ttf',
78
+ '.otf': 'font/otf',
79
+ '.eot': 'application/vnd.ms-fontobject',
80
+
81
+ // Text/Code
82
+ '.html': 'text/html',
83
+ '.htm': 'text/html',
84
+ '.css': 'text/css',
85
+ '.js': 'text/javascript',
86
+ '.mjs': 'text/javascript',
87
+ '.json': 'application/json',
88
+ '.xml': 'application/xml',
89
+ '.txt': 'text/plain',
90
+ '.md': 'text/markdown',
91
+ '.csv': 'text/csv',
92
+ '.yaml': 'text/yaml',
93
+ '.yml': 'text/yaml',
94
+ '.ts': 'text/typescript',
95
+ '.tsx': 'text/typescript',
96
+ '.jsx': 'text/javascript',
97
+
98
+ // Documents
99
+ '.pdf': 'application/pdf',
100
+ '.doc': 'application/msword',
101
+ '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
102
+ '.xls': 'application/vnd.ms-excel',
103
+ '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
104
+ '.ppt': 'application/vnd.ms-powerpoint',
105
+ '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
106
+
107
+ // Archives
108
+ '.zip': 'application/zip',
109
+ '.tar': 'application/x-tar',
110
+ '.gz': 'application/gzip',
111
+ '.rar': 'application/vnd.rar',
112
+ '.7z': 'application/x-7z-compressed',
113
+
114
+ // Other
115
+ '.wasm': 'application/wasm',
116
+ '.bin': 'application/octet-stream'
117
+ };
118
+
119
+ /**
120
+ * Get the MIME type for a file based on its extension.
121
+ *
122
+ * This function uses a built-in mapping of file extensions to MIME types,
123
+ * which is faster and more portable than calling external tools like `file`.
124
+ * Falls back to 'application/octet-stream' for unknown extensions.
125
+ *
126
+ * @param {string} filePath - The path to the file
127
+ * @returns {string} The MIME type for the file
128
+ */
129
+ function getMimeType(filePath) {
130
+ const ext = path.extname(filePath).toLowerCase();
131
+ return MIME_TYPES[ext] || 'application/octet-stream';
132
+ }
133
+
8
134
  /**
9
- * Converts a file to a base64-encoded data URI string.
10
- * Automatically detects the MIME type from the file.
135
+ * Check if a MIME type represents text content.
136
+ *
137
+ * Text content should have charset=utf-8 appended to the MIME type
138
+ * in data URIs for proper character encoding.
139
+ *
140
+ * @param {string} mimeType - The MIME type to check
141
+ * @returns {boolean} True if the MIME type is text-based
142
+ */
143
+ function isTextMimeType(mimeType) {
144
+ // Text types start with 'text/'
145
+ if (mimeType.startsWith('text/')) {
146
+ return true;
147
+ }
148
+
149
+ // Some application types are also text-based
150
+ const textApplicationTypes = [
151
+ 'application/json',
152
+ 'application/xml',
153
+ 'application/javascript',
154
+ 'application/x-javascript'
155
+ ];
156
+
157
+ return textApplicationTypes.includes(mimeType);
158
+ }
159
+
160
+ /**
161
+ * Pure Node.js implementation that works on any platform.
162
+ *
163
+ * This function reads a file, detects its MIME type based on extension,
164
+ * encodes the content as base64, and outputs a complete data URI string.
165
+ *
166
+ * The data URI format is: data:[<mediatype>][;base64],<data>
167
+ *
168
+ * For text content, we append ;charset=utf-8 to the MIME type to ensure
169
+ * proper character encoding, matching the original bash function behavior.
170
+ *
171
+ * @param {string[]} args - Command line arguments, expects file path as first element
172
+ * @returns {Promise<void>}
173
+ */
174
+ async function do_datauri_nodejs(args) {
175
+ // Check if a file path was provided
176
+ if (!args || args.length === 0) {
177
+ console.error('Usage: datauri <file>');
178
+ console.error('');
179
+ console.error('Convert a file to a base64-encoded data URI string.');
180
+ console.error('');
181
+ console.error('Example:');
182
+ console.error(' datauri image.png');
183
+ console.error(' datauri styles.css');
184
+ process.exit(1);
185
+ }
186
+
187
+ const filePath = args[0];
188
+
189
+ // Resolve the file path (handles relative paths)
190
+ const resolvedPath = path.resolve(filePath);
191
+
192
+ // Check if the file exists
193
+ if (!fs.existsSync(resolvedPath)) {
194
+ console.error(`${filePath} is not a file.`);
195
+ process.exit(1);
196
+ }
197
+
198
+ // Check if it's actually a file (not a directory)
199
+ const stats = fs.statSync(resolvedPath);
200
+ if (!stats.isFile()) {
201
+ console.error(`${filePath} is not a file.`);
202
+ process.exit(1);
203
+ }
204
+
205
+ // Get the MIME type based on file extension
206
+ let mimeType = getMimeType(resolvedPath);
207
+
208
+ // For text content, append charset=utf-8 (matching original bash behavior)
209
+ if (isTextMimeType(mimeType)) {
210
+ mimeType = `${mimeType};charset=utf-8`;
211
+ }
212
+
213
+ // Read the file contents as a Buffer
214
+ const fileBuffer = fs.readFileSync(resolvedPath);
215
+
216
+ // Convert to base64 string
217
+ const base64Data = fileBuffer.toString('base64');
218
+
219
+ // Output the complete data URI
220
+ // Using process.stdout.write to avoid trailing newline (matching original printf behavior)
221
+ process.stdout.write(`data:${mimeType};base64,${base64Data}`);
222
+ }
223
+
224
+ /**
225
+ * Convert a file to data URI on macOS.
226
+ *
227
+ * macOS can use the pure Node.js implementation since file reading,
228
+ * MIME type detection, and base64 encoding all work identically.
11
229
  *
12
230
  * @param {string[]} args - Command line arguments
13
- * @param {string} args.0 - Path to the file to convert
14
231
  * @returns {Promise<void>}
15
232
  */
16
- async function main(args) {
17
- // TODO: Implement data URI conversion
233
+ async function do_datauri_macos(args) {
234
+ return do_datauri_nodejs(args);
235
+ }
236
+
237
+ /**
238
+ * Convert a file to data URI on Ubuntu.
239
+ *
240
+ * Ubuntu can use the pure Node.js implementation since file reading,
241
+ * MIME type detection, and base64 encoding all work identically.
242
+ *
243
+ * @param {string[]} args - Command line arguments
244
+ * @returns {Promise<void>}
245
+ */
246
+ async function do_datauri_ubuntu(args) {
247
+ return do_datauri_nodejs(args);
248
+ }
249
+
250
+ /**
251
+ * Convert a file to data URI on Raspberry Pi OS.
252
+ *
253
+ * Raspberry Pi OS can use the pure Node.js implementation since file reading,
254
+ * MIME type detection, and base64 encoding all work identically.
255
+ *
256
+ * @param {string[]} args - Command line arguments
257
+ * @returns {Promise<void>}
258
+ */
259
+ async function do_datauri_raspbian(args) {
260
+ return do_datauri_nodejs(args);
261
+ }
262
+
263
+ /**
264
+ * Convert a file to data URI on Amazon Linux.
265
+ *
266
+ * Amazon Linux can use the pure Node.js implementation since file reading,
267
+ * MIME type detection, and base64 encoding all work identically.
268
+ *
269
+ * @param {string[]} args - Command line arguments
270
+ * @returns {Promise<void>}
271
+ */
272
+ async function do_datauri_amazon_linux(args) {
273
+ return do_datauri_nodejs(args);
274
+ }
275
+
276
+ /**
277
+ * Convert a file to data URI on Windows Command Prompt.
278
+ *
279
+ * Windows CMD can use the pure Node.js implementation since file reading,
280
+ * MIME type detection, and base64 encoding all work identically.
281
+ * Node.js handles path separators and file system differences automatically.
282
+ *
283
+ * @param {string[]} args - Command line arguments
284
+ * @returns {Promise<void>}
285
+ */
286
+ async function do_datauri_cmd(args) {
287
+ return do_datauri_nodejs(args);
288
+ }
289
+
290
+ /**
291
+ * Convert a file to data URI on Windows PowerShell.
292
+ *
293
+ * Windows PowerShell can use the pure Node.js implementation since file reading,
294
+ * MIME type detection, and base64 encoding all work identically.
295
+ * Node.js handles path separators and file system differences automatically.
296
+ *
297
+ * @param {string[]} args - Command line arguments
298
+ * @returns {Promise<void>}
299
+ */
300
+ async function do_datauri_powershell(args) {
301
+ return do_datauri_nodejs(args);
302
+ }
303
+
304
+ /**
305
+ * Convert a file to data URI on Git Bash.
306
+ *
307
+ * Git Bash can use the pure Node.js implementation since file reading,
308
+ * MIME type detection, and base64 encoding all work identically.
309
+ * Node.js handles path separators and file system differences automatically.
310
+ *
311
+ * @param {string[]} args - Command line arguments
312
+ * @returns {Promise<void>}
313
+ */
314
+ async function do_datauri_gitbash(args) {
315
+ return do_datauri_nodejs(args);
316
+ }
317
+
318
+ /**
319
+ * Main entry point - detects environment and executes appropriate implementation.
320
+ *
321
+ * The "datauri" command converts any file to a base64-encoded data URI string.
322
+ * Data URIs embed file contents directly in the string, useful for:
323
+ * - Embedding small images in HTML img src or CSS background-image
324
+ * - Avoiding additional HTTP requests for small resources
325
+ * - Creating self-contained HTML documents
326
+ *
327
+ * Usage: datauri <file>
328
+ *
329
+ * Example output:
330
+ * datauri image.png
331
+ * => data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
332
+ *
333
+ * datauri styles.css
334
+ * => data:text/css;charset=utf-8;base64,LyogU3R5bGVz...
335
+ *
336
+ * @param {string[]} args - Command line arguments, expects file path as first element
337
+ * @returns {Promise<void>}
338
+ */
339
+ async function do_datauri(args) {
340
+ const platform = os.detect();
341
+
342
+ const handlers = {
343
+ 'macos': do_datauri_macos,
344
+ 'ubuntu': do_datauri_ubuntu,
345
+ 'debian': do_datauri_ubuntu,
346
+ 'raspbian': do_datauri_raspbian,
347
+ 'amazon_linux': do_datauri_amazon_linux,
348
+ 'rhel': do_datauri_amazon_linux,
349
+ 'fedora': do_datauri_ubuntu,
350
+ 'linux': do_datauri_ubuntu,
351
+ 'wsl': do_datauri_ubuntu,
352
+ 'cmd': do_datauri_cmd,
353
+ 'windows': do_datauri_cmd,
354
+ 'powershell': do_datauri_powershell,
355
+ 'gitbash': do_datauri_gitbash
356
+ };
357
+
358
+ const handler = handlers[platform.type];
359
+ if (!handler) {
360
+ console.error(`Platform '${platform.type}' is not supported for this command.`);
361
+ console.error('');
362
+ console.error('Supported platforms:');
363
+ console.error(' - macOS');
364
+ console.error(' - Ubuntu, Debian, and other Linux distributions');
365
+ console.error(' - Raspberry Pi OS');
366
+ console.error(' - Amazon Linux');
367
+ console.error(' - Windows (CMD, PowerShell, Git Bash)');
368
+ process.exit(1);
369
+ }
370
+
371
+ await handler(args);
18
372
  }
19
373
 
20
- module.exports = { main };
374
+ module.exports = {
375
+ main: do_datauri,
376
+ do_datauri,
377
+ do_datauri_nodejs,
378
+ do_datauri_macos,
379
+ do_datauri_ubuntu,
380
+ do_datauri_raspbian,
381
+ do_datauri_amazon_linux,
382
+ do_datauri_cmd,
383
+ do_datauri_powershell,
384
+ do_datauri_gitbash
385
+ };
21
386
 
22
387
  if (require.main === module) {
23
- main(process.argv.slice(2));
388
+ do_datauri(process.argv.slice(2));
24
389
  }