@kokiito0926/fs2xml 0.0.3 → 0.0.5
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/aaaa.xml +452 -0
- package/index.js +42 -9
- package/package.json +2 -1
package/aaaa.xml
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<files>
|
|
3
|
+
<file>
|
|
4
|
+
<name>index.js</name>
|
|
5
|
+
<path>index.js</path>
|
|
6
|
+
<content>#!/usr/bin/env node
|
|
7
|
+
|
|
8
|
+
// >> $ ./index.js "./example/example.txt"
|
|
9
|
+
// >> $ ./index.js "./example/sub/example.js"
|
|
10
|
+
|
|
11
|
+
// >> $ ./index.js "./example/**/*.txt"
|
|
12
|
+
// >> $ ./index.js "./example/**/*.txt" --ignore "./example/ignore/**"
|
|
13
|
+
|
|
14
|
+
import { fs, path, minimist, glob } from "zx";
|
|
15
|
+
import { create } from "xmlbuilder2";
|
|
16
|
+
import ignore from "ignore";
|
|
17
|
+
import globParent from "glob-parent";
|
|
18
|
+
|
|
19
|
+
async function loadNearestGitignore(targetPattern) {
|
|
20
|
+
const ig = ignore();
|
|
21
|
+
|
|
22
|
+
const parentDir = globParent(targetPattern);
|
|
23
|
+
let currentDir = path.resolve(parentDir);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const stats = await fs.stat(currentDir);
|
|
27
|
+
if (stats.isFile()) {
|
|
28
|
+
currentDir = path.dirname(currentDir);
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {}
|
|
31
|
+
|
|
32
|
+
while (true) {
|
|
33
|
+
const gitignorePath = path.join(currentDir, ".gitignore");
|
|
34
|
+
|
|
35
|
+
if (fs.existsSync(gitignorePath)) {
|
|
36
|
+
// console.log(gitignorePath);
|
|
37
|
+
|
|
38
|
+
const content = await fs.readFile(gitignorePath, "utf8");
|
|
39
|
+
ig.add(content);
|
|
40
|
+
|
|
41
|
+
return { ig, baseDir: currentDir };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const parent = path.dirname(currentDir);
|
|
45
|
+
if (parent === currentDir) break;
|
|
46
|
+
currentDir = parent;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { ig, baseDir: process.cwd() };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const args = minimist(process.argv.slice(2));
|
|
53
|
+
const target = args._[0] || "**/*";
|
|
54
|
+
const dot = args.dot || false;
|
|
55
|
+
const gitignore = args.gitignore || true;
|
|
56
|
+
|
|
57
|
+
const { ig, baseDir } =
|
|
58
|
+
gitignore == false ? { ig: ignore(), baseDir: process.cwd() } : await loadNearestGitignore(target);
|
|
59
|
+
|
|
60
|
+
const defaultIgnore = [];
|
|
61
|
+
// const defaultIgnore = ["node_modules/**", ".git/**"];
|
|
62
|
+
|
|
63
|
+
const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
|
|
64
|
+
|
|
65
|
+
const ignorePatterns = [...defaultIgnore, ...userIgnore].filter(Boolean);
|
|
66
|
+
|
|
67
|
+
let files = await glob(target, {
|
|
68
|
+
ignore: ignorePatterns,
|
|
69
|
+
nodir: true,
|
|
70
|
+
dot: dot,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
files = files.filter((file) => {
|
|
74
|
+
const relativePath = path.relative(baseDir, path.resolve(file));
|
|
75
|
+
if (relativePath === "") return true;
|
|
76
|
+
return !ig.ignores(relativePath);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
async function getFileData(filePath) {
|
|
80
|
+
let content = await fs.readFile(filePath, "utf8");
|
|
81
|
+
if (!content) return null;
|
|
82
|
+
|
|
83
|
+
content = content.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
|
|
84
|
+
if (!content) return null;
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
name: path.basename(filePath),
|
|
88
|
+
path: filePath.replace(/\\/g, "/"),
|
|
89
|
+
content: content,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (files.length === 0) {
|
|
94
|
+
process.stderr.write(`No files matched the pattern: ${pattern}\n`);
|
|
95
|
+
process.exit(0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let xmlOutput = "";
|
|
99
|
+
|
|
100
|
+
if (files.length === 1) {
|
|
101
|
+
const data = await getFileData(files[0]);
|
|
102
|
+
if (!data) {
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
xmlOutput = create({ version: "1.0", encoding: "UTF-8" })
|
|
107
|
+
.ele("file")
|
|
108
|
+
.ele("name")
|
|
109
|
+
.txt(data.name)
|
|
110
|
+
.up()
|
|
111
|
+
.ele("path")
|
|
112
|
+
.txt(data.path)
|
|
113
|
+
.up()
|
|
114
|
+
.ele("content")
|
|
115
|
+
.txt(data.content)
|
|
116
|
+
// .dat(data.content)
|
|
117
|
+
.up()
|
|
118
|
+
.end({ prettyPrint: true });
|
|
119
|
+
} else {
|
|
120
|
+
const allFiles = [];
|
|
121
|
+
for (const file of files) {
|
|
122
|
+
const fileData = await getFileData(file);
|
|
123
|
+
if (!fileData) continue;
|
|
124
|
+
|
|
125
|
+
allFiles.push(fileData);
|
|
126
|
+
}
|
|
127
|
+
if (!allFiles.length) {
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
// console.log(allFiles);
|
|
131
|
+
|
|
132
|
+
const root = create({ version: "1.0", encoding: "UTF-8" }).ele("files");
|
|
133
|
+
for (const f of allFiles) {
|
|
134
|
+
root.ele("file")
|
|
135
|
+
.ele("name")
|
|
136
|
+
.txt(f.name)
|
|
137
|
+
.up()
|
|
138
|
+
.ele("path")
|
|
139
|
+
.txt(f.path)
|
|
140
|
+
.up()
|
|
141
|
+
.ele("content")
|
|
142
|
+
.txt(f.content)
|
|
143
|
+
// .dat(f.content)
|
|
144
|
+
.up()
|
|
145
|
+
.up();
|
|
146
|
+
}
|
|
147
|
+
xmlOutput = root.end({ prettyPrint: true });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
console.log(xmlOutput);
|
|
151
|
+
</content>
|
|
152
|
+
</file>
|
|
153
|
+
<file>
|
|
154
|
+
<name>LICENSE</name>
|
|
155
|
+
<path>LICENSE</path>
|
|
156
|
+
<content>MIT License
|
|
157
|
+
|
|
158
|
+
Copyright (c) 2026 Koki Ito
|
|
159
|
+
|
|
160
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
161
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
162
|
+
in the Software without restriction, including without limitation the rights
|
|
163
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
164
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
165
|
+
furnished to do so, subject to the following conditions:
|
|
166
|
+
|
|
167
|
+
The above copyright notice and this permission notice shall be included in all
|
|
168
|
+
copies or substantial portions of the Software.
|
|
169
|
+
|
|
170
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
171
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
172
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
173
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
174
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
175
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
176
|
+
SOFTWARE.</content>
|
|
177
|
+
</file>
|
|
178
|
+
<file>
|
|
179
|
+
<name>package-lock.json</name>
|
|
180
|
+
<path>package-lock.json</path>
|
|
181
|
+
<content>{
|
|
182
|
+
"name": "@kokiito0926/fs2xml",
|
|
183
|
+
"version": "0.0.4",
|
|
184
|
+
"lockfileVersion": 3,
|
|
185
|
+
"requires": true,
|
|
186
|
+
"packages": {
|
|
187
|
+
"": {
|
|
188
|
+
"name": "@kokiito0926/fs2xml",
|
|
189
|
+
"version": "0.0.4",
|
|
190
|
+
"license": "MIT",
|
|
191
|
+
"dependencies": {
|
|
192
|
+
"glob-parent": "^6.0.2",
|
|
193
|
+
"ignore": "^7.0.5",
|
|
194
|
+
"xmlbuilder2": "^4.0.3",
|
|
195
|
+
"zx": "^8.8.4"
|
|
196
|
+
},
|
|
197
|
+
"bin": {
|
|
198
|
+
"fs2xml": "index.js"
|
|
199
|
+
},
|
|
200
|
+
"engines": {
|
|
201
|
+
"node": ">=24.0.0"
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
"node_modules/@oozcitak/dom": {
|
|
205
|
+
"version": "2.0.2",
|
|
206
|
+
"resolved": "https://registry.npmjs.org/@oozcitak/dom/-/dom-2.0.2.tgz",
|
|
207
|
+
"integrity": "sha512-GjpKhkSYC3Mj4+lfwEyI1dqnsKTgwGy48ytZEhm4A/xnH/8z9M3ZVXKr/YGQi3uCLs1AEBS+x5T2JPiueEDW8w==",
|
|
208
|
+
"license": "MIT",
|
|
209
|
+
"dependencies": {
|
|
210
|
+
"@oozcitak/infra": "^2.0.2",
|
|
211
|
+
"@oozcitak/url": "^3.0.0",
|
|
212
|
+
"@oozcitak/util": "^10.0.0"
|
|
213
|
+
},
|
|
214
|
+
"engines": {
|
|
215
|
+
"node": ">=20.0"
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
"node_modules/@oozcitak/infra": {
|
|
219
|
+
"version": "2.0.2",
|
|
220
|
+
"resolved": "https://registry.npmjs.org/@oozcitak/infra/-/infra-2.0.2.tgz",
|
|
221
|
+
"integrity": "sha512-2g+E7hoE2dgCz/APPOEK5s3rMhJvNxSMBrP+U+j1OWsIbtSpWxxlUjq1lU8RIsFJNYv7NMlnVsCuHcUzJW+8vA==",
|
|
222
|
+
"license": "MIT",
|
|
223
|
+
"dependencies": {
|
|
224
|
+
"@oozcitak/util": "^10.0.0"
|
|
225
|
+
},
|
|
226
|
+
"engines": {
|
|
227
|
+
"node": ">=20.0"
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
"node_modules/@oozcitak/url": {
|
|
231
|
+
"version": "3.0.0",
|
|
232
|
+
"resolved": "https://registry.npmjs.org/@oozcitak/url/-/url-3.0.0.tgz",
|
|
233
|
+
"integrity": "sha512-ZKfET8Ak1wsLAiLWNfFkZc/BraDccuTJKR6svTYc7sVjbR+Iu0vtXdiDMY4o6jaFl5TW2TlS7jbLl4VovtAJWQ==",
|
|
234
|
+
"license": "MIT",
|
|
235
|
+
"dependencies": {
|
|
236
|
+
"@oozcitak/infra": "^2.0.2",
|
|
237
|
+
"@oozcitak/util": "^10.0.0"
|
|
238
|
+
},
|
|
239
|
+
"engines": {
|
|
240
|
+
"node": ">=20.0"
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
"node_modules/@oozcitak/util": {
|
|
244
|
+
"version": "10.0.0",
|
|
245
|
+
"resolved": "https://registry.npmjs.org/@oozcitak/util/-/util-10.0.0.tgz",
|
|
246
|
+
"integrity": "sha512-hAX0pT/73190NLqBPPWSdBVGtbY6VOhWYK3qqHqtXQ1gK7kS2yz4+ivsN07hpJ6I3aeMtKP6J6npsEKOAzuTLA==",
|
|
247
|
+
"license": "MIT",
|
|
248
|
+
"engines": {
|
|
249
|
+
"node": ">=20.0"
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
"node_modules/argparse": {
|
|
253
|
+
"version": "2.0.1",
|
|
254
|
+
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
|
255
|
+
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
|
256
|
+
"license": "Python-2.0"
|
|
257
|
+
},
|
|
258
|
+
"node_modules/glob-parent": {
|
|
259
|
+
"version": "6.0.2",
|
|
260
|
+
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",
|
|
261
|
+
"integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==",
|
|
262
|
+
"license": "ISC",
|
|
263
|
+
"dependencies": {
|
|
264
|
+
"is-glob": "^4.0.3"
|
|
265
|
+
},
|
|
266
|
+
"engines": {
|
|
267
|
+
"node": ">=10.13.0"
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
"node_modules/ignore": {
|
|
271
|
+
"version": "7.0.5",
|
|
272
|
+
"resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz",
|
|
273
|
+
"integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==",
|
|
274
|
+
"license": "MIT",
|
|
275
|
+
"engines": {
|
|
276
|
+
"node": ">= 4"
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
"node_modules/is-extglob": {
|
|
280
|
+
"version": "2.1.1",
|
|
281
|
+
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
|
282
|
+
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
|
283
|
+
"license": "MIT",
|
|
284
|
+
"engines": {
|
|
285
|
+
"node": ">=0.10.0"
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
"node_modules/is-glob": {
|
|
289
|
+
"version": "4.0.3",
|
|
290
|
+
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
|
291
|
+
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
|
292
|
+
"license": "MIT",
|
|
293
|
+
"dependencies": {
|
|
294
|
+
"is-extglob": "^2.1.1"
|
|
295
|
+
},
|
|
296
|
+
"engines": {
|
|
297
|
+
"node": ">=0.10.0"
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
"node_modules/js-yaml": {
|
|
301
|
+
"version": "4.1.1",
|
|
302
|
+
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz",
|
|
303
|
+
"integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==",
|
|
304
|
+
"license": "MIT",
|
|
305
|
+
"dependencies": {
|
|
306
|
+
"argparse": "^2.0.1"
|
|
307
|
+
},
|
|
308
|
+
"bin": {
|
|
309
|
+
"js-yaml": "bin/js-yaml.js"
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
"node_modules/xmlbuilder2": {
|
|
313
|
+
"version": "4.0.3",
|
|
314
|
+
"resolved": "https://registry.npmjs.org/xmlbuilder2/-/xmlbuilder2-4.0.3.tgz",
|
|
315
|
+
"integrity": "sha512-bx8Q1STctnNaaDymWnkfQLKofs0mGNN7rLLapJlGuV3VlvegD7Ls4ggMjE3aUSWItCCzU0PEv45lI87iSigiCA==",
|
|
316
|
+
"license": "MIT",
|
|
317
|
+
"dependencies": {
|
|
318
|
+
"@oozcitak/dom": "^2.0.2",
|
|
319
|
+
"@oozcitak/infra": "^2.0.2",
|
|
320
|
+
"@oozcitak/util": "^10.0.0",
|
|
321
|
+
"js-yaml": "^4.1.1"
|
|
322
|
+
},
|
|
323
|
+
"engines": {
|
|
324
|
+
"node": ">=20.0"
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
"node_modules/zx": {
|
|
328
|
+
"version": "8.8.5",
|
|
329
|
+
"resolved": "https://registry.npmjs.org/zx/-/zx-8.8.5.tgz",
|
|
330
|
+
"integrity": "sha512-SNgDF5L0gfN7FwVOdEFguY3orU5AkfFZm9B5YSHog/UDHv+lvmd82ZAsOenOkQixigwH2+yyH198AwNdKhj+RA==",
|
|
331
|
+
"license": "Apache-2.0",
|
|
332
|
+
"bin": {
|
|
333
|
+
"zx": "build/cli.js"
|
|
334
|
+
},
|
|
335
|
+
"engines": {
|
|
336
|
+
"node": ">= 12.17.0"
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
</content>
|
|
342
|
+
</file>
|
|
343
|
+
<file>
|
|
344
|
+
<name>package.json</name>
|
|
345
|
+
<path>package.json</path>
|
|
346
|
+
<content>{
|
|
347
|
+
"name": "@kokiito0926/fs2xml",
|
|
348
|
+
"version": "0.0.4",
|
|
349
|
+
"private": false,
|
|
350
|
+
"description": "ファイルをXML形式でまとめることができます。",
|
|
351
|
+
"keywords": [
|
|
352
|
+
"cli",
|
|
353
|
+
"bash",
|
|
354
|
+
"shell",
|
|
355
|
+
"script",
|
|
356
|
+
"nodejs",
|
|
357
|
+
"fs",
|
|
358
|
+
"xml",
|
|
359
|
+
"fs2xml"
|
|
360
|
+
],
|
|
361
|
+
"homepage": "https://github.com/kokiito0926/fs2xml#readme",
|
|
362
|
+
"publishConfig": {
|
|
363
|
+
"access": "public"
|
|
364
|
+
},
|
|
365
|
+
"bin": {
|
|
366
|
+
"fs2xml": "index.js"
|
|
367
|
+
},
|
|
368
|
+
"bugs": {
|
|
369
|
+
"url": "https://github.com/kokiito0926/fs2xml/issues"
|
|
370
|
+
},
|
|
371
|
+
"repository": {
|
|
372
|
+
"type": "git",
|
|
373
|
+
"url": "git+https://github.com/kokiito0926/fs2xml.git"
|
|
374
|
+
},
|
|
375
|
+
"license": "MIT",
|
|
376
|
+
"author": "Koki Ito <kokiito0926@gmail.com>",
|
|
377
|
+
"type": "module",
|
|
378
|
+
"scripts": {
|
|
379
|
+
"test": "node --test"
|
|
380
|
+
},
|
|
381
|
+
"dependencies": {
|
|
382
|
+
"glob-parent": "^6.0.2",
|
|
383
|
+
"ignore": "^7.0.5",
|
|
384
|
+
"xmlbuilder2": "^4.0.3",
|
|
385
|
+
"zx": "^8.8.4"
|
|
386
|
+
},
|
|
387
|
+
"engines": {
|
|
388
|
+
"node": ">=24.0.0"
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
</content>
|
|
392
|
+
</file>
|
|
393
|
+
<file>
|
|
394
|
+
<name>README.md</name>
|
|
395
|
+
<path>README.md</path>
|
|
396
|
+
<content>## fs2xml
|
|
397
|
+
|
|
398
|
+
fs2xmlは、ファイルをXML形式でまとめることができます。
|
|
399
|
+
ファイルをXML形式でまとめるようにすると、大規模言語モデルに与えやすくなります。
|
|
400
|
+
|
|
401
|
+
## インストール
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
$ npm install --global @kokiito0926/fs2xml
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## 使用方法
|
|
408
|
+
|
|
409
|
+
カレントディレクトリ内のすべてのファイルをXML形式でまとめます。
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
$ fs2xml
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
特定のディレクトリ内のすべてのファイルをXML形式でまとめます。
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
$ fs2xml "./src/**/*"
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
特定のディレクトリ内の特定の拡張子のみを対象にして、XML形式でまとめます。
|
|
422
|
+
|
|
423
|
+
```bash
|
|
424
|
+
$ fs2xml "./src/**/*.txt"
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
--ignoreのオプションを用いると、特定のパターンを除外することができます。
|
|
428
|
+
現状の実装では、現在の作業中のディレクトリの.gitignoreが読み込まれ、そのパターンが自動的に適用されます。
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
$ fs2xml "./src/**/*" --ignore "./src/test/**" --ignore "**/*.log"
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## 出力例
|
|
435
|
+
|
|
436
|
+
```xml
|
|
437
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
438
|
+
<files>
|
|
439
|
+
<file>
|
|
440
|
+
<name>example.js</name>
|
|
441
|
+
<path>src/example.js</path>
|
|
442
|
+
<content>console.log("Hello world!");</content>
|
|
443
|
+
</file>
|
|
444
|
+
</files>
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## ライセンス
|
|
448
|
+
|
|
449
|
+
[MIT](LICENSE)
|
|
450
|
+
</content>
|
|
451
|
+
</file>
|
|
452
|
+
</files>
|
package/index.js
CHANGED
|
@@ -9,18 +9,51 @@
|
|
|
9
9
|
import { fs, path, minimist, glob } from "zx";
|
|
10
10
|
import { create } from "xmlbuilder2";
|
|
11
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
|
+
}
|
|
12
46
|
|
|
13
47
|
const args = minimist(process.argv.slice(2));
|
|
14
48
|
const target = args._[0] || "**/*";
|
|
49
|
+
const dot = args.dot || false;
|
|
50
|
+
const gitignore = args.gitignore || true;
|
|
15
51
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (fs.existsSync(gitignorePath)) {
|
|
19
|
-
const gitignoreContent = await fs.readFile(gitignorePath, "utf8");
|
|
20
|
-
ig.add(gitignoreContent);
|
|
21
|
-
}
|
|
52
|
+
const { ig, baseDir } =
|
|
53
|
+
gitignore == false ? { ig: ignore(), baseDir: process.cwd() } : await loadNearestGitignore(target);
|
|
22
54
|
|
|
23
|
-
const defaultIgnore = [
|
|
55
|
+
const defaultIgnore = [];
|
|
56
|
+
// const defaultIgnore = ["node_modules/**", ".git/**"];
|
|
24
57
|
|
|
25
58
|
const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
|
|
26
59
|
|
|
@@ -29,11 +62,11 @@ const ignorePatterns = [...defaultIgnore, ...userIgnore].filter(Boolean);
|
|
|
29
62
|
let files = await glob(target, {
|
|
30
63
|
ignore: ignorePatterns,
|
|
31
64
|
nodir: true,
|
|
32
|
-
dot:
|
|
65
|
+
dot: dot,
|
|
33
66
|
});
|
|
34
67
|
|
|
35
68
|
files = files.filter((file) => {
|
|
36
|
-
const relativePath = path.relative(
|
|
69
|
+
const relativePath = path.relative(baseDir, path.resolve(file));
|
|
37
70
|
if (relativePath === "") return true;
|
|
38
71
|
return !ig.ignores(relativePath);
|
|
39
72
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokiito0926/fs2xml",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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
|
+
"glob-parent": "^6.0.2",
|
|
37
38
|
"ignore": "^7.0.5",
|
|
38
39
|
"xmlbuilder2": "^4.0.3",
|
|
39
40
|
"zx": "^8.8.4"
|