x3d-tidy 2.0.7 → 2.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.
- package/README.md +12 -6
- package/package.json +3 -3
- package/src/main.js +74 -57
package/README.md
CHANGED
|
@@ -10,19 +10,19 @@ X3D converter, beautifier and minimizer
|
|
|
10
10
|
|
|
11
11
|
You can run *x3d-tidy* without installing it using **npx**:
|
|
12
12
|
|
|
13
|
-
**npx x3d-tidy** \[options\]
|
|
13
|
+
**npx x3d-tidy** \[options\] input-file output-file [input-file output-file ...]
|
|
14
14
|
|
|
15
15
|
## Options
|
|
16
16
|
|
|
17
17
|
**x3d-tidy** interprets the following options when it is invoked:
|
|
18
18
|
|
|
19
|
-
### -i *file*
|
|
19
|
+
### -i *file* ...
|
|
20
20
|
|
|
21
|
-
Set input file. This can be either a local file path or a URL.
|
|
21
|
+
Set input file(s). This can be either a local file path or a URL. If there are less input files than output files, the last input file is used for the remaining output files.
|
|
22
22
|
|
|
23
|
-
### -o *file*
|
|
23
|
+
### -o *file* ...
|
|
24
24
|
|
|
25
|
-
Set output file.
|
|
25
|
+
Set output file(s).
|
|
26
26
|
|
|
27
27
|
### -s *[**TIDY**, COMPACT, SMALL, CLEAN]*
|
|
28
28
|
|
|
@@ -80,7 +80,13 @@ Show help.
|
|
|
80
80
|
Convert an XML encoded file into a VRML encoded file.
|
|
81
81
|
|
|
82
82
|
```sh
|
|
83
|
-
$ npx x3d-tidy
|
|
83
|
+
$ npx x3d-tidy file.x3d file.x3dv
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Convert an XML encoded file into a VRML encoded file and a JSON encoded file.
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
$ npx x3d-tidy -i file.x3d -o file.x3dv file.x3dj
|
|
84
90
|
```
|
|
85
91
|
|
|
86
92
|
## Online Converter
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x3d-tidy",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "X3D Converter, Beautifier and Minimizer",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"colors": "^1.4.0",
|
|
57
|
-
"x_ite": "^
|
|
58
|
-
"x_ite-node": "^1.0.
|
|
57
|
+
"x_ite": "^11.0.0",
|
|
58
|
+
"x_ite-node": "^1.0.18",
|
|
59
59
|
"x3d-traverse": "^1.0.6",
|
|
60
60
|
"yargs": "^17.7.2"
|
|
61
61
|
},
|
package/src/main.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const
|
|
4
|
-
X3D
|
|
5
|
-
pkg
|
|
6
|
-
infer
|
|
7
|
-
metadata
|
|
8
|
-
yargs
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
X3D = require ("x_ite-node"),
|
|
5
|
+
pkg = require ("../package.json"),
|
|
6
|
+
infer = require ("./infer"),
|
|
7
|
+
metadata = require ("./metadata"),
|
|
8
|
+
yargs = require ("yargs"),
|
|
9
|
+
{ hideBin } = require ("yargs/helpers"),
|
|
10
|
+
url = require ("url"),
|
|
11
|
+
path = require ("path"),
|
|
12
|
+
fs = require ("fs"),
|
|
13
|
+
zlib = require ("zlib"),
|
|
14
|
+
DEBUG = false;
|
|
14
15
|
|
|
15
16
|
main ();
|
|
16
17
|
|
|
@@ -31,10 +32,10 @@ async function main ()
|
|
|
31
32
|
|
|
32
33
|
async function convert ()
|
|
33
34
|
{
|
|
34
|
-
const args = yargs (process .argv)
|
|
35
|
+
const args = yargs (hideBin (process .argv))
|
|
35
36
|
.scriptName ("x3d-tidy")
|
|
36
|
-
.usage ("$0
|
|
37
|
-
.command ("
|
|
37
|
+
.usage ("$0 [options] input-file output-file [input-file output-file ...]")
|
|
38
|
+
.command ("X3D converter, beautifier and minimizer")
|
|
38
39
|
.version (pkg .version)
|
|
39
40
|
.alias ("v", "version")
|
|
40
41
|
.fail ((msg, error, yargs) =>
|
|
@@ -46,15 +47,17 @@ async function convert ()
|
|
|
46
47
|
{
|
|
47
48
|
type: "string",
|
|
48
49
|
alias: "i",
|
|
49
|
-
description: "Set input file.",
|
|
50
|
-
|
|
50
|
+
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.",
|
|
51
|
+
array: true,
|
|
52
|
+
implies: "output",
|
|
51
53
|
})
|
|
52
54
|
.option ("output",
|
|
53
55
|
{
|
|
54
56
|
type: "string",
|
|
55
57
|
alias: "o",
|
|
56
|
-
description: "Set output file. To output it to stdout use only the extension, e.g. '.x3dv'.",
|
|
57
|
-
|
|
58
|
+
description: "Set output file(s). To output it to stdout use only the extension, e.g. '.x3dv'.",
|
|
59
|
+
array: true,
|
|
60
|
+
implies: "input",
|
|
58
61
|
})
|
|
59
62
|
.option ("style",
|
|
60
63
|
{
|
|
@@ -90,18 +93,27 @@ async function convert ()
|
|
|
90
93
|
.help ()
|
|
91
94
|
.alias ("help", "h") .argv;
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
args .input ??= [ ];
|
|
97
|
+
args .output ??= [ ];
|
|
95
98
|
|
|
96
|
-
if (args .
|
|
97
|
-
|
|
99
|
+
if (args .input .length === 0 && args .output .length === 0)
|
|
100
|
+
{
|
|
101
|
+
if (args ._ .length % 2 === 0)
|
|
102
|
+
{
|
|
103
|
+
for (let i = 0; i < args ._ .length; i += 2)
|
|
104
|
+
{
|
|
105
|
+
args .input .push (args ._ [i + 0]);
|
|
106
|
+
args .output .push (args ._ [i + 1]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
98
110
|
|
|
99
111
|
// Fixes an issue with URL, if it matches a drive letter.
|
|
100
|
-
args .input = args .input .replace (/^([A-Za-z]:)/, "file://$1");
|
|
112
|
+
args .input = args .input .map (input => input .replace (/^([A-Za-z]:)/, "file://$1"));
|
|
101
113
|
|
|
102
114
|
const
|
|
103
115
|
Browser = X3D .createBrowser () .browser,
|
|
104
|
-
|
|
116
|
+
scenes = new Map ();
|
|
105
117
|
|
|
106
118
|
Browser .endUpdate ();
|
|
107
119
|
Browser .setBrowserOption ("LoadUrlObjects", false);
|
|
@@ -109,45 +121,50 @@ async function convert ()
|
|
|
109
121
|
Browser .setBrowserOption ("TextureQuality", "HIGH");
|
|
110
122
|
|
|
111
123
|
await Browser .loadComponents (Browser .getProfile ("Full"));
|
|
112
|
-
await Browser .loadURL (new X3D .MFString (input));
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
scene = Browser .currentScene,
|
|
116
|
-
generator = scene .getMetaData ("generator") ?.filter (value => !value .startsWith (pkg .name)) ?? [ ];
|
|
117
|
-
|
|
118
|
-
generator .push (`${pkg .name} V${pkg .version}, ${pkg .homepage}`);
|
|
119
|
-
|
|
120
|
-
scene .setMetaData ("generator", generator);
|
|
121
|
-
scene .setMetaData ("modified", new Date () .toUTCString ());
|
|
122
|
-
|
|
123
|
-
if (args .infer)
|
|
124
|
-
infer (scene);
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
metadata (scene);
|
|
128
|
-
|
|
129
|
-
const options =
|
|
130
|
-
{
|
|
131
|
-
scene: scene,
|
|
132
|
-
style: args .style,
|
|
133
|
-
precision: args .float,
|
|
134
|
-
doublePrecision: args .double,
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
if (args .output)
|
|
125
|
+
for (const i of args .output .keys ())
|
|
138
126
|
{
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
127
|
+
const
|
|
128
|
+
input = new URL (args .input [i] ?? args .input .at (-1), url .pathToFileURL (path .join (process .cwd (), "/"))),
|
|
129
|
+
scene = scenes .get (input .href) ?? await Browser .createX3DFromURL (new X3D .MFString (input)),
|
|
130
|
+
generator = scene .getMetaData ("generator") ?.filter (value => !value .startsWith (pkg .name)) ?? [ ];
|
|
131
|
+
|
|
132
|
+
scenes .set (input .href, scene);
|
|
133
|
+
generator .push (`${pkg .name} V${pkg .version}, ${pkg .homepage}`);
|
|
134
|
+
|
|
135
|
+
scene .setMetaData ("generator", generator);
|
|
136
|
+
scene .setMetaData ("modified", new Date () .toUTCString ());
|
|
137
|
+
|
|
138
|
+
if (args .infer)
|
|
139
|
+
infer (scene);
|
|
140
|
+
|
|
141
|
+
if (args .metadata)
|
|
142
|
+
metadata (scene);
|
|
143
|
+
|
|
144
|
+
const options =
|
|
145
|
+
{
|
|
146
|
+
scene: scene,
|
|
147
|
+
style: args .style,
|
|
148
|
+
precision: args .float,
|
|
149
|
+
doublePrecision: args .double,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
if (args .output [i])
|
|
153
|
+
{
|
|
154
|
+
const output = path .resolve (process .cwd (), args .output [i]);
|
|
155
|
+
|
|
156
|
+
if (path .extname (output))
|
|
157
|
+
fs .writeFileSync (output, getContents ({ ... options, type: path .extname (output) }));
|
|
158
|
+
else
|
|
159
|
+
console .log (getContents ({ ... options, type: path .basename (output) }));
|
|
160
|
+
}
|
|
143
161
|
else
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
{
|
|
148
|
-
console .log (getContents ({ ... options, type: path .extname (input) }));
|
|
162
|
+
{
|
|
163
|
+
console .log (getContents ({ ... options, type: path .extname (input) }));
|
|
164
|
+
}
|
|
149
165
|
}
|
|
150
166
|
|
|
167
|
+
scenes .forEach (scene => scene .dispose ());
|
|
151
168
|
Browser .dispose ();
|
|
152
169
|
}
|
|
153
170
|
|