x3d-tidy 2.0.6 → 2.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 (3) hide show
  1. package/README.md +12 -6
  2. package/package.json +4 -4
  3. package/src/main.js +76 -56
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 -i file.x3d -o file.x3dv
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.6",
3
+ "version": "2.0.8",
4
4
  "description": "X3D Converter, Beautifier and Minimizer",
5
5
  "main": "src/main.js",
6
6
  "bin": {
@@ -54,9 +54,9 @@
54
54
  ],
55
55
  "dependencies": {
56
56
  "colors": "^1.4.0",
57
- "x_ite": "^10.5.14",
58
- "x_ite-node": "^1.0.16",
59
- "x3d-traverse": "^1.0.5",
57
+ "x_ite": "^11.0.0",
58
+ "x_ite-node": "^1.0.17",
59
+ "x3d-traverse": "^1.0.6",
60
60
  "yargs": "^17.7.2"
61
61
  },
62
62
  "devDependencies": {
package/src/main.js CHANGED
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  const
4
- X3D = require ("x_ite-node"),
5
- pkg = require ("../package.json"),
6
- infer = require ("./infer"),
7
- metadata = require ("./metadata"),
8
- yargs = require ("yargs"),
9
- url = require ("url"),
10
- path = require ("path"),
11
- fs = require ("fs"),
12
- zlib = require ("zlib"),
13
- DEBUG = false;
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 args")
37
- .command ("x3d-tidy", "X3D converter, beautifier and minimizer")
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
- demandOption: true,
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
- demandOption: true,
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,15 +93,27 @@ async function convert ()
90
93
  .help ()
91
94
  .alias ("help", "h") .argv;
92
95
 
93
- if (args .version)
94
- return;
96
+ args .input ??= [ ];
97
+ args .output ??= [ ];
95
98
 
96
- if (args .help)
97
- return;
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
+ }
110
+
111
+ // Fixes an issue with URL, if it matches a drive letter.
112
+ args .input = args .input .map (input => input .replace (/^([A-Za-z]:)/, "file://$1"));
98
113
 
99
114
  const
100
115
  Browser = X3D .createBrowser () .browser,
101
- input = new URL (args .input, url .pathToFileURL (path .join (process .cwd (), "/")));
116
+ scenes = new Map ();
102
117
 
103
118
  Browser .endUpdate ();
104
119
  Browser .setBrowserOption ("LoadUrlObjects", false);
@@ -106,45 +121,50 @@ async function convert ()
106
121
  Browser .setBrowserOption ("TextureQuality", "HIGH");
107
122
 
108
123
  await Browser .loadComponents (Browser .getProfile ("Full"));
109
- await Browser .loadURL (new X3D .MFString (input));
110
-
111
- const
112
- scene = Browser .currentScene,
113
- generator = scene .getMetaData ("generator") ?.filter (value => !value .startsWith (pkg .name)) ?? [ ];
114
-
115
- generator .push (`${pkg .name} V${pkg .version}, ${pkg .homepage}`);
116
-
117
- scene .setMetaData ("generator", generator);
118
- scene .setMetaData ("modified", new Date () .toUTCString ());
119
124
 
120
- if (args .infer)
121
- infer (scene);
122
-
123
- if (args .metadata)
124
- metadata (scene);
125
-
126
- const options =
127
- {
128
- scene: scene,
129
- style: args .style,
130
- precision: args .float,
131
- doublePrecision: args .double,
132
- };
133
-
134
- if (args .output)
125
+ for (const i of args .output .keys ())
135
126
  {
136
- const output = path .resolve (process .cwd (), args .output);
137
-
138
- if (path .extname (output))
139
- fs .writeFileSync (output, getContents ({ ... options, type: path .extname (output) }));
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
+ }
140
161
  else
141
- console .log (getContents ({ ... options, type: path .basename (output) }));
142
- }
143
- else
144
- {
145
- console .log (getContents ({ ... options, type: path .extname (input) }));
162
+ {
163
+ console .log (getContents ({ ... options, type: path .extname (input) }));
164
+ }
146
165
  }
147
166
 
167
+ scenes .forEach (scene => scene .dispose ());
148
168
  Browser .dispose ();
149
169
  }
150
170