@kokiito0926/fs2xml 0.0.0 → 0.0.2
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 +47 -2
- package/index.js +26 -24
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,52 @@
|
|
|
1
1
|
## fs2xml
|
|
2
2
|
|
|
3
|
-
fs2xml
|
|
4
|
-
ファイルをXML
|
|
3
|
+
fs2xmlは、ファイルをXML形式でまとめることができます。
|
|
4
|
+
ファイルをXML形式でまとめるようにすると、大規模言語モデルに与えやすくなります。
|
|
5
|
+
|
|
6
|
+
## インストール
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
$ npm install --global @kokiito0926/fs2xml
|
|
10
|
+
```
|
|
11
|
+
|
|
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
|
+
|
|
34
|
+
```bash
|
|
35
|
+
$ fs2xml "./src/**/*" --ignore "./src/test/**" --ignore "**/*.log"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 出力例
|
|
39
|
+
|
|
40
|
+
```xml
|
|
41
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
42
|
+
<files>
|
|
43
|
+
<file>
|
|
44
|
+
<name>example.js</name>
|
|
45
|
+
<path>src/example.js</path>
|
|
46
|
+
<content>console.log("Hello world!");</content>
|
|
47
|
+
</file>
|
|
48
|
+
</files>
|
|
49
|
+
```
|
|
5
50
|
|
|
6
51
|
## ライセンス
|
|
7
52
|
|
package/index.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
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";
|
|
8
11
|
|
|
9
12
|
const args = minimist(process.argv.slice(2));
|
|
10
|
-
const target = args._[0] || "
|
|
13
|
+
const target = args._[0] || "**/*";
|
|
14
|
+
|
|
15
|
+
const defaultIgnore = ["node_modules/**", ".git/**"];
|
|
16
|
+
|
|
17
|
+
const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
|
|
18
|
+
|
|
19
|
+
const ignorePatterns = [...defaultIgnore, ...userIgnore].filter(Boolean);
|
|
20
|
+
|
|
21
|
+
const files = await glob(target, {
|
|
22
|
+
ignore: ignorePatterns,
|
|
23
|
+
nodir: true,
|
|
24
|
+
});
|
|
11
25
|
|
|
12
26
|
async function getFileData(filePath) {
|
|
13
27
|
let content = await fs.readFile(filePath, "utf8");
|
|
@@ -23,17 +37,15 @@ async function getFileData(filePath) {
|
|
|
23
37
|
};
|
|
24
38
|
}
|
|
25
39
|
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
process.exit(
|
|
40
|
+
if (files.length === 0) {
|
|
41
|
+
process.stderr.write(`No files matched the pattern: ${pattern}\n`);
|
|
42
|
+
process.exit(0);
|
|
29
43
|
}
|
|
30
44
|
|
|
31
|
-
const stats = await fs.stat(target);
|
|
32
|
-
|
|
33
45
|
let xmlOutput = "";
|
|
34
46
|
|
|
35
|
-
if (
|
|
36
|
-
const data = await getFileData(
|
|
47
|
+
if (files.length === 1) {
|
|
48
|
+
const data = await getFileData(files[0]);
|
|
37
49
|
if (!data) {
|
|
38
50
|
process.exit(1);
|
|
39
51
|
}
|
|
@@ -48,24 +60,13 @@ if (stats.isFile()) {
|
|
|
48
60
|
.up()
|
|
49
61
|
.ele("content")
|
|
50
62
|
.txt(data.content)
|
|
63
|
+
// .dat(data.content)
|
|
51
64
|
.up()
|
|
52
65
|
.end({ prettyPrint: true });
|
|
53
66
|
} 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
67
|
const allFiles = [];
|
|
61
68
|
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);
|
|
69
|
+
const fileData = await getFileData(file);
|
|
69
70
|
if (!fileData) continue;
|
|
70
71
|
|
|
71
72
|
allFiles.push(fileData);
|
|
@@ -86,6 +87,7 @@ if (stats.isFile()) {
|
|
|
86
87
|
.up()
|
|
87
88
|
.ele("content")
|
|
88
89
|
.txt(f.content)
|
|
90
|
+
// .dat(f.content)
|
|
89
91
|
.up()
|
|
90
92
|
.up();
|
|
91
93
|
}
|
package/package.json
CHANGED