fnogatz / xsd2json

Translate XML Schema into equivalent JSON Schema
MIT License
149 stars 28 forks source link

Not installed correctly on Windows #51

Closed HayDegha0917 closed 7 years ago

HayDegha0917 commented 7 years ago

The xsd2json command is not installed correctly on Windows. It assumes the presence of /bin/sh.exe or /bin/sh, which (ha ha) does not exist on Windows unless you have Cygwin or similar.

At the very least, the documentation should be updated to reflect that. Ideally, unless a UNIX shell is required, the install should only reference Windows standard executable.

fnogatz commented 7 years ago

The lib-pl/cli file is only a placeholder for the executable that is created in the postinstall step (see package.json), so it does not require a shell at first. Unfortunately it seems that the intermediate code file created by SWI-Prolog's -c flag is Linux-only. I will have a further look on how to get it working in Windows, tooo. In the mean time you can use the Prolog interface:

> swipl -q lib-pl/xsd2json.pl
?- use_module(library(http/json)).
?- xsd2json('/path/to/your.xsd',JSON), json_write(user_output,JSON).
HayDegha0917 commented 7 years ago

Ok thanks.

HayDegha0917 commented 7 years ago

Picking up this issue again. I tried your suggestion, but after the last line, the Prolog interface just hangs.

Incidentally, I also tried running xsd2json from a Bash shell, but now get:

/c/Users/akassabi/AppData/Roaming/npm/node_modules/xsd2json/lib-pl/cli: line 3: /home/fnogatz/.swivm/versions/7.5.1/lib/swipl-7.5.1/bin/x86_64-linux/swipl: No such file or directory

It seems there is a reference to your home directory that is hard-coded somewhere.

fnogatz commented 7 years ago

Thank you for coming back to this. Although this will not fix your initial problem of installing xsd2json on Windows, I added a prepublish script in 5784888 to revert local changes of /lib-pl/cli before publishing on npm.

fnogatz commented 7 years ago

At least the (global and local) installation works for me on Windows 7, e.g., calling npm install xsd2json -g. Unfortunately I am not familiar on node.js on Windows, so I don't know how to test if the global xsd2json command works. How do you normally use executables created by npm install's on Windows? Do you have a working example of another npm package?

HayDegha0917 commented 7 years ago

The xsd2json cmd file is added to the Windows path, so you can just call xsd2json with arguments.

Of course, if the xsd2json.cmd file has Bash shell syntax, then it is not going to work very well... :-)

fnogatz commented 7 years ago

At least I got the Prolog CLI working on Windows. With SWI-Prolog installed as swipl (which is default, try swipl --version), you can call it like the following, with lib-pl/cli.pl relative to this module's installation directory:

swipl -g main lib-pl/cli.pl -- path/to/schema.xsd

Using the schema file located at /test/xsd/element_float.xsd this will result in the following output:

{
  "type":"number"
}

Note that you need at least SWI-Prolog of version 7.4.x, since version 7.2.x unfortunately ships with a bug in the CHR implementation.

Also this method lacks the pre-compilation done in the postinstall phase of npm install, which creates the /lib-pl/cli resp. lib-pl/cli.exe executable. So it has a significant performance tradeoff.

HayDegha0917 commented 7 years ago

I'll try again. I suspect the other half of my problem is that I am using XSD tags that are apparently (per some of the other issues here): e.g., xs:choice, xs:all.

fnogatz commented 7 years ago

I solved the Windows installation problem by moving the postinstall scripts into preinstall. Therefore the pre-compiled executable is created first and is linked to by npm just as the second step.

The new version is available on npm as v1.11.3 and should by correctly installed on Linux and Windows machines. It makes the xsd2json command globally available.