-
-
Save danil-z/c52363cdb6e501f2a8b29040653d0746 to your computer and use it in GitHub Desktop.
Make a playground with access to an SPM library ready for importing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eux | |
PROJ_NAME=myproj2 | |
PKG_URL=https://github.com/johnsundell/plot.git | |
PKG_FROM=0.1.0 | |
LIB_NAME=Plot | |
SWIFT_VERSION=5.1.3 | |
PLATFORM=macos | |
rm -rf $PROJ_NAME | |
mkdir $PROJ_NAME | |
cd $PROJ_NAME | |
swiftenv local $SWIFT_VERSION | |
swift package init | |
# add package | |
cat <<EOF > Package.swift | |
// swift-tools-version:5.1 | |
import PackageDescription | |
let package = Package( | |
name: "$PROJ_NAME", | |
products: [ | |
.library(name: "$PROJ_NAME", targets: ["$PROJ_NAME"]), | |
], | |
dependencies: [ | |
.package(url: "$PKG_URL", from: "$PKG_FROM") | |
], | |
targets: [ | |
.target(name: "$PROJ_NAME", dependencies: ["$LIB_NAME"]), | |
] | |
) | |
EOF | |
# generate xcodeproj | |
swift package generate-xcodeproj | |
# make workspace | |
mkdir $PROJ_NAME.xcworkspace | |
cat <<EOF > $PROJ_NAME.xcworkspace/contents.xcworkspacedata | |
<?xml version="1.0" encoding="UTF-8"?> | |
<Workspace | |
version = "1.0"> | |
<FileRef | |
location = "group:MyPlayground.playground"> | |
</FileRef> | |
<FileRef | |
location = "container:$PROJ_NAME.xcodeproj"> | |
</FileRef> | |
</Workspace> | |
EOF | |
# add playground | |
mkdir MyPlayground.playground | |
echo "import $LIB_NAME" > MyPlayground.playground/Contents.swift | |
cat <<EOF > MyPlayground.playground/contents.xcplayground | |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<playground version='5.0' target-platform='$PLATFORM'> | |
<timeline fileName='timeline.xctimeline'/> | |
</playground> | |
EOF | |
open $PROJ_NAME.xcworkspace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment