binary-collections 2.0.10 → 2.0.11

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 (165) hide show
  1. package/.puppeterrc.cjs +25 -0
  2. package/binaries/binary-executor.cjs +138 -3
  3. package/binaries/clean-nodemodule.cjs +138 -3
  4. package/binaries/clean-nodemodules.cjs +138 -3
  5. package/binaries/dev.cjs +138 -3
  6. package/binaries/empty.cjs +138 -3
  7. package/binaries/git-reduce-size.cjs +138 -3
  8. package/binaries/javakill.cjs +138 -3
  9. package/binaries/kill-night-crows.bat +7 -0
  10. package/binaries/kill-night-crows.ps1 +172 -0
  11. package/binaries/kill-process.cjs +138 -3
  12. package/binaries/nodekill.cjs +138 -3
  13. package/binaries/prod.cjs +138 -3
  14. package/binaries/py +111 -0
  15. package/binaries/py.cjs +178 -0
  16. package/binaries/py.cmd +49 -0
  17. package/binaries/rmfind.cjs +138 -3
  18. package/binaries/rmx.cjs +138 -3
  19. package/binaries/submodule-token.cjs +138 -3
  20. package/binaries/test-cjs +10 -0
  21. package/binaries/test-cjs.cjs +178 -0
  22. package/binaries/test-cjs.cmd +11 -0
  23. package/binaries/yarn-clean +32 -0
  24. package/binaries/yarn-clean.cjs +178 -0
  25. package/binaries/yarn-clean.cmd +30 -0
  26. package/binaries/yarn-clean.py +148 -0
  27. package/lib/binary-collections-config.cjs +1 -1
  28. package/lib/binary-collections-config.mjs +1 -1
  29. package/lib/binary-collections.cjs +167 -106
  30. package/lib/binary-collections.mjs +108 -94
  31. package/lib/changelog.cjs +61 -13
  32. package/lib/changelog.mjs +1 -1
  33. package/lib/{chunk-AI4CVPJ7.mjs → chunk-2CBJCW7E.mjs} +4 -4
  34. package/lib/chunk-34IQDTLZ.mjs +27 -0
  35. package/lib/chunk-3HFFECCI.mjs +27 -0
  36. package/lib/{chunk-SBNDSKG5.mjs → chunk-4UHL4WVN.mjs} +1 -1
  37. package/lib/chunk-7XTEJHOE.mjs +193 -0
  38. package/lib/chunk-AJDD5DZM.mjs +109 -0
  39. package/lib/chunk-BZWVHODJ.mjs +62 -0
  40. package/lib/{chunk-BEZKJ25G.mjs → chunk-FCDQGYBF.mjs} +5 -9
  41. package/lib/chunk-GEYA2USY.mjs +207 -0
  42. package/lib/chunk-ID2WBTE2.mjs +80 -0
  43. package/lib/chunk-JXFOHKDM.mjs +239 -0
  44. package/lib/{chunk-DI5MDPSN.mjs → chunk-N436BNBK.mjs} +192 -64
  45. package/lib/chunk-NCXAP7AA.mjs +31 -0
  46. package/lib/chunk-PDN26I7O.mjs +188 -0
  47. package/lib/{chunk-E6FDDAOO.mjs → chunk-RWLXRTYP.mjs} +1 -1
  48. package/lib/{chunk-BDCHCWHD.mjs → chunk-TOIVAQF7.mjs} +4 -4
  49. package/lib/chunk-V5SKYJUB.mjs +136 -0
  50. package/lib/{chunk-HMRMTYZM.mjs → chunk-WSRETQCA.mjs} +21 -2
  51. package/lib/chunk-XA3SNBPA.mjs +184 -0
  52. package/lib/chunk-YYLIQQKF.mjs +31 -0
  53. package/lib/{chunk-V3N3JEUF.mjs → chunk-Z6JLYU2J.mjs} +60 -13
  54. package/lib/{chunk-O6SWBEOQ.mjs → chunk-ZDMWBSYF.mjs} +2 -2
  55. package/lib/clean-github-actions-caches.cjs +63 -15
  56. package/lib/clean-github-actions-caches.mjs +3 -3
  57. package/lib/del-gradle.cjs +61 -13
  58. package/lib/del-gradle.js +1 -0
  59. package/lib/del-gradle.mjs +1 -1
  60. package/lib/del-node-modules.cjs +143 -148
  61. package/lib/del-node-modules.js +210 -14
  62. package/lib/del-node-modules.mjs +148 -17
  63. package/lib/del-ps.cjs +61 -13
  64. package/lib/del-ps.js +1 -0
  65. package/lib/del-ps.mjs +1 -1
  66. package/lib/del-yarn-caches.cjs +61 -13
  67. package/lib/del-yarn-caches.mjs +1 -1
  68. package/lib/find-node-modules-cli.js +1 -0
  69. package/lib/free-chatgpt.cjs +253 -47
  70. package/lib/free-chatgpt.mjs +2 -2
  71. package/lib/git/gitattributes.cjs +1 -0
  72. package/lib/git/gitattributes.d.cts +7 -2
  73. package/lib/git/gitattributes.mjs +1 -1
  74. package/lib/git/line-endings.cjs +2 -1
  75. package/lib/git/line-endings.mjs +2 -2
  76. package/lib/git/undo-commit-cli.cjs +110 -0
  77. package/lib/git/undo-commit-cli.d.ts +1 -0
  78. package/lib/git/undo-commit-cli.js +4 -0
  79. package/lib/git/undo-commit-cli.mjs +14 -0
  80. package/lib/git/undo-commit.cjs +81 -0
  81. package/lib/git/undo-commit.d.cts +1 -0
  82. package/lib/git/undo-commit.mjs +7 -0
  83. package/lib/git/undo-staged-cli.cjs +110 -0
  84. package/lib/git/undo-staged-cli.d.ts +1 -0
  85. package/lib/git/undo-staged-cli.js +4 -0
  86. package/lib/git/undo-staged-cli.mjs +14 -0
  87. package/lib/git/undo-staged.cjs +81 -0
  88. package/lib/git/undo-staged.d.cts +1 -0
  89. package/lib/git/undo-staged.mjs +7 -0
  90. package/lib/git/user-config.cjs +61 -14
  91. package/lib/git/user-config.mjs +2 -2
  92. package/lib/git-diff-cli.cjs +255 -49
  93. package/lib/git-diff-cli.d.ts +1 -0
  94. package/lib/git-diff-cli.js +1 -0
  95. package/lib/git-diff-cli.mjs +5 -4
  96. package/lib/git-diff.cjs +254 -49
  97. package/lib/git-diff.mjs +4 -4
  98. package/lib/git-fix.cjs +64 -16
  99. package/lib/git-fix.mjs +10 -10
  100. package/lib/git-purge.cjs +61 -13
  101. package/lib/git-purge.mjs +1 -1
  102. package/lib/kill-night-crows.cjs +87 -0
  103. package/lib/kill-night-crows.d.mts +1 -0
  104. package/lib/kill-night-crows.mjs +65 -0
  105. package/lib/npm-run-series.cjs +60 -13
  106. package/lib/npm-run-series.mjs +1 -1
  107. package/lib/package-resolutions-updater-cli.cjs +560 -0
  108. package/lib/package-resolutions-updater-cli.d.mts +1 -0
  109. package/lib/package-resolutions-updater-cli.mjs +124 -0
  110. package/lib/package-resolutions-updater.cjs +174 -154
  111. package/lib/package-resolutions-updater.d.mts +32 -1
  112. package/lib/package-resolutions-updater.mjs +16 -294
  113. package/lib/php-cs-fixer-staged.cjs +105 -0
  114. package/lib/php-cs-fixer-staged.d.cts +2 -0
  115. package/lib/php-cs-fixer-staged.mjs +117 -0
  116. package/lib/print-directory-tree.cjs +62 -14
  117. package/lib/print-directory-tree.mjs +2 -2
  118. package/lib/ps/connected-domain.d.ts +1 -1
  119. package/lib/ps/index.js +1 -0
  120. package/lib/remove-module.cjs +61 -13
  121. package/lib/remove-module.mjs +1 -1
  122. package/lib/rmpath.cjs +63 -15
  123. package/lib/rmpath.mjs +2 -2
  124. package/lib/submodule-install.cjs +62 -15
  125. package/lib/submodule-install.mjs +3 -3
  126. package/lib/submodule-remove-cli.cjs +5 -1
  127. package/lib/submodule-remove-cli.mjs +1 -1
  128. package/lib/submodule-remove.cjs +4 -1
  129. package/lib/submodule-remove.mjs +1 -1
  130. package/lib/utils/chatgpt.cjs +192 -34
  131. package/lib/utils/chatgpt.js +210 -43
  132. package/lib/utils/chatgpt.mjs +1 -1
  133. package/lib/utils/findEnvFiles.cjs +107 -0
  134. package/lib/utils/findEnvFiles.d.ts +8 -0
  135. package/lib/utils/findEnvFiles.js +121 -0
  136. package/lib/utils/findEnvFiles.mjs +8 -0
  137. package/lib/utils/findWorkspaceRoot.cjs +70 -0
  138. package/lib/utils/findWorkspaceRoot.d.ts +9 -0
  139. package/lib/utils/findWorkspaceRoot.js +57 -0
  140. package/lib/utils/findWorkspaceRoot.mjs +40 -0
  141. package/lib/utils/index.cjs +60 -13
  142. package/lib/utils/index.mjs +1 -1
  143. package/lib/utils/isGithubTokenValid.cjs +64 -0
  144. package/lib/utils/isGithubTokenValid.d.ts +7 -0
  145. package/lib/utils/isGithubTokenValid.js +48 -0
  146. package/lib/utils/isGithubTokenValid.mjs +36 -0
  147. package/lib/yarn-reinstall.cjs +61 -13
  148. package/lib/yarn-reinstall.mjs +1 -1
  149. package/package.json +107 -93
  150. package/readme.md +33 -34
  151. package/releases/readme.md +1 -1
  152. package/requirements.txt +1 -0
  153. package/lib/chunk-4EWQC6GZ.mjs +0 -382
  154. package/lib/chunk-4ZI7BQKQ.mjs +0 -381
  155. package/lib/chunk-5J2BEPY5.mjs +0 -83
  156. package/lib/chunk-AGZYRDC2.mjs +0 -323
  157. package/lib/chunk-HN52G2YL.mjs +0 -305
  158. package/lib/chunk-HO6GHCOB.mjs +0 -385
  159. package/lib/chunk-LEM5OMRP.mjs +0 -384
  160. package/lib/chunk-RCP7DHVY.mjs +0 -190
  161. package/lib/chunk-U6SO4QEV.mjs +0 -320
  162. package/lib/chunk-XD6BJK6Q.mjs +0 -351
  163. package/lib/chunk-YXSFGA2D.mjs +0 -383
  164. package/lib/git/gitattributes.d.ts +0 -33
  165. package/lib/git/gitattributes.js +0 -223
