@kokiito0926/fs2xml 0.0.9 → 0.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.
- package/index.js +19 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { fs, path,
|
|
3
|
+
import { fs, path, argv, glob } from "zx";
|
|
4
4
|
import ignore from "ignore";
|
|
5
5
|
import globParent from "glob-parent";
|
|
6
6
|
import xml2js from "xml2js";
|
|
7
7
|
|
|
8
|
+
function isBinary(buffer) {
|
|
9
|
+
for (let i = 0; i < Math.min(buffer.length, 4096); i++) {
|
|
10
|
+
if (buffer[i] === 0) return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
async function loadNearestGitignore(targetPattern) {
|
|
9
16
|
const ig = ignore();
|
|
10
17
|
|
|
@@ -36,17 +43,16 @@ async function loadNearestGitignore(targetPattern) {
|
|
|
36
43
|
return { ig, baseDir: process.cwd() };
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const gitignore = args.gitignore || true;
|
|
46
|
+
const target = argv?._[0] || "**/*";
|
|
47
|
+
const dot = argv?.dot || false;
|
|
48
|
+
const gitignore = argv?.gitignore || true;
|
|
43
49
|
|
|
44
50
|
const { ig, baseDir } =
|
|
45
51
|
gitignore == false ? { ig: ignore(), baseDir: process.cwd() } : await loadNearestGitignore(target);
|
|
46
52
|
|
|
47
53
|
const defaultIgnore = [];
|
|
48
54
|
|
|
49
|
-
const userIgnore =
|
|
55
|
+
const userIgnore = argv.ignore ? (Array.isArray(argv.ignore) ? argv.ignore : [argv.ignore]) : [];
|
|
50
56
|
|
|
51
57
|
const ignorePatterns = [...defaultIgnore, ...userIgnore].filter(Boolean);
|
|
52
58
|
|
|
@@ -63,7 +69,13 @@ files = files.filter((file) => {
|
|
|
63
69
|
});
|
|
64
70
|
|
|
65
71
|
async function getFileData(filePath) {
|
|
66
|
-
|
|
72
|
+
const buffer = await fs.readFile(filePath);
|
|
73
|
+
if (isBinary(buffer)) {
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let content = buffer.toString("utf8");
|
|
78
|
+
// let content = await fs.readFile(filePath, "utf8");
|
|
67
79
|
if (!content) return null;
|
|
68
80
|
|
|
69
81
|
content = content.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
|