x3d-tidy 2.2.1 → 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.
- package/README.md +4 -4
- package/package.json +1 -1
- package/src/main.js +36 -29
package/README.md
CHANGED
|
@@ -35,15 +35,15 @@ Set double precision, default is 15.
|
|
|
35
35
|
|
|
36
36
|
### -e *extension(s)* ...
|
|
37
37
|
|
|
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
|
|
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
|
-
### -
|
|
44
|
+
### -l
|
|
45
45
|
|
|
46
|
-
Log output filenames to stdout
|
|
46
|
+
Log output filenames to stdout.
|
|
47
47
|
|
|
48
48
|
### -h
|
|
49
49
|
|
|
@@ -59,7 +59,7 @@ If set, remove metadata nodes.
|
|
|
59
59
|
|
|
60
60
|
### -o *file(s)* ...
|
|
61
61
|
|
|
62
|
-
Set output file(s). To output it to stdout use only the extension, e.g. ".x3dv". Use either
|
|
62
|
+
Set output file(s). To output it to stdout use only the extension, e.g. ".x3dv". Use either "-e" or "-o".
|
|
63
63
|
|
|
64
64
|
### -r
|
|
65
65
|
|
package/package.json
CHANGED
package/src/main.js
CHANGED
|
@@ -76,7 +76,7 @@ async function convert ()
|
|
|
76
76
|
.option ("log",
|
|
77
77
|
{
|
|
78
78
|
type: "boolean",
|
|
79
|
-
alias: "
|
|
79
|
+
alias: "l",
|
|
80
80
|
description: `Log output filenames to stdout.`,
|
|
81
81
|
implies: "input",
|
|
82
82
|
})
|
|
@@ -125,6 +125,13 @@ async function convert ()
|
|
|
125
125
|
requiresArg: true,
|
|
126
126
|
default: ["TIDY"],
|
|
127
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
|
+
})
|
|
128
135
|
.example ([
|
|
129
136
|
[
|
|
130
137
|
"npx x3d-tidy -i file.x3d -o file.x3dv",
|
|
@@ -138,12 +145,6 @@ async function convert ()
|
|
|
138
145
|
.help ()
|
|
139
146
|
.alias ("help", "h") .argv;
|
|
140
147
|
|
|
141
|
-
if (!args .output && !args .extension)
|
|
142
|
-
{
|
|
143
|
-
console .error (colors .red ("Missing argument output or extension."));
|
|
144
|
-
process .exit (1);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
148
|
// Fixes an issue with URL, if it matches a drive letter.
|
|
148
149
|
args .input = args .input .map (input => input .replace (/^([A-Za-z]:)/, "file://$1"));
|
|
149
150
|
|
|
@@ -159,15 +160,37 @@ async function convert ()
|
|
|
159
160
|
|
|
160
161
|
await browser .loadComponents (browser .getProfile ("Full"));
|
|
161
162
|
|
|
162
|
-
if (!args .input .length)
|
|
163
|
-
console .warn ("No input files specified.");
|
|
164
|
-
|
|
165
163
|
const argc = Math .max (args .input .length, args .output ?.length ?? args .extension ?.length);
|
|
166
164
|
|
|
167
165
|
for (let i = 0; i < argc; ++ i)
|
|
168
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
|
+
|
|
169
193
|
const
|
|
170
|
-
input = new URL (arg (args .input, i), url .pathToFileURL (path .join (process .cwd (), "/"))),
|
|
171
194
|
scene = scenes .get (input .href) ?? await browser .createX3DFromURL (new X3D .MFString (input)),
|
|
172
195
|
generator = scene .getMetaData ("generator") ?.filter (value => !value .startsWith (pkg .name)) ?? [ ];
|
|
173
196
|
|
|
@@ -177,6 +200,8 @@ async function convert ()
|
|
|
177
200
|
scene .setMetaData ("generator", generator);
|
|
178
201
|
scene .setMetaData ("modified", new Date () .toUTCString ());
|
|
179
202
|
|
|
203
|
+
// Output scene.
|
|
204
|
+
|
|
180
205
|
if (arg (args .infer, i))
|
|
181
206
|
infer (scene);
|
|
182
207
|
|
|
@@ -191,24 +216,6 @@ async function convert ()
|
|
|
191
216
|
doublePrecision: arg (args .double, i),
|
|
192
217
|
};
|
|
193
218
|
|
|
194
|
-
let output;
|
|
195
|
-
|
|
196
|
-
if (args .output)
|
|
197
|
-
{
|
|
198
|
-
output = path .resolve (process .cwd (), arg (args .output, i));
|
|
199
|
-
}
|
|
200
|
-
else if (args .extension)
|
|
201
|
-
{
|
|
202
|
-
const
|
|
203
|
-
filename = url .fileURLToPath (input),
|
|
204
|
-
extension = arg (args .extension, i);
|
|
205
|
-
|
|
206
|
-
output = `${filename .slice (0, -path. extname (filename) .length)}${extension}`;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (args .log)
|
|
210
|
-
console .log (output);
|
|
211
|
-
|
|
212
219
|
if (path .extname (output))
|
|
213
220
|
fs .writeFileSync (output, getContents ({ ... options, type: path .extname (output) }));
|
|
214
221
|
else
|