@kokiito0926/fs2xml 0.0.3 → 0.0.4
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 +37 -7
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -9,17 +9,47 @@
|
|
|
9
9
|
import { fs, path, minimist, glob } from "zx";
|
|
10
10
|
import { create } from "xmlbuilder2";
|
|
11
11
|
import ignore from "ignore";
|
|
12
|
+
import globParent from "glob-parent";
|
|
13
|
+
|
|
14
|
+
async function loadNearestGitignore(targetPattern) {
|
|
15
|
+
const ig = ignore();
|
|
16
|
+
|
|
17
|
+
const parentDir = globParent(targetPattern);
|
|
18
|
+
let currentDir = path.resolve(parentDir);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const stats = await fs.stat(currentDir);
|
|
22
|
+
if (stats.isFile()) {
|
|
23
|
+
currentDir = path.dirname(currentDir);
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {}
|
|
26
|
+
|
|
27
|
+
while (true) {
|
|
28
|
+
const gitignorePath = path.join(currentDir, ".gitignore");
|
|
29
|
+
|
|
30
|
+
if (fs.existsSync(gitignorePath)) {
|
|
31
|
+
// console.log(gitignorePath);
|
|
32
|
+
|
|
33
|
+
const content = await fs.readFile(gitignorePath, "utf8");
|
|
34
|
+
ig.add(content);
|
|
35
|
+
|
|
36
|
+
return { ig, baseDir: currentDir };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const parent = path.dirname(currentDir);
|
|
40
|
+
if (parent === currentDir) break;
|
|
41
|
+
currentDir = parent;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { ig, baseDir: process.cwd() };
|
|
45
|
+
}
|
|
12
46
|
|
|
13
47
|
const args = minimist(process.argv.slice(2));
|
|
14
48
|
const target = args._[0] || "**/*";
|
|
15
49
|
|
|
16
|
-
|
|
17
|
-
const gitignorePath = path.join(process.cwd(), ".gitignore");
|
|
18
|
-
if (fs.existsSync(gitignorePath)) {
|
|
19
|
-
const gitignoreContent = await fs.readFile(gitignorePath, "utf8");
|
|
20
|
-
ig.add(gitignoreContent);
|
|
21
|
-
}
|
|
50
|
+
const { ig, baseDir } = await loadNearestGitignore(target);
|
|
22
51
|
|
|
52
|
+
// const defaultIgnore = [];
|
|
23
53
|
const defaultIgnore = ["node_modules/**", ".git/**"];
|
|
24
54
|
|
|
25
55
|
const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
|
|
@@ -33,7 +63,7 @@ let files = await glob(target, {
|
|
|
33
63
|
});
|
|
34
64
|
|
|
35
65
|
files = files.filter((file) => {
|
|
36
|
-
const relativePath = path.relative(
|
|
66
|
+
const relativePath = path.relative(baseDir, path.resolve(file));
|
|
37
67
|
if (relativePath === "") return true;
|
|
38
68
|
return !ig.ignores(relativePath);
|
|
39
69
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokiito0926/fs2xml",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ファイルをXML形式でまとめることができます。",
|
|
6
6
|
"keywords": [
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"test": "node --test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"glob-parent": "^6.0.2",
|
|
37
38
|
"ignore": "^7.0.5",
|
|
38
39
|
"xmlbuilder2": "^4.0.3",
|
|
39
40
|
"zx": "^8.8.4"
|