tracespace / gerber-to-svg

gerber-to-svg development moved to tracespace/tracespace
https://github.com/tracespace/tracespace
MIT License
81 stars 20 forks source link

Use console.log and force synchronous print instead of streaming #44

Closed Immortalin closed 6 years ago

Immortalin commented 6 years ago

Hi, is it possible to use force synchronous console.log instead of streaming to stdout? I am running it as a subprocess and the async nature is creating a lot of hard-to-debug bugs. It would be awesome if there's a flag that allows you to just console.log everything since it's more predictable and battle tested.

mcous commented 6 years ago

What sort of bugs are you running into? Also, are you asking about the API or the CLI?

The streaming aspect was selected because (my) primary usages of this library always involved asynchronously reading a file piece by piece, e.g. as part of a file upload to a server. I agree that having async all this time was a heavy-handed decision, and that part of the design is not likely to survive the next rewrite. However, until that rewrite happens, forcing synchronous output is unfortunately not an available feature.

And not that this helps anything, but in Node calling console.log calls process.stdout.write under the hood, so you end up writing to a stream no matter what 😃

Immortalin commented 6 years ago

Install gitea. Append the below in custom/conf/app.ini

It doesn't work :(

Print-line debugging shows console.log works perfectly well but the streaming to stdout does not get shown. I thought it was a buffer issue and tried to flush things by using process.stdout.write() but it did not make much of a difference.

ENABLED = true
; List of file extensions that should be rendered by an external command
FILE_EXTENSIONS = .gtl, .gts, .gto, .gtp, .gbl, .gbs, .gbo, .GBO, .gbp, .gm1, .gbr
; External command to render all matching extensions
RENDER_COMMAND = "gerber2svg"
; Input is not a standard input but a file
IS_INPUT_FILE = true⏎         
Immortalin commented 6 years ago

You can remove the carriage return in the last line 😅

mcous commented 6 years ago

Is there anyway you could put together a more minimal reproduction case? I don't have the time to debug integration with a tool I've never used (although gitea does look cool!). Without something smaller to test, I can't know this isn't a problem with gitea.

You could also try building a minimal CLI that uses console.log instead of process.write and see where that gets you. The API has a callback interface, so you could do whatever you want:

#!/usr/bin/env node
const gerberToSvg = require('gerber-to-svg')

// get file contents or stream from args or stdin somehow...

// convert
gerberToSvg(fileContentsOrStream, options, (error, results) => {
  if (error) {
    console.error(error)
    process.exit(1)
  }

  console.log(results)
  process.exit()
})
mcous commented 6 years ago

@Immortalin if this is still something you're interested in, I'm deprecating the gerber-to-svg CLI (gerber2svg) in favor of @tracespace/cli. It's a little less complex than gerber2svg and may work for your use case (although I haven't tested it myself with gitea).

npm i -g @tracespace/cli@next

# mimic gerber2svg by printing to stdout and only outputting a layer render
tracespace --no-board --out=- filename.gbr

If it still doesn't work and you can put together a reproduction / demonstration of a bug that doesn't involve installing gitea, feel free to open a new ticket over in tracespace/tracespace