binary-collections 2.0.6 → 2.0.8
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/bin/dir-tree.cmd +7 -0
- package/bin/git-diff +4 -0
- package/bin/git-diff.cmd +7 -0
- package/bin/{git-fix-encoding → git-fix} +1 -4
- package/bin/git-fix.cmd +7 -0
- package/bin/nodekill +0 -0
- package/bin/nodekill.cmd +0 -0
- package/bin/{submodule-install → submodule-install.txt} +0 -0
- package/bin/{submodule → submodule.txt} +0 -0
- package/lib/binary-collections-config.cjs +14 -0
- package/lib/binary-collections-config.d.mts +18 -0
- package/lib/binary-collections-config.d.ts +16 -0
- package/lib/binary-collections-config.js +39 -0
- package/lib/binary-collections-config.mjs +6 -0
- package/lib/binary-collections.cjs +105 -0
- package/lib/binary-collections.d.cts +2 -0
- package/lib/binary-collections.d.mts +121 -0
- package/lib/binary-collections.d.ts +121 -0
- package/lib/binary-collections.mjs +108 -0
- package/lib/chunk-4BYBVEYC.mjs +30 -0
- package/lib/chunk-AASHBCRW.mjs +57 -0
- package/lib/chunk-APBWENF6.mjs +135 -0
- package/lib/{chunk-M4IBUK4H.mjs → chunk-DPKAJKFO.mjs} +2 -4
- package/lib/chunk-EGSSKVDH.mjs +66 -0
- package/lib/{chunk-GA4DDV65.mjs → chunk-G3THLIDT.mjs} +3 -5
- package/lib/chunk-JGR2NW6D.mjs +187 -0
- package/lib/chunk-ONIBBBQ3.mjs +108 -0
- package/lib/chunk-SH3L6HHV.mjs +27 -0
- package/lib/chunk-VVEZVNIV.mjs +81 -0
- package/lib/{chunk-E75HJFJO.mjs → chunk-W3ENOM53.mjs} +2 -4
- package/lib/chunk-YV7DO3YV.mjs +48 -0
- package/lib/chunk-YX5U7XDR.mjs +58 -0
- package/lib/chunk-ZYAQRPUL.mjs +28 -0
- package/lib/clean-github-actions-caches.cjs +162 -0
- package/lib/clean-github-actions-caches.d.cts +1 -0
- package/lib/clean-github-actions-caches.d.mts +169 -0
- package/lib/clean-github-actions-caches.d.ts +169 -0
- package/lib/clean-github-actions-caches.mjs +132 -0
- package/lib/del-gradle.cjs +99 -15
- package/lib/del-gradle.d.ts +1 -2
- package/lib/del-gradle.js +12 -69
- package/lib/del-gradle.mjs +4 -6
- package/lib/del-node-modules.cjs +98 -14
- package/lib/del-node-modules.d.ts +1 -2
- package/lib/del-node-modules.js +11 -68
- package/lib/del-node-modules.mjs +3 -5
- package/lib/del-ps.cjs +98 -627
- package/lib/del-ps.d.ts +1 -2
- package/lib/del-ps.js +27 -702
- package/lib/del-ps.mjs +7 -12
- package/lib/del-yarn-caches.cjs +98 -14
- package/lib/del-yarn-caches.d.ts +1 -2
- package/lib/del-yarn-caches.js +6 -63
- package/lib/del-yarn-caches.mjs +3 -5
- package/lib/find-node-modules-cli.cjs +67 -0
- package/lib/find-node-modules-cli.d.mts +1 -0
- package/lib/find-node-modules-cli.d.ts +2 -0
- package/lib/find-node-modules-cli.js +3 -0
- package/lib/find-node-modules-cli.mjs +13 -0
- package/lib/find-node-modules.cjs +39 -9
- package/lib/find-node-modules.d.mts +12 -1
- package/lib/find-node-modules.d.ts +12 -2
- package/lib/find-node-modules.js +53 -12
- package/lib/find-node-modules.mjs +4 -19
- package/lib/git/gitattributes.cjs +171 -0
- package/lib/git/gitattributes.d.mts +35 -0
- package/lib/git/gitattributes.d.ts +33 -0
- package/lib/git/gitattributes.js +223 -0
- package/lib/git/gitattributes.mjs +6 -0
- package/lib/git/line-endings.cjs +74 -0
- package/lib/git/line-endings.d.cts +7 -0
- package/lib/git/line-endings.d.mts +83 -0
- package/lib/git/line-endings.d.ts +83 -0
- package/lib/git/line-endings.mjs +8 -0
- package/lib/git/normalize.cjs +42 -0
- package/lib/git/normalize.d.cts +6 -0
- package/lib/git/normalize.d.mts +43 -0
- package/lib/git/normalize.d.ts +43 -0
- package/lib/git/normalize.mjs +6 -0
- package/lib/git/permissions.cjs +15 -0
- package/lib/git/permissions.d.cts +6 -0
- package/lib/git/permissions.d.mts +17 -0
- package/lib/git/permissions.d.ts +17 -0
- package/lib/git/permissions.mjs +7 -0
- package/lib/git/pull-strategy.cjs +13 -0
- package/lib/git/pull-strategy.d.cts +5 -0
- package/lib/git/pull-strategy.d.mts +15 -0
- package/lib/git/pull-strategy.d.ts +15 -0
- package/lib/git/pull-strategy.mjs +7 -0
- package/lib/git/user-config.cjs +100 -0
- package/lib/git/user-config.d.cts +10 -0
- package/lib/git/user-config.d.mts +105 -0
- package/lib/git/user-config.d.ts +105 -0
- package/lib/git/user-config.mjs +8 -0
- package/lib/git/utils.cjs +70 -0
- package/lib/git/utils.d.cts +20 -0
- package/lib/git/utils.d.mts +69 -0
- package/lib/git/utils.d.ts +69 -0
- package/lib/git/utils.mjs +6 -0
- package/lib/git-diff.cjs +73 -0
- package/lib/git-diff.d.cts +2 -0
- package/lib/git-diff.d.mts +84 -0
- package/lib/git-diff.d.ts +84 -0
- package/lib/git-diff.mjs +88 -0
- package/lib/git-fix.cjs +129 -0
- package/lib/git-fix.d.cts +2 -0
- package/lib/git-fix.d.mts +141 -0
- package/lib/git-fix.d.ts +141 -0
- package/lib/git-fix.mjs +151 -0
- package/lib/git-purge.cjs +92 -621
- package/lib/git-purge.d.ts +1 -2
- package/lib/git-purge.js +53 -698
- package/lib/git-purge.mjs +4 -9
- package/lib/index.cjs +99 -1
- package/lib/index.d.mts +1 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +8 -2
- package/lib/index.mjs +10 -3
- package/lib/npm-run-series.cjs +140 -1
- package/lib/npm-run-series.d.ts +1 -0
- package/lib/npm-run-series.js +81 -56
- package/lib/npm-run-series.mjs +7 -5
- package/lib/package-resolutions-updater.cjs +274 -0
- package/lib/package-resolutions-updater.d.mts +1 -0
- package/lib/package-resolutions-updater.d.ts +326 -0
- package/lib/package-resolutions-updater.mjs +316 -0
- package/lib/print-directory-tree.cjs +241 -0
- package/lib/print-directory-tree.d.cts +1 -0
- package/lib/print-directory-tree.d.mts +234 -0
- package/lib/print-directory-tree.d.ts +234 -0
- package/lib/print-directory-tree.mjs +182 -0
- package/lib/ps/connected-domain.cjs +0 -0
- package/lib/ps/connected-domain.d.ts +1 -2
- package/lib/ps/connected-domain.js +196 -150
- package/lib/ps/connected-domain.mjs +2 -3
- package/lib/ps/index.cjs +3 -3
- package/lib/ps/index.d.mjs +1 -2
- package/lib/ps/index.d.ts +2 -26
- package/lib/ps/index.js +233 -535
- package/lib/ps/index.mjs +9 -11
- package/lib/ps/isWin.cjs +0 -0
- package/lib/ps/isWin.d.ts +1 -2
- package/lib/ps/isWin.js +1 -2
- package/lib/ps/isWin.mjs +2 -3
- package/lib/ps/table-parser.cjs +0 -0
- package/lib/ps/table-parser.d.ts +1 -3
- package/lib/ps/table-parser.js +254 -345
- package/lib/ps/table-parser.mjs +3 -4
- package/lib/submodule-install.cjs +100 -0
- package/lib/submodule-install.d.cts +2 -0
- package/lib/submodule-install.d.mts +121 -0
- package/lib/submodule-install.d.ts +121 -0
- package/lib/submodule-install.mjs +107 -0
- package/lib/utils.cjs +98 -14
- package/lib/utils.d.mts +29 -9
- package/lib/utils.d.ts +30 -14
- package/lib/utils.js +173 -27
- package/lib/utils.mjs +2 -3
- package/lib/yarn-reinstall.cjs +44 -0
- package/lib/yarn-reinstall.d.cts +1 -0
- package/lib/yarn-reinstall.d.mts +49 -0
- package/lib/yarn-reinstall.d.ts +49 -0
- package/lib/yarn-reinstall.mjs +54 -0
- package/package.json +126 -99
- package/readme.md +238 -50
- package/src/package-resolutions-updater.mjs +325 -0
- package/src/print-directory-tree.cjs +234 -0
- package/src/ps/index.js +4 -3
- package/src/yarn-reinstall.cjs +49 -0
- package/test-project/package.json +16 -0
- package/tmp/test-repo/package.json +7 -0
- package/bin/git-fix-encoding.cmd +0 -6
- package/eslint.config.cjs +0 -97
- package/lib/chunk-7MSZ52XC.mjs +0 -14
- package/lib/chunk-AVDT32AY.mjs +0 -20
- package/lib/chunk-LPLPQBYP.mjs +0 -53
- package/lib/chunk-S4SJ7SDW.mjs +0 -625
- package/lib/package-resolutions.cjs +0 -28
- package/lib/package-resolutions.d.mts +0 -25
- package/lib/package-resolutions.d.ts +0 -25
- package/lib/package-resolutions.js +0 -28
- package/lib/package-resolutions.mjs +0 -31
- package/lib/ps/index.d.js +0 -17
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
const fs = require("fs").promises;
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const crypto = require("crypto");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
const glob = require("glob");
|
|
6
|
+
const { getArgs } = require("./utils.js");
|
|
7
|
+
const sbgUtil = require("sbg-utility");
|
|
8
|
+
const dotenv = require("dotenv");
|
|
9
|
+
|
|
10
|
+
const projectDir = process.cwd();
|
|
11
|
+
const envPath = path.join(projectDir, ".env");
|
|
12
|
+
|
|
13
|
+
// Load the .env file using dotenv (ESM import)
|
|
14
|
+
if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
|
|
15
|
+
|
|
16
|
+
// Parse CLI arguments
|
|
17
|
+
const argv = getArgs();
|
|
18
|
+
|
|
19
|
+
// Main logic wrapped in an async function
|
|
20
|
+
async function main() {
|
|
21
|
+
// Determine output file from CLI args
|
|
22
|
+
let relativeOutputFile = "tmp/directory-structure.txt";
|
|
23
|
+
if (argv.output || argv.o) {
|
|
24
|
+
relativeOutputFile = argv.output || argv.o;
|
|
25
|
+
}
|
|
26
|
+
// If not absolute, resolve relative to projectDir
|
|
27
|
+
const outputFile = path.isAbsolute(relativeOutputFile)
|
|
28
|
+
? relativeOutputFile
|
|
29
|
+
: path.join(projectDir, relativeOutputFile);
|
|
30
|
+
|
|
31
|
+
// Create or clear the hash file
|
|
32
|
+
sbgUtil.writefile(outputFile, "");
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* List of file extensions to include
|
|
36
|
+
* @type {string[]}
|
|
37
|
+
*/
|
|
38
|
+
let extensions = [];
|
|
39
|
+
if (argv.ext) {
|
|
40
|
+
extensions = argv.ext
|
|
41
|
+
.split(",")
|
|
42
|
+
.map((e) => e.trim().replace(/^\./, ""))
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Directories to exclude
|
|
47
|
+
let excludeDirs = [
|
|
48
|
+
"node_modules",
|
|
49
|
+
"vendor",
|
|
50
|
+
"venv",
|
|
51
|
+
".venv",
|
|
52
|
+
".git",
|
|
53
|
+
".hg",
|
|
54
|
+
".svn",
|
|
55
|
+
".idea",
|
|
56
|
+
".vscode",
|
|
57
|
+
"dist",
|
|
58
|
+
"build",
|
|
59
|
+
"out",
|
|
60
|
+
"coverage",
|
|
61
|
+
".DS_Store"
|
|
62
|
+
];
|
|
63
|
+
if (argv.exclude) {
|
|
64
|
+
const userExcludes = argv.exclude
|
|
65
|
+
.split(",")
|
|
66
|
+
.map((d) => d.trim())
|
|
67
|
+
.filter(Boolean);
|
|
68
|
+
if (argv["override-exclude"] || argv.we) {
|
|
69
|
+
// Override the default excludes with user-provided ones
|
|
70
|
+
excludeDirs = userExcludes;
|
|
71
|
+
} else {
|
|
72
|
+
// Append user-provided excludes to the default ones
|
|
73
|
+
excludeDirs = excludeDirs.concat(userExcludes);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Convert excludeDirs into glob ignore patterns
|
|
78
|
+
const ignorePatterns = excludeDirs.map((dir) => `**/${dir}/**`);
|
|
79
|
+
|
|
80
|
+
// Initialize an array to hold the formatted outputs
|
|
81
|
+
let hashArray = [];
|
|
82
|
+
|
|
83
|
+
// Helper function to hash and add file if not already processed
|
|
84
|
+
const processedFiles = new Set();
|
|
85
|
+
/**
|
|
86
|
+
* Hashes a file and pushes its relative path and hash to the hashArray.
|
|
87
|
+
* @param {string} file - The absolute path to the file.
|
|
88
|
+
* @returns {Promise<void>} Resolves when the file has been processed and added to hashArray.
|
|
89
|
+
*/
|
|
90
|
+
async function hashAndPush(file) {
|
|
91
|
+
if (processedFiles.has(file)) return;
|
|
92
|
+
processedFiles.add(file);
|
|
93
|
+
let relativePath = path.relative(projectDir, file);
|
|
94
|
+
relativePath = relativePath.split(path.sep).join("/");
|
|
95
|
+
try {
|
|
96
|
+
const stats = await fs.stat(file);
|
|
97
|
+
const pseudoHash = `${stats.size}-${stats.mtimeMs}`;
|
|
98
|
+
const hash = crypto.createHash("sha256").update(pseudoHash).digest("hex");
|
|
99
|
+
hashArray.push(`${relativePath} ${hash.slice(0, 8)}`);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.error(`Error processing file: ${file}`, err instanceof Error ? err.message : "<unknown error>");
|
|
102
|
+
if (err && err.code === "ENOENT") {
|
|
103
|
+
hashArray.push(`${relativePath} <file not found>`);
|
|
104
|
+
} else {
|
|
105
|
+
hashArray.push(`${relativePath} <error: ${err && err.code ? `code ${err.code}` : "unknown"}>`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Collect all files to process (extensions + special files)
|
|
111
|
+
const initialFiles = [
|
|
112
|
+
path.join(projectDir, "package.json"),
|
|
113
|
+
path.join(projectDir, "composer.json"),
|
|
114
|
+
path.join(projectDir, "requirements.txt")
|
|
115
|
+
];
|
|
116
|
+
let patterns = [];
|
|
117
|
+
if (argv.pattern) {
|
|
118
|
+
if (Array.isArray(argv.pattern)) {
|
|
119
|
+
patterns = argv.pattern.map((p) => p.trim()).filter(Boolean);
|
|
120
|
+
} else {
|
|
121
|
+
patterns = [argv.pattern.trim()];
|
|
122
|
+
}
|
|
123
|
+
} else if (extensions.length === 0) {
|
|
124
|
+
patterns = ["**/*.*"];
|
|
125
|
+
} else {
|
|
126
|
+
patterns = extensions.map((ext) => `**/*.${ext}`);
|
|
127
|
+
}
|
|
128
|
+
const globFiles = glob.sync(patterns.length === 1 ? patterns[0] : `{${patterns.join(",")}}`, {
|
|
129
|
+
cwd: projectDir,
|
|
130
|
+
ignore: ignorePatterns,
|
|
131
|
+
absolute: true,
|
|
132
|
+
nodir: true
|
|
133
|
+
});
|
|
134
|
+
const allFiles = new Set([...initialFiles, ...globFiles]);
|
|
135
|
+
|
|
136
|
+
// Hash all unique files
|
|
137
|
+
await Promise.all(Array.from(allFiles).map(hashAndPush));
|
|
138
|
+
|
|
139
|
+
// Sort the hashArray by file paths
|
|
140
|
+
hashArray.sort((a, b) => a.localeCompare(b));
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Generates a directory/file tree string from a hash array of file paths and hashes.
|
|
144
|
+
*
|
|
145
|
+
* @param {string[]} hashArray - Array of strings in the format 'relative/path/to/file hash'.
|
|
146
|
+
* @returns {string} The directory/file tree as a string, with file hashes.
|
|
147
|
+
*/
|
|
148
|
+
function getFileTreeString(hashArray) {
|
|
149
|
+
const tree = {};
|
|
150
|
+
// Map file paths to hashes for quick lookup
|
|
151
|
+
const hashMap = {};
|
|
152
|
+
for (const entry of hashArray) {
|
|
153
|
+
const [filePath, hash] = entry.split(" ");
|
|
154
|
+
hashMap[filePath] = hash;
|
|
155
|
+
const parts = filePath.split("/");
|
|
156
|
+
let current = tree;
|
|
157
|
+
for (let i = 0; i < parts.length; i++) {
|
|
158
|
+
const part = parts[i];
|
|
159
|
+
if (i === parts.length - 1) {
|
|
160
|
+
current[part] = null; // file
|
|
161
|
+
} else {
|
|
162
|
+
current[part] = current[part] || {};
|
|
163
|
+
current = current[part];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Recursively builds the tree string for a given node.
|
|
169
|
+
*
|
|
170
|
+
* @param {Object} node - The current node in the tree.
|
|
171
|
+
* @param {string} prefix - The prefix for the current tree level.
|
|
172
|
+
* @param {string} parentPath - The path to the current node.
|
|
173
|
+
* @returns {string[]} Array of lines representing the tree structure.
|
|
174
|
+
*/
|
|
175
|
+
function printNode(node, prefix = "", parentPath = "") {
|
|
176
|
+
const keys = Object.keys(node).sort();
|
|
177
|
+
let lines = [];
|
|
178
|
+
keys.forEach((key, idx) => {
|
|
179
|
+
const isLast = idx === keys.length - 1;
|
|
180
|
+
const branch = isLast ? "└── " : "├── ";
|
|
181
|
+
const currentPath = parentPath ? parentPath + "/" + key : key;
|
|
182
|
+
if (node[key] === null) {
|
|
183
|
+
// file: show hash
|
|
184
|
+
lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
|
|
185
|
+
} else {
|
|
186
|
+
lines.push(prefix + branch + key + "/");
|
|
187
|
+
lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "│ "), currentPath));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return lines;
|
|
191
|
+
}
|
|
192
|
+
return printNode(tree, "", "").join("\n");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Write directory/file tree to the output file (hashes are included in the tree)
|
|
196
|
+
const fileTreeString = getFileTreeString(hashArray);
|
|
197
|
+
await fs.writeFile(outputFile, fileTreeString + "\n", "utf-8");
|
|
198
|
+
|
|
199
|
+
// Add the hash file to the commit if --git-add is present
|
|
200
|
+
if (argv["git-add"]) {
|
|
201
|
+
execSync(`git add ${relativeOutputFile}`);
|
|
202
|
+
console.log(`Directory tree written to ${relativeOutputFile} and staged for git.`);
|
|
203
|
+
} else {
|
|
204
|
+
console.log(`Directory tree written to ${relativeOutputFile}.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (argv.help || argv.h) {
|
|
209
|
+
console.log(`
|
|
210
|
+
Usage: node print-directory-tree.cjs [options]
|
|
211
|
+
|
|
212
|
+
Options:
|
|
213
|
+
--output, -o <file> Output file path (default: tmp/directory-structure.txt)
|
|
214
|
+
--ext <exts> Comma-separated list of file extensions (no dot, e.g. js,ts)
|
|
215
|
+
--pattern <glob> Glob pattern(s) for files (can be repeated)
|
|
216
|
+
--exclude <dirs> Comma-separated list of directories to exclude (appends to default)
|
|
217
|
+
--override-exclude, -we Override default exclude directories with --exclude
|
|
218
|
+
--git-add Add output file to git after writing
|
|
219
|
+
--help, -h Show this help message
|
|
220
|
+
|
|
221
|
+
Examples:
|
|
222
|
+
node print-directory-tree.cjs --ext=js,ts
|
|
223
|
+
node print-directory-tree.cjs --pattern=src/**/*.js --pattern=test/**/*.js
|
|
224
|
+
node print-directory-tree.cjs --exclude=dist,build
|
|
225
|
+
node print-directory-tree.cjs --output=tmp/tree.txt
|
|
226
|
+
`);
|
|
227
|
+
process.exit(0);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Execute the main function
|
|
231
|
+
main().catch((err) => {
|
|
232
|
+
console.error(err);
|
|
233
|
+
process.exit(1);
|
|
234
|
+
});
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
const fs = require("fs").promises;
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const crypto = require("crypto");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
const glob = require("glob");
|
|
6
|
+
const { getArgs } = require("./utils.js");
|
|
7
|
+
const sbgUtil = require("sbg-utility");
|
|
8
|
+
const dotenv = require("dotenv");
|
|
9
|
+
|
|
10
|
+
const projectDir = process.cwd();
|
|
11
|
+
const envPath = path.join(projectDir, ".env");
|
|
12
|
+
|
|
13
|
+
// Load the .env file using dotenv (ESM import)
|
|
14
|
+
if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
|
|
15
|
+
|
|
16
|
+
// Parse CLI arguments
|
|
17
|
+
const argv = getArgs();
|
|
18
|
+
|
|
19
|
+
// Main logic wrapped in an async function
|
|
20
|
+
async function main() {
|
|
21
|
+
// Determine output file from CLI args
|
|
22
|
+
let relativeOutputFile = "tmp/directory-structure.txt";
|
|
23
|
+
if (argv.output || argv.o) {
|
|
24
|
+
relativeOutputFile = argv.output || argv.o;
|
|
25
|
+
}
|
|
26
|
+
// If not absolute, resolve relative to projectDir
|
|
27
|
+
const outputFile = path.isAbsolute(relativeOutputFile)
|
|
28
|
+
? relativeOutputFile
|
|
29
|
+
: path.join(projectDir, relativeOutputFile);
|
|
30
|
+
|
|
31
|
+
// Create or clear the hash file
|
|
32
|
+
sbgUtil.writefile(outputFile, "");
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* List of file extensions to include
|
|
36
|
+
* @type {string[]}
|
|
37
|
+
*/
|
|
38
|
+
let extensions = [];
|
|
39
|
+
if (argv.ext) {
|
|
40
|
+
extensions = argv.ext
|
|
41
|
+
.split(",")
|
|
42
|
+
.map((e) => e.trim().replace(/^\./, ""))
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Directories to exclude
|
|
47
|
+
let excludeDirs = [
|
|
48
|
+
"node_modules",
|
|
49
|
+
"vendor",
|
|
50
|
+
"venv",
|
|
51
|
+
".venv",
|
|
52
|
+
".git",
|
|
53
|
+
".hg",
|
|
54
|
+
".svn",
|
|
55
|
+
".idea",
|
|
56
|
+
".vscode",
|
|
57
|
+
"dist",
|
|
58
|
+
"build",
|
|
59
|
+
"out",
|
|
60
|
+
"coverage",
|
|
61
|
+
".DS_Store"
|
|
62
|
+
];
|
|
63
|
+
if (argv.exclude) {
|
|
64
|
+
const userExcludes = argv.exclude
|
|
65
|
+
.split(",")
|
|
66
|
+
.map((d) => d.trim())
|
|
67
|
+
.filter(Boolean);
|
|
68
|
+
if (argv["override-exclude"] || argv.we) {
|
|
69
|
+
// Override the default excludes with user-provided ones
|
|
70
|
+
excludeDirs = userExcludes;
|
|
71
|
+
} else {
|
|
72
|
+
// Append user-provided excludes to the default ones
|
|
73
|
+
excludeDirs = excludeDirs.concat(userExcludes);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Convert excludeDirs into glob ignore patterns
|
|
78
|
+
const ignorePatterns = excludeDirs.map((dir) => `**/${dir}/**`);
|
|
79
|
+
|
|
80
|
+
// Initialize an array to hold the formatted outputs
|
|
81
|
+
let hashArray = [];
|
|
82
|
+
|
|
83
|
+
// Helper function to hash and add file if not already processed
|
|
84
|
+
const processedFiles = new Set();
|
|
85
|
+
/**
|
|
86
|
+
* Hashes a file and pushes its relative path and hash to the hashArray.
|
|
87
|
+
* @param {string} file - The absolute path to the file.
|
|
88
|
+
* @returns {Promise<void>} Resolves when the file has been processed and added to hashArray.
|
|
89
|
+
*/
|
|
90
|
+
async function hashAndPush(file) {
|
|
91
|
+
if (processedFiles.has(file)) return;
|
|
92
|
+
processedFiles.add(file);
|
|
93
|
+
let relativePath = path.relative(projectDir, file);
|
|
94
|
+
relativePath = relativePath.split(path.sep).join("/");
|
|
95
|
+
try {
|
|
96
|
+
const stats = await fs.stat(file);
|
|
97
|
+
const pseudoHash = `${stats.size}-${stats.mtimeMs}`;
|
|
98
|
+
const hash = crypto.createHash("sha256").update(pseudoHash).digest("hex");
|
|
99
|
+
hashArray.push(`${relativePath} ${hash.slice(0, 8)}`);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.error(`Error processing file: ${file}`, err instanceof Error ? err.message : "<unknown error>");
|
|
102
|
+
if (err && err.code === "ENOENT") {
|
|
103
|
+
hashArray.push(`${relativePath} <file not found>`);
|
|
104
|
+
} else {
|
|
105
|
+
hashArray.push(`${relativePath} <error: ${err && err.code ? `code ${err.code}` : "unknown"}>`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Collect all files to process (extensions + special files)
|
|
111
|
+
const initialFiles = [
|
|
112
|
+
path.join(projectDir, "package.json"),
|
|
113
|
+
path.join(projectDir, "composer.json"),
|
|
114
|
+
path.join(projectDir, "requirements.txt")
|
|
115
|
+
];
|
|
116
|
+
let patterns = [];
|
|
117
|
+
if (argv.pattern) {
|
|
118
|
+
if (Array.isArray(argv.pattern)) {
|
|
119
|
+
patterns = argv.pattern.map((p) => p.trim()).filter(Boolean);
|
|
120
|
+
} else {
|
|
121
|
+
patterns = [argv.pattern.trim()];
|
|
122
|
+
}
|
|
123
|
+
} else if (extensions.length === 0) {
|
|
124
|
+
patterns = ["**/*.*"];
|
|
125
|
+
} else {
|
|
126
|
+
patterns = extensions.map((ext) => `**/*.${ext}`);
|
|
127
|
+
}
|
|
128
|
+
const globFiles = glob.sync(patterns.length === 1 ? patterns[0] : `{${patterns.join(",")}}`, {
|
|
129
|
+
cwd: projectDir,
|
|
130
|
+
ignore: ignorePatterns,
|
|
131
|
+
absolute: true,
|
|
132
|
+
nodir: true
|
|
133
|
+
});
|
|
134
|
+
const allFiles = new Set([...initialFiles, ...globFiles]);
|
|
135
|
+
|
|
136
|
+
// Hash all unique files
|
|
137
|
+
await Promise.all(Array.from(allFiles).map(hashAndPush));
|
|
138
|
+
|
|
139
|
+
// Sort the hashArray by file paths
|
|
140
|
+
hashArray.sort((a, b) => a.localeCompare(b));
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Generates a directory/file tree string from a hash array of file paths and hashes.
|
|
144
|
+
*
|
|
145
|
+
* @param {string[]} hashArray - Array of strings in the format 'relative/path/to/file hash'.
|
|
146
|
+
* @returns {string} The directory/file tree as a string, with file hashes.
|
|
147
|
+
*/
|
|
148
|
+
function getFileTreeString(hashArray) {
|
|
149
|
+
const tree = {};
|
|
150
|
+
// Map file paths to hashes for quick lookup
|
|
151
|
+
const hashMap = {};
|
|
152
|
+
for (const entry of hashArray) {
|
|
153
|
+
const [filePath, hash] = entry.split(" ");
|
|
154
|
+
hashMap[filePath] = hash;
|
|
155
|
+
const parts = filePath.split("/");
|
|
156
|
+
let current = tree;
|
|
157
|
+
for (let i = 0; i < parts.length; i++) {
|
|
158
|
+
const part = parts[i];
|
|
159
|
+
if (i === parts.length - 1) {
|
|
160
|
+
current[part] = null; // file
|
|
161
|
+
} else {
|
|
162
|
+
current[part] = current[part] || {};
|
|
163
|
+
current = current[part];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Recursively builds the tree string for a given node.
|
|
169
|
+
*
|
|
170
|
+
* @param {Object} node - The current node in the tree.
|
|
171
|
+
* @param {string} prefix - The prefix for the current tree level.
|
|
172
|
+
* @param {string} parentPath - The path to the current node.
|
|
173
|
+
* @returns {string[]} Array of lines representing the tree structure.
|
|
174
|
+
*/
|
|
175
|
+
function printNode(node, prefix = "", parentPath = "") {
|
|
176
|
+
const keys = Object.keys(node).sort();
|
|
177
|
+
let lines = [];
|
|
178
|
+
keys.forEach((key, idx) => {
|
|
179
|
+
const isLast = idx === keys.length - 1;
|
|
180
|
+
const branch = isLast ? "└── " : "├── ";
|
|
181
|
+
const currentPath = parentPath ? parentPath + "/" + key : key;
|
|
182
|
+
if (node[key] === null) {
|
|
183
|
+
// file: show hash
|
|
184
|
+
lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
|
|
185
|
+
} else {
|
|
186
|
+
lines.push(prefix + branch + key + "/");
|
|
187
|
+
lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "│ "), currentPath));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return lines;
|
|
191
|
+
}
|
|
192
|
+
return printNode(tree, "", "").join("\n");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Write directory/file tree to the output file (hashes are included in the tree)
|
|
196
|
+
const fileTreeString = getFileTreeString(hashArray);
|
|
197
|
+
await fs.writeFile(outputFile, fileTreeString + "\n", "utf-8");
|
|
198
|
+
|
|
199
|
+
// Add the hash file to the commit if --git-add is present
|
|
200
|
+
if (argv["git-add"]) {
|
|
201
|
+
execSync(`git add ${relativeOutputFile}`);
|
|
202
|
+
console.log(`Directory tree written to ${relativeOutputFile} and staged for git.`);
|
|
203
|
+
} else {
|
|
204
|
+
console.log(`Directory tree written to ${relativeOutputFile}.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (argv.help || argv.h) {
|
|
209
|
+
console.log(`
|
|
210
|
+
Usage: node print-directory-tree.cjs [options]
|
|
211
|
+
|
|
212
|
+
Options:
|
|
213
|
+
--output, -o <file> Output file path (default: tmp/directory-structure.txt)
|
|
214
|
+
--ext <exts> Comma-separated list of file extensions (no dot, e.g. js,ts)
|
|
215
|
+
--pattern <glob> Glob pattern(s) for files (can be repeated)
|
|
216
|
+
--exclude <dirs> Comma-separated list of directories to exclude (appends to default)
|
|
217
|
+
--override-exclude, -we Override default exclude directories with --exclude
|
|
218
|
+
--git-add Add output file to git after writing
|
|
219
|
+
--help, -h Show this help message
|
|
220
|
+
|
|
221
|
+
Examples:
|
|
222
|
+
node print-directory-tree.cjs --ext=js,ts
|
|
223
|
+
node print-directory-tree.cjs --pattern=src/**/*.js --pattern=test/**/*.js
|
|
224
|
+
node print-directory-tree.cjs --exclude=dist,build
|
|
225
|
+
node print-directory-tree.cjs --output=tmp/tree.txt
|
|
226
|
+
`);
|
|
227
|
+
process.exit(0);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Execute the main function
|
|
231
|
+
main().catch((err) => {
|
|
232
|
+
console.error(err);
|
|
233
|
+
process.exit(1);
|
|
234
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
require_utils
|
|
4
|
+
} from "./chunk-APBWENF6.mjs";
|
|
5
|
+
import {
|
|
6
|
+
__commonJS,
|
|
7
|
+
__require,
|
|
8
|
+
init_esm_shims
|
|
9
|
+
} from "./chunk-AASHBCRW.mjs";
|
|
10
|
+
|
|
11
|
+
// src/print-directory-tree.cjs
|
|
12
|
+
var require_print_directory_tree = __commonJS({
|
|
13
|
+
"src/print-directory-tree.cjs"() {
|
|
14
|
+
init_esm_shims();
|
|
15
|
+
var fs = __require("fs").promises;
|
|
16
|
+
var path = __require("path");
|
|
17
|
+
var crypto = __require("crypto");
|
|
18
|
+
var { execSync } = __require("child_process");
|
|
19
|
+
var glob = __require("glob");
|
|
20
|
+
var { getArgs } = require_utils();
|
|
21
|
+
var sbgUtil = __require("sbg-utility");
|
|
22
|
+
var dotenv = __require("dotenv");
|
|
23
|
+
var projectDir = process.cwd();
|
|
24
|
+
var envPath = path.join(projectDir, ".env");
|
|
25
|
+
if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
|
|
26
|
+
var argv = getArgs();
|
|
27
|
+
async function main() {
|
|
28
|
+
let relativeOutputFile = "tmp/directory-structure.txt";
|
|
29
|
+
if (argv.output || argv.o) {
|
|
30
|
+
relativeOutputFile = argv.output || argv.o;
|
|
31
|
+
}
|
|
32
|
+
const outputFile = path.isAbsolute(relativeOutputFile) ? relativeOutputFile : path.join(projectDir, relativeOutputFile);
|
|
33
|
+
sbgUtil.writefile(outputFile, "");
|
|
34
|
+
let extensions = [];
|
|
35
|
+
if (argv.ext) {
|
|
36
|
+
extensions = argv.ext.split(",").map((e) => e.trim().replace(/^\./, "")).filter(Boolean);
|
|
37
|
+
}
|
|
38
|
+
let excludeDirs = [
|
|
39
|
+
"node_modules",
|
|
40
|
+
"vendor",
|
|
41
|
+
"venv",
|
|
42
|
+
".venv",
|
|
43
|
+
".git",
|
|
44
|
+
".hg",
|
|
45
|
+
".svn",
|
|
46
|
+
".idea",
|
|
47
|
+
".vscode",
|
|
48
|
+
"dist",
|
|
49
|
+
"build",
|
|
50
|
+
"out",
|
|
51
|
+
"coverage",
|
|
52
|
+
".DS_Store"
|
|
53
|
+
];
|
|
54
|
+
if (argv.exclude) {
|
|
55
|
+
const userExcludes = argv.exclude.split(",").map((d) => d.trim()).filter(Boolean);
|
|
56
|
+
if (argv["override-exclude"] || argv.we) {
|
|
57
|
+
excludeDirs = userExcludes;
|
|
58
|
+
} else {
|
|
59
|
+
excludeDirs = excludeDirs.concat(userExcludes);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const ignorePatterns = excludeDirs.map((dir) => `**/${dir}/**`);
|
|
63
|
+
let hashArray = [];
|
|
64
|
+
const processedFiles = /* @__PURE__ */ new Set();
|
|
65
|
+
async function hashAndPush(file) {
|
|
66
|
+
if (processedFiles.has(file)) return;
|
|
67
|
+
processedFiles.add(file);
|
|
68
|
+
let relativePath = path.relative(projectDir, file);
|
|
69
|
+
relativePath = relativePath.split(path.sep).join("/");
|
|
70
|
+
try {
|
|
71
|
+
const stats = await fs.stat(file);
|
|
72
|
+
const pseudoHash = `${stats.size}-${stats.mtimeMs}`;
|
|
73
|
+
const hash = crypto.createHash("sha256").update(pseudoHash).digest("hex");
|
|
74
|
+
hashArray.push(`${relativePath} ${hash.slice(0, 8)}`);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
console.error(`Error processing file: ${file}`, err instanceof Error ? err.message : "<unknown error>");
|
|
77
|
+
if (err && err.code === "ENOENT") {
|
|
78
|
+
hashArray.push(`${relativePath} <file not found>`);
|
|
79
|
+
} else {
|
|
80
|
+
hashArray.push(`${relativePath} <error: ${err && err.code ? `code ${err.code}` : "unknown"}>`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const initialFiles = [
|
|
85
|
+
path.join(projectDir, "package.json"),
|
|
86
|
+
path.join(projectDir, "composer.json"),
|
|
87
|
+
path.join(projectDir, "requirements.txt")
|
|
88
|
+
];
|
|
89
|
+
let patterns = [];
|
|
90
|
+
if (argv.pattern) {
|
|
91
|
+
if (Array.isArray(argv.pattern)) {
|
|
92
|
+
patterns = argv.pattern.map((p) => p.trim()).filter(Boolean);
|
|
93
|
+
} else {
|
|
94
|
+
patterns = [argv.pattern.trim()];
|
|
95
|
+
}
|
|
96
|
+
} else if (extensions.length === 0) {
|
|
97
|
+
patterns = ["**/*.*"];
|
|
98
|
+
} else {
|
|
99
|
+
patterns = extensions.map((ext) => `**/*.${ext}`);
|
|
100
|
+
}
|
|
101
|
+
const globFiles = glob.sync(patterns.length === 1 ? patterns[0] : `{${patterns.join(",")}}`, {
|
|
102
|
+
cwd: projectDir,
|
|
103
|
+
ignore: ignorePatterns,
|
|
104
|
+
absolute: true,
|
|
105
|
+
nodir: true
|
|
106
|
+
});
|
|
107
|
+
const allFiles = /* @__PURE__ */ new Set([...initialFiles, ...globFiles]);
|
|
108
|
+
await Promise.all(Array.from(allFiles).map(hashAndPush));
|
|
109
|
+
hashArray.sort((a, b) => a.localeCompare(b));
|
|
110
|
+
function getFileTreeString(hashArray2) {
|
|
111
|
+
const tree = {};
|
|
112
|
+
const hashMap = {};
|
|
113
|
+
for (const entry of hashArray2) {
|
|
114
|
+
const [filePath, hash] = entry.split(" ");
|
|
115
|
+
hashMap[filePath] = hash;
|
|
116
|
+
const parts = filePath.split("/");
|
|
117
|
+
let current = tree;
|
|
118
|
+
for (let i = 0; i < parts.length; i++) {
|
|
119
|
+
const part = parts[i];
|
|
120
|
+
if (i === parts.length - 1) {
|
|
121
|
+
current[part] = null;
|
|
122
|
+
} else {
|
|
123
|
+
current[part] = current[part] || {};
|
|
124
|
+
current = current[part];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function printNode(node, prefix = "", parentPath = "") {
|
|
129
|
+
const keys = Object.keys(node).sort();
|
|
130
|
+
let lines = [];
|
|
131
|
+
keys.forEach((key, idx) => {
|
|
132
|
+
const isLast = idx === keys.length - 1;
|
|
133
|
+
const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
134
|
+
const currentPath = parentPath ? parentPath + "/" + key : key;
|
|
135
|
+
if (node[key] === null) {
|
|
136
|
+
lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
|
|
137
|
+
} else {
|
|
138
|
+
lines.push(prefix + branch + key + "/");
|
|
139
|
+
lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "\u2502 "), currentPath));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return lines;
|
|
143
|
+
}
|
|
144
|
+
return printNode(tree, "", "").join("\n");
|
|
145
|
+
}
|
|
146
|
+
const fileTreeString = getFileTreeString(hashArray);
|
|
147
|
+
await fs.writeFile(outputFile, fileTreeString + "\n", "utf-8");
|
|
148
|
+
if (argv["git-add"]) {
|
|
149
|
+
execSync(`git add ${relativeOutputFile}`);
|
|
150
|
+
console.log(`Directory tree written to ${relativeOutputFile} and staged for git.`);
|
|
151
|
+
} else {
|
|
152
|
+
console.log(`Directory tree written to ${relativeOutputFile}.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (argv.help || argv.h) {
|
|
156
|
+
console.log(`
|
|
157
|
+
Usage: node print-directory-tree.cjs [options]
|
|
158
|
+
|
|
159
|
+
Options:
|
|
160
|
+
--output, -o <file> Output file path (default: tmp/directory-structure.txt)
|
|
161
|
+
--ext <exts> Comma-separated list of file extensions (no dot, e.g. js,ts)
|
|
162
|
+
--pattern <glob> Glob pattern(s) for files (can be repeated)
|
|
163
|
+
--exclude <dirs> Comma-separated list of directories to exclude (appends to default)
|
|
164
|
+
--override-exclude, -we Override default exclude directories with --exclude
|
|
165
|
+
--git-add Add output file to git after writing
|
|
166
|
+
--help, -h Show this help message
|
|
167
|
+
|
|
168
|
+
Examples:
|
|
169
|
+
node print-directory-tree.cjs --ext=js,ts
|
|
170
|
+
node print-directory-tree.cjs --pattern=src/**/*.js --pattern=test/**/*.js
|
|
171
|
+
node print-directory-tree.cjs --exclude=dist,build
|
|
172
|
+
node print-directory-tree.cjs --output=tmp/tree.txt
|
|
173
|
+
`);
|
|
174
|
+
process.exit(0);
|
|
175
|
+
}
|
|
176
|
+
main().catch((err) => {
|
|
177
|
+
console.error(err);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
export default require_print_directory_tree();
|
|
File without changes
|