vadymmarkov/Fakery

Swift Package Support

Strobocop opened this issue · 9 comments

From what I can tell, it is not currently possible to support bundled assets with swift packages, rendering this library incompatible with SPM based projects at the moment since it requires the .json files to generate localized data. (I am hoping to use this library on a server side project). Do you know of any ways to accomplish this with SPM or have any ideas on how to refactor this to be compatible? I made a quick proof of concept that it could technically work by simply maintaining the local source data as .swift files with static strings (in my fork here: https://github.com/Appsaurus/Fakery), however I have a feeling this is not the best approach. Guessing it could have performance issues or simply maintainability issues since Xcode seems to sometimes choke on strings of that size.

Any thoughts on this? If you think that is actually a viable approach I wouldn't mind refactoring and putting up a PR. Otherwise, maybe the best approach is to wait until SPM updates to support bundled assets, and I can just maintain my own fork with this approach as a stopgap until then.

Anyway...thanks for the great library!

Hi @Strobocop, I think the best approach would be to wait until SPM updates to support bundled assets. In the meanwhile, maintaining the local source data as .swift files could potentially work if the process of generating them is automated somehow and those files are used only for SPM projects (excluded in Podfile, etc.)

That makes sense. Maybe I will look into Sourcery as a possible solution.

I've made a fork of this package that makes it a little easier to work with SPM.

https://github.com/EricWVGG/Fakery

I've also modified the Faker.lorem.paragraphs() method to do random-range paragraph and sentence lengths. If either of these modifications is desirable to the master package, let me know and I'll put together a formal pull request.

That's great @EricWVGG, just make one pull request per feature/change you're adding and I'll take a look 😉

mxcl commented

An easy addition that would be very useful to SwiftPM users would be to check the working directory for the JSON if nothing else is found.

I tried to make it do this but my immediate attempt did not work.

Hello everyone. I've updated my branch and have a pull request in the works.

I was looking into adding a test for my additions, but currently most of the tests are failing on my system. I don't know much about QuickSpec or Nimble, so I'm unsure if I need to follow some steps, or if the tests are actually broken. Any advice?

After this PR, I'll have another one ready that adds ranges to paragraphs and sentences, so you can have some fun like…
let paragraphs = lorem.paragraphs(amount: 3..<15, sentencesAmount: 5..<10, wordsAmount: 10..<20)
(3 to fifteen paragraphs, each five to ten sentences in length, each sentence ten to twenty words in length)

mxcl commented

So… this is now possible. If not implemented here next time I need faked data I will PR, but anyone else with time should totally go for it.

Any updates on getting this fixed? I'm getting a code sign issue, and I think it's related to the resources issue

Fakery supports SPM since version 5.0.0 https://github.com/vadymmarkov/Fakery/releases/tag/5.0.0. I think it's time to close this issue.