package/binaries/dev.cjs CHANGED
@@ -1,43 +1,178 @@
1
1
  #!/usr/bin/env node
2
+
3
+ /**
4
+ * Built-in Node.js modules:
5
+ *
6
+ * - child_process:
7
+ * Used to launch external scripts/programs.
8
+ *
9
+ * - path:
10
+ * Safely handles file paths across operating systems.
11
+ *
12
+ * - fs:
13
+ * Used to check whether files exist.
14
+ */
2
15
  const { spawnSync } = require("child_process");
3
16
  const path = require("path");
4
17
  const fs = require("fs");
5
18
 
19
+ /**
20
+ * __dirname
21
+ * Absolute directory path of this launcher script.
22
+ *
23
+ * __filename
24
+ * Absolute path of this launcher file itself.
25
+ *
26
+ * base
27
+ * Filename without extension.
28
+ *
29
+ * Example:
30
+ * File = "/tools/mytool.js"
31
+ *
32
+ * binDir = "/tools"
33
+ * base = "mytool"
34
+ */
6
35
  const binDir = __dirname;
7
36
  const base = path.basename(__filename, path.extname(__filename));
8
37
 
9
- // Define possible script extensions by platform
38
+ /**
39
+ * Determine which script extensions to search for
40
+ * based on the current operating system.
41
+ *
42
+ * Windows:
43
+ * .cmd
44
+ * .bat
45
+ * .ps1
46
+ * .vbs
47
+ *
48
+ * Linux/macOS:
49
+ * .sh
50
+ * executable file without extension
51
+ */
10
52
  const candidates = process.platform === "win32" ? [".cmd", ".bat", ".ps1", ".vbs"] : [".sh", ""];
