-
-
Save krzysztofzablocki/338eddf527a351de825bd62cf2a1de28 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash | |
<% for type in types.classes { -%> | |
<%_ if type.modifiers.map{ $0.name }.contains("final") || type.modifiers.map{ $0.name }.contains("open") || types.based[type.name].isEmpty == false { continue } -%> | |
<%_ _%>git grep -lz 'class <%= type.name %>' | xargs -0 perl -i'' -pE "s/class <%= type.name %>(?=\s|:)/final class <%= type.name %>/g" | |
<% } %> | |
// Run with Sourcery on your codebase and then execute generated code via bash :) |
This isn't EJS, it's Swift template as far as I remember @skerjie
This isn't EJS, it's Swift template as far as I remember @skerjie
Thanks a lot for clarification @krzysztofzablocki . But could you please in general describe how to run it.
when I run
sourcery --verbose --config sourcery.yml
I can see that processing happens
Using configuration file at 'sourcery.yml'
Resolving configurations took 0.3633742332458496
Scanning sources...
loadOrParse: 1.7482719421386719
reduce: 0.0030188560485839844
composer: 2.5047950744628906
total: 4.256098747253418
Found 8281 types in 5076 files, 0 changed from last run.
Loading templates...
Loaded 1 templates.
Loading took 0.0037119388580322266
Generating code...
But how exactly run this swift template to add final keyword to files?
Thanks in advance
it generates a file as output, run it as bash script so need to add chmod +x
and then ./generated-file-name
@skerjie It's been a while since I used this but I remember it was working fine.
@krzysztofzablocki , @Nikoloutsos thank you for your feedback. I still don't get the result that I want, but I strongly believe this is a working solution. Sourcery works for me extremely fine when I work with stencil templates especially since it is easy to do in Sourcery Pro, but for some reason, I couldn't achieve the same with this type of template. In the very best situation so far it's generated exactly the same script as the output but doesn't modify files ( I will try again
so you need to name it .swifttemplate
run sourcery on it, if it sees your source files it should output a lot of lines for the command line grep / xargs pair, when you do so does it generate anything at all?
OMG. Finally, it did work. The problem was indeed in the file type .swifttemplate
. @krzysztofzablocki thanks once again for the explanation, patience and help 🤝
glad it works now :)
@Nikoloutsos @krzysztofzablocki I played a couple of hours and still can't run it. I had to fix an issue with EJS, but now, when Sourcery can finally find EJS dependency I get the following error
I used above snipped as FinalKeywordForClasses.ejs as template in
templates:
What exactly did I do wrong?