Closed choonkeat closed 6 years ago
After https://github.com/volatiletech/sqlboiler/issues/303, I see now this case of use.
There should be an option to generate separate files with a custom name and output directory.
Perhaps setting special comments at beginning of the tpl file, for example:
// FILENAME=my_file.js // OUTDIR=/path/to/some/dir
@saulortega The custom output directory is a harder sell. I don't think it's particularly difficult to move those files after the fact, no? I'm thinking about working on this today so I'd like to know what's deemed acceptable.
My plan for this currently is going to be:
.go.tpl
, .js.tpl
), everything named with .tpl
will be processed..go
files get special stuff (imports + gofmt), other files are rendered as isIn terms of organization and folders, I think I want to do this:
Here's an example:
templates
|- 00_struct.go.tpl
|- 00_struct.ts.js.tpl
|- css
|- singleton
|- some_tests.css.tpl
|- 00_struct.css.tpl
|- singleton
|- some_tests.go.tpl
Output:
outputdir
|- users.go
|- users.ts.js
|- some_tests.go
|- css
|- users.css
|- some_tests.css
Will probably look at implementing this soon unless there's objections to the proposal. @choonkeat, @saulortega Let me know, this must be done before v3 releases because it's technically a breaking change (template file names change).
I like your plan. I have no objections. :+1:
However, let me insist on the output directory. :)
Maybe, in subfolders there could be a special file that contains the output directory path. Maybe a JSON string.
I'm not sure I understand why that's desirable. Take the example we had before:
outputdir
|- users.go
|- users.ts.js
|- some_tests.go
|- css
|- users.css
|- some_tests.css
In order to "control output directory" you simply have to do the following:
rm -rf wherever/you/want/it # Effectively --wipe
mv models/css wherever/you/want/it
Because you control the local output directory, it's easy to then just move that/the files inside it wherever you'd like. It doesn't seem worth it to add the extra interface because it's not an easy thing to specify. JSON Files and magic comments both feel bad. Command line flags are difficult because there's a whole directory tree you could specify. Just not seeing the value.
Okay that's fine. :+1:
Done in rc2 (v3.0.0-rc2). I really hate how the implementation came together, it's actually horrible. But the actual feature is ok. Works as described above, there's a section in the readme for it.
At the moment, sqlboiler has strong assumptions that we are generating
.go
files.We could potentially leverage sqlboiler to generate graphql schema files or React js apps.
Currently https://github.com/choonkeat/hellocrud project uses code comments to generate what we need and then post process the generated go files.
One possibility is to accept an optional cli flag
-ext
; for any non.go
value, we simply skip the go lang headers and stuff.