11
53
 
54
+ /**
55
+ * Search for the first matching script
56
+ * in the same directory as this launcher.
57
+ *
58
+ * Example:
59
+ * If base = "mytool"
60
+ *
61
+ * Windows checks:
62
+ * mytool.cmd
63
+ * mytool.bat
64
+ * mytool.ps1
65
+ * mytool.vbs
66
+ *
67
+ * Linux/macOS checks:
68
+ * mytool.sh
69
+ * mytool
70
+ */
12
71
  let found = null;
72
+
13
73
  for (const ext of candidates) {
14
74
  const script = path.join(binDir, base + ext);
75
+
15
76
  if (fs.existsSync(script)) {
16
77
  found = script;
17
78
  break;
18
79
  }
19
80
  }
20
81
 
82
+ /**
83
+ * If no matching script was found,
84
+ * print an error and exit with failure code 1.
85
+ */
21
86
  if (!found) {
22
87
  console.error(`No script found for ${base} in ${binDir}`);
23
88
  process.exit(1);
24
89
  }
25
90
 
91
+ /**
92
+ * Detect special script types
93
+ * that require a shell/interpreter.
94
+ */
26
95
  const isPs1 = found.endsWith(".ps1");
27
96
  const isCmd = found.endsWith(".cmd");
28
- // const isSh = found.endsWith(".sh") || (found === found && process.platform !== "win32");
29
97
 
98
+ /**
99
+ * cmd
100
+ * The executable program to launch.
101
+ *
102
+ * args
103
+ * Arguments passed to the executable.
104
+ */
30
105
  let cmd, args;
106
+
107
+ /**
108
+ * PowerShell scripts:
109
+ *
110
+ * Run through powershell.exe because .ps1 files
111
+ * are not directly executable like binaries.
112
+ *
113
+ * Flags:
114
+ * -NoProfile
115
+ * Prevent loading user profile scripts.
116
+ *
117
+ * -ExecutionPolicy Bypass
118
+ * Allow script execution even if policy blocks it.
119
+ *
120
+ * -File
121
+ * Specifies the script to execute.
122
+ *
123
+ * process.argv.slice(2)
124
+ * Forward all user-provided command-line arguments.
125
+ */
31
126
  if (isPs1) {
32
127
  cmd = "powershell.exe";
128
+
33
129
  args = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", found, ...process.argv.slice(2)];
130
+
131
+ /**
132
+ * CMD batch files:
133
+ *
134
+ * Run through cmd.exe using:
135
+ * /c
136
+ * which means:
137
+ * "execute command and terminate"
138
+ */
34
139
  } else if (isCmd) {
35
140
  cmd = "cmd.exe";
141
+
36
142
  args = ["/c", found, ...process.argv.slice(2)];
143
+
144
+ /**
145
+ * Other scripts:
146
+ *
147
+ * Usually:
148
+ * - shell scripts (.sh)
149
+ * - executable binaries
150
+ *
151
+ * These can be executed directly.
152
+ */
37
153
  } else {
38
154
  cmd = found;
39
155
  args = process.argv.slice(2);
40
156
  }
41
157
 
42
- const result = spawnSync(cmd, args, { stdio: "inherit" });
158
+ /**
159
+ * Execute the selected script synchronously.
160
+ *
161
+ * stdio: "inherit"
162
+ * Shares the current terminal with the child process,
163
+ * so stdout/stderr/input behave normally.
164
+ *
165
+ * spawnSync waits until the child process exits.
166
+ */
167
+ const result = spawnSync(cmd, args, {
168
+ stdio: "inherit"
169
+ });
170
+
171
+ /**
172
+ * Exit using the same exit code
173
+ * returned by the child process.
174
+ *
175
+ * If result.status is null/undefined,
176
+ * default to exit code 1.
177
+ */
43
178
  process.exit(result.status ?? 1);
