binary-collections 2.0.7 → 2.0.9

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 (155) hide show
  1. package/bin/dir-tree.cmd +7 -0
  2. package/bin/git-diff +4 -0
  3. package/bin/git-diff.cmd +5 -2
  4. package/bin/{git-fix-encoding → git-fix} +1 -4
  5. package/bin/git-fix.cmd +7 -0
  6. package/bin/nodekill +0 -0
  7. package/bin/nodekill.ps1 +0 -0
  8. package/bin/{submodule → submodule.txt} +0 -0
  9. package/lib/binary-collections-config.cjs +14 -0
  10. package/lib/binary-collections-config.d.mts +18 -0
  11. package/lib/binary-collections-config.d.ts +16 -0
  12. package/lib/binary-collections-config.js +39 -0
  13. package/lib/binary-collections-config.mjs +6 -0
  14. package/lib/binary-collections.cjs +123 -0
  15. package/lib/binary-collections.d.cts +2 -0
  16. package/lib/binary-collections.d.mts +137 -0
  17. package/lib/binary-collections.d.ts +137 -0
  18. package/lib/binary-collections.mjs +300 -0
  19. package/lib/changelog.cjs +328 -0
  20. package/lib/changelog.d.mts +2 -0
  21. package/lib/changelog.d.ts +1 -0
  22. package/lib/changelog.js +226 -0
  23. package/lib/changelog.mjs +199 -0
  24. package/lib/chunk-4BYBVEYC.mjs +30 -0
  25. package/lib/{chunk-FB6YIQYR.mjs → chunk-AASHBCRW.mjs} +17 -2
  26. package/lib/chunk-APBWENF6.mjs +135 -0
  27. package/lib/{chunk-4LEXWIIF.mjs → chunk-DPKAJKFO.mjs} +2 -4
  28. package/lib/chunk-EGSSKVDH.mjs +66 -0
  29. package/lib/{chunk-3LOB2P54.mjs → chunk-G3THLIDT.mjs} +3 -5
  30. package/lib/chunk-JGR2NW6D.mjs +187 -0
  31. package/lib/chunk-ONIBBBQ3.mjs +108 -0
  32. package/lib/chunk-SH3L6HHV.mjs +27 -0
  33. package/lib/chunk-VVEZVNIV.mjs +81 -0
  34. package/lib/{chunk-JL32QDSH.mjs → chunk-W3ENOM53.mjs} +2 -4
  35. package/lib/chunk-YV7DO3YV.mjs +48 -0
  36. package/lib/{chunk-BSD5CIRU.mjs → chunk-YX5U7XDR.mjs} +11 -5
  37. package/lib/chunk-ZYAQRPUL.mjs +28 -0
  38. package/lib/clean-github-actions-caches.cjs +162 -0
  39. package/lib/clean-github-actions-caches.d.cts +1 -0
  40. package/lib/clean-github-actions-caches.d.mts +169 -0
  41. package/lib/clean-github-actions-caches.d.ts +169 -0
  42. package/lib/clean-github-actions-caches.mjs +132 -0
  43. package/lib/del-gradle.cjs +87 -3
  44. package/lib/del-gradle.js +1 -1
  45. package/lib/del-gradle.mjs +4 -6
  46. package/lib/del-node-modules.cjs +86 -2
  47. package/lib/del-node-modules.mjs +3 -5
  48. package/lib/del-ps.cjs +89 -5
  49. package/lib/del-ps.js +2 -2
  50. package/lib/del-ps.mjs +6 -8
  51. package/lib/del-yarn-caches.cjs +86 -2
  52. package/lib/del-yarn-caches.mjs +3 -5
  53. package/lib/find-node-modules-cli.cjs +8 -0
  54. package/lib/find-node-modules-cli.mjs +2 -3
  55. package/lib/find-node-modules.cjs +8 -0
  56. package/lib/find-node-modules.d.mts +3 -0
  57. package/lib/find-node-modules.d.ts +3 -0
  58. package/lib/find-node-modules.js +12 -0
  59. package/lib/find-node-modules.mjs +2 -3
  60. package/lib/git/gitattributes.cjs +171 -0
  61. package/lib/git/gitattributes.d.mts +35 -0
  62. package/lib/git/gitattributes.d.ts +33 -0
  63. package/lib/git/gitattributes.js +223 -0
  64. package/lib/git/gitattributes.mjs +6 -0
  65. package/lib/git/line-endings.cjs +74 -0
  66. package/lib/git/line-endings.d.cts +7 -0
  67. package/lib/git/line-endings.d.mts +83 -0
  68. package/lib/git/line-endings.d.ts +83 -0
  69. package/lib/git/line-endings.mjs +8 -0
  70. package/lib/git/normalize.cjs +42 -0
  71. package/lib/git/normalize.d.cts +6 -0
  72. package/lib/git/normalize.d.mts +43 -0
  73. package/lib/git/normalize.d.ts +43 -0
  74. package/lib/git/normalize.mjs +6 -0
  75. package/lib/git/permissions.cjs +15 -0
  76. package/lib/git/permissions.d.cts +6 -0
  77. package/lib/git/permissions.d.mts +17 -0
  78. package/lib/git/permissions.d.ts +17 -0
  79. package/lib/git/permissions.mjs +7 -0
  80. package/lib/git/pull-strategy.cjs +13 -0
  81. package/lib/git/pull-strategy.d.cts +5 -0
  82. package/lib/git/pull-strategy.d.mts +15 -0
  83. package/lib/git/pull-strategy.d.ts +15 -0
  84. package/lib/git/pull-strategy.mjs +7 -0
  85. package/lib/git/user-config.cjs +100 -0
  86. package/lib/git/user-config.d.cts +10 -0
  87. package/lib/git/user-config.d.mts +105 -0
  88. package/lib/git/user-config.d.ts +105 -0
  89. package/lib/git/user-config.mjs +8 -0
  90. package/lib/git/utils.cjs +70 -0
  91. package/lib/git/utils.d.cts +20 -0
  92. package/lib/git/utils.d.mts +69 -0
  93. package/lib/git/utils.d.ts +69 -0
  94. package/lib/git/utils.mjs +6 -0
  95. package/lib/git-diff.cjs +23 -24
  96. package/lib/git-diff.d.mts +25 -28
  97. package/lib/git-diff.d.ts +25 -28
  98. package/lib/git-diff.mjs +32 -27
  99. package/lib/git-fix.cjs +129 -0
  100. package/lib/git-fix.d.cts +2 -0
  101. package/lib/git-fix.d.mts +141 -0
  102. package/lib/git-fix.d.ts +141 -0
  103. package/lib/git-fix.mjs +151 -0
  104. package/lib/git-purge.cjs +86 -2
  105. package/lib/git-purge.mjs +3 -5
  106. package/lib/index.cjs +8 -0
  107. package/lib/index.mjs +3 -5
  108. package/lib/npm-run-series.cjs +140 -1
  109. package/lib/npm-run-series.js +2 -1
  110. package/lib/npm-run-series.mjs +7 -5
  111. package/lib/package-resolutions-updater.cjs +447 -0
  112. package/lib/package-resolutions-updater.d.mts +1 -0
  113. package/lib/package-resolutions-updater.d.ts +352 -0
  114. package/lib/package-resolutions-updater.mjs +339 -0
  115. package/lib/print-directory-tree.cjs +241 -0
  116. package/lib/print-directory-tree.d.cts +1 -0
  117. package/lib/print-directory-tree.d.mts +234 -0
  118. package/lib/print-directory-tree.d.ts +234 -0
  119. package/lib/print-directory-tree.mjs +182 -0
  120. package/lib/ps/connected-domain.mjs +2 -3
  121. package/lib/ps/index.cjs +3 -3
  122. package/lib/ps/index.d.mjs +1 -2
  123. package/lib/ps/index.js +6 -3
  124. package/lib/ps/index.mjs +9 -11
  125. package/lib/ps/isWin.mjs +2 -3
  126. package/lib/ps/table-parser.mjs +3 -4
  127. package/lib/submodule-install.cjs +18 -35
  128. package/lib/submodule-install.d.mts +17 -37
  129. package/lib/submodule-install.d.ts +17 -37
  130. package/lib/submodule-install.mjs +21 -29
  131. package/lib/utils.cjs +86 -2
  132. package/lib/utils.d.mts +29 -9
  133. package/lib/utils.d.ts +28 -8
  134. package/lib/utils.js +139 -8
  135. package/lib/utils.mjs +2 -3
  136. package/lib/yarn-reinstall.cjs +9 -7
  137. package/lib/yarn-reinstall.d.mts +12 -8
  138. package/lib/yarn-reinstall.d.ts +12 -8
  139. package/lib/yarn-reinstall.mjs +14 -10
  140. package/package.json +109 -80
  141. package/readme.md +74 -11
  142. package/src/package-resolutions-updater.mjs +350 -0
  143. package/src/print-directory-tree.cjs +234 -0
  144. package/src/ps/index.js +4 -3
  145. package/src/yarn-reinstall.cjs +49 -0
  146. package/test-project/package.json +16 -0
  147. package/tmp/test-repo/package.json +7 -0
  148. package/bin/git-fix-encoding.cmd +0 -6
  149. package/lib/chunk-OKYLF2MU.mjs +0 -53
  150. package/lib/chunk-VXZQNLPU.mjs +0 -23
  151. package/lib/package-resolutions.cjs +0 -28
  152. package/lib/package-resolutions.d.mts +0 -25
  153. package/lib/package-resolutions.d.ts +0 -25
  154. package/lib/package-resolutions.mjs +0 -31
  155. /package/bin/{submodule-install → submodule-install.txt} +0 -0
