x3d-tidy 2.1.26 → 2.2.1
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 +9 -1
- package/package.json +2 -1
- package/src/main.js +61 -15
package/README.md
CHANGED
|
@@ -33,10 +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(s)* ...
|
|
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 '-e' or '-o'.
|
|
39
|
+
|
|
36
40
|
### -f *integer*
|
|
37
41
|
|
|
38
42
|
Set float precision, default is 7.
|
|
39
43
|
|
|
44
|
+
### -g
|
|
45
|
+
|
|
46
|
+
Log output filenames to stdout..
|
|
47
|
+
|
|
40
48
|
### -h
|
|
41
49
|
|
|
42
50
|
Show help.
|
|
@@ -51,7 +59,7 @@ If set, remove metadata nodes.
|
|
|
51
59
|
|
|
52
60
|
### -o *file(s)* ...
|
|
53
61
|
|
|
54
|
-
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'.
|
|
55
63
|
|
|
56
64
|
### -r
|
|
57
65
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x3d-tidy",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "X3D Converter, Beautifier and Minimizer",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
}
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
|
+
"colors": "^1.4.0",
|
|
56
57
|
"x_ite": "^12.0.7",
|
|
57
58
|
"x_ite-node": "^1.1.0",
|
|
58
59
|
"x3d-traverse": "^1.0.13",
|
package/src/main.js
CHANGED
|
@@ -11,6 +11,7 @@ const
|
|
|
11
11
|
path = require ("path"),
|
|
12
12
|
fs = require ("fs"),
|
|
13
13
|
zlib = require ("zlib"),
|
|
14
|
+
colors = require ("colors"),
|
|
14
15
|
DEBUG = false;
|
|
15
16
|
|
|
16
17
|
main ();
|
|
@@ -25,7 +26,7 @@ async function main ()
|
|
|
25
26
|
}
|
|
26
27
|
catch (error)
|
|
27
28
|
{
|
|
28
|
-
console .error (error .message || error);
|
|
29
|
+
console .error (colors .red (error .message || error));
|
|
29
30
|
process .exit (1);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -41,7 +42,7 @@ async function convert ()
|
|
|
41
42
|
.alias ("v", "version")
|
|
42
43
|
.fail ((msg, error, yargs) =>
|
|
43
44
|
{
|
|
44
|
-
console .error (msg);
|
|
45
|
+
console .error (colors .red (msg));
|
|
45
46
|
process .exit (1);
|
|
46
47
|
})
|
|
47
48
|
.option ("double",
|
|
@@ -51,6 +52,17 @@ async function convert ()
|
|
|
51
52
|
description: "Set double precision, default is 15.",
|
|
52
53
|
array: true,
|
|
53
54
|
default: [15],
|
|
55
|
+
requiresArg: true,
|
|
56
|
+
})
|
|
57
|
+
.option ("extension",
|
|
58
|
+
{
|
|
59
|
+
type: "string",
|
|
60
|
+
alias: "e",
|
|
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
|
+
array: true,
|
|
63
|
+
requiresArg: true,
|
|
64
|
+
implies: "input",
|
|
65
|
+
conflicts: "output",
|
|
54
66
|
})
|
|
55
67
|
.option ("float",
|
|
56
68
|
{
|
|
@@ -59,6 +71,22 @@ async function convert ()
|
|
|
59
71
|
description: "Set float precision, default is 7.",
|
|
60
72
|
array: true,
|
|
61
73
|
default: [7],
|
|
74
|
+
requiresArg: true,
|
|
75
|
+
})
|
|
76
|
+
.option ("log",
|
|
77
|
+
{
|
|
78
|
+
type: "boolean",
|
|
79
|
+
alias: "g",
|
|
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],
|
|
62
90
|
})
|
|
63
91
|
.option ("input",
|
|
64
92
|
{
|
|
@@ -66,8 +94,8 @@ async function convert ()
|
|
|
66
94
|
alias: "i",
|
|
67
95
|
description: "Set input file(s). If there are less input files than output files, the last input file is used for the remaining output files.",
|
|
68
96
|
array: true,
|
|
69
|
-
|
|
70
|
-
|
|
97
|
+
requiresArg: true,
|
|
98
|
+
demandOption: true,
|
|
71
99
|
})
|
|
72
100
|
.option ("metadata",
|
|
73
101
|
{
|
|
@@ -83,16 +111,9 @@ async function convert ()
|
|
|
83
111
|
alias: "o",
|
|
84
112
|
description: `Set output file(s). To output it to stdout use only the extension, e.g. ".x3dv".`,
|
|
85
113
|
array: true,
|
|
86
|
-
|
|
114
|
+
requiresArg: true,
|
|
87
115
|
implies: "input",
|
|
88
|
-
|
|
89
|
-
.option ("infer",
|
|
90
|
-
{
|
|
91
|
-
type: "boolean",
|
|
92
|
-
alias: "r",
|
|
93
|
-
description: "If set, infer profile and components from used nodes.",
|
|
94
|
-
array: true,
|
|
95
|
-
default: [false],
|
|
116
|
+
conflicts: "extension",
|
|
96
117
|
})
|
|
97
118
|
.option ("style",
|
|
98
119
|
{
|
|
@@ -101,6 +122,7 @@ async function convert ()
|
|
|
101
122
|
description: `Set output style, default is "TIDY". "TIDY" results in a good readable file, but with larger size, whereas "CLEAN" result in the smallest size possible by removing all redundant whitespaces. The other values are somewhere in between.`,
|
|
102
123
|
choices: ["TIDY", "COMPACT", "SMALL", "CLEAN"],
|
|
103
124
|
array: true,
|
|
125
|
+
requiresArg: true,
|
|
104
126
|
default: ["TIDY"],
|
|
105
127
|
})
|
|
106
128
|
.example ([
|
|
@@ -116,6 +138,12 @@ async function convert ()
|
|
|
116
138
|
.help ()
|
|
117
139
|
.alias ("help", "h") .argv;
|
|
118
140
|
|
|
141
|
+
if (!args .output && !args .extension)
|
|
142
|
+
{
|
|
143
|
+
console .error (colors .red ("Missing argument output or extension."));
|
|
144
|
+
process .exit (1);
|
|
145
|
+
}
|
|
146
|
+
|
|
119
147
|
// Fixes an issue with URL, if it matches a drive letter.
|
|
120
148
|
args .input = args .input .map (input => input .replace (/^([A-Za-z]:)/, "file://$1"));
|
|
121
149
|
|
|
@@ -134,7 +162,9 @@ async function convert ()
|
|
|
134
162
|
if (!args .input .length)
|
|
135
163
|
console .warn ("No input files specified.");
|
|
136
164
|
|
|
137
|
-
|
|
165
|
+
const argc = Math .max (args .input .length, args .output ?.length ?? args .extension ?.length);
|
|
166
|
+
|
|
167
|
+
for (let i = 0; i < argc; ++ i)
|
|
138
168
|
{
|
|
139
169
|
const
|
|
140
170
|
input = new URL (arg (args .input, i), url .pathToFileURL (path .join (process .cwd (), "/"))),
|
|
@@ -161,7 +191,23 @@ async function convert ()
|
|
|
161
191
|
doublePrecision: arg (args .double, i),
|
|
162
192
|
};
|
|
163
193
|
|
|
164
|
-
|
|
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);
|
|
165
211
|
|
|
166
212
|
if (path .extname (output))
|
|
167
213
|
fs .writeFileSync (output, getContents ({ ... options, type: path .extname (output) }));
|