@@ -1,43 +1,178 @@
1
1
  #!/usr/bin/env node
2
+
3
+ /**
4
+ * Built-in Node.js modules:
5
+ *
6
+ * - child_process:
7
+ * Used to launch external scripts/programs.
8
+ *
9
+ * - path:
10
+ * Safely handles file paths across operating systems.
11
+ *
12
+ * - fs:
13
+ * Used to check whether files exist.
14
+ */
2
15
  const { spawnSync } = require("child_process");
3
16
  const path = require("path");
4
17
  const fs = require("fs");
5
18
 
19
+ /**
20
+ * __dirname
21
+ * Absolute directory path of this launcher script.
22
+ *
23
+ * __filename
24
+ * Absolute path of this launcher file itself.
25
+ *
26
+ * base
27
+ * Filename without extension.
28
+ *
29
+ * Example:
30
+ * File = "/tools/mytool.js"
31
+ *
32
+ * binDir = "/tools"
33
+ * base = "mytool"
34
+ */
6
35
  const binDir = __dirname;
7
36
  const base = path.basename(__filename, path.extname(__filename));
8
37
 
9
- // Define possible script extensions by platform
38
+ /**
39
+ * Determine which script extensions to search for
40
+ * based on the current operating system.
41
+ *
42
+ * Windows:
43
+ * .cmd
44
+ * .bat
45
+ * .ps1
46
+ * .vbs
47
+ *
48
+ * Linux/macOS:
49
+ * .sh
50
+ * executable file without extension
51
+ */
10
52
  const candidates = process.platform === "win32" ? [".cmd", ".bat", ".ps1", ".vbs"] : [".sh", ""];
11
53
 
54
+ /**
55
+ * Search for the first matching script
56
+ * in the same directory as this launcher.
57
+ *
58
+ * Example:
59
+ * If base = "mytool"
60
+ *
61
+ * Windows checks:
62
+ * mytool.cmd
63
+ * mytool.bat
64
+ * mytool.ps1
65
+ * mytool.vbs
66
+ *
67
+ * Linux/macOS checks:
68
+ * mytool.sh
69
+ * mytool
70
+ */
12
71
  let found = null;
72
+
13
73
  for (const ext of candidates) {
14
74
  const script = path.join(binDir, base + ext);
75
+
15
76
  if (fs.existsSync(script)) {
16
77
  found = script;
17
78
  break;
18
79
  }
19
80
  }
20
81
 
82
+ /**
83
+ * If no matching script was found,
84
+ * print an error and exit with failure code 1.
85
+ */
21
86
  if (!found) {
22
87
  console.error(`No script found for ${base} in ${binDir}`);
23
88
  process.exit(1);
24
89
  }
25
90
 
91
+ /**
92
+ * Detect special script types
93
+ * that require a shell/interpreter.
94
+ */
26
95
  const isPs1 = found.endsWith(".ps1");
27
96
  const isCmd = found.endsWith(".cmd");
28
- // const isSh = found.endsWith(".sh") || (found === found && process.platform !== "win32");
29
97
 
98
+ /**
99
+ * cmd
100
+ * The executable program to launch.
101
+ *
102
+ * args
103
+ * Arguments passed to the executable.
104
+ */
30
105
  let cmd, args;
106
+
107
+ /**
108
+ * PowerShell scripts:
109
+ *
110
+ * Run through powershell.exe because .ps1 files
111
+ * are not directly executable like binaries.
112
+ *
113
+ * Flags:
114
+ * -NoProfile
115
+ * Prevent loading user profile scripts.
116
+ *
117
+ * -ExecutionPolicy Bypass
118
+ * Allow script execution even if policy blocks it.
119
+ *
120
+ * -File
121
+ * Specifies the script to execute.
122
+ *
123
+ * process.argv.slice(2)
124
+ * Forward all user-provided command-line arguments.
125
+ */
31
126
  if (isPs1) {
32
127
  cmd = "powershell.exe";
128
+
33
129
  args = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", found, ...process.argv.slice(2)];
130
+
131
+ /**
132
+ * CMD batch files:
133
+ *
134
+ * Run through cmd.exe using:
135
+ * /c
136
+ * which means:
137
+ * "execute command and terminate"
138
+ */
34
139
  } else if (isCmd) {
35
140
  cmd = "cmd.exe";
141
+
36
142
  args = ["/c", found, ...process.argv.slice(2)];
143
+
144
+ /**
145
+ * Other scripts:
146
+ *
147
+ * Usually:
148
+ * - shell scripts (.sh)
149
+ * - executable binaries
150
+ *
151
+ * These can be executed directly.
152
+ */
37
153
  } else {
38
154
  cmd = found;
39
155
  args = process.argv.slice(2);
40
156
  }
