Skip to content

Commit

Permalink
Fix lint issue and improve documentation
Browse files Browse the repository at this point in the history
* Replace accidental tab indentation with spaces

* Update README.md and installation instructions

* Documentation improvements
  • Loading branch information
stackotter authored Apr 2, 2022
1 parent 2a33a85 commit 0f03132
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ prebuild_script = "./utils/prebuild.sh"
postbuild_script = "./utils/postbuild.sh"

[apps.HelloWorld.extra_plist_entries]
commit = "{COMMIT}" # This could be any key-value pair, 'commit' is just an example
commit = "{COMMIT_HASH}" # This could be any key-value pair, 'commit' is just an example
```

> Note: Only the `product` and `version` fields are required.
Expand Down
14 changes: 11 additions & 3 deletions Documentation/SwiftBundler/SwiftBundler.docc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ Installing Swift Bundler on your system.

## Recommended

Install the latest version of Swift Bundler from the main branch.
Install the latest release of Swift Bundler.

```sh
sh <(curl -L https://stackotter.dev/swift-bundler/install.sh)
```

### Installing from a specific branch

Install the latest version of Swift Bundler from a specific branch.
Install Swift Bundler from the latest commit of a specific branch.

```sh
sh <(curl -L https://stackotter.dev/swift-bundler/install.sh) [branch]
```

### Installing from a specific commit

Install Swift Bundler from a specific commit.

```sh
sh <(curl -L https://stackotter.dev/swift-bundler/install.sh) [commit]
```

### Manual installation

Install any version of Swift Bundler that you want by doing it manually.
Install Swift Bundler however you want by doing it manually.

```sh
git clone https://github.com/stackotter/swift-bundler
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="https://discord.gg/6mUFu3KtAn"><img src="https://img.shields.io/discord/949626773295988746?color=6A7EC2&label=discord&logo=discord&logoColor=ffffff"></a>
</p>

A tool to create macOS apps with Swift packages instead of Xcode projects. The end goal is to be able to create apps for all desktop platforms with a single Swift codebase.
A tool for creating macOS apps with Swift packages instead of Xcode projects. The end goal is to be able to create apps for all desktop platforms with a single Swift codebase.

You may also be interested in [SwiftCrossUI](https://github.com/stackotter/swift-cross-ui), a UI framework with a similar goal.

Expand All @@ -22,6 +22,8 @@ The documentation is hosted on [GitHub pages](https://stackotter.github.io/swift

## Installation 📦

Install the latest version of Swift Bundler with a single command:

```sh
sh <(curl -L https://stackotter.dev/swift-bundler/install.sh)
```
Expand Down Expand Up @@ -58,7 +60,7 @@ open Package.swift

### Learning more

The [documentation](https://stackotter.github.io/swift-bundler/documentation/swiftbundler) contains everything you need to know about Swift Bundler.
To learn more about Swift Bundler refer to the [documentation](https://stackotter.github.io/swift-bundler/documentation/swiftbundler).

## Contributing 🛠

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import ArgumentParser

/// An architecture to build for.
enum BuildArchitecture: String, CaseIterable, ExpressibleByArgument {
case x86_64 // swiftlint:disable:this identifier_name
case arm64
case x86_64 // swiftlint:disable:this identifier_name
case arm64

#if arch(x86_64)
static let current: BuildArchitecture = .x86_64
static let current: BuildArchitecture = .x86_64
#elseif arch(arm64)
static let current: BuildArchitecture = .arm64
static let current: BuildArchitecture = .arm64
#endif

var defaultValueDescription: String {
rawValue
}
var defaultValueDescription: String {
rawValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Foundation

/// A Swift build configuration.
enum BuildConfiguration: String, CaseIterable {
case debug
case release
case debug
case release
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Foundation

/// An extremely simplified version of the output of `swift -print-target-info`.
struct SwiftTargetInfo: Codable {
/// Info about a target platform.
struct Target: Codable {
/// The platform's unversioned triple.
var unversionedTriple: String
}
/// Info about a target platform.
struct Target: Codable {
/// The platform's unversioned triple.
var unversionedTriple: String
}

/// Info about the target platform.
var target: Target
/// Info about the target platform.
var target: Target
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Foundation

/// A system dependency required by a template.
struct SystemDependency: Codable {
/// The name (or names separated by spaces) of the brew package/s that satisfies this dependency.
var brew: String?
/// The name (or names separated by spaces) of the brew package/s that satisfies this dependency.
var brew: String?
}
16 changes: 8 additions & 8 deletions Sources/swift-bundler/Bundler/Templater/TemplateManifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ struct TemplateManifest: Codable {
var platforms: [String]
/// The minimum Swift version required to use the template.
var minimumSwiftVersion: Version
/// The system dependencies required by this template (keyed by the user-facing dependency name).
var systemDependencies: [String: SystemDependency]?
/// The system dependencies required by this template (keyed by the user-facing dependency name).
var systemDependencies: [String: SystemDependency]?

private enum CodingKeys: String, CodingKey {
case description
case platforms
case minimumSwiftVersion = "minimum_swift_version"
case systemDependencies = "system_dependencies"
}
private enum CodingKeys: String, CodingKey {
case description
case platforms
case minimumSwiftVersion = "minimum_swift_version"
case systemDependencies = "system_dependencies"
}

/// Loads a template's manifest file.
/// - Parameters:
Expand Down
54 changes: 27 additions & 27 deletions Sources/swift-bundler/Bundler/Templater/Templater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ enum Templater {
return .failure(.packageDirectoryAlreadyExists(outputDirectory))
}

// If no template is specified, create the most basic package that just prints 'Hello, World!'
// If no template is specified, create the most basic package that just prints 'Hello, World!'
guard let template = template else {
log.info("Creating package")

return SwiftPackageManager.createPackage(in: outputDirectory, name: packageName)
.mapError { error -> TemplaterError in
.failedToCreateBareMinimumPackage(error)
}
.flatMap { _ in
log.info("Updating indentation to '\(indentationStyle.defaultValueDescription)'")
return updateIndentationStyle(in: outputDirectory, from: .spaces(4), to: indentationStyle)
}
.mapError { error -> TemplaterError in
attemptCleanup(outputDirectory)
return error
}
.map { (_: Void) -> Template? in
return nil // No template was used
}
log.info("Creating package")

return SwiftPackageManager.createPackage(in: outputDirectory, name: packageName)
.mapError { error -> TemplaterError in
.failedToCreateBareMinimumPackage(error)
}
.flatMap { _ in
log.info("Updating indentation to '\(indentationStyle.defaultValueDescription)'")
return updateIndentationStyle(in: outputDirectory, from: .spaces(4), to: indentationStyle)
}
.mapError { error -> TemplaterError in
attemptCleanup(outputDirectory)
return error
}
.map { (_: Void) -> Template? in
return nil // No template was used
}
}

// If a template was specified: Get the default templates directory (and download if not present), and then create the package
Expand All @@ -59,9 +59,9 @@ enum Templater {
forceCreation: forceCreation,
indentationStyle: indentationStyle)
}
.map { template in
return .some(template)
}
.map { template in
return .some(template)
}
}

/// Creates a package from the specified template from the specified template repository.
Expand Down Expand Up @@ -90,7 +90,7 @@ enum Templater {
return .failure(.cannotCreatePackageFromBaseTemplate)
}

log.info("Creating package from the '\(template)' template")
log.info("Creating package from the '\(template)' template")

// Check that the template exists
let templateDirectory = templatesDirectory.appendingPathComponent(template)
Expand Down Expand Up @@ -134,7 +134,7 @@ enum Templater {
indentationStyle: .tabs)
if case let .failure(error) = result {
attemptCleanup(outputDirectory)
return .failure(error)
return .failure(error)
}
}

Expand All @@ -147,9 +147,9 @@ enum Templater {
).mapError { error in
attemptCleanup(outputDirectory)
return error
}.map { _ in
return Template(name: template, manifest: manifest)
}
}.map { _ in
return Template(name: template, manifest: manifest)
}
}

/// Verifies that the given template supports the current OS and Swift version.
Expand Down Expand Up @@ -259,7 +259,7 @@ enum Templater {
let templateName = directory.lastPathComponent

// Skip `Base` template and `.git` directory
guard templateName != "Base" && !templateName.starts(with: ".") else {
guard templateName != "Base" && !templateName.starts(with: ".") else {
continue
}

Expand Down
16 changes: 8 additions & 8 deletions Sources/swift-bundler/Bundler/Templater/TemplaterError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ enum TemplaterError: LocalizedError {
case .failedToCreateOutputDirectory(let directory, _):
return "Failed to create package directory at '\(directory.relativePath)'"
case .failedToDecodeTemplateManifest(let template, _, _):
return Output {
"Failed to decode the manifest for the '\(template)' template"
""
Section("Troubleshooting") {
"Have you updated your templates recently?"
ExampleCommand("swift bundler templates update")
}
}.description
return Output {
"Failed to decode the manifest for the '\(template)' template"
""
Section("Troubleshooting") {
"Have you updated your templates recently?"
ExampleCommand("swift bundler templates update")
}
}.description
case .failedToReadTemplateManifest(let template, _, _):
return "Failed to read the contents of the manifest for the '\(template)' template"
case .templateDoesNotSupportCurrentPlatform(let template, let platform, let supportedPlatforms):
Expand Down
32 changes: 16 additions & 16 deletions Sources/swift-bundler/Commands/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import ArgumentParser

/// An extension to the `ParsableCommand` API with custom error handling.
protocol Command: ParsableCommand {
/// Implement this instead of `validate()` to get custom Swift Bundler error handling.
func wrappedValidate() throws
/// Implement this instead of `validate()` to get custom Swift Bundler error handling.
func wrappedValidate() throws

/// Implement this instead of `run()` to get custom Swift Bundler error handling.
func wrappedRun() throws
}

extension Command {
func wrappedValidate() {}
func wrappedValidate() {}
}

extension Command {
Expand All @@ -20,21 +20,21 @@ extension Command {
try wrappedRun()
} catch {
log.error("\(error.localizedDescription)")
log.debug("Error details: \(error)")
log.debug("Error details: \(error)")
Foundation.exit(1)
}
}

func validate() {
do {
try wrappedValidate()
} catch {
if let error = error as? ValidationError {
log.error("\(error)")
} else {
log.error("\(error.localizedDescription)")
}
Foundation.exit(1)
}
}
func validate() {
do {
try wrappedValidate()
} catch {
if let error = error as? ValidationError {
log.error("\(error)")
} else {
log.error("\(error.localizedDescription)")
}
Foundation.exit(1)
}
}
}
Loading

0 comments on commit 0f03132

Please sign in to comment.