Is there any way to exclude a module from storyboard file imports?
With 4.1.0 SwiftGen is started to automatically add modules to generated file, so one of this imports is the same as my project's module and now I'm getting a lot of warnings like "File 'Storyboards.swift' is part of module '
I know I can create a custom template for it, but I'm wondering if there is any built-in way to do it?
Or maybe I'm just missing something in my setup
Hmmm, is there a way we can avoid this? Maybe a way to silence the warning?
As far as I know there's no way to suppress specific warning currently
If in understand the issue correctly, this problem is because the generated code happens to import the module corresponding to the app target where the generated code will happen to be too, right?
Once #253 will be implemented this will be trivial to fix.
Because #253 will then allow us to pass --param AppModule=MyAwesomeApp when invoking SwiftGen, and in the template we could then do:
{% for module in modules %}
{% if not module == param.AppModule %}
import {{module}}
{% endif %}
{% endfor %}
Yeah, I think for now we'll have to either live with the warning, or a custom template that excludes your specific module.
@AliSoftware Yes, that was exactly my problem.
I think I'll stick to 4.0.1 until #253 is implemented then.
Thank you, guys. Can we maybe close this issue now?
I think we can keep it open so we don't forget to implement it later after #253 ๐
Btw the last version is 4.1.0 not 4.0.1 ๐ (4.1 won't solve that specific problem but still has other bug fixes and improvements)
Yes, I know 4.1.0 is the latest one, but seems like 4.0.1 is working just fine for my project and I'm not getting those warnings :)
I just had an idea: what about environment variables? Most people run SwiftGen as a build phase, which receives a whole bunch of environment variables. For example, Fabric relies on this to locate the target's dSYM files and upload them.
I'm not saying we should only rely on env variables, but it could be an additional mechanism for solving this (and other) issues. It would just provide all variables available to the template as a env variable.
Seems like it would be a nice feature to me, good idea ๐
Only "problem" with that is if we want to allow overriding values in templates we might need to check first in param. then in env. then default value, which could lead to complex expressions, like {% set appModule %}{{param.appModule|default:env.PRODUCT_MODULE_NAME}}{% endset %} and {% set enumName %}{{param.enumName|default:env.SWIFTGEN_STORYBOARDS_ENUM_NAME|default:"StoryboardScene"}}{% endset %}. But that seams reasonable enough, given that the name you'll be able to give via --param (see #253) and the one provided by ENV will likely be different anyway.
When we rewrite the templates to use params, I'd just use params, not env to replace enumName and such. Just make env available and, for now, only use it for this specific case.
This has been finally fixed in Swift 4.2.0 which has been proposed to Homebrew just now!
See this CHANGELOG for more details.
It will be available in homebrew as soon as https://github.com/Homebrew/homebrew-core/pull/10132 is merged by the Homebrew team.
I'm still seeing this, even though I'm using the currently latest swiftgen 4.2.1 version, installed through Homebrew.
Here is the generation command I'm using:
swiftgen storyboards -t swift3 -o {path} {path}
Hi @damirstuhec,
Please check the instructions in the changelog mentioned by @AliSoftware:
- It works by checking the environment variable
PRODUCT_MODULE_NAME, which is automatically injected by Xcode if you runswiftgenas part of a Script Build Phase in your Xcode project.- If you don't use
swiftgenin a Script Build Phase of your Xcode project but manually in the terminal, you can instead useswiftgen storyboards --param module=YourAppModuleName โฆwhen invoking SwiftGen to inject it manually instead.
If you're still seeing the problem after following these instructions, we can reopen this issue or create a separate one.
@djbe worked! Thanks a bunch. ๐
HI @djbe I've set the module param in the swiftgen.yml yet I still see the warning ๐ค
Hey @hernangonzalez,
does it work for you when invoking swiftgen without a configuration file (swiftgen storyboards ...)? Make sure to check the parameter documentation for your template, for example https://github.com/SwiftGen/templates/blob/master/Documentation/storyboards/swift4.md.
Anyway, if you still have the issue, we'll need more information, and you might want to open a separate issue for this.
@hernangonzalez Which version of Swiftgen did you try that with? 5.2.1 or earlier?
Also, you can use swiftgen config lint and swiftgen config run --verbose to have more information about what the config file will execute (it will try to print the equivalent command line to run), so you can compare the calls between when you use a config file and when you invoke the command directly.
For example maybe you misspelled the params: entry in the YAML? Can you post here the content of your swiftgen.yml? swiftgen config lint will help you check if what you put in your YAML matches the intended structure. Don't also hesitate to double-check the Config File dedicated documentation for the exact syntax to use in your swiftgen.yml
I am on SwiftGen v5.2.1 (Stencil v0.9.0, StencilSwiftKit v2.3.0, SwiftGenKit v2.1.1)
I'll try to find out more info with those tips and let you know.
Beware, ๐คฆโโ๏ธ moment... lol.
I had misspelled params. Sorry about that.
Thank you guys!
Ahah ๐ I'm curious as to what helped you figure that out though. Did swiftgen config lint help you? (Or could we make it more helpful?)
@AliSoftware I went straight to check if params was properly written and you know the rest ja.
Most helpful comment
This has been finally fixed in Swift 4.2.0 which has been proposed to Homebrew just now!
See this CHANGELOG for more details.
It will be available in homebrew as soon as https://github.com/Homebrew/homebrew-core/pull/10132 is merged by the Homebrew team.