41
157
 
42
- const result = spawnSync(cmd, args, { stdio: "inherit" });
158
+ /**
159
+ * Execute the selected script synchronously.
160
+ *
161
+ * stdio: "inherit"
162
+ * Shares the current terminal with the child process,
163
+ * so stdout/stderr/input behave normally.
164
+ *
165
+ * spawnSync waits until the child process exits.
166
+ */
167
+ const result = spawnSync(cmd, args, {
168
+ stdio: "inherit"
169
+ });
170
+
171
+ /**
172
+ * Exit using the same exit code
173
+ * returned by the child process.
174
+ *
175
+ * If result.status is null/undefined,
176
+ * default to exit code 1.
177
+ */
43
178
  process.exit(result.status ?? 1);
@@ -1,43 +1,178 @@
1
1
  #!/usr/bin/env node
2
+
3
+ /**
4
+ * Built-in Node.js modules:
5
+ *
6
+ * - child_process:
7
+ * Used to launch external scripts/programs.
8
+ *
9
+ * - path:
10
+ * Safely handles file paths across operating systems.
11
+ *
12
+ * - fs:
13
+ * Used to check whether files exist.
14
+ */
2
15
  const { spawnSync } = require("child_process");
3
16
  const path = require("path");
4
17
  const fs = require("fs");
5
18
 
19
+ /**
20
+ * __dirname
21
+ * Absolute directory path of this launcher script.
22
+ *
23
+ * __filename
24
+ * Absolute path of this launcher file itself.
25
+ *
26
+ * base
27
+ * Filename without extension.
28
+ *
29
+ * Example:
30
+ * File = "/tools/mytool.js"
31
+ *
32
+ * binDir = "/tools"
33
+ * base = "mytool"
34
+ */
6
35
  const binDir = __dirname;
7
36
  const base = path.basename(__filename, path.extname(__filename));
8
37
 
9
- // Define possible script extensions by platform
38
+ /**
39
+ * Determine which script extensions to search for
40
+ * based on the current operating system.
41
+ *
42
+ * Windows:
43
+ * .cmd
44
+ * .bat
45
+ * .ps1
46
+ * .vbs
47
+ *
48
+ * Linux/macOS:
49
+ * .sh
50
+ * executable file without extension
51
+ */
10
52
  const candidates = process.platform === "win32" ? [".cmd", ".bat", ".ps1", ".vbs"] : [".sh", ""];
11
53
 
54
+ /**
55
+ * Search for the first matching script
56
+ * in the same directory as this launcher.
57
+ *
58
+ * Example:
59
+ * If base = "mytool"
60
+ *
61
+ * Windows checks:
62
+ * mytool.cmd
63
+ * mytool.bat
64
+ * mytool.ps1
65
+ * mytool.vbs
66
+ *
67
+ * Linux/macOS checks:
68
+ * mytool.sh
69
+ * mytool
70
+ */
12
71
  let found = null;
72
+
13
73
  for (const ext of candidates) {
14
74
  const script = path.join(binDir, base + ext);
75
+
15
76
  if (fs.existsSync(script)) {
16
77
  found = script;
17
78
  break;
18
79
  }
19
80
  }
20
81
 
82
+ /**
83
+ * If no matching script was found,
84
+ * print an error and exit with failure code 1.
85
+ */
21
86
  if (!found) {
22
87
  console.error(`No script found for ${base} in ${binDir}`);
23
88
  process.exit(1);
24
89
  }
