x3d-tidy 1.0.4 → 1.0.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/convert.js +28 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x3d-tidy",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "X3D Converter, Beautifier and Minimizer",
5
5
  "bin": {
6
6
  "x3d-tidy": "bin/x3d-tidy.js"
package/src/convert.js CHANGED
@@ -24,7 +24,10 @@ async function main (argv)
24
24
 
25
25
  async function convert (argv)
26
26
  {
27
- const args = yargs (argv) .command ("x3d-tidy", "X3D converter, beautifier and minimizer")
27
+ const args = yargs (argv)
28
+ .scriptName ("x3d-tidy")
29
+ .usage ("$0 args")
30
+ .command ("x3d-tidy", "X3D converter, beautifier and minimizer")
28
31
  .fail ((msg, error, yargs) =>
29
32
  {
30
33
  process .stderr .write (msg)
@@ -32,16 +35,23 @@ async function convert (argv)
32
35
  })
33
36
  .option ("input",
34
37
  {
38
+ type: "string",
35
39
  alias: "i",
36
40
  description: "Input filename",
37
- type: "string",
38
41
  demandOption: true,
39
42
  })
40
43
  .option ("output",
41
44
  {
45
+ type: "string",
42
46
  alias: "o",
43
47
  description: "Output filename",
48
+ })
49
+ .option ("style",
50
+ {
44
51
  type: "string",
52
+ alias: "s",
53
+ description: "Output style",
54
+ choices: ["CLEAN", "SMALL", "COMPACT", "TIDY"],
45
55
  })
46
56
  .help ()
47
57
  .alias ("help", "h") .argv;
@@ -59,36 +69,40 @@ async function convert (argv)
59
69
  const output = path .resolve (process .cwd (), args .output)
60
70
 
61
71
  if (path .extname (output))
62
- fs .writeFileSync (output, getContents (Browser .currentScene, path .extname (output)))
72
+ fs .writeFileSync (output, getContents (Browser .currentScene, path .extname (output), args .style))
63
73
  else
64
- process .stdout .write (getContents (Browser .currentScene, path .basename (output)))
74
+ process .stdout .write (getContents (Browser .currentScene, path .basename (output), args .style))
65
75
  }
66
76
  else
67
77
  {
68
- process .stdout .write (getContents (Browser .currentScene, path .extname (input)))
78
+ process .stdout .write (getContents (Browser .currentScene, path .extname (input), args .style))
69
79
  }
70
80
  }
71
81
 
72
- function getContents (scene, type)
82
+ function getContents (scene, type, style)
73
83
  {
74
84
  switch (type)
75
85
  {
76
86
  default:
77
87
  case ".x3d":
78
- return scene .toXMLString ()
88
+ return scene .toXMLString ({ style: style || "TIDY" })
79
89
  case ".x3dz":
80
- return zlib .gzipSync (scene .toXMLString ())
90
+ return zlib .gzipSync (scene .toXMLString ({ style: style || "CLEAN" }))
81
91
  case ".x3dv":
82
- return scene .toVRMLString ()
92
+ return scene .toVRMLString ({ style: style || "TIDY" })
83
93
  case ".x3dvz":
84
- return zlib .gzipSync (scene .toVRMLString ())
94
+ return zlib .gzipSync (scene .toVRMLString ({ style: style || "CLEAN" }))
85
95
  case ".x3dj":
86
- return scene .toJSONString ()
96
+ return scene .toJSONString ({ style: style || "TIDY" })
87
97
  case ".x3djz":
88
- return zlib .gzipSync (scene .toJSONString ())
98
+ return zlib .gzipSync (scene .toJSONString ({ style: style || "CLEAN" }))
89
99
  }
90
100
  }
91
101
 
92
102
  process .exit = (status) => electron .ipcRenderer .send (status ? "error" : "ready", "")
93
- console .log = (s = "") => process .stdout .write (s + "\n")
94
- console .error = (s = "") => process .stderr .write (s + "\n")
103
+ // console .log = (s = "") => process .stdout .write (s + "\n")
104
+ // console .warn = (s = "") => process .stdout .write (s + "\n")
105
+ // console .error = (s = "") => process .stderr .write (s + "\n")
106
+ console .log = Function .prototype
107
+ console .warn = Function .prototype
108
+ console .error = Function .prototype