@kokiito0926/fs2xml 0.0.7 → 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.
Files changed (2) hide show
  1. package/index.js +32 -0
  2. package/package.json +2 -1
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")
@@ -111,6 +129,7 @@ if (files.length === 1) {
111
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")
@@ -140,6 +170,8 @@ if (files.length === 1) {
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.7",
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
  },