25
90
 
91
+ /**
92
+ * Detect special script types
93
+ * that require a shell/interpreter.
94
+ */
26
95
  const isPs1 = found.endsWith(".ps1");
27
96
  const isCmd = found.endsWith(".cmd");
28
- // const isSh = found.endsWith(".sh") || (found === found && process.platform !== "win32");
29
97
 
98
+ /**
99
+ * cmd
100
+ * The executable program to launch.
101
+ *
102
+ * args
103
+ * Arguments passed to the executable.
104
+ */
30
105
  let cmd, args;
106
+
107
+ /**
108
+ * PowerShell scripts:
109
+ *
110
+ * Run through powershell.exe because .ps1 files
111
+ * are not directly executable like binaries.
112
+ *
113
+ * Flags:
114
+ * -NoProfile
115
+ * Prevent loading user profile scripts.
116
+ *
117
+ * -ExecutionPolicy Bypass
118
+ * Allow script execution even if policy blocks it.
119
+ *
120
+ * -File
121
+ * Specifies the script to execute.
122
+ *
123
+ * process.argv.slice(2)
124
+ * Forward all user-provided command-line arguments.
125
+ */
31
126
  if (isPs1) {
32
127
  cmd = "powershell.exe";
128
+
33
129
  args = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", found, ...process.argv.slice(2)];
130
+
131
+ /**
132
+ * CMD batch files:
133
+ *
134
+ * Run through cmd.exe using:
135
+ * /c
136
+ * which means:
137
+ * "execute command and terminate"
138
+ */
34
139
  } else if (isCmd) {
35
140
  cmd = "cmd.exe";
141
+
36
142
  args = ["/c", found, ...process.argv.slice(2)];
143
+
144
+ /**
145
+ * Other scripts:
146
+ *
147
+ * Usually:
148
+ * - shell scripts (.sh)
149
+ * - executable binaries
150
+ *
151
+ * These can be executed directly.
152
+ */
37
153
  } else {
38
154
  cmd = found;
39
155
  args = process.argv.slice(2);
40
156
  }
41
157
 
42
- const result = spawnSync(cmd, args, { stdio: "inherit" });
158
+ /**
159
+ * Execute the selected script synchronously.
160
+ *
161
+ * stdio: "inherit"
162
+ * Shares the current terminal with the child process,
163
+ * so stdout/stderr/input behave normally.
164
+ *
165
+ * spawnSync waits until the child process exits.
166
+ */
167
+ const result = spawnSync(cmd, args, {
168
+ stdio: "inherit"
169
+ });
170
+
171
+ /**
172
+ * Exit using the same exit code
173
+ * returned by the child process.
174
+ *
175
+ * If result.status is null/undefined,
176
+ * default to exit code 1.
177
+ */
43
178
  process.exit(result.status ?? 1);
@@ -1,43 +1,178 @@
1
1
  #!/usr/bin/env node
2
+
3
+ /**
4
+ * Built-in Node.js modules:
5
+ *
6
+ * - child_process:
7
+ * Used to launch external scripts/programs.
8
+ *
9
+ * - path:
10
+ * Safely handles file paths across operating systems.
11
+ *
12
+ * - fs:
13
+ * Used to check whether files exist.
14
+ */
2
15
  const { spawnSync } = require("child_process");
3
16
  const path = require("path");
4
17
  const fs = require("fs");
5
18
 
19
+ /**
20
+ * __dirname
21
+ * Absolute directory path of this launcher script.
22
+ *
23
+ * __filename
24
+ * Absolute path of this launcher file itself.
25
+ *
26
+ * base
27
+ * Filename without extension.
28
+ *
29
+ * Example:
30
+ * File = "/tools/mytool.js"
31
+ *
32
+ * binDir = "/tools"
33
+ * base = "mytool"
34
+ */
6
35
  const binDir = __dirname;
7
36
  const base = path.basename(__filename, path.extname(__filename));
8
37
 
