Skip to content

Commit 8e3fa92

Browse files
authored
Use supportedDestinations to create a multiplatform target (#1202)
* Use `supportedDestinations` to create a multiplatform target * Add `.gitignore`
1 parent 1cb6748 commit 8e3fa92

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

lib/mix/tasks/install.ex

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ defmodule Mix.Tasks.Lvn.SwiftUI.Install do
4343
targets: %{
4444
type: :multiselect,
4545
label: "Select any number of deployment targets for your app.",
46-
options: ["iOS", "macOS", "watchOS"],
46+
options: ["iOS", "macOS", "watchOS", "tvOS (Experimental)"],
4747
default: ["iOS"],
4848
default_label: "1"
4949
}
@@ -136,14 +136,16 @@ defmodule Mix.Tasks.Lvn.SwiftUI.Install do
136136
end
137137

138138
defp run_xcodegen(%{app_namespace: app_namespace, native_path: native_path}, %{targets: targets}) do
139-
lvn_ios_include_path = if "iOS" in targets, do: "project_ios.yml", else: "skip_spec.yml"
140-
lvn_macos_include_path = if "macOS" in targets, do: "project_macos.yml", else: "skip_spec.yml"
139+
lvn_ios = if "iOS" in targets, do: "iOS", else: ""
140+
lvn_macos = if "macOS" in targets, do: "macOS", else: ""
141+
lvn_tvos = if "tvOS (Experimental)" in targets, do: "tvOS", else: ""
141142
lvn_watchos_include_path = if "watchOS" in targets, do: "project_watchos.yml", else: "skip_spec.yml"
142143
xcodegen_env = [
143144
{"LVN_APP_NAME", app_namespace},
144-
{"LVN_BUNDLE_IDENTIFIER", "com.myorg.#{app_namespace}"},
145-
{"LVN_IOS_INCLUDE_PATH", lvn_ios_include_path},
146-
{"LVN_MACOS_INCLUDE_PATH", lvn_macos_include_path},
145+
{"LVN_BUNDLE_IDENTIFIER", "com.example.#{app_namespace}"},
146+
{"LVN_IOS", lvn_ios},
147+
{"LVN_MACOS", lvn_macos},
148+
{"LVN_TVOS", lvn_tvos},
147149
{"LVN_WATCHOS_INCLUDE_PATH", lvn_watchos_include_path}
148150
]
149151
native_project_path = Path.join(native_path, "swiftui")
@@ -160,7 +162,7 @@ defmodule Mix.Tasks.Lvn.SwiftUI.Install do
160162
defp remove_xcodegen_files(%{native_path: native_path}) do
161163
client_path = Path.join(native_path, "swiftui")
162164

163-
["base_spec.yml", "project_ios.yml", "project_macos.yml", "project_watchos.yml", "project.yml", "skip_spec.yml"]
165+
["base_spec.yml", "project_watchos.yml", "project.yml", "skip_spec.yml"]
164166
|> Enum.map(&(Path.join(client_path, &1)))
165167
|> Enum.map(&File.rm/1)
166168
end

priv/xcodegen/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## User settings
2+
xcuserdata/
3+
4+
## Xcode 8 and earlier
5+
*.xcscmblueprint
6+
*.xccheckout

priv/xcodegen/Sources/TemplateApp/ContentView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import LiveViewNative
88

99
struct ContentView: View {
1010
var body: some View {
11-
LiveView(.automatic(URL(string: "https://%LVN_PREFERRED_PROD_URL%%LVN_PREFERRED_ROUTE%")!))
11+
LiveView(.automatic(
12+
development: .localhost(path: "%LVN_PREFERRED_ROUTE%"),
13+
production: .custom(URL(string: "https://%LVN_PREFERRED_PROD_URL%%LVN_PREFERRED_ROUTE%")!)
14+
))
1215
}
1316
}

priv/xcodegen/project.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ name: ${LVN_APP_NAME}
22
include:
33
- path: base_spec.yml
44
relativePaths: false
5-
- path: ${LVN_IOS_INCLUDE_PATH}
6-
relativePaths: false
7-
- path: ${LVN_MACOS_INCLUDE_PATH}
8-
relativePaths: false
95
- path: ${LVN_WATCHOS_INCLUDE_PATH}
106
relativePaths: false
7+
targets:
8+
${LVN_APP_NAME}:
9+
type: application
10+
supportedDestinations:
11+
- ${LVN_IOS}
12+
- ${LVN_MACOS}
13+
- ${LVN_TVOS}
14+
sources:
15+
- Sources/${LVN_APP_NAME}
16+
settings:
17+
PRODUCT_BUNDLE_IDENTIFIER: ${LVN_BUNDLE_IDENTIFIER}
18+
dependencies:
19+
- package: LiveViewNative

priv/xcodegen/project_ios.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

priv/xcodegen/project_macos.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

priv/xcodegen/project_watchos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
targets:
2-
watchOS:
2+
"${LVN_APP_NAME} Watch App":
33
type: application
44
platform: watchOS
55
sources:

0 commit comments

Comments
 (0)