@kokiito0926/fs2xml 0.0.8 → 0.0.10

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 (2) hide show
  1. package/index.js +8 -54
  2. package/package.json +1 -2
package/index.js CHANGED
@@ -1,13 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // >> $ ./index.js "./example/example.txt"
4
- // >> $ ./index.js "./example/sub/example.js"
5
-
6
- // >> $ ./index.js "./example/**/*.txt"
7
- // >> $ ./index.js "./example/**/*.txt" --ignore "./example/ignore/**"
8
-
9
- import { fs, path, minimist, glob } from "zx";
10
- import { create } from "xmlbuilder2";
3
+ import { fs, path, argv, glob } from "zx";
11
4
  import ignore from "ignore";
12
5
  import globParent from "glob-parent";
13
6
  import xml2js from "xml2js";
@@ -29,8 +22,6 @@ async function loadNearestGitignore(targetPattern) {
29
22
  const gitignorePath = path.join(currentDir, ".gitignore");
30
23
 
31
24
  if (fs.existsSync(gitignorePath)) {
32
- // console.log(gitignorePath);
33
-
34
25
  const content = await fs.readFile(gitignorePath, "utf8");
35
26
  ig.add(content);
36
27
 
@@ -45,16 +36,14 @@ async function loadNearestGitignore(targetPattern) {
45
36
  return { ig, baseDir: process.cwd() };
46
37
  }
47
38
 
48
- const args = minimist(process.argv.slice(2));
49
- const target = args._[0] || "**/*";
50
- const dot = args.dot || false;
51
- const gitignore = args.gitignore || true;
39
+ const target = argv?._[0] || "**/*";
40
+ const dot = argv?.dot || false;
41
+ const gitignore = argv?.gitignore || true;
52
42
 
53
43
  const { ig, baseDir } =
54
44
  gitignore == false ? { ig: ignore(), baseDir: process.cwd() } : await loadNearestGitignore(target);
55
45
 
56
46
  const defaultIgnore = [];
57
- // const defaultIgnore = ["node_modules/**", ".git/**"];
58
47
 
59
48
  const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
60
49
 
@@ -79,6 +68,9 @@ async function getFileData(filePath) {
79
68
  content = content.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
80
69
  if (!content) return null;
81
70
 
71
+ content = content.replace(/]]>/g, "]]]]><![CDATA[>");
72
+ if (!content) return null;
73
+
82
74
  return {
83
75
  name: path.basename(filePath),
84
76
  path: filePath.replace(/\\/g, "/"),
@@ -87,8 +79,7 @@ async function getFileData(filePath) {
87
79
  }
88
80
 
89
81
  if (files.length === 0) {
90
- process.stderr.write(`No files matched the pattern: ${pattern}\n`);
91
- process.exit(0);
82
+ process.exit(1);
92
83
  }
93
84
 
94
85
  let xmlOutput = "";
@@ -98,7 +89,6 @@ const builder = new xml2js.Builder({
98
89
  cdata: true,
99
90
  xmldec: { version: "1.0", encoding: "UTF-8" },
100
91
  renderOpts: { pretty: true },
101
- // renderOpts: { pretty: true, indent: " ", newline: "\n" },
102
92
  });
103
93
 
104
94
  if (files.length === 1) {
@@ -114,22 +104,6 @@ if (files.length === 1) {
114
104
  content: data.content,
115
105
  },
116
106
  };
117
-
118
- /*
119
- xmlOutput = create({ version: "1.0", encoding: "UTF-8" })
120
- .ele("file")
121
- .ele("name")
122
- .txt(data.name)
123
- .up()
124
- .ele("path")
125
- .txt(data.path)
126
- .up()
127
- .ele("content")
128
- // .txt(data.content)
129
- .dat(data.content)
130
- .up()
131
- .end({ prettyPrint: true });
132
- */
133
107
  } else {
134
108
  const allFiles = [];
135
109
  for (const file of files) {
@@ -141,7 +115,6 @@ if (files.length === 1) {
141
115
  if (!allFiles.length) {
142
116
  process.exit(1);
143
117
  }
144
- // console.log(allFiles);
145
118
 
146
119
  xmlObject = {
147
120
  files: {
@@ -152,25 +125,6 @@ if (files.length === 1) {
152
125
  })),
153
126
  },
154
127
  };
155
-
156
- /*
157
- const root = create({ version: "1.0", encoding: "UTF-8" }).ele("files");
158
- for (const f of allFiles) {
159
- root.ele("file")
160
- .ele("name")
161
- .txt(f.name)
162
- .up()
163
- .ele("path")
164
- .txt(f.path)
165
- .up()
166
- .ele("content")
167
- // .txt(f.content)
168
- .dat(f.content)
169
- .up()
170
- .up();
171
- }
172
- xmlOutput = root.end({ prettyPrint: true });
173
- */
174
128
  }
175
129
 
176
130
  xmlOutput = builder.buildObject(xmlObject);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokiito0926/fs2xml",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "private": false,
5
5
  "description": "ファイルをXML形式でまとめることができるコマンドラインのツールです。",
6
6
  "keywords": [
@@ -37,7 +37,6 @@
37
37
  "glob-parent": "^6.0.2",
38
38
  "ignore": "^7.0.5",
39
39
  "xml2js": "^0.6.2",
40
- "xmlbuilder2": "^4.0.3",
41
40
  "zx": "^8.8.4"
42
41
  },
43
42
  "engines": {