Skip to content

Commit 0883c18

Browse files
committed
Update package scripts
1 parent 417bfd1 commit 0883c18

13 files changed

+179
-24
lines changed

Sources/SwiftUIKit/Buttons/StandardButtonType.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ public extension ButtonType {
7373
}
7474
}
7575

76+
#if os(iOS) || os(macOS)
7677
var keyboardShortcut: KeyEquivalent? {
7778
switch self {
7879
case .search: "f"
7980
default: nil
8081
}
8182
}
83+
#endif
8284

8385
var keyboardShortcutModifier: EventModifiers? {
8486
switch self {
@@ -124,6 +126,7 @@ public extension View {
124126
func keyboardShortcut(
125127
_ button: ButtonType
126128
) -> some View {
129+
#if os(iOS) || os(macOS)
127130
if let shortcut = button.keyboardShortcut {
128131
if let modifier = button.keyboardShortcutModifier {
129132
self.keyboardShortcut(shortcut, modifiers: modifier)
@@ -133,6 +136,9 @@ public extension View {
133136
} else {
134137
self
135138
}
139+
#else
140+
self
141+
#endif
136142
}
137143
}
138144

package_version.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/bin/bash
22

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

8-
NAME="SwiftUIKit"
97
DEFAULT_BRANCH="main"
108
BRANCH=${1:-$DEFAULT_BRANCH}
11-
SCRIPT="scripts/version.sh"
12-
chmod +x $SCRIPT
13-
bash $SCRIPT $NAME $BRANCH
9+
SCRIPT="scripts/package_version.sh"
10+
chmod +x $SCRIPT && bash $SCRIPT $BRANCH

scripts/build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

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

68
# Usage:
79
# build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
@@ -62,4 +64,4 @@ done
6264
# Complete successfully
6365
echo ""
6466
echo "Building $TARGET completed successfully!"
65-
echo ""
67+
echo ""

scripts/docc.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/bash
22

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

79
# Usage:
@@ -11,6 +13,9 @@
1113
# Exit immediately if a command exits with a non-zero status
1214
set -e
1315

16+
# Fail if any command in a pipeline fails
17+
set -o pipefail
18+
1419
# Verify that all required arguments are provided
1520
if [ $# -eq 0 ]; then
1621
echo "Error: This script requires at least one argument"
@@ -38,8 +43,9 @@ swift package resolve;
3843
# A function that builds $TARGET for a specific platform
3944
build_platform() {
4045

41-
# Define a local $PLATFORM variable
46+
# Define a local $PLATFORM variable and set an exit code
4247
local PLATFORM=$1
48+
local EXIT_CODE=0
4349

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

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

7180
# Transform docs for static hosting
72-
$(xcrun --find docc) process-archive \
81+
if ! $(xcrun --find docc) process-archive \
7382
transform-for-static-hosting .build/docbuild/Build/Products/$DEBUG_PATH/$TARGET.doccarchive \
7483
--output-path .build/docs-$PLATFORM \
75-
--hosting-base-path "$TARGET";
84+
--hosting-base-path "$TARGET"; then
85+
echo "Error: Failed to transform documentation for $PLATFORM" >&2
86+
return 1
87+
fi
7688

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

8092
# Complete successfully
8193
echo "Successfully built $TARGET docs for $PLATFORM"
94+
return 0
8295
}
8396

8497
# Start script

scripts/framework.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/bash
22

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

68
# Important:
79
# This script doesn't work on packages, only on .xcproj projects that generate a framework.
@@ -111,4 +113,4 @@ echo ""
111113
# Complete successfully
112114
echo ""
113115
echo "$TARGET XCFramework created successfully!"
114-
echo ""
116+
echo ""

scripts/package_docc.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script builds DocC documentation for `Package.swift`.
5+
# This script targets iOS by default, but you can pass in custom <PLATFORMS>.
6+
7+
# Usage:
8+
# package_docc.sh [<PLATFORMS> default:iOS]
9+
# e.g. `bash scripts/package_docc.sh iOS macOS`
10+
11+
# Exit immediately if a command exits with non-zero status
12+
set -e
13+
14+
# Use the script folder to refer to other scripts.
15+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
16+
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
17+
SCRIPT_DOCC="$FOLDER/docc.sh"
18+
19+
# Define platforms variable
20+
if [ $# -eq 0 ]; then
21+
set -- iOS
22+
fi
23+
PLATFORMS=$@
24+
25+
# Get package name
26+
PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; }
27+
28+
# Build package documentation
29+
bash $SCRIPT_DOCC $PACKAGE_NAME $PLATFORMS || { echo "DocC script failed"; exit 1; }

scripts/package_framework.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script generates an XCFramework for `Package.swift`.
5+
# This script targets iOS by default, but you can pass in custom <PLATFORMS>.
6+
7+
# Usage:
8+
# package_framework.sh [<PLATFORMS> default:iOS]
9+
# e.g. `bash scripts/package_framework.sh iOS macOS`
10+
11+
# Exit immediately if a command exits with non-zero status
12+
set -e
13+
14+
# Use the script folder to refer to other scripts.
15+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
16+
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
17+
SCRIPT_FRAMEWORK="$FOLDER/framework.sh"
18+
19+
# Define platforms variable
20+
if [ $# -eq 0 ]; then
21+
set -- iOS
22+
fi
23+
PLATFORMS=$@
24+
25+
# Get package name
26+
PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; }
27+
28+
# Build package framework
29+
bash $SCRIPT_FRAMEWORK $PACKAGE_NAME $PLATFORMS

scripts/package_name.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#!/bin/bash
22

3+
# Documentation:
4+
# This script finds the main target name in `Package.swift`.
5+
6+
# Usage:
7+
# package_name.sh
8+
# e.g. `bash scripts/package_name.sh`
9+
10+
# Exit immediately if a command exits with non-zero status
11+
set -e
12+
13+
# Check that a Package.swift file exists
314
if [ ! -f "Package.swift" ]; then
415
echo "Error: Package.swift not found in current directory"
516
exit 1

scripts/package_version.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script creates a new version for `Package.swift`.
5+
# You can pass in a <BRANCH> to validate any non-main branch.
6+
7+
# Usage:
8+
# package_version.sh <BRANCH default:main>
9+
# e.g. `bash scripts/package_version.sh master`
10+
11+
# Exit immediately if a command exits with non-zero status
12+
set -e
13+
14+
# Use the script folder to refer to other scripts.
15+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
16+
SCRIPT_BRANCH_NAME="$FOLDER/git_default_branch.sh"
17+
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
18+
SCRIPT_VERSION="$FOLDER/version.sh"
19+
20+
# Get branch name
21+
DEFAULT_BRANCH=$("$SCRIPT_BRANCH_NAME") || { echo "Failed to get branch name"; exit 1; }
22+
BRANCH_NAME=${1:-$DEFAULT_BRANCH}
23+
24+
# Get package name
25+
PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; }
26+
27+
# Build package version
28+
bash $SCRIPT_VERSION $PACKAGE_NAME $BRANCH_NAME

scripts/sync_from.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script syncs Swift Package Scripts from a <FOLDER>.
5+
# This script will overwrite the existing "scripts" folder.
6+
# Only pass in the full path to a Swift Package Scripts root.
7+
8+
# Usage:
9+
# package_name.sh <FOLDER>
10+
# e.g. `bash sync_from.sh ../SwiftPackageScripts`
11+
12+
# Define argument variables
13+
SOURCE=$1
14+
15+
# Define variables
16+
FOLDER="scripts/"
17+
SOURCE_FOLDER="$SOURCE/$FOLDER"
18+
19+
# Start script
20+
echo ""
21+
echo "Syncing scripts from $SOURCE_FOLDER..."
22+
echo ""
23+
24+
# Remove existing folder
25+
rm -rf $FOLDER
26+
27+
# Copy folder
28+
cp -r "$SOURCE_FOLDER/" "$FOLDER/"
29+
30+
# Complete successfully
31+
echo ""
32+
echo "Script syncing from $SOURCE_FOLDER completed successfully!"
33+
echo ""

0 commit comments

Comments
 (0)