@kokiito0926/fs2xml 0.0.6 → 0.0.8
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 -2
- package/index.js +36 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -44,10 +44,10 @@ $ fs2xml "./src/**/*" --dot true
|
|
|
44
44
|
|
|
45
45
|
デフォルトでは、自動的に.gitignoreが読み込まれるようになっております。
|
|
46
46
|
globのパターンの親ディレクトリから、現在の作業中のディレクトリまでさかのぼり、.gitignoreが探索されます。
|
|
47
|
-
--gitignore
|
|
47
|
+
--gitignoreのオプションにfalseを渡すようにすれば、そのような挙動を無効化することができます。
|
|
48
48
|
|
|
49
49
|
```bash
|
|
50
|
-
$ fs2xml "./src/**/*" --gitignore
|
|
50
|
+
$ fs2xml "./src/**/*" --gitignore false
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
## 出力例
|
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { fs, path, minimist, glob } from "zx";
|
|
|
10
10
|
import { create } from "xmlbuilder2";
|
|
11
11
|
import ignore from "ignore";
|
|
12
12
|
import globParent from "glob-parent";
|
|
13
|
+
import xml2js from "xml2js";
|
|
13
14
|
|
|
14
15
|
async function loadNearestGitignore(targetPattern) {
|
|
15
16
|
const ig = ignore();
|
|
@@ -91,6 +92,14 @@ if (files.length === 0) {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
let xmlOutput = "";
|
|
95
|
+
let xmlObject = {};
|
|
96
|
+
|
|
97
|
+
const builder = new xml2js.Builder({
|
|
98
|
+
cdata: true,
|
|
99
|
+
xmldec: { version: "1.0", encoding: "UTF-8" },
|
|
100
|
+
renderOpts: { pretty: true },
|
|
101
|
+
// renderOpts: { pretty: true, indent: " ", newline: "\n" },
|
|
102
|
+
});
|
|
94
103
|
|
|
95
104
|
if (files.length === 1) {
|
|
96
105
|
const data = await getFileData(files[0]);
|
|
@@ -98,6 +107,15 @@ if (files.length === 1) {
|
|
|
98
107
|
process.exit(1);
|
|
99
108
|
}
|
|
100
109
|
|
|
110
|
+
xmlObject = {
|
|
111
|
+
file: {
|
|
112
|
+
name: data.name,
|
|
113
|
+
path: data.path,
|
|
114
|
+
content: data.content,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/*
|
|
101
119
|
xmlOutput = create({ version: "1.0", encoding: "UTF-8" })
|
|
102
120
|
.ele("file")
|
|
103
121
|
.ele("name")
|
|
@@ -107,10 +125,11 @@ if (files.length === 1) {
|
|
|
107
125
|
.txt(data.path)
|
|
108
126
|
.up()
|
|
109
127
|
.ele("content")
|
|
110
|
-
.txt(data.content)
|
|
111
|
-
|
|
128
|
+
// .txt(data.content)
|
|
129
|
+
.dat(data.content)
|
|
112
130
|
.up()
|
|
113
131
|
.end({ prettyPrint: true });
|
|
132
|
+
*/
|
|
114
133
|
} else {
|
|
115
134
|
const allFiles = [];
|
|
116
135
|
for (const file of files) {
|
|
@@ -124,6 +143,17 @@ if (files.length === 1) {
|
|
|
124
143
|
}
|
|
125
144
|
// console.log(allFiles);
|
|
126
145
|
|
|
146
|
+
xmlObject = {
|
|
147
|
+
files: {
|
|
148
|
+
file: allFiles.map((f) => ({
|
|
149
|
+
name: f.name,
|
|
150
|
+
path: f.path,
|
|
151
|
+
content: f.content,
|
|
152
|
+
})),
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/*
|
|
127
157
|
const root = create({ version: "1.0", encoding: "UTF-8" }).ele("files");
|
|
128
158
|
for (const f of allFiles) {
|
|
129
159
|
root.ele("file")
|
|
@@ -134,12 +164,14 @@ if (files.length === 1) {
|
|
|
134
164
|
.txt(f.path)
|
|
135
165
|
.up()
|
|
136
166
|
.ele("content")
|
|
137
|
-
.txt(f.content)
|
|
138
|
-
|
|
167
|
+
// .txt(f.content)
|
|
168
|
+
.dat(f.content)
|
|
139
169
|
.up()
|
|
140
170
|
.up();
|
|
141
171
|
}
|
|
142
172
|
xmlOutput = root.end({ prettyPrint: true });
|
|
173
|
+
*/
|
|
143
174
|
}
|
|
144
175
|
|
|
176
|
+
xmlOutput = builder.buildObject(xmlObject);
|
|
145
177
|
console.log(xmlOutput);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokiito0926/fs2xml",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ファイルをXML形式でまとめることができるコマンドラインのツールです。",
|
|
6
6
|
"keywords": [
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"glob-parent": "^6.0.2",
|
|
38
38
|
"ignore": "^7.0.5",
|
|
39
|
+
"xml2js": "^0.6.2",
|
|
39
40
|
"xmlbuilder2": "^4.0.3",
|
|
40
41
|
"zx": "^8.8.4"
|
|
41
42
|
},
|