diff --git a/README.md b/README.md index 0f2e32f..26d24a7 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,24 @@ playbook_configuration: - `testable_imports` - Additional `@testable` imports for the generated Playbook/Tests. Optional parameter. - `sources` - Paths to swift file or directory sources. __Default__: File paths of a specific target or project +## Distribution + +When preparing for distribution, you may want to exclude your `PreviewProvider` and mock data from release builds. This can be achieved by wrapping them in `#if DEBUG` compiler directives. Alternatively, you can pass a compiler flag to exclude `PreviewModels` from release builds. + +To exclude `PreviewModels` using Swift Package Manager, pass the `NO_PLAYBOOK` swift setting in the package that links `PrefirePlaybookPlugin`: + +```swift +swiftSettings: [ + .define("NO_PLAYBOOK", .when(configuration: .release)), +] +``` + +If you are using Xcode, you can pass the compiler flag in the Xcode build settings: + +``` +SWIFT_ACTIVE_COMPILATION_CONDITIONS = NO_PLAYBOOK; +``` + ## Requirements - Swift 5.6 or higher diff --git a/Templates/PreviewModels.stencil b/Templates/PreviewModels.stencil index 456ecd6..48ae80d 100644 --- a/Templates/PreviewModels.stencil +++ b/Templates/PreviewModels.stencil @@ -13,7 +13,7 @@ import {{ import }} public enum PreviewModels { public static var models: [PreviewModel] = { var views: [PreviewModel] = [] - +#if !PLAYBOOK_DISABLED // PreviewProvider {% for type in types.types where type.implements.PrefireProvider or type.based.PrefireProvider or type|annotated:"PrefireProvider" %} views.append(contentsOf: createModel(for: {{ type.name }}.self, name: "{{ type.name | replace:"_Previews","" | replace:"_Preview","" }}")) @@ -23,7 +23,7 @@ public enum PreviewModels { // #Preview macro views.append(contentsOf: MacroPreviews.previews) {% endif %} - +#endif return views.sorted(by: { $0.name > $1.name || $0.story ?? "" > $1.story ?? "" }) }()