@kokiito0926/fs2xml 0.0.8 → 0.0.9

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 +4 -49
  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
3
  import { fs, path, minimist, glob } from "zx";
10
- import { create } from "xmlbuilder2";
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
 
@@ -54,7 +45,6 @@ const { ig, baseDir } =
54
45
  gitignore == false ? { ig: ignore(), baseDir: process.cwd() } : await loadNearestGitignore(target);
55
46
 
56
47
  const defaultIgnore = [];
57
- // const defaultIgnore = ["node_modules/**", ".git/**"];
58
48
 
59
49
  const userIgnore = args.ignore ? (Array.isArray(args.ignore) ? args.ignore : [args.ignore]) : [];
60
50
 
@@ -79,6 +69,9 @@ async function getFileData(filePath) {
79
69
  content = content.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
80
70
  if (!content) return null;
81
71
 
72
+ content = content.replace(/]]>/g, "]]]]><![CDATA[>");
73
+ if (!content) return null;
74
+
82
75
  return {
83
76
  name: path.basename(filePath),
84
77
  path: filePath.replace(/\\/g, "/"),
@@ -87,8 +80,7 @@ async function getFileData(filePath) {
87
80
  }
88
81
 
89
82
  if (files.length === 0) {
90
- process.stderr.write(`No files matched the pattern: ${pattern}\n`);
91
- process.exit(0);
83
+ process.exit(1);
92
84
  }
93
85
 
94
86
  let xmlOutput = "";
@@ -98,7 +90,6 @@ const builder = new xml2js.Builder({
98
90
  cdata: true,
99
91
  xmldec: { version: "1.0", encoding: "UTF-8" },
100
92
  renderOpts: { pretty: true },
101
- // renderOpts: { pretty: true, indent: " ", newline: "\n" },
102
93
  });
103
94
 
104
95
  if (files.length === 1) {
@@ -114,22 +105,6 @@ if (files.length === 1) {
114
105
  content: data.content,
115
106
  },
116
107
  };
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
108
  } else {
134
109
  const allFiles = [];
135
110
  for (const file of files) {
@@ -141,7 +116,6 @@ if (files.length === 1) {
141
116
  if (!allFiles.length) {
142
117
  process.exit(1);
143
118
  }
144
- // console.log(allFiles);
145
119
 
146
120
  xmlObject = {
147
121
  files: {
@@ -152,25 +126,6 @@ if (files.length === 1) {
152
126
  })),
153
127
  },
154
128
  };
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
129
  }
175
130
 
176
131
  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.9",
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": {