Skip to content

Instantly share code, notes, and snippets.

@alexdremov
Last active October 7, 2022 12:38
Show Gist options
  • Save alexdremov/cd2e7aedb2753b1db76a86b3ad6292b7 to your computer and use it in GitHub Desktop.
Save alexdremov/cd2e7aedb2753b1db76a86b3ad6292b7 to your computer and use it in GitHub Desktop.
Tuist example project snippets
public extension Target {
static func feature(
interface featureName: Feature,
dependencies: [ProjectDescription.TargetDependency] = [],
resources: ProjectDescription.ResourceFileElements? = []
) -> Target {
.makeFramework(
name: featureName.rawValue + "Interface",
sources: [ "interface/**" ],
dependencies: dependencies,
resources: resources
)
}
static func feature(
interface featureName: Feature,
dependencies: [ProjectDescription.TargetDependency] = [],
resources: ProjectDescription.ResourceFileElements? = []
) -> Target {
.makeFramework(
name: featureName.rawValue,
sources: [ "src/**" ],
dependencies: dependencies,
resources: resources
)
}
}
public extension Target {
static func makeApp(
name: String,
sources: ProjectDescription.SourceFilesList,
dependencies: [ProjectDescription.TargetDependency]
) -> Target {
Target(
name: name,
platform: .iOS,
product: .app,
bundleId: makeBundleID(with: "app"),
deploymentTarget: .iOS(targetVersion: "16.0", devices: .iphone),
sources: sources,
dependencies: dependencies
)
}
}
let project = Project(
name: "ExampleApp",
targets: [
.makeApp(
name: "ExampleApp",
sources: [
"src/**"
],
dependencies: [
.common,
.feature(implementation: .Foo),
.feature(interface: .Foo),
.feature(implementation: .Biz),
.feature(interface: .Biz),
.external(.FoggyColors)
]
)
]
)
public extension Target {
static func makeFramework(
name: String,
sources: ProjectDescription.SourceFilesList,
dependencies: [ProjectDescription.TargetDependency] = [],
resources: ProjectDescription.ResourceFileElements? = []
) -> Target {
Target(
name: name,
platform: .iOS,
product: defaultPackageType,
bundleId: makeBundleID(with: name + ".framework"),
sources: sources,
resources: resources,
dependencies: dependencies
)
}
}
// Interface
public protocol NumberProvider {
var number: Int { get }
}
// Implementation
public struct NumberProviderZero: NumberProvider {
public let number = 0
public init() {
}
}
public struct NumberProviderRandom: NumberProvider {
private let range: ClosedRange<Int>
public var number: Int {
Int.random(in: range)
}
public init(range: ClosedRange<Int>) {
self.range = range
}
}
import ProjectDescription
import ProjectDescriptionHelpers
let project = Project(
name: Feature.Foo.rawValue,
targets: [
.feature(
implementation: .Foo,
dependencies: [
.feature(interface: .Biz),
.external(.AsyncAlgorithms)
]
),
.feature(
interface: .Foo,
dependencies: [
.feature(interface: .Biz)
]
)
]
)
Your project root
├── Workspace.swift
├── Tuist
│ ├── Config.swift
│ ├── Dependencies.swift
│ └── ProjectDescriptionHelpers
│ └── <tuist helpers>
└── modules
├── Foo
│ ├── Project.swift
│ └── <module code, folders>
├── Biz
│ ├── Project.swift
│ └── <module code, folders>
└── ...
import ProjectDescription
import ProjectDescriptionHelpers
let project = Project(
name: "ProjectName",
targets: [
...
]
)
Your project root
├── Workspace.swift
├── Tuist
│ ├── Config.swift
│ ├── Dependencies.swift
│ └── ProjectDescriptionHelpers
│ └── <tuist helpers>
└── modules
├── Foo
│ └── Project.swift
│ ├── interface
│ │ └── <interface files>
│ └── src
│ └── <implementation files>
├── Biz
│ └── Project.swift
│ ├── interface
│ │ └── <interface files>
│ └── src
│ └── <implementation files>
└── ...
public struct RandomScreenSimple: RandomScreen {
let randomProvider: NumberProvider
@State var number: Int = 0
public init(randomProvider: NumberProvider) {
self.randomProvider = randomProvider
}
public var body: some View {
VStack {
Text("\(number)")
Button("generate") {
number = randomProvider.number
}
}.onAppear {
number = randomProvider.number
}
.animation(.default, value: number)
}
}
import ProjectDescription
let workspace = Workspace(
name: "ExampleWorkspace",
projects: [
"modules/*"
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment