x3d-tidy 2.2.0 → 2.2.2

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 (3) hide show
  1. package/README.md +7 -3
  2. package/package.json +1 -1
  3. package/src/main.js +52 -36
package/README.md CHANGED
@@ -33,14 +33,18 @@ This tool is particularly useful for developers, 3D artists, and researchers wor
33
33
 
34
34
  Set double precision, default is 15.
35
35
 
36
- ### -e *extension*
36
+ ### -e *extension(s)* ...
37
37
 
38
- Set output file extension(s), e.g. ".x3dv". The output file will have the same basename as the input file.
38
+ Set output file extension(s), e.g. ".x3dv" or ".tidy.x3d". The output file will have the same basename as the input file. Use either "-e" or "-o".
39
39
 
40
40
  ### -f *integer*
41
41
 
42
42
  Set float precision, default is 7.
43
43
 
44
+ ### -l
45
+
46
+ Log output filenames to stdout.
47
+
44
48
  ### -h
45
49
 
46
50
  Show help.
@@ -55,7 +59,7 @@ If set, remove metadata nodes.
55
59
 
56
60
  ### -o *file(s)* ...
57
61
 
58
- Set output file(s). To output it to stdout use only the extension, e.g. ".x3dv".
62
+ Set output file(s). To output it to stdout use only the extension, e.g. ".x3dv". Use either "-e" or "-o".
59
63
 
60
64
  ### -r
61
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x3d-tidy",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "X3D Converter, Beautifier and Minimizer",
5
5
  "main": "src/main.js",
6
6
  "bin": {
package/src/main.js CHANGED
@@ -26,7 +26,7 @@ async function main ()
26
26
  }
27
27
  catch (error)
28
28
  {
29
- console .error (error .message || error);
29
+ console .error (colors .red (error .message || error));
30
30
  process .exit (1);
31
31
  }
32
32
  }
@@ -58,7 +58,7 @@ async function convert ()
58
58
  {
59
59
  type: "string",
60
60
  alias: "e",
61
- description: `Set output file extension(s), e.g. ".x3dv". The output file will have the same basename as the input file.`,
61
+ description: `Set output file extension(s), e.g. ".x3dv" or ".tidy.x3d". The output file will have the same basename as the input file.`,
62
62
  array: true,
63
63
  requiresArg: true,
64
64
  implies: "input",
@@ -73,6 +73,21 @@ async function convert ()
73
73
  default: [7],
74
74
  requiresArg: true,
75
75
  })
76
+ .option ("log",
77
+ {
78
+ type: "boolean",
79
+ alias: "l",
80
+ description: `Log output filenames to stdout.`,
81
+ implies: "input",
82
+ })
83
+ .option ("infer",
84
+ {
85
+ type: "boolean",
86
+ alias: "r",
87
+ description: "If set, infer profile and components from used nodes.",
88
+ array: true,
89
+ default: [false],
90
+ })
76
91
  .option ("input",
77
92
  {
78
93
  type: "string",
@@ -100,14 +115,6 @@ async function convert ()
100
115
  implies: "input",
101
116
  conflicts: "extension",
102
117
  })
103
- .option ("infer",
104
- {
105
- type: "boolean",
106
- alias: "r",
107
- description: "If set, infer profile and components from used nodes.",
108
- array: true,
109
- default: [false],
110
- })
111
118
  .option ("style",
112
119
  {
113
120
  type: "string",
@@ -118,6 +125,13 @@ async function convert ()
118
125
  requiresArg: true,
119
126
  default: ["TIDY"],
120
127
  })
128
+ .check (args =>
129
+ {
130
+ if (!args .output && !args .extension)
131
+ throw new Error ("Missing argument output or extension.");
132
+
133
+ return true;
134
+ })
121
135
  .example ([
122
136
  [
123
137
  "npx x3d-tidy -i file.x3d -o file.x3dv",
@@ -128,16 +142,9 @@ async function convert ()
128
142
  "Convert an XML encoded file to a VRML encoded file and a JSON encoded file with smallest size possible by removing redundant whitespaces"
129
143
  ],
130
144
  ])
131
- .requiresArg (["extension", "output"])
132
145
  .help ()
133
146
  .alias ("help", "h") .argv;
134
147
 
135
- if (!args .output && !args .extension)
136
- {
137
- console .error (colors .red ("Missing argument output or extension."));
138
- process .exit (1);
139
- }
140
-
141
148
  // Fixes an issue with URL, if it matches a drive letter.
142
149
  args .input = args .input .map (input => input .replace (/^([A-Za-z]:)/, "file://$1"));
143
150
 
@@ -153,15 +160,37 @@ async function convert ()
153
160
 
154
161
  await browser .loadComponents (browser .getProfile ("Full"));
155
162
 
156
- if (!args .input .length)
157
- console .warn ("No input files specified.");
158
-
159
163
  const argc = Math .max (args .input .length, args .output ?.length ?? args .extension ?.length);
160
164
 
161
165
  for (let i = 0; i < argc; ++ i)
162
166
  {
167
+ // Create input filename.
168
+
169
+ const input = new URL (arg (args .input, i), url .pathToFileURL (path .join (process .cwd (), "/")));
170
+
171
+ // Create output filename.
172
+
173
+ let output;
174
+
175
+ if (args .output)
176
+ {
177
+ output = path .resolve (process .cwd (), arg (args .output, i));
178
+ }
179
+ else if (args .extension)
180
+ {
181
+ const
182
+ filename = url .fileURLToPath (input),
183
+ extension = arg (args .extension, i);
184
+
185
+ output = `${filename .slice (0, -path. extname (filename) .length)}${extension}`;
186
+ }
187
+
188
+ if (args .log)
189
+ console .log (output);
190
+
191
+ // Load scene.
192
+
163
193
  const
164
- input = new URL (arg (args .input, i), url .pathToFileURL (path .join (process .cwd (), "/"))),
165
194
  scene = scenes .get (input .href) ?? await browser .createX3DFromURL (new X3D .MFString (input)),
166
195
  generator = scene .getMetaData ("generator") ?.filter (value => !value .startsWith (pkg .name)) ?? [ ];
167
196
 
@@ -171,6 +200,8 @@ async function convert ()
171
200
  scene .setMetaData ("generator", generator);
172
201
  scene .setMetaData ("modified", new Date () .toUTCString ());
173
202
 
203
+ // Output scene.
204
+
174
205
  if (arg (args .infer, i))
175
206
  infer (scene);
176
207
 
@@ -185,21 +216,6 @@ async function convert ()
185
216
  doublePrecision: arg (args .double, i),
186
217
  };
187
218
 
188
- let output;
189
-
190
- if (args .output)
191
- {
192
- output = path .resolve (process .cwd (), arg (args .output, i));
193
- }
194
- else if (args .extension)
195
- {
196
- const
197
- filename = url .fileURLToPath (input),
198
- extension = arg (args .extension, i);
199
-
200
- output = `${filename .slice (0, -path. extname (filename) .length)}${extension}`;
201
- }
202
-
203
219
  if (path .extname (output))
204
220
  fs .writeFileSync (output, getContents ({ ... options, type: path .extname (output) }));
205
221
  else