@kokiito0926/fs2xml 0.0.2 → 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/README.md +2 -1
- package/index.js +46 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -29,7 +29,8 @@ $ fs2xml "./src/**/*"
|
|
|
29
29
|
$ fs2xml "./src/**/*.txt"
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
--ignoreのオプションを用いると、特定のパターンを除外することができます。
|
|
32
|
+
--ignoreのオプションを用いると、特定のパターンを除外することができます。
|
|
33
|
+
現状の実装では、現在の作業中のディレクトリの.gitignoreが読み込まれ、そのパターンが自動的に適用されます。
|
|
33
34
|
|
|
34
35
|
```bash
|
|
35
36
|
$ fs2xml "./src/**/*" --ignore "./src/test/**" --ignore "**/*.log"
|
package/index.js
CHANGED
|
@@ -8,19 +8,64 @@
|
|
|
8
8
|
|
|
9
9
|
import { fs, path, minimist, glob } from "zx";
|
|
10
10
|
import { create } from "xmlbuilder2";
|
|
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
|
+
}
|
|
11
46
|
|
|
12
47
|
const args = minimist(process.argv.slice(2));
|
|
13
48
|
const target = args._[0] || "**/*";
|
|
14
49
|
|
|
50
|
+
const { ig, baseDir } = await loadNearestGitignore(target);
|
|
51
|
+
|
|
52
|
+
// const defaultIgnore = [];
|
|
15
53
|
const defaultIgnore = ["node_modules/**", ".git/**"];
|
|
16
54
|
|
|
17
55
|
const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
|
|
18
56
|
|
|
19
57
|
const ignorePatterns = [...defaultIgnore, ...userIgnore].filter(Boolean);
|
|
20
58
|
|
|
21
|
-
|
|
59
|
+
let files = await glob(target, {
|
|
22
60
|
ignore: ignorePatterns,
|
|
23
61
|
nodir: true,
|
|
62
|
+
dot: true,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
files = files.filter((file) => {
|
|
66
|
+
const relativePath = path.relative(baseDir, path.resolve(file));
|
|
67
|
+
if (relativePath === "") return true;
|
|
68
|
+
return !ig.ignores(relativePath);
|
|
24
69
|
});
|
|
25
70
|
|
|
26
71
|
async function getFileData(filePath) {
|
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,8 @@
|
|
|
34
34
|
"test": "node --test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"glob-parent": "^6.0.2",
|
|
38
|
+
"ignore": "^7.0.5",
|
|
37
39
|
"xmlbuilder2": "^4.0.3",
|
|
38
40
|
"zx": "^8.8.4"
|
|
39
41
|
},
|