@kokiito0926/fs2xml 0.0.1 → 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.
- package/README.md +38 -5
- package/index.js +41 -24
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
## fs2xml
|
|
2
2
|
|
|
3
|
-
fs2xml
|
|
4
|
-
ファイルをXML
|
|
3
|
+
fs2xmlは、ファイルをXML形式でまとめることができます。
|
|
4
|
+
ファイルをXML形式でまとめるようにすると、大規模言語モデルに与えやすくなります。
|
|
5
5
|
|
|
6
6
|
## インストール
|
|
7
7
|
|
|
@@ -9,11 +9,44 @@ fs2xmlを用いれば、ファイルをXML形式でまとめることができ
|
|
|
9
9
|
$ npm install --global @kokiito0926/fs2xml
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## 使用方法
|
|
13
|
+
|
|
14
|
+
カレントディレクトリ内のすべてのファイルをXML形式でまとめます。
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
$ fs2xml
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
特定のディレクトリ内のすべてのファイルをXML形式でまとめます。
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ fs2xml "./src/**/*"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
特定のディレクトリ内の特定の拡張子のみを対象にして、XML形式でまとめます。
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
$ fs2xml "./src/**/*.txt"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
--ignoreのオプションを用いると、特定のパターンを除外することができます。
|
|
33
|
+
現状の実装では、現在の作業中のディレクトリの.gitignoreが読み込まれ、そのパターンが自動的に適用されます。
|
|
13
34
|
|
|
14
35
|
```bash
|
|
15
|
-
$ fs2xml
|
|
16
|
-
|
|
36
|
+
$ fs2xml "./src/**/*" --ignore "./src/test/**" --ignore "**/*.log"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 出力例
|
|
40
|
+
|
|
41
|
+
```xml
|
|
42
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
43
|
+
<files>
|
|
44
|
+
<file>
|
|
45
|
+
<name>example.js</name>
|
|
46
|
+
<path>src/example.js</path>
|
|
47
|
+
<content>console.log("Hello world!");</content>
|
|
48
|
+
</file>
|
|
49
|
+
</files>
|
|
17
50
|
```
|
|
18
51
|
|
|
19
52
|
## ライセンス
|
package/index.js
CHANGED
|
@@ -1,13 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// >> $ ./index.js
|
|
4
|
-
// >> $ ./index.js
|
|
3
|
+
// >> $ ./index.js "./example/example.txt"
|
|
4
|
+
// >> $ ./index.js "./example/sub/example.js"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// >> $ ./index.js "./example/**/*.txt"
|
|
7
|
+
// >> $ ./index.js "./example/**/*.txt" --ignore "./example/ignore/**"
|
|
8
|
+
|
|
9
|
+
import { fs, path, minimist, glob } from "zx";
|
|
7
10
|
import { create } from "xmlbuilder2";
|
|
11
|
+
import ignore from "ignore";
|
|
8
12
|
|
|
9
13
|
const args = minimist(process.argv.slice(2));
|
|
10
|
-
const target = args._[0] || "
|
|
14
|
+
const target = args._[0] || "**/*";
|
|
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
|
+
|
|
23
|
+
const defaultIgnore = ["node_modules/**", ".git/**"];
|
|
24
|
+
|
|
25
|
+
const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
|
|
26
|
+
|
|
27
|
+
const ignorePatterns = [...defaultIgnore, ...userIgnore].filter(Boolean);
|
|
28
|
+
|
|
29
|
+
let files = await glob(target, {
|
|
30
|
+
ignore: ignorePatterns,
|
|
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);
|
|
39
|
+
});
|
|
11
40
|
|
|
12
41
|
async function getFileData(filePath) {
|
|
13
42
|
let content = await fs.readFile(filePath, "utf8");
|
|
@@ -23,17 +52,15 @@ async function getFileData(filePath) {
|
|
|
23
52
|
};
|
|
24
53
|
}
|
|
25
54
|
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
process.exit(
|
|
55
|
+
if (files.length === 0) {
|
|
56
|
+
process.stderr.write(`No files matched the pattern: ${pattern}\n`);
|
|
57
|
+
process.exit(0);
|
|
29
58
|
}
|
|
30
59
|
|
|
31
|
-
const stats = await fs.stat(target);
|
|
32
|
-
|
|
33
60
|
let xmlOutput = "";
|
|
34
61
|
|
|
35
|
-
if (
|
|
36
|
-
const data = await getFileData(
|
|
62
|
+
if (files.length === 1) {
|
|
63
|
+
const data = await getFileData(files[0]);
|
|
37
64
|
if (!data) {
|
|
38
65
|
process.exit(1);
|
|
39
66
|
}
|
|
@@ -48,24 +75,13 @@ if (stats.isFile()) {
|
|
|
48
75
|
.up()
|
|
49
76
|
.ele("content")
|
|
50
77
|
.txt(data.content)
|
|
78
|
+
// .dat(data.content)
|
|
51
79
|
.up()
|
|
52
80
|
.end({ prettyPrint: true });
|
|
53
81
|
} else {
|
|
54
|
-
const files = await fs.readdir(target, { recursive: true });
|
|
55
|
-
if (!files.length) {
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
58
|
-
// console.log(files);
|
|
59
|
-
|
|
60
82
|
const allFiles = [];
|
|
61
83
|
for (const file of files) {
|
|
62
|
-
const
|
|
63
|
-
const fStats = await fs.stat(filePath);
|
|
64
|
-
if (fStats.isDirectory()) continue;
|
|
65
|
-
|
|
66
|
-
// console.error(file);
|
|
67
|
-
|
|
68
|
-
const fileData = await getFileData(filePath);
|
|
84
|
+
const fileData = await getFileData(file);
|
|
69
85
|
if (!fileData) continue;
|
|
70
86
|
|
|
71
87
|
allFiles.push(fileData);
|
|
@@ -86,6 +102,7 @@ if (stats.isFile()) {
|
|
|
86
102
|
.up()
|
|
87
103
|
.ele("content")
|
|
88
104
|
.txt(f.content)
|
|
105
|
+
// .dat(f.content)
|
|
89
106
|
.up()
|
|
90
107
|
.up();
|
|
91
108
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokiito0926/fs2xml",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "ファイルをXML形式でまとめることができます。",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cli",
|
|
8
8
|
"bash",
|
|
@@ -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
|
},
|