fmvilas / swagger-node-codegen

An OpenAPI 3.x/Swagger 2 code generator for Node.js
Apache License 2.0
200 stars 55 forks source link

feature request: rename hbs to js #37

Closed tswaters closed 6 years ago

tswaters commented 6 years ago

So, my IDE really doesn't like it when I look at these template js files - it whines and complains about syntax errors and it's really hard to see where real problems are.

I can rename the files to .hbs and the IDE is much happier, and I get near things like syntax highlighting and the like

But now when I run generate, it generates a bunch of hbs files which I need to either rename afterwards or configure my loader to recognize hbs as js - but only in the output directory.

It would be really great if this use case "just worked" -- i.e., if we see hbs files in source, just rename to .js in the output (it's probably what the user wanted). Of course, this doesn't work for other file formats, like TS -- so maybe a configuration option can be provided to overwrite this behavior

tswaters commented 6 years ago

For posterity -- this can be accomplished with npm scripts and a bit of bash --

"pregenerate": "rimraf ./stub",
"generate": "snc --templates ./template --output ./stub path/to/swagger.yml",
"postgenerate": "for file in ./stub/*.hbs; do mv \"$file\" \"./stub/$(basename \"$file\" .hbs).js\"; done"

Not the cleanest, nor cross-platform but it works for my use case.

fmvilas commented 6 years ago

Hi @tswaters. Thanks for opening the issue. Honestly, I don't think the problem is related to the library. You said:

So, my IDE really doesn't like it when I look at these template js files - it whines and complains about syntax errors and it's really hard to see where real problems are.

What you're describing is a problem with your IDE. Please, open an issue in their repo.

Thank you!

tswaters commented 6 years ago

Hey {IDE Maintainer}, can you treat js files as handlebar templates ?

I'm fairly sure that this type of things crops up in pretty much any ide with filetype recognition and syntax highlighting. Baring any pre-existing configuration option to interpret certain files as different types (I know intellij can do this, still a pain to configure), I'm fairly certain any issue I add would fall on deaf ears.

The workaround I have works well for me, so I'll continue to use it.

It would be great if there was an option for this. Right now the UX of this tool leaves a bit to be desired.... when you open one of these template js files in an IDE, do you just ignore all the underlines and syntax errors? Drives me bonkers looking at them.

fmvilas commented 6 years ago

What can I say, man? Just see how it looks like in Atom:

Using JS syntax:

screen shot 2018-10-24 at 21 24 29

Using Handlebars syntax:

screen shot 2018-10-24 at 21 25 07

It's not the problem of a library that your IDE doesn't colour syntax correctly. It's like when you have HTML + CSS + JS in a single file and the file extension is .html. Your IDE still works, right? Go blame them or just use another editor. For sure it's not the problem of this or any other library.

Right now the UX of this tool leaves a bit to be desired...

Obviously. It's free, open source and done on my spare time. There are plenty of paid code generators out there. Feel free.