Skip to content

Commit

Permalink
Update package scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Jan 20, 2025
1 parent 417bfd1 commit 0883c18
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 24 deletions.
6 changes: 6 additions & 0 deletions Sources/SwiftUIKit/Buttons/StandardButtonType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ public extension ButtonType {
}
}

#if os(iOS) || os(macOS)
var keyboardShortcut: KeyEquivalent? {
switch self {
case .search: "f"
default: nil
}
}
#endif

var keyboardShortcutModifier: EventModifiers? {
switch self {
Expand Down Expand Up @@ -124,6 +126,7 @@ public extension View {
func keyboardShortcut(
_ button: ButtonType
) -> some View {
#if os(iOS) || os(macOS)
if let shortcut = button.keyboardShortcut {
if let modifier = button.keyboardShortcutModifier {
self.keyboardShortcut(shortcut, modifiers: modifier)
Expand All @@ -133,6 +136,9 @@ public extension View {
} else {
self
}
#else
self
#endif
}
}

Expand Down
11 changes: 4 additions & 7 deletions package_version.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/bin/bash

# Documentation:
# This script creates a new project version for the current project.
# You can customize this to fit your project when you copy these scripts.
# You can pass in a custom branch if you don't want to use the default one.
# This script creates a new project version for the package.
# You can pass in a BRANCH to not use the default git branch.

NAME="SwiftUIKit"
DEFAULT_BRANCH="main"
BRANCH=${1:-$DEFAULT_BRANCH}
SCRIPT="scripts/version.sh"
chmod +x $SCRIPT
bash $SCRIPT $NAME $BRANCH
SCRIPT="scripts/package_version.sh"
chmod +x $SCRIPT && bash $SCRIPT $BRANCH
4 changes: 3 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Documentation:
# This script builds a <TARGET> for all provided <PLATFORMS>.
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
# You can pass in a list of <PLATFORMS> if you want to customize the build.

# Usage:
# build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
Expand Down Expand Up @@ -62,4 +64,4 @@ done
# Complete successfully
echo ""
echo "Building $TARGET completed successfully!"
echo ""
echo ""
23 changes: 18 additions & 5 deletions scripts/docc.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

# Documentation:
# This script builds DocC for a <TARGET> for all provided <PLATFORMS>.
# This script builds DocC for a <TARGET> and certain <PLATFORMS>.
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
# You can pass in a list of <PLATFORMS> if you want to customize the build.
# The documentation ends up in to .build/docs-<PLATFORM>.

# Usage:
Expand All @@ -11,6 +13,9 @@
# Exit immediately if a command exits with a non-zero status
set -e

# Fail if any command in a pipeline fails
set -o pipefail

# Verify that all required arguments are provided
if [ $# -eq 0 ]; then
echo "Error: This script requires at least one argument"
Expand Down Expand Up @@ -38,8 +43,9 @@ swift package resolve;
# A function that builds $TARGET for a specific platform
build_platform() {

# Define a local $PLATFORM variable
# Define a local $PLATFORM variable and set an exit code
local PLATFORM=$1
local EXIT_CODE=0

# Define the build folder name, based on the $PLATFORM
case $PLATFORM in
Expand All @@ -66,19 +72,26 @@ build_platform() {

# Build $TARGET docs for the $PLATFORM
echo "Building $TARGET docs for $PLATFORM..."
xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination 'generic/platform='$PLATFORM;
if ! xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination "generic/platform=$PLATFORM"; then
echo "Error: Failed to build documentation for $PLATFORM" >&2
return 1
fi

# Transform docs for static hosting
$(xcrun --find docc) process-archive \
if ! $(xcrun --find docc) process-archive \
transform-for-static-hosting .build/docbuild/Build/Products/$DEBUG_PATH/$TARGET.doccarchive \
--output-path .build/docs-$PLATFORM \
--hosting-base-path "$TARGET";
--hosting-base-path "$TARGET"; then
echo "Error: Failed to transform documentation for $PLATFORM" >&2
return 1
fi

# Inject a root redirect script on the root page
echo "<script>window.location.href += \"/documentation/$TARGET_LOWERCASED\"</script>" > .build/docs-$PLATFORM/index.html;

# Complete successfully
echo "Successfully built $TARGET docs for $PLATFORM"
return 0
}

# Start script
Expand Down
6 changes: 4 additions & 2 deletions scripts/framework.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

# Documentation:
# This script generates an XCFramework for a certain <TARGET> for all provided <PLATFORMS>.
# This script builds DocC for a <TARGET> and certain <PLATFORMS>.
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
# You can pass in a list of <PLATFORMS> if you want to customize the build.

# Important:
# This script doesn't work on packages, only on .xcproj projects that generate a framework.
Expand Down Expand Up @@ -111,4 +113,4 @@ echo ""
# Complete successfully
echo ""
echo "$TARGET XCFramework created successfully!"
echo ""
echo ""
29 changes: 29 additions & 0 deletions scripts/package_docc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Documentation:
# This script builds DocC documentation for `Package.swift`.
# This script targets iOS by default, but you can pass in custom <PLATFORMS>.

# Usage:
# package_docc.sh [<PLATFORMS> default:iOS]
# e.g. `bash scripts/package_docc.sh iOS macOS`

# Exit immediately if a command exits with non-zero status
set -e

# Use the script folder to refer to other scripts.
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
SCRIPT_DOCC="$FOLDER/docc.sh"

# Define platforms variable
if [ $# -eq 0 ]; then
set -- iOS
fi
PLATFORMS=$@

# Get package name
PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; }

# Build package documentation
bash $SCRIPT_DOCC $PACKAGE_NAME $PLATFORMS || { echo "DocC script failed"; exit 1; }
29 changes: 29 additions & 0 deletions scripts/package_framework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Documentation:
# This script generates an XCFramework for `Package.swift`.
# This script targets iOS by default, but you can pass in custom <PLATFORMS>.

# Usage:
# package_framework.sh [<PLATFORMS> default:iOS]
# e.g. `bash scripts/package_framework.sh iOS macOS`

# Exit immediately if a command exits with non-zero status
set -e

# Use the script folder to refer to other scripts.
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
SCRIPT_FRAMEWORK="$FOLDER/framework.sh"

# Define platforms variable
if [ $# -eq 0 ]; then
set -- iOS
fi
PLATFORMS=$@

# Get package name
PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; }

# Build package framework
bash $SCRIPT_FRAMEWORK $PACKAGE_NAME $PLATFORMS
11 changes: 11 additions & 0 deletions scripts/package_name.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash

# Documentation:
# This script finds the main target name in `Package.swift`.

# Usage:
# package_name.sh
# e.g. `bash scripts/package_name.sh`

# Exit immediately if a command exits with non-zero status
set -e

# Check that a Package.swift file exists
if [ ! -f "Package.swift" ]; then
echo "Error: Package.swift not found in current directory"
exit 1
Expand Down
28 changes: 28 additions & 0 deletions scripts/package_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Documentation:
# This script creates a new version for `Package.swift`.
# You can pass in a <BRANCH> to validate any non-main branch.

# Usage:
# package_version.sh <BRANCH default:main>
# e.g. `bash scripts/package_version.sh master`

# Exit immediately if a command exits with non-zero status
set -e

# Use the script folder to refer to other scripts.
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SCRIPT_BRANCH_NAME="$FOLDER/git_default_branch.sh"
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
SCRIPT_VERSION="$FOLDER/version.sh"

# Get branch name
DEFAULT_BRANCH=$("$SCRIPT_BRANCH_NAME") || { echo "Failed to get branch name"; exit 1; }
BRANCH_NAME=${1:-$DEFAULT_BRANCH}

# Get package name
PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; }

# Build package version
bash $SCRIPT_VERSION $PACKAGE_NAME $BRANCH_NAME
33 changes: 33 additions & 0 deletions scripts/sync_from.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Documentation:
# This script syncs Swift Package Scripts from a <FOLDER>.
# This script will overwrite the existing "scripts" folder.
# Only pass in the full path to a Swift Package Scripts root.

# Usage:
# package_name.sh <FOLDER>
# e.g. `bash sync_from.sh ../SwiftPackageScripts`

# Define argument variables
SOURCE=$1

# Define variables
FOLDER="scripts/"
SOURCE_FOLDER="$SOURCE/$FOLDER"

# Start script
echo ""
echo "Syncing scripts from $SOURCE_FOLDER..."
echo ""

# Remove existing folder
rm -rf $FOLDER

# Copy folder
cp -r "$SOURCE_FOLDER/" "$FOLDER/"

# Complete successfully
echo ""
echo "Script syncing from $SOURCE_FOLDER completed successfully!"
echo ""
10 changes: 6 additions & 4 deletions scripts/version.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash

# Documentation:
# This script creates a new version for the provided <TARGET>, git <BRANCH> and <PLATFORMS>.
# This script creates a new version for the provided <TARGET> and <BRANCH>.
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
# You can pass in a list of <PLATFORMS> if you want to customize the build.

# Usage:
# version.sh <TARGET> <BRANCH default:main> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
# e.g. `scripts/version.sh MyTarget master iOS macOS`

# This script will:
# * Call version_validate_git.sh to validate the git repo.
# * Call version_validate_project to run tests, swiftlint, etc.
# * Call version_validate_target to run tests, swiftlint, etc.
# * Call version_bump.sh if all validation steps above passed.

# Exit immediately if a command exits with a non-zero status
Expand Down Expand Up @@ -39,7 +41,7 @@ fi
# Use the script folder to refer to other scripts.
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SCRIPT_VALIDATE_GIT="$FOLDER/version_validate_git.sh"
SCRIPT_VALIDATE_PROJECT="$FOLDER/version_validate_project.sh"
SCRIPT_VALIDATE_TARGET="$FOLDER/version_validate_target.sh"
SCRIPT_VERSION_BUMP="$FOLDER/version_bump.sh"

# A function that run a certain script and checks for errors
Expand Down Expand Up @@ -67,7 +69,7 @@ echo ""
# Validate git and project
echo "Validating..."
run_script "$SCRIPT_VALIDATE_GIT" "$BRANCH"
run_script "$SCRIPT_VALIDATE_PROJECT" "$TARGET"
run_script "$SCRIPT_VALIDATE_TARGET" "$TARGET"

# Bump version
echo "Bumping version..."
Expand Down
3 changes: 2 additions & 1 deletion scripts/version_validate_git.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

# Documentation:
# This script validates the Git repository for a <BRANCH>.
# This script validates the Git repository for release.
# You can pass in a <BRANCH> to validate any non-main branch.

# Usage:
# version_validate_git.sh <BRANCH default:main>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/bash

# Documentation:
# This script validates the project for a <TARGET>.
# This script validates a <TARGET> for release.
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
# You can pass in a list of <PLATFORMS> if you want to customize the build.

# Usage:
# version_validate_project.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
# e.g. `bash scripts/version_validate_project.sh iOS macOS`
# version_validate_target.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
# e.g. `bash scripts/version_validate_target.sh iOS macOS`

# This script will:
# * Validate that swiftlint passes.
Expand Down Expand Up @@ -70,4 +72,4 @@ run_script "$SCRIPT_TEST" "$TARGET" "$PLATFORMS"
# Complete successfully
echo ""
echo "Project successfully validated!"
echo ""
echo ""

0 comments on commit 0883c18

Please sign in to comment.