@kokiito0926/fs2xml 0.0.2 → 0.0.3

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 (3) hide show
  1. package/README.md +2 -1
  2. package/index.js +16 -1
  3. package/package.json +2 -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,34 @@
8
8
 
9
9
  import { fs, path, minimist, glob } from "zx";
10
10
  import { create } from "xmlbuilder2";
11
+ import ignore from "ignore";
11
12
 
12
13
  const args = minimist(process.argv.slice(2));
13
14
  const target = args._[0] || "**/*";
14
15
 
16
+ let ig = ignore();
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
+ }
22
+
15
23
  const defaultIgnore = ["node_modules/**", ".git/**"];
16
24
 
17
25
  const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
18
26
 
19
27
  const ignorePatterns = [...defaultIgnore, ...userIgnore].filter(Boolean);
20
28
 
21
- const files = await glob(target, {
29
+ let files = await glob(target, {
22
30
  ignore: ignorePatterns,
23
31
  nodir: true,
32
+ dot: true,
33
+ });
34
+
35
+ files = files.filter((file) => {
36
+ const relativePath = path.relative(process.cwd(), file);
37
+ if (relativePath === "") return true;
38
+ return !ig.ignores(relativePath);
24
39
  });
25
40
 
26
41
  async function getFileData(filePath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokiito0926/fs2xml",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
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
+ "ignore": "^7.0.5",
37
38
  "xmlbuilder2": "^4.0.3",
38
39
  "zx": "^8.8.4"
39
40
  },