9
- // Define possible script extensions by platform
38
+ /**
39
+ * Determine which script extensions to search for
40
+ * based on the current operating system.
41
+ *
42
+ * Windows:
43
+ * .cmd
44
+ * .bat
45
+ * .ps1
46
+ * .vbs
47
+ *
48
+ * Linux/macOS:
49
+ * .sh
50
+ * executable file without extension
51
+ */
10
52
  const candidates = process.platform === "win32" ? [".cmd", ".bat", ".ps1", ".vbs"] : [".sh", ""];
11
53
 
54
+ /**
55
+ * Search for the first matching script
56
+ * in the same directory as this launcher.
57
+ *
58
+ * Example:
59
+ * If base = "mytool"
60
+ *
61
+ * Windows checks:
62
+ * mytool.cmd
63
+ * mytool.bat
64
+ * mytool.ps1
65
+ * mytool.vbs
66
+ *
67
+ * Linux/macOS checks:
68
+ * mytool.sh
69
+ * mytool
70
+ */
12
71
  let found = null;
72
+
13
73
  for (const ext of candidates) {
14
74
  const script = path.join(binDir, base + ext);
75
+
15
76
  if (fs.existsSync(script)) {
16
77
  found = script;
17
78
  break;
18
79
  }
19
80
  }
20
81
 
82
+ /**
83
+ * If no matching script was found,
84
+ * print an error and exit with failure code 1.
85
+ */
21
86
  if (!found) {
22
87
  console.error(`No script found for ${base} in ${binDir}`);
23
88
  process.exit(1);
24
89
  }
25
90
 
91
+ /**
92
+ * Detect special script types
93
+ * that require a shell/interpreter.
94
+ */
26
95
  const isPs1 = found.endsWith(".ps1");
27
96
  const isCmd = found.endsWith(".cmd");
28
- // const isSh = found.endsWith(".sh") || (found === found && process.platform !== "win32");
29
97
 
98
+ /**
99
+ * cmd
100
+ * The executable program to launch.
101
+ *
102
+ * args
103
+ * Arguments passed to the executable.
104
+ */
30
105
  let cmd, args;
106
+
107
+ /**
108
+ * PowerShell scripts:
109
+ *
110
+ * Run through powershell.exe because .ps1 files
111
+ * are not directly executable like binaries.
112
+ *
113
+ * Flags:
114
+ * -NoProfile
115
+ * Prevent loading user profile scripts.
116
+ *
117
+ * -ExecutionPolicy Bypass
118
+ * Allow script execution even if policy blocks it.
119
+ *
120
+ * -File
121
+ * Specifies the script to execute.
122
+ *
123
+ * process.argv.slice(2)
124
+ * Forward all user-provided command-line arguments.
125
+ */
31
126
  if (isPs1) {
32
127
  cmd = "powershell.exe";
128
+
33
129
  args = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", found, ...process.argv.slice(2)];
130
+
131
+ /**
132
+ * CMD batch files:
133
+ *
134
+ * Run through cmd.exe using:
135
+ * /c
136
+ * which means:
137
+ * "execute command and terminate"
138
+ */
34
139
  } else if (isCmd) {
35
140
  cmd = "cmd.exe";
141
+
36
142
  args = ["/c", found, ...process.argv.slice(2)];
143
+
144
+ /**
145
+ * Other scripts:
146
+ *
147
+ * Usually:
148
+ * - shell scripts (.sh)
149
+ * - executable binaries
150
+ *
151
+ * These can be executed directly.
152
+ */
37
153
  } else {
38
154
  cmd = found;
39
155
  args = process.argv.slice(2);
40
156
  }
41
157
 
42
- const result = spawnSync(cmd, args, { stdio: "inherit" });
158
+ /**
159
+ * Execute the selected script synchronously.
160
+ *
161
+ * stdio: "inherit"
162
+ * Shares the current terminal with the child process,
163
+ * so stdout/stderr/input behave normally.
164
+ *
165
+ * spawnSync waits until the child process exits.
166
+ */
167
+ const result = spawnSync(cmd, args, {
168
+ stdio: "inherit"
169
+ });
170
+
171
+ /**
172
+ * Exit using the same exit code
173
+ * returned by the child process.
174
+ *
175
+ * If result.status is null/undefined,
176
+ * default to exit code 1.
177
+ */
43
178
  process.exit(result.status ?? 1);