{"id":15038822,"url":"https://github.com/zweigraf/fakebundle","last_synced_at":"2025-04-10T00:03:28.233Z","repository":{"id":63921284,"uuid":"107044089","full_name":"zweigraf/FakeBundle","owner":"zweigraf","description":"🗄 Use Resources in your Swift Package Manager executable","archived":false,"fork":false,"pushed_at":"2019-04-30T17:01:16.000Z","size":9,"stargazers_count":14,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T00:02:49.397Z","etag":null,"topics":["bundle","mint","resources","swift-package-manager","swift4"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zweigraf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-15T19:51:05.000Z","updated_at":"2025-02-23T11:31:48.000Z","dependencies_parsed_at":"2023-01-14T14:15:19.567Z","dependency_job_id":null,"html_url":"https://github.com/zweigraf/FakeBundle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweigraf%2FFakeBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweigraf%2FFakeBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweigraf%2FFakeBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweigraf%2FFakeBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zweigraf","download_url":"https://codeload.github.com/zweigraf/FakeBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131321,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundle","mint","resources","swift-package-manager","swift4"],"created_at":"2024-09-24T20:40:21.264Z","updated_at":"2025-04-10T00:03:28.201Z","avatar_url":"https://github.com/zweigraf.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FakeBundle\n\n🗄 Use Resources in your Swift Package Manager executable\n\n## Description\n\nAs Swift Package Manager does not support Resources or `Bundle` for Swift executables, I needed a way to integrate generic file resources (including folder structure) in my binary.\n\n`FakeBundle` takes an input folder and generates a single file of code, which can be used to export the complete folder, or single files, onto the file system during runtime.\n\n## Usage with [Mint](https://github.com/yonaskolb/mint) 🌱\n\n    $ mint run zweigraf/FakeBundle fakebundle --input ./Resources --output ./Resources.swift\n\n## Use Case\n\nSay you have a folder of templates but want to distribute your app as a single binary (or otherwise simplify installation). You could add all of these templates to your code as strings, but maintaining this gets cumbersome. \nIn this case you could run `FakeBundle` as a pre-compile script phase and generate a class that contains all of your templates, automatically.\nDuring runtime you can then export the templates back to the file system or use them directly from code.\n\n## Exported Code\n\nMy main use case was directly exporting the whole input folder back onto the file system. This can be done like this (`Resources` here is the name of the top level input folder):\n\n    Resources().export(to: \u003cpath\u003e)\n\nThis will create the Resources folder in `\u003cpath\u003e` on the disk and export all children recursively into it. Single files can also be exported, but getting a reference to them is right now quite annoying (traversing through children).\n\nCurrently you cannot easily access files directly.\n\n## More complicated use cases\n\n    Resources().children.forEach {\n        if $0.isDirectory {\n            // Special directory handling\n        } else if let file = $0 as? File {\n            if file.filename == \"MyImage.png\", \n                let data = file.contents,\n                let image = UIImage(data: data) {\n                    // You now have an image\n            }\n        }\n    }\n\n## Types\n\nThe generated code conforms to these protocols (which are included in the generated resources file):\n\n    protocol FileType {\n        var isDirectory: Bool { get }\n        var filename: String { get }\n        func export(to path: String) throws\n    }\n    protocol File: FileType {\n        var contentsBase64: String { get }\n    }\n    extension File {\n        var isDirectory: Bool {\n            return false\n        }\n        var contents: Data? {\n            return Data(base64Encoded: contentsBase64)\n        }\n    \n        func export(to path: String) throws {\n            guard let contents = contents else { return }\n            let originalUrl = URL(fileURLWithPath: path)\n            let myUrl = originalUrl.appendingPathComponent(filename)\n            try contents.write(to: myUrl)\n        }\n    }\n    protocol Directory: FileType {\n        var children: [FileType] { get }\n    }\n    extension Directory {\n        var isDirectory: Bool {\n            return true\n        }\n        func export(to path: String) throws {\n            let originalUrl = URL(fileURLWithPath: path)\n            let myUrl = originalUrl.appendingPathComponent(filename)\n            try FileManager.default.createDirectory(at: myUrl, withIntermediateDirectories: true, attributes: nil)\n            try children.forEach { try $0.export(to: myUrl.path) }\n        }\n    }\n\n## License\n\nFakeBundle is licensed under MIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweigraf%2Ffakebundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzweigraf%2Ffakebundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweigraf%2Ffakebundle/lists"}