@@ -0,0 +1,7 @@
1
+ @echo off
2
+ setlocal
3
+ set SCRIPT_DIR=%~dp0
4
+
5
+ echo Running script: %~f0
6
+
7
+ node "%SCRIPT_DIR%..\lib\print-directory-tree.cjs" %*
package/bin/git-diff ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
3
+
4
+ node "$SCRIPT_DIR/../lib/git-diff.cjs" "$@"
package/bin/git-diff.cmd CHANGED
@@ -1,4 +1,7 @@
1
1
  @echo off
2
+ setlocal
2
3
  set SCRIPT_DIR=%~dp0
3
- set SRC_DIR=%SCRIPT_DIR%..\src
4
- node "%SRC_DIR%\git-diff.cjs" %*
4
+
5
+ echo Running script: %~f0
6
+
7
+ node "%SCRIPT_DIR%..\lib\git-diff.cjs" %*
@@ -33,7 +33,4 @@ if [ -f ".env" ]; then
33
33
  export $(egrep -v '^#' .env | xargs)
34
34
  fi
35
35
 
36
- echo "fix auto rebase"
37
- git config config.pull false
38
- echo "force LF end of line"
39
- git config core.autocrlf false
36
+ node "$basedir/../lib/git-fix.cjs" "$@"
@@ -0,0 +1,7 @@
1
+ @echo off
2
+ setlocal
3
+ set SCRIPT_DIR=%~dp0
4
+
5
+ echo Running script: %~f0
6
+
7
+ node "%SCRIPT_DIR%..\lib\git-fix.cjs" %*
package/bin/nodekill CHANGED
File without changes
package/bin/nodekill.ps1 CHANGED
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ // src/binary-collections-config.js
2
+ var path = require("path");
3
+ function getTempDir() {
4
+ return process.env.TEMP_DIR || "tmp";
5
+ }
6
+ function getTempPath(...segments) {
7
+ return path.join(getTempDir(), ...segments);
8
+ }
9
+ var TEMP_BASE_DIR = getTempDir();
10
+ module.exports = {
11
+ getTempDir,
12
+ getTempPath,
13
+ TEMP_BASE_DIR
14
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Get the base temporary directory path
3
+ * Can be overridden via TEMP_DIR environment variable
4
+ * @returns {string} The base temporary directory path
5
+ */
6
+ declare function getTempDir(): string;
7
+ /**
8
+ * Get a temporary file or directory path
9
+ * @param {...string} segments - Path segments to join with the temp directory
10
+ * @returns {string} The full temporary path
11
+ */
12
+ declare function getTempPath(...segments: string[]): string;
13
+ /**
14
+ * Legacy aliases for backward compatibility
15
+ */
16
+ declare const TEMP_BASE_DIR: string;
17
+
18
+ export { TEMP_BASE_DIR, getTempDir, getTempPath };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Get the base temporary directory path
3
+ * Can be overridden via TEMP_DIR environment variable
4
+ * @returns {string} The base temporary directory path
5
+ */
6
+ export function getTempDir(): string;
7
+ /**
8
+ * Get a temporary file or directory path
9
+ * @param {...string} segments - Path segments to join with the temp directory
10
+ * @returns {string} The full temporary path
11
+ */
12
+ export function getTempPath(...segments: string[]): string;
13
+ /**
14
+ * Legacy aliases for backward compatibility
15
+ */
16
+ export const TEMP_BASE_DIR: string;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Centralized configuration for binary-collections
3
+ * This module provides a consistent way to handle temporary directories and other configuration across the project.
4
+ *
5
+ * Usage:
6
+ * const { getTempDir, getTempPath } = require('./binary-collections-config');
7
+ *
8
+ * // Get base temp directory
9
+ * const tempDir = getTempDir();
10
+ *
11
+ * // Get specific temp path
12
+ * const myTempPath = getTempPath('my-module', 'output.txt');
13
+ */
14
+ const path = require("path");
15
+ /**
16
+ * Get the base temporary directory path
17
+ * Can be overridden via TEMP_DIR environment variable
18
+ * @returns {string} The base temporary directory path
19
+ */
20
+ function getTempDir() {
21
+ return process.env.TEMP_DIR || "tmp";
22
+ }
23
+ /**
24
+ * Get a temporary file or directory path
25
+ * @param {...string} segments - Path segments to join with the temp directory
26
+ * @returns {string} The full temporary path
27
+ */
28
+ function getTempPath(...segments) {
29
+ return path.join(getTempDir(), ...segments);
30
+ }
31
+ /**
32
+ * Legacy aliases for backward compatibility
33
+ */
34
+ const TEMP_BASE_DIR = getTempDir();
35
+ module.exports = {
36
+ getTempDir,
37
+ getTempPath,
38
+ TEMP_BASE_DIR
39
+ };
@@ -0,0 +1,6 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_binary_collections_config
4
+ } from "./chunk-4BYBVEYC.mjs";
5
+ import "./chunk-AASHBCRW.mjs";
6
+ export default require_binary_collections_config();
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ const { spawn } = require("child_process");
4
+ const { glob } = require("glob");
5
+ const path = require("path");
6
+ const { getArgs } = require("./utils.js");
7
+ const pkgJson = require("../package.json");
8
+ const fs = require("fs");
9
+ /**
10
+ * Main binary-collections script that dynamically finds and executes other scripts
11
+ * Usage: npx binary-collections <script-name> [...args]
12
+ * Example: npx binary-collections git-diff -s
13
+ */
14
+ function showHelp() {
15
+ console.log("🚀 Binary Collections - Dynamic Script Runner");
16
+ console.log("═══════════════════════════════════════════════");
17
+ console.log("");
18
+ console.log("📋 Usage: npx binary-collections <script-name> [...args]");
19
+ console.log("");
20
+ console.log("✨ Examples:");
21
+ console.log(" 📊 npx binary-collections git-diff -s");
22
+ console.log(" 🧹 npx binary-collections del-node-modules");
23
+ console.log(" 🔍 npx binary-collections find-node-modules --help");
24
+ console.log("");
25
+ console.log("ℹ️ This tool will search for <script-name>.{cjs,js,mjs} in the script's directory");
26
+ console.log(" and execute it with the provided arguments.");
27
+ console.log("");
28
+ console.log("⚙️ Options:");
29
+ console.log(" --help, -h Show this help message");
30
+ process.exit(0);
31
+ }
32
+ function findScript(scriptName, searchDir = null) {
33
+ if (!searchDir)
34
+ searchDir = __dirname;
35
+ // Define ignore patterns for library config and utils
36
+ const ignorePatterns = [
37
+ `**/*config*.{cjs,js,mjs}`,
38
+ `**/utils.{cjs,js,mjs}`,
39
+ `**/index.{cjs,js,mjs}`,
40
+ `**/chunk-*.{cjs,js,mjs}`,
41
+ `**/*.d.{ts,cts,mts}` // ignore TypeScript declaration files
42
+ ];
43
+ try {
44
+ // Use glob to find script files, excluding ignored patterns
45
+ // Use cwd option for better path handling
46
+ const pattern = `${scriptName}.{cjs,js,mjs}`;
47
+ const files = glob.sync(pattern, {
48
+ cwd: searchDir,
49
+ ignore: ignorePatterns,
50
+ absolute: true
51
+ });
52
+ if (files.length > 0) {
53
+ // Return the first match if found
54
+ return files[0];
55
+ }
56
+ else {
57
+ // If not found pick from pkg.bin[scriptName] when exist
58
+ if (pkgJson.bin[scriptName]) {
59
+ const find = [
60
+ path.join(searchDir, pkgJson.bin[scriptName]),
61
+ path.join(process.cwd(), "node_modules/binary-collections", pkgJson.bin[scriptName])
62
+ ].filter((file) => fs.existsSync(file));
63
+ if (find.length > 0) {
64
+ return find[0];
65
+ }
66
+ else {
67
+ console.warn(`⚠️ Script "${scriptName}" not found in ${searchDir}.`);
68
+ console.warn(`🔍 Searched for: ${pattern} in ${searchDir}`);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ catch (error) {
74
+ console.error(`🔍 Error searching for script: ${error.message}`);
75
+ }
76
+ return null;
77
+ }
78
+ function executeScript(scriptPath, args) {
79
+ const child = spawn("node", [scriptPath, ...args], {
80
+ stdio: "inherit",
81
+ shell: true
82
+ });
83
+ child.on("error", (error) => {
84
+ console.error(`❌ Error executing script: ${error.message}`);
85
+ process.exit(1);
86
+ });
87
+ child.on("close", (code) => {
88
+ process.exit(code);
89
+ });
90
+ }
91
+ function main() {
92
+ const args = getArgs();
93
+ const positional = args._ || [];
94
+ // Show help if no arguments or if help is requested without a script name
95
+ if (positional.length === 0 || (positional.length === 1 && (args.help || args.h))) {
96
+ showHelp();
97
+ }
98
+ const scriptName = positional[0];
99
+ const scriptArgs = positional.slice(1);
100
+ // Find the script in current directory
101
+ const scriptPath = findScript(scriptName);
102
+ if (!scriptPath) {
103
+ console.error(`❌ Error: Script "${scriptName}" not found.`);
104
+ console.error(`🔍 Searched for: ${scriptName}.{cjs,js,mjs} in ${__dirname}`);
105
+ console.error("");
106
+ console.error("📝 Available extensions: .cjs, .js, .mjs");
107
+ process.exit(1);
108
+ }
109
+ // Show relative path from current working directory
110
+ const relativePath = path.relative(process.cwd(), scriptPath);
111
+ console.log(`✅ Found script: ${relativePath}`);
112
+ executeScript(scriptPath, scriptArgs);
113
+ }
114
+ // Handle uncaught exceptions
115
+ process.on("uncaughtException", (error) => {
116
+ console.error("💥 Uncaught Exception:", error.message);
117
+ process.exit(1);
118
+ });
119
+ process.on("unhandledRejection", (reason, promise) => {
120
+ console.error("⚠️ Unhandled Rejection at:", promise, "reason:", reason);
121
+ process.exit(1);
122
+ });
123
+ main();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require("child_process");
3
+ const { glob } = require("glob");
4
+ const path = require("path");
5
+ const { getArgs } = require("./utils.js");
6
+ const pkgJson = require("../package.json");
7
+ const fs = require("fs");
8
+
9
+ /**
10
+ * Main binary-collections script that dynamically finds and executes other scripts
11
+ * Usage: npx binary-collections <script-name> [...args]
12
+ * Example: npx binary-collections git-diff -s
13
+ */
14
+
15
+ function showHelp() {
16
+ console.log("🚀 Binary Collections - Dynamic Script Runner");
17
+ console.log("═══════════════════════════════════════════════");
18
+ console.log("");
19
+ console.log("📋 Usage: npx binary-collections <script-name> [...args]");
20
+ console.log("");
21
+ console.log("✨ Examples:");
22
+ console.log(" 📊 npx binary-collections git-diff -s");
23
+ console.log(" 🧹 npx binary-collections del-node-modules");
24
+ console.log(" 🔍 npx binary-collections find-node-modules --help");
25
+ console.log("");
26
+ console.log("ℹ️ This tool will search for <script-name>.{cjs,js,mjs} in the script's directory");
27
+ console.log(" and execute it with the provided arguments.");
28
+ console.log("");
29
+ console.log("⚙️ Options:");
30
+ console.log(" --help, -h Show this help message");
31
+ process.exit(0);
32
+ }
33
+
34
+ function findScript(scriptName, searchDir = null) {
35
+ if (!searchDir) searchDir = __dirname;
36
+
37
+ // Define ignore patterns for library config and utils
38
+ const ignorePatterns = [
39
+ `**/*config*.{cjs,js,mjs}`,
40
+ `**/utils.{cjs,js,mjs}`,
41
+ `**/index.{cjs,js,mjs}`,
42
+ `**/chunk-*.{cjs,js,mjs}`,
43
+ `**/*.d.{ts,cts,mts}` // ignore TypeScript declaration files
44
+ ];
45
+
46
+ try {
47
+ // Use glob to find script files, excluding ignored patterns
48
+ // Use cwd option for better path handling
49
+ const pattern = `${scriptName}.{cjs,js,mjs}`;
50
+ const files = glob.sync(pattern, {
51
+ cwd: searchDir,
52
+ ignore: ignorePatterns,
53
+ absolute: true
54
+ });
55
+
56
+ if (files.length > 0) {
57
+ // Return the first match if found
58
+ return files[0];
59
+ } else {
60
+ // If not found pick from pkg.bin[scriptName] when exist
61
+ if (pkgJson.bin[scriptName]) {
62
+ const find = [
63
+ path.join(searchDir, pkgJson.bin[scriptName]),
64
+ path.join(process.cwd(), "node_modules/binary-collections", pkgJson.bin[scriptName])
65
+ ].filter((file) => fs.existsSync(file));
66
+ if (find.length > 0) {
67
+ return find[0];
68
+ } else {
69
+ console.warn(`⚠️ Script "${scriptName}" not found in ${searchDir}.`);
70
+ console.warn(`🔍 Searched for: ${pattern} in ${searchDir}`);
71
+ }
72
+ }
73
+ }
74
+ } catch (error) {
75
+ console.error(`🔍 Error searching for script: ${error.message}`);
76
+ }
77
+
78
+ return null;
79
+ }
80
+
81
+ function executeScript(scriptPath, args) {
82
+ const child = spawn("node", [scriptPath, ...args], {
83
+ stdio: "inherit",
84
+ shell: true
85
+ });
86
+
87
+ child.on("error", (error) => {
88
+ console.error(`❌ Error executing script: ${error.message}`);
89
+ process.exit(1);
90
+ });
91
+
92
+ child.on("close", (code) => {
93
+ process.exit(code);
94
+ });
95
+ }
96
+
97
+ function main() {
98
+ const args = getArgs();
99
+ const positional = args._ || [];
100
+
101
+ // Show help if no arguments or if help is requested without a script name
102
+ if (positional.length === 0 || (positional.length === 1 && (args.help || args.h))) {
103
+ showHelp();
104
+ }
105
+
106
+ const scriptName = positional[0];
107
+ const scriptArgs = positional.slice(1);
108
+
109
+ // Find the script in current directory
110
+ const scriptPath = findScript(scriptName);
111
+
112
+ if (!scriptPath) {
113
+ console.error(`❌ Error: Script "${scriptName}" not found.`);
114
+ console.error(`🔍 Searched for: ${scriptName}.{cjs,js,mjs} in ${__dirname}`);
115
+ console.error("");
116
+ console.error("📝 Available extensions: .cjs, .js, .mjs");
117
+ process.exit(1);
118
+ }
119
+
120
+ // Show relative path from current working directory
121
+ const relativePath = path.relative(process.cwd(), scriptPath);
122
+ console.log(`✅ Found script: ${relativePath}`);
123
+ executeScript(scriptPath, scriptArgs);
124
+ }
125
+
126
+ // Handle uncaught exceptions
127
+ process.on("uncaughtException", (error) => {
128
+ console.error("💥 Uncaught Exception:", error.message);
129
+ process.exit(1);
130
+ });
131
+
132
+ process.on("unhandledRejection", (reason, promise) => {
133
+ console.error("⚠️ Unhandled Rejection at:", promise, "reason:", reason);
134
+ process.exit(1);
135
+ });
136
+
137
+ main();
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require("child_process");
3
+ const { glob } = require("glob");
4
+ const path = require("path");
5
+ const { getArgs } = require("./utils.js");
6
+ const pkgJson = require("../package.json");
7
+ const fs = require("fs");
8
+
9
+ /**
10
+ * Main binary-collections script that dynamically finds and executes other scripts
11
+ * Usage: npx binary-collections <script-name> [...args]
12
+ * Example: npx binary-collections git-diff -s
13
+ */
14
+
15
+ function showHelp() {
16
+ console.log("🚀 Binary Collections - Dynamic Script Runner");
17
+ console.log("═══════════════════════════════════════════════");
18
+ console.log("");
19
+ console.log("📋 Usage: npx binary-collections <script-name> [...args]");
20
+ console.log("");
21
+ console.log("✨ Examples:");
22
+ console.log(" 📊 npx binary-collections git-diff -s");
23
+ console.log(" 🧹 npx binary-collections del-node-modules");
24
+ console.log(" 🔍 npx binary-collections find-node-modules --help");
25
+ console.log("");
26
+ console.log("ℹ️ This tool will search for <script-name>.{cjs,js,mjs} in the script's directory");
27
+ console.log(" and execute it with the provided arguments.");
28
+ console.log("");
29
+ console.log("⚙️ Options:");
30
+ console.log(" --help, -h Show this help message");
31
+ process.exit(0);
32
+ }
33
+
34
+ function findScript(scriptName, searchDir = null) {
35
+ if (!searchDir) searchDir = __dirname;
36
+
37
+ // Define ignore patterns for library config and utils
38
+ const ignorePatterns = [
39
+ `**/*config*.{cjs,js,mjs}`,
40
+ `**/utils.{cjs,js,mjs}`,
41
+ `**/index.{cjs,js,mjs}`,
42
+ `**/chunk-*.{cjs,js,mjs}`,
43
+ `**/*.d.{ts,cts,mts}` // ignore TypeScript declaration files
44
+ ];
45
+
46
+ try {
47
+ // Use glob to find script files, excluding ignored patterns
48
+ // Use cwd option for better path handling
49
+ const pattern = `${scriptName}.{cjs,js,mjs}`;
50
+ const files = glob.sync(pattern, {
51
+ cwd: searchDir,
52
+ ignore: ignorePatterns,
53
+ absolute: true
54
+ });
55
+
56
+ if (files.length > 0) {
57
+ // Return the first match if found
58
+ return files[0];
59
+ } else {
60
+ // If not found pick from pkg.bin[scriptName] when exist
61
+ if (pkgJson.bin[scriptName]) {
62
+ const find = [
63
+ path.join(searchDir, pkgJson.bin[scriptName]),
64
+ path.join(process.cwd(), "node_modules/binary-collections", pkgJson.bin[scriptName])
65
+ ].filter((file) => fs.existsSync(file));
66
+ if (find.length > 0) {
67
+ return find[0];
68
+ } else {
69
+ console.warn(`⚠️ Script "${scriptName}" not found in ${searchDir}.`);
70
+ console.warn(`🔍 Searched for: ${pattern} in ${searchDir}`);
71
+ }
72
+ }
73
+ }
74
+ } catch (error) {
75
+ console.error(`🔍 Error searching for script: ${error.message}`);
76
+ }
77
+
78
+ return null;
79
+ }
80
+
81
+ function executeScript(scriptPath, args) {
82
+ const child = spawn("node", [scriptPath, ...args], {
83
+ stdio: "inherit",
84
+ shell: true
85
+ });
86
+
87
+ child.on("error", (error) => {
88
+ console.error(`❌ Error executing script: ${error.message}`);
89
+ process.exit(1);
90
+ });
91
+
92
+ child.on("close", (code) => {
93
+ process.exit(code);
94
+ });
95
+ }
96
+
97
+ function main() {
98
+ const args = getArgs();
99
+ const positional = args._ || [];
100
+
101
+ // Show help if no arguments or if help is requested without a script name
102
+ if (positional.length === 0 || (positional.length === 1 && (args.help || args.h))) {
103
+ showHelp();
104
+ }
105
+
106
+ const scriptName = positional[0];
107
+ const scriptArgs = positional.slice(1);
108
+
109
+ // Find the script in current directory
110
+ const scriptPath = findScript(scriptName);
111
+
112
+ if (!scriptPath) {
113
+ console.error(`❌ Error: Script "${scriptName}" not found.`);
114
+ console.error(`🔍 Searched for: ${scriptName}.{cjs,js,mjs} in ${__dirname}`);
115
+ console.error("");
116
+ console.error("📝 Available extensions: .cjs, .js, .mjs");
117
+ process.exit(1);
118
+ }
119
+
120
+ // Show relative path from current working directory
121
+ const relativePath = path.relative(process.cwd(), scriptPath);
122
+ console.log(`✅ Found script: ${relativePath}`);
123
+ executeScript(scriptPath, scriptArgs);
124
+ }
125
+
126
+ // Handle uncaught exceptions
127
+ process.on("uncaughtException", (error) => {
128
+ console.error("💥 Uncaught Exception:", error.message);
129
+ process.exit(1);
130
+ });
131
+
132
+ process.on("unhandledRejection", (reason, promise) => {
133
+ console.error("⚠️ Unhandled Rejection at:", promise, "reason:", reason);
134
+ process.exit(1);
135
+ });
136
+